Skip to content

Commit

Permalink
feat: conditionally enable auth providers
Browse files Browse the repository at this point in the history
  • Loading branch information
katallaxie authored Oct 19, 2024
1 parent 83335c2 commit f057f6b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 9 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ func init() {
Root.PersistentFlags().StringVar(&config.Flags.Environment, "environment", config.Flags.Environment, "environment")
Root.PersistentFlags().StringVar(&config.Flags.DatabaseURI, "db-rul", config.Flags.DatabaseURI, "Database URI")
Root.PersistentFlags().StringVar(&config.Flags.DatabaseTablePrefix, "db-table-prefix", config.Flags.DatabaseTablePrefix, "Database table prefix")
Root.PersistentFlags().BoolVar(&config.Flags.GitHubEnabled, "github-enabled", config.Flags.GitHubEnabled, "GitHub enabled")
Root.PersistentFlags().BoolVar(&config.Flags.EntraIDEnabled, "entraid-enabled", config.Flags.EntraIDEnabled, "EntraID enabled")

Root.SilenceUsage = true
}
Expand Down Expand Up @@ -89,8 +91,13 @@ func NewWebSrv(cfg *cfg.Config) *WebSrv {
// Start starts the server.
func (s *WebSrv) Start(ctx context.Context, ready server.ReadyFunc, run server.RunFunc) func() error {
return func() error {
providers.RegisterProvider(github.New(s.cfg.Flags.GitHubClientID, s.cfg.Flags.GitHubClientSecret, s.cfg.Flags.GitHubCallbackURL))
providers.RegisterProvider(entraid.New(s.cfg.Flags.EntraIDClientID, s.cfg.Flags.EntraIDClientSecret, s.cfg.Flags.EntraIDCallbackURL, entraid.TenantType(s.cfg.Flags.EntraIDTenantID)))
if s.cfg.Flags.GitHubEnabled {
providers.RegisterProvider(github.New(s.cfg.Flags.GitHubClientID, s.cfg.Flags.GitHubClientSecret, s.cfg.Flags.GitHubCallbackURL))
}

if s.cfg.Flags.EntraIDEnabled {
providers.RegisterProvider(entraid.New(s.cfg.Flags.EntraIDClientID, s.cfg.Flags.EntraIDClientSecret, s.cfg.Flags.EntraIDCallbackURL, entraid.TenantType(s.cfg.Flags.EntraIDTenantID)))
}

conn, err := gorm.Open(postgres.Open(config.Flags.DatabaseURI), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
Expand Down
2 changes: 2 additions & 0 deletions internal/cfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ type Flags struct {
Addr string `envconfig:"SERVICE_LENS_ADDR" default:":8084"`
DatabaseURI string `envconfig:"POSTGRES_URL" default:""`
DatabaseTablePrefix string `envconfig:"SERVICE_LENS_DATABASE_TABLE_PREFIX" default:"service_lens_"`
GitHubEnabled bool `envconfig:"SERVICE_LENS_GITHUB_ENABLED" default:"false"`
GitHubCallbackURL string `envconfig:"SERVICE_LENS_GITHUB_CALLBACK_URL" default:""`
GitHubClientID string `envconfig:"SERVICE_LENS_GITHUB_CLIENT_ID" default:""`
GitHubClientSecret string `envconfig:"SERVICE_LENS_GITHUB_CLIENT_SECRET" default:""`
EntraIDEnabled bool `envconfig:"SERVICE_LENS_ENTRAID_ENABLED" default:"true"`
EntraIDClientID string `envconfig:"SERVICE_LENS_ENTRAID_CLIENT_ID" default:""`
EntraIDClientSecret string `envconfig:"SERVICE_LENS_ENTRAID_CLIENT_SECRET" default:""`
EntraIDCallbackURL string `envconfig:"SERVICE_LENS_ENTRAID_CALLBACK_URL" default:""`
Expand Down

0 comments on commit f057f6b

Please sign in to comment.