@@ -451,11 +451,11 @@ func GetSupportedOauth2TokenExchangeJwtAlgorithms() []string {
451451 return algs
452452}
453453
454- type stringOrArrayConfig struct {
454+ type StringOrArrayConfig struct {
455455 Values []string
456456}
457457
458- func (a * stringOrArrayConfig ) UnmarshalJSON (data []byte ) error {
458+ func (a * StringOrArrayConfig ) UnmarshalJSON (data []byte ) error {
459459 // Case 1: string
460460 var s string
461461 err := json .Unmarshal (data , & s )
@@ -497,7 +497,7 @@ func (d *prettyTTL) UnmarshalJSON(data []byte) error {
497497}
498498
499499//nolint:tagliatelle
500- type oauth2TokenSourceConfig struct {
500+ type OAuth2TokenSourceConfig struct {
501501 Type string `json:"type"`
502502
503503 // Fixed
@@ -510,7 +510,7 @@ type oauth2TokenSourceConfig struct {
510510 KeyID string `json:"kid"`
511511 Issuer string `json:"iss"`
512512 Subject string `json:"sub"`
513- Audience * stringOrArrayConfig `json:"aud"`
513+ Audience * StringOrArrayConfig `json:"aud"`
514514 ID string `json:"jti"`
515515 TTL * prettyTTL `json:"ttl"`
516516}
@@ -529,7 +529,7 @@ func signingMethodNotSupportedError(method string) error {
529529 return fmt .Errorf ("%w: %q. Supported signing methods are %s" , errUnsupportedSigningMethod , method , supported )
530530}
531531
532- func (cfg * oauth2TokenSourceConfig ) applyConfigFixed (tokenSrcType int ) (* tokenSourceOption , error ) {
532+ func (cfg * OAuth2TokenSourceConfig ) applyConfigFixed (tokenSrcType int ) (* tokenSourceOption , error ) {
533533 if cfg .Token == "" || cfg .TokenType == "" {
534534 return nil , xerrors .WithStackTrace (errTokenAndTokenTypeRequired )
535535 }
@@ -542,7 +542,7 @@ func (cfg *oauth2TokenSourceConfig) applyConfigFixed(tokenSrcType int) (*tokenSo
542542 }, nil
543543}
544544
545- func (cfg * oauth2TokenSourceConfig ) applyConfigFixedJWT (tokenSrcType int ) (* tokenSourceOption , error ) {
545+ func (cfg * OAuth2TokenSourceConfig ) applyConfigFixedJWT (tokenSrcType int ) (* tokenSourceOption , error ) {
546546 var opts []JWTTokenSourceOption
547547
548548 if cfg .Algorithm == "" || cfg .PrivateKey == "" {
@@ -591,7 +591,7 @@ func (cfg *oauth2TokenSourceConfig) applyConfigFixedJWT(tokenSrcType int) (*toke
591591 }, nil
592592}
593593
594- func (cfg * oauth2TokenSourceConfig ) applyConfig (tokenSrcType int ) (* tokenSourceOption , error ) {
594+ func (cfg * OAuth2TokenSourceConfig ) applyConfig (tokenSrcType int ) (* tokenSourceOption , error ) {
595595 if strings .EqualFold (cfg .Type , "FIXED" ) {
596596 return cfg .applyConfigFixed (tokenSrcType )
597597 }
@@ -604,19 +604,28 @@ func (cfg *oauth2TokenSourceConfig) applyConfig(tokenSrcType int) (*tokenSourceO
604604}
605605
606606//nolint:tagliatelle
607- type oauth2Config struct {
607+ type OAuth2Config struct {
608608 GrantType string `json:"grant-type"`
609- Resource * stringOrArrayConfig `json:"res"`
610- Audience * stringOrArrayConfig `json:"aud"`
611- Scope * stringOrArrayConfig `json:"scope"`
609+ Resource * StringOrArrayConfig `json:"res"`
610+ Audience * StringOrArrayConfig `json:"aud"`
611+ Scope * StringOrArrayConfig `json:"scope"`
612612 RequestedTokenType string `json:"requested-token-type"`
613613 TokenEndpoint string `json:"token-endpoint"`
614614
615- SubjectCreds * oauth2TokenSourceConfig `json:"subject-credentials"`
616- ActorCreds * oauth2TokenSourceConfig `json:"actor-credentials"`
615+ SubjectCreds * OAuth2TokenSourceConfig `json:"subject-credentials"`
616+ ActorCreds * OAuth2TokenSourceConfig `json:"actor-credentials"`
617617}
618618
619- func (cfg * oauth2Config ) applyConfig (opts * []Oauth2TokenExchangeCredentialsOption ) error {
619+ func (cfg * OAuth2Config ) AsOptions () ([]Oauth2TokenExchangeCredentialsOption , error ) {
620+ var fullOptions []Oauth2TokenExchangeCredentialsOption
621+ if err := cfg .applyConfig (& fullOptions ); err != nil {
622+ return nil , xerrors .WithStackTrace (err )
623+ }
624+
625+ return fullOptions , nil
626+ }
627+
628+ func (cfg * OAuth2Config ) applyConfig (opts * []Oauth2TokenExchangeCredentialsOption ) error {
620629 if cfg .GrantType != "" {
621630 * opts = append (* opts , WithGrantType (cfg .GrantType ))
622631 }
@@ -669,7 +678,7 @@ func NewOauth2TokenExchangeCredentialsFile(
669678 return nil , xerrors .WithStackTrace (fmt .Errorf ("%w: %w" , errCouldNotReadConfigFile , err ))
670679 }
671680
672- var cfg oauth2Config
681+ var cfg OAuth2Config
673682 if err = json .Unmarshal (configFileData , & cfg ); err != nil {
674683 return nil , xerrors .WithStackTrace (fmt .Errorf ("%w: %w" , errCouldNotUnmarshalJSON , err ))
675684 }
0 commit comments