Skip to content
This repository has been archived by the owner on Feb 16, 2023. It is now read-only.

Commit

Permalink
Merge pull request #202 from secrethub/feature/clarify-user-managed
Browse files Browse the repository at this point in the history
Rename ValidateGCPServiceAccountEmail to ValidateGCPUserManagedServic…
  • Loading branch information
SimonBarendse authored Jul 7, 2020
2 parents c91e33e + 5e56021 commit 9000de5
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion internals/api/credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ var credentialTypesMetadata = map[CredentialType]map[string]func(string) error{
CredentialMetadataAWSKMSKey: nil,
},
CredentialTypeGCPServiceAccount: {
CredentialMetadataGCPServiceAccountEmail: ValidateGCPServiceAccountEmail,
CredentialMetadataGCPServiceAccountEmail: ValidateGCPUserManagedServiceAccountEmail,
CredentialMetadataGCPKMSKeyResourceID: ValidateGCPKMSKeyResourceID,
},
CredentialTypeBackupCode: {},
Expand Down
10 changes: 5 additions & 5 deletions internals/api/patterns.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ func ValidateShortCredentialFingerprint(fingerprint string) error {
return nil
}

// ValidateGCPServiceAccountEmail validates whether the given string is potentially a valid email for a GCP
// Service Account. The function does a best-effort check. If no error is returned, this does not mean the value is
// accepted by GCP.
func ValidateGCPServiceAccountEmail(v string) error {
// ValidateGCPUserManagedServiceAccountEmail validates whether the given string is potentially a valid email for a
// user-managed GCP Service Account. The function does a best-effort check. If no error is returned, this does not mean
// the value is accepted by GCP.
func ValidateGCPUserManagedServiceAccountEmail(v string) error {
if !govalidator.IsEmail(v) {
return ErrInvalidGCPServiceAccountEmail
}
Expand All @@ -320,7 +320,7 @@ func ValidateGCPServiceAccountEmail(v string) error {
// ProjectIDFromGCPEmail returns the project ID included in the email of a GCP Service Account.
// If the input is not a valid user-managed GCP Service Account email, an error is returned.
func ProjectIDFromGCPEmail(in string) (string, error) {
err := ValidateGCPServiceAccountEmail(in)
err := ValidateGCPUserManagedServiceAccountEmail(in)
if err != nil {
return "", err
}
Expand Down
2 changes: 1 addition & 1 deletion internals/api/patterns_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ func TestValidateGCPServiceAccountEmail(t *testing.T) {

for name, tc := range cases {
t.Run(name, func(t *testing.T) {
err := api.ValidateGCPServiceAccountEmail(tc.in)
err := api.ValidateGCPUserManagedServiceAccountEmail(tc.in)

assert.Equal(t, err != nil, tc.expectErr)
})
Expand Down
2 changes: 1 addition & 1 deletion internals/gcp/service_creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type CredentialCreator struct {
// NewCredentialCreator returns a CredentialCreator that uses the provided GCP KMS key and Service Account Email to create a new credential.
// The GCP client is configured with the optionally provided option.ClientOption.
func NewCredentialCreator(serviceAccountEmail, keyResourceID string, gcpOptions ...option.ClientOption) (*CredentialCreator, map[string]string, error) {
if err := api.ValidateGCPServiceAccountEmail(serviceAccountEmail); err != nil {
if err := api.ValidateGCPUserManagedServiceAccountEmail(serviceAccountEmail); err != nil {
return nil, nil, err
}
if err := api.ValidateGCPKMSKeyResourceID(keyResourceID); err != nil {
Expand Down

0 comments on commit 9000de5

Please sign in to comment.