refactor: make config stateful

This commit is contained in:
Derrick Hammer 2024-02-11 16:33:56 -05:00
parent bbe7e8e053
commit 8dd6e83fae
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
1 changed files with 15 additions and 12 deletions

View File

@ -18,6 +18,7 @@ type Oauth struct {
token *oauth2.Token token *oauth2.Token
refresher oauth2.TokenSource refresher oauth2.TokenSource
keepAliveRunning bool keepAliveRunning bool
oauthCfg *oauth2.Config
} }
func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth { func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
@ -35,7 +36,8 @@ func NewOauth(lc fx.Lifecycle, cfg *config.Config, logger *zap.Logger) *Oauth {
} }
func (o Oauth) config() *oauth2.Config { func (o Oauth) config() *oauth2.Config {
cfg := &oauth2.Config{ if o.oauthCfg == nil {
o.oauthCfg = &oauth2.Config{
ClientID: o.cfg.Oauth.ClientId, ClientID: o.cfg.Oauth.ClientId,
ClientSecret: o.cfg.Oauth.ClientSecret, ClientSecret: o.cfg.Oauth.ClientSecret,
Scopes: []string{"admin"}, Scopes: []string{"admin"},
@ -46,10 +48,11 @@ func (o Oauth) config() *oauth2.Config {
}, },
} }
o.loadToken(cfg) }
o.loadToken(o.oauthCfg)
o.keepAlive() o.keepAlive()
return cfg return o.oauthCfg
} }
func (o Oauth) authUrl() string { func (o Oauth) authUrl() string {