mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-01-08 15:14:00 -05:00
chore: embed Config into Auth (#1865)
To keep a persistent backend storage for configuration, we will have to keep a single source of truth. This involves supporting bi-directional conversion between Config and AuthService. This PR make the following changes: * Embed Config in AuthService * Add `ToConfig()` to extract Config from AuthService.
This commit is contained in:
@@ -30,4 +30,5 @@ type AuthService interface {
|
|||||||
AuthServiceKind() string
|
AuthServiceKind() string
|
||||||
GetName() string
|
GetName() string
|
||||||
GetClaimsFromHeader(context.Context, http.Header) (map[string]any, error)
|
GetClaimsFromHeader(context.Context, http.Header) (map[string]any, error)
|
||||||
|
ToConfig() AuthServiceConfig
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,9 +43,7 @@ func (cfg Config) AuthServiceConfigKind() string {
|
|||||||
// Initialize a Google auth service
|
// Initialize a Google auth service
|
||||||
func (cfg Config) Initialize() (auth.AuthService, error) {
|
func (cfg Config) Initialize() (auth.AuthService, error) {
|
||||||
a := &AuthService{
|
a := &AuthService{
|
||||||
Name: cfg.Name,
|
Config: cfg,
|
||||||
Kind: AuthServiceKind,
|
|
||||||
ClientID: cfg.ClientID,
|
|
||||||
}
|
}
|
||||||
return a, nil
|
return a, nil
|
||||||
}
|
}
|
||||||
@@ -54,9 +52,7 @@ var _ auth.AuthService = AuthService{}
|
|||||||
|
|
||||||
// struct used to store auth service info
|
// struct used to store auth service info
|
||||||
type AuthService struct {
|
type AuthService struct {
|
||||||
Name string `yaml:"name"`
|
Config
|
||||||
Kind string `yaml:"kind"`
|
|
||||||
ClientID string `yaml:"clientId"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the auth service kind
|
// Returns the auth service kind
|
||||||
@@ -64,6 +60,10 @@ func (a AuthService) AuthServiceKind() string {
|
|||||||
return AuthServiceKind
|
return AuthServiceKind
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a AuthService) ToConfig() auth.AuthServiceConfig {
|
||||||
|
return a.Config
|
||||||
|
}
|
||||||
|
|
||||||
// Returns the name of the auth service
|
// Returns the name of the auth service
|
||||||
func (a AuthService) GetName() string {
|
func (a AuthService) GetName() string {
|
||||||
return a.Name
|
return a.Name
|
||||||
|
|||||||
Reference in New Issue
Block a user