Skip to content

Commit

Permalink
Initial framework for adding an OpenAI token to the base config (#217)
Browse files Browse the repository at this point in the history
Co-authored-by: Ben McNicholl <hello@benmcnicholl.com>
  • Loading branch information
mcncl and Ben McNicholl authored Mar 26, 2024
1 parent 104fb6b commit a33b0e9
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (

const (
APITokenConfigKey = "api_token"
OpenAIAPITokenConfigKey = "openai_api_token"
OrganizationsSlugConfigKey = "organizations"
SelectedOrgKey = "selected_org"
)
Expand All @@ -32,9 +33,10 @@ const (
// buildkite-oss:
// api_token: <token>
type Config struct {
APIToken string
Organization string
V ViperConfig
APIToken string
OpenAIAPIToken string
Organization string
V ViperConfig
}

type ProjectConfig struct {
Expand All @@ -57,11 +59,13 @@ func (conf *Config) merge() {
APITokenConfigKey: conf.APIToken,
}
conf.V.Set(OrganizationsSlugConfigKey, orgs)
conf.V.Set(OpenAIAPITokenConfigKey, conf.OpenAIAPIToken)
}

// Save sets the current config values into viper and writes the config file
func (conf *Config) Save() error {
conf.V.Set(SelectedOrgKey, conf.Organization)
conf.V.Set(OpenAIAPITokenConfigKey, conf.OpenAIAPIToken)
conf.merge()

return conf.V.WriteConfig()
Expand Down

0 comments on commit a33b0e9

Please sign in to comment.