Skip to content

Commit 2c207e7

Browse files
committed
Raise error when service account mandator params are missing
1 parent 048dd52 commit 2c207e7

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

sumologic/resource_sumologic_generic_polling_source.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ func getPollingSnsTopicOrSubscriptionArn(d *schema.ResourceData) PollingSnsTopic
467467
return snsTopicOrSubscriptionArn
468468
}
469469

470-
func addGcpServiceAccountDetailsToAuth(authSettings *PollingAuthentication, auth map[string]interface{}) {
470+
func addGcpServiceAccountDetailsToAuth(authSettings *PollingAuthentication, auth map[string]interface{}) error {
471471
authSettings.Type = "service_account"
472472
authSettings.ProjectId = auth["project_id"].(string)
473473
authSettings.PrivateKeyId = auth["private_key_id"].(string)
@@ -478,6 +478,23 @@ func addGcpServiceAccountDetailsToAuth(authSettings *PollingAuthentication, auth
478478
authSettings.TokenUrl = auth["token_uri"].(string)
479479
authSettings.AuthProviderX509CertUrl = auth["auth_provider_x509_cert_url"].(string)
480480
authSettings.ClientX509CertUrl = auth["client_x509_cert_url"].(string)
481+
482+
errTxt := ""
483+
if len(strings.Trim(authSettings.ProjectId, " \t")) == 0 {
484+
errTxt = errTxt + "\nproject_id is mandator while using service_account authentication"
485+
}
486+
if len(authSettings.ClientEmail) == 0 {
487+
errTxt = errTxt + "\nclient_email is mandator while using service_account authentication"
488+
}
489+
if len(authSettings.PrivateKey) == 0 {
490+
errTxt = errTxt + "\nprivate_key is mandator while using service_account authentication"
491+
}
492+
493+
if len(errTxt) == 0 {
494+
return nil
495+
} else {
496+
return errors.New(errTxt)
497+
}
481498
}
482499

483500
func getPollingAuthentication(d *schema.ResourceData) (PollingAuthentication, error) {
@@ -505,7 +522,10 @@ func getPollingAuthentication(d *schema.ResourceData) (PollingAuthentication, er
505522
authSettings.Region = auth["region"].(string)
506523
}
507524
case "service_account":
508-
addGcpServiceAccountDetailsToAuth(&authSettings, auth)
525+
err := addGcpServiceAccountDetailsToAuth(&authSettings, auth)
526+
if err != nil {
527+
return authSettings, err
528+
}
509529

510530
default:
511531
errorMessage := fmt.Sprintf("[ERROR] Unknown authType: %v", authType)

0 commit comments

Comments
 (0)