Skip to content

Commit

Permalink
Fix const names.
Browse files Browse the repository at this point in the history
  • Loading branch information
dargudear-google committed Sep 12, 2024
1 parent e07f429 commit 8edaa43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions server/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package server

const (
LOCATION_LENGTH_LIMIT = 30 // Maximun length of location is string is 30
REGIONAL_SECRET_REGEX = "projects/([^/]+)/locations/([^/]+)/secrets/([^/]+)/versions/([^/]+)$"
GLOBAL_SECRET_REGEX = "projects/([^/]+)/secrets/([^/]+)/versions/([^/]+)$"
locationLengthLimit = 30 // Maximun length of location is string is 30
regionalSecretRegex = "projects/([^/]+)/locations/([^/]+)/secrets/([^/]+)/versions/([^/]+)$"
globalSecretRegex = "projects/([^/]+)/secrets/([^/]+)/versions/([^/]+)$"
)
6 changes: 3 additions & 3 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func handleMountEvent(ctx context.Context, client *secretmanager.Client, creds c
return
}

if len(loc) > LOCATION_LENGTH_LIMIT {
if len(loc) > locationLengthLimit {
errs[i] = fmt.Errorf("invalid location string, please check the location")
return
}
Expand Down Expand Up @@ -231,11 +231,11 @@ func buildErr(errs []error) error {
// locationFromSecretResource returns location from the secret resource if the resource is in format "projects/<project_id>/locations/<location_id>/..."
// returns "" for global secret resource.
func locationFromSecretResource(resource string) (string, error) {
globalSecretRegexp := regexp.MustCompile(GLOBAL_SECRET_REGEX)
globalSecretRegexp := regexp.MustCompile(globalSecretRegex)
if m := globalSecretRegexp.FindStringSubmatch(resource); m != nil {
return "", nil
}
regionalSecretRegexp := regexp.MustCompile(REGIONAL_SECRET_REGEX)
regionalSecretRegexp := regexp.MustCompile(regionalSecretRegex)
if m := regionalSecretRegexp.FindStringSubmatch(resource); m != nil {
return m[2], nil
}
Expand Down
10 changes: 5 additions & 5 deletions server/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func TestHandleMountEventSMMultipleErrors(t *testing.T) {
func TestHandleMountEventForRegionalSecret(t *testing.T) {
secretFileMode := int32(0600) // decimal 384
const secretVersionByAlias = "projects/project/locations/us-central1/secrets/test/versions/latest"
const secretVersionById = "projects/project/locations/us-central1/secrets/test/versions/2"
const secretVersionByID = "projects/project/locations/us-central1/secrets/test/versions/2"

cfg := &config.MountConfig{
Secrets: []*config.Secret{
Expand All @@ -245,11 +245,11 @@ func TestHandleMountEventForRegionalSecret(t *testing.T) {
ObjectVersion: []*v1alpha1.ObjectVersion{
{
Id: secretVersionByAlias,
Version: secretVersionById,
Version: secretVersionByID,
},
{
Id: secretVersionByAlias,
Version: secretVersionById,
Version: secretVersionByID,
},
},
Files: []*v1alpha1.File{
Expand All @@ -269,7 +269,7 @@ func TestHandleMountEventForRegionalSecret(t *testing.T) {
client := mock(t, &mockSecretServer{
accessFn: func(ctx context.Context, _ *secretmanagerpb.AccessSecretVersionRequest) (*secretmanagerpb.AccessSecretVersionResponse, error) {
return &secretmanagerpb.AccessSecretVersionResponse{
Name: secretVersionById,
Name: secretVersionByID,
Payload: &secretmanagerpb.SecretPayload{
Data: []byte("Global Secret"),
},
Expand All @@ -280,7 +280,7 @@ func TestHandleMountEventForRegionalSecret(t *testing.T) {
regionalClient := mock(t, &mockSecretServer{
accessFn: func(ctx context.Context, _ *secretmanagerpb.AccessSecretVersionRequest) (*secretmanagerpb.AccessSecretVersionResponse, error) {
return &secretmanagerpb.AccessSecretVersionResponse{
Name: secretVersionById,
Name: secretVersionByID,
Payload: &secretmanagerpb.SecretPayload{
Data: []byte("My Secret"),
},
Expand Down

0 comments on commit 8edaa43

Please sign in to comment.