Skip to content

Commit

Permalink
fix(jwt): set jwt token refresh (#8)
Browse files Browse the repository at this point in the history
* fix: change mechanism by set refresh jwt token
  • Loading branch information
iomarmochtar authored Aug 16, 2022
1 parent 3ba40ff commit 1b5b40c
Show file tree
Hide file tree
Showing 7 changed files with 265 additions and 61 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/rs/zerolog/log"
)

const VERSION = "0.1.1"
const VERSION = "0.1.2"

type App struct {
config c.IConfig
Expand Down Expand Up @@ -43,7 +43,7 @@ func (a App) DeleteRepositories(repositories []reg.Repository) (err error) {
continue
}

log.Info().Str("repo", repo.Name).Msg("deleting repository")
log.Info().Str("repo", repo.Name).Msg("deleting matched images in the repository")
if err = a.config.ImageRegistry().Delete(repo); err != nil {
return err
}
Expand Down
9 changes: 5 additions & 4 deletions app/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ type Config struct {
ExcludeFilters []string
IncludeFilters []string
AllowInsecure bool
JWExpirySecond uint

excludeEngine fl.IFilterEngine
includeEngine fl.IFilterEngine
Expand Down Expand Up @@ -164,19 +165,19 @@ func (c *Config) initHTTPClient() (err error) {
hcOptions := http.Option{AllowInsecureSSL: c.AllowInsecure}
// prioritizing service path setups
if c.ServiceAccountPath != "" {
tokenGenerator := reg.TokenGeneratorMapper[c.RegistryType]
if tokenGenerator == nil {
tokenSource := reg.TokenSourceMapper[c.RegistryType]
if tokenSource == nil {
return fmt.Errorf("cannot use %s for service account method", c.RegistryType)
}
data, err := ioutil.ReadFile(c.ServiceAccountPath)
if err != nil {
return err
}
token, err := tokenGenerator(data)
ts, err := tokenSource(data)
if err != nil {
return err
}
hcOptions.Token = token
hcOptions.TokenSource = ts
if c.httpClient, err = http.New(hcOptions); err != nil {
return err
}
Expand Down
38 changes: 26 additions & 12 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,55 @@ module github.com/iomarmochtar/cir-rotator
go 1.18

require (
github.com/imroc/req/v3 v3.11.4
github.com/antonmedv/expr v1.9.0
github.com/golang/mock v1.6.0
github.com/imroc/req/v3 v3.17.7
github.com/jedib0t/go-pretty v4.3.0+incompatible
github.com/pkg/errors v0.9.1
github.com/rs/zerolog v1.26.1
github.com/stretchr/testify v1.7.2
github.com/urfave/cli/v2 v2.7.1
golang.org/x/oauth2 v0.0.0-20220524215830-622c5d57e401
)

require (
cloud.google.com/go v0.65.0 // indirect
github.com/antonmedv/expr v1.9.0 // indirect
github.com/antzucaro/matchr v0.0.0-20210222213004-b04723ef80f0 // indirect
github.com/asaskevich/govalidator v0.0.0-20200907205600-7a23bdc65eef // indirect
github.com/cheekybits/genny v1.0.0 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/go-openapi/errors v0.19.8 // indirect
github.com/go-openapi/strfmt v0.21.2 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/golang/protobuf v1.4.2 // indirect
github.com/hashicorp/errwrap v1.0.0 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/jedib0t/go-pretty v4.3.0+incompatible // indirect
github.com/lucas-clemente/quic-go v0.28.1 // indirect
github.com/marten-seemann/qpack v0.2.1 // indirect
github.com/marten-seemann/qtls-go1-16 v0.1.5 // indirect
github.com/marten-seemann/qtls-go1-17 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.2 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.0 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mitchellh/mapstructure v1.3.3 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/oklog/ulid v1.3.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/onsi/ginkgo v1.16.5 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.2.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stretchr/objx v0.1.0 // indirect
github.com/stretchr/testify v1.7.2 // indirect
go.mongodb.org/mongo-driver v1.7.5 // indirect
golang.org/x/net v0.0.0-20220127200216-cd36cc0744dd // indirect
golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e // indirect
golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220812174116-3211cb980234 // indirect
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.25.0 // indirect
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit 1b5b40c

Please sign in to comment.