Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Settings API with OAuth credentials #1636

Merged
merged 3 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cmd/monaco/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,14 @@ func validateAuthenticationWithProjectConfigs(projects []project.Project, enviro
}

switch conf.Type.(type) {
case config.ClassicApiType,
config.SettingsType:
arthurpitman marked this conversation as resolved.
Show resolved Hide resolved
case config.ClassicApiType:
if environments[envName].Auth.Token == nil {
return fmt.Errorf("API of type '%s' requires a token for environment '%s'", conf.Type, envName)
}
case config.SettingsType:
if environments[envName].Auth.Token == nil && environments[envName].Auth.OAuth == nil {
return fmt.Errorf("API of type '%s' requires a token or OAuth for environment '%s'", conf.Type, envName)
}
default:
if environments[envName].Auth.OAuth == nil {
return fmt.Errorf("API of type '%s' requires OAuth for environment '%s'", conf.Type, envName)
Expand Down
17 changes: 17 additions & 0 deletions cmd/monaco/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
Type: config.ClassicApiType{},
Skip: false,
}
settingsConf := config.Config{
Type: config.SettingsType{},
Skip: false,
}
classicConfSkip := classicConf
classicConfSkip.Skip = true
documentConfSkip := documentConf
Expand Down Expand Up @@ -496,6 +500,19 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
"",
},
{
"OAuth manifest with settings api",
manifest.Environments{
envId: manifest.EnvironmentDefinition{
Name: envId,
Auth: manifest.Auth{
OAuth: &oAuth},
}},
project.ConfigsPerType{
string(config.SettingsTypeId): []config.Config{settingsConf},
},
"",
},
}

for _, tc := range success_tests {
Expand Down
3 changes: 0 additions & 3 deletions cmd/monaco/download/download_configs.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ func downloadConfigs(clientSet *client.ClientSet, apisToDownload api.APIs, opts
}

if shouldDownloadSettings(opts) {
if opts.auth.Token == nil {
return nil, errors.New("settings client config requires token")
}
log.Info("Downloading settings objects")
settingCfgs, err := fn.settingsDownload(clientSet.Settings(), opts.projectName, settings.DefaultSettingsFilters, makeSettingTypes(opts.specificSchemas)...)
if err != nil {
Expand Down
11 changes: 11 additions & 0 deletions cmd/monaco/download/download_configs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,17 @@ func TestDownloadConfigs_OnlyAutomationWithoutAutomationCredentials(t *testing.T
assert.ErrorContains(t, err, "no OAuth credentials configured")
}

func TestDownloadConfigs_OnlySettings(t *testing.T) {
opts := downloadConfigsOptions{
onlySettings: true,
}
c := client.NewMockSettingsClient(gomock.NewController(t))
c.EXPECT().ListSchemas(gomock.Any()).Return(dtclient.SchemaList{{SchemaId: "builtin:auto.schema"}}, nil)
c.EXPECT().List(gomock.Any(), gomock.Any(), gomock.Any()).AnyTimes().Return([]dtclient.DownloadSettingsObject{}, nil)
err := doDownloadConfigs(testutils.CreateTestFileSystem(), &client.ClientSet{SettingsClient: c}, nil, opts)
assert.NoError(t, err)
}

func Test_downloadConfigsOptions_valid(t *testing.T) {
t.Run("no error for konwn api", func(t *testing.T) {
given := downloadConfigsOptions{specificAPIs: []string{"alerting-profile"}}
Expand Down
Loading