Skip to content

Commit

Permalink
fix: check every config entry in a file (#1628)
Browse files Browse the repository at this point in the history
* fix: on authentication, validation check every config entry in a file and improve test
  • Loading branch information
tomazpu authored Nov 13, 2024
1 parent 5cd8e2c commit e565222
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
28 changes: 15 additions & 13 deletions cmd/monaco/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,20 +281,22 @@ func platformEnvironment(e manifest.EnvironmentDefinition) bool {
func validateAuthenticationWithProjectConfigs(projects []project.Project, environments manifest.Environments) error {
for _, p := range projects {
for envName, env := range p.Configs {
for _, conf := range env {
if conf[0].Skip == true {
continue
}

switch conf[0].Type.(type) {
case config.ClassicApiType,
config.SettingsType:
if environments[envName].Auth.Token == nil {
return fmt.Errorf("API of type '%s' requires a token for environment '%s'", conf[0].Type, envName)
for _, file := range env {
for _, conf := range file {
if conf.Skip == true {
continue
}
default:
if environments[envName].Auth.OAuth == nil {
return fmt.Errorf("API of type '%s' requires OAuth for environment '%s'", conf[0].Type, envName)

switch conf.Type.(type) {
case config.ClassicApiType,
config.SettingsType:
if environments[envName].Auth.Token == nil {
return fmt.Errorf("API of type '%s' requires a token 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
20 changes: 13 additions & 7 deletions cmd/monaco/deploy/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
classicConfSkip := classicConf
classicConfSkip.Skip = true
documentConfSkip := documentConf
classicConfSkip.Skip = true
documentConfSkip.Skip = true

success_tests := []struct {
name string
Expand All @@ -413,7 +413,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
OAuth: &oAuth},
}},
project.ConfigsPerType{
"dashboard": []config.Config{documentConf}},
string(config.DocumentTypeId): []config.Config{documentConf}},
"",
},
{
Expand All @@ -425,7 +425,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
Token: &token},
}},
project.ConfigsPerType{
"dashboard": []config.Config{classicConf}},
string(config.ClassicApiTypeId): []config.Config{classicConf}},
"",
},
{
Expand All @@ -439,7 +439,9 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
},
}},
project.ConfigsPerType{
"dashboard": []config.Config{classicConf, documentConf}},
string(config.DocumentTypeId): []config.Config{documentConf},
string(config.ClassicApiTypeId): []config.Config{classicConf, classicConfSkip},
},
"",
},
{
Expand All @@ -451,7 +453,7 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
Token: &token},
}},
project.ConfigsPerType{
"dashboard": []config.Config{documentConf}},
string(config.DocumentTypeId): []config.Config{documentConf}},
"requires OAuth for environment",
},
{
Expand All @@ -463,7 +465,9 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
OAuth: &oAuth},
}},
project.ConfigsPerType{
"dashboard": []config.Config{classicConf, documentConf}},
string(config.DocumentTypeId): []config.Config{documentConf},
string(config.ClassicApiTypeId): []config.Config{classicConf},
},
"requires a token for environment",
},
{
Expand All @@ -487,7 +491,9 @@ func Test_ValidateAuthenticationWithProjectConfigs(t *testing.T) {
Token: &token},
}},
project.ConfigsPerType{
"dashboard": []config.Config{classicConf, documentConfSkip}},
string(config.DocumentTypeId): []config.Config{documentConfSkip},
string(config.ClassicApiTypeId): []config.Config{classicConf},
},
"",
},
}
Expand Down

0 comments on commit e565222

Please sign in to comment.