Skip to content

Commit 5287135

Browse files
committed
shortened consts
1 parent 7023500 commit 5287135

File tree

3 files changed

+53
-54
lines changed

3 files changed

+53
-54
lines changed

secretstores/akeyless/akeyless.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func (a *akeylessSecretStore) BulkGetSecret(ctx context.Context, req secretstore
150150
defer wg.Done()
151151
if len(staticItemNames) == 1 {
152152
staticSecretName := staticItemNames[0]
153-
value, err := a.GetSingleSecretValue(staticSecretName, AKEYLESS_SECRET_TYPE_STATIC_SECRET_RESPONSE)
153+
value, err := a.GetSingleSecretValue(staticSecretName, STATIC_SECRET_RESPONSE)
154154
secretResultChannels <- secretResultCollection{name: staticSecretName, value: value, err: err}
155155
} else {
156156
secretResponse := a.GetBulkStaticSecretValues(staticItemNames)
@@ -167,7 +167,7 @@ func (a *akeylessSecretStore) BulkGetSecret(ctx context.Context, req secretstore
167167
go func() {
168168
defer wg.Done()
169169
for _, item := range dynamicItemNames {
170-
value, err := a.GetSingleSecretValue(item, AKEYLESS_SECRET_TYPE_DYNAMIC_SECRET_RESPONSE)
170+
value, err := a.GetSingleSecretValue(item, DYNAMIC_SECRET_RESPONSE)
171171
if err != nil {
172172
secretResultChannels <- secretResultCollection{name: item, value: "", err: err}
173173
} else {
@@ -181,7 +181,7 @@ func (a *akeylessSecretStore) BulkGetSecret(ctx context.Context, req secretstore
181181
go func() {
182182
defer wg.Done()
183183
for _, item := range rotatedItemNames {
184-
value, err := a.GetSingleSecretValue(item, AKEYLESS_SECRET_TYPE_ROTATED_SECRET_RESPONSE)
184+
value, err := a.GetSingleSecretValue(item, ROTATED_SECRET_RESPONSE)
185185
if err != nil {
186186
secretResultChannels <- secretResultCollection{name: item, value: "", err: err}
187187
} else {
@@ -266,11 +266,11 @@ func (a *akeylessSecretStore) parseMetadata(meta secretstores.Metadata) (*akeyle
266266
a.logger.Debugf("access type detected: %s", accessTypeDisplayName)
267267

268268
switch accessTypeDisplayName {
269-
case AKEYLESS_AUTH_DEFAULT_ACCESS_TYPE:
269+
case DEFAULT_AUTH_TYPE:
270270
if m.AccessKey == "" {
271271
return nil, errors.New("accessKey is required")
272272
}
273-
case AKEYLESS_AUTH_ACCESS_JWT:
273+
case AUTH_JWT:
274274
if m.JWT == "" {
275275
return nil, errors.New("jwt is required")
276276
}
@@ -279,8 +279,8 @@ func (a *akeylessSecretStore) parseMetadata(meta secretstores.Metadata) (*akeyle
279279

280280
// Set default gateway URL if not specified
281281
if m.GatewayURL == "" {
282-
a.logger.Infof("Gateway URL is not set, using default value %s...", AKEYLESS_PUBLIC_GATEWAY_URL)
283-
m.GatewayURL = AKEYLESS_PUBLIC_GATEWAY_URL
282+
a.logger.Infof("Gateway URL is not set, using default value %s...", PUBLIC_GATEWAY_URL)
283+
m.GatewayURL = PUBLIC_GATEWAY_URL
284284
}
285285

286286
return &m, nil
@@ -309,7 +309,7 @@ func (a *akeylessSecretStore) GetSingleSecretValue(secretName string, secretType
309309
var err error
310310

311311
switch secretType {
312-
case AKEYLESS_SECRET_TYPE_STATIC_SECRET_RESPONSE:
312+
case STATIC_SECRET_RESPONSE:
313313
getSecretValue := akeyless.NewGetSecretValue([]string{secretName})
314314
getSecretValue.SetToken(a.token)
315315
secretRespMap, _, apiErr := a.v2.GetSecretValue(context.Background()).Body(*getSecretValue).Execute()
@@ -333,7 +333,7 @@ func (a *akeylessSecretStore) GetSingleSecretValue(secretName string, secretType
333333
break
334334
}
335335

336-
case AKEYLESS_SECRET_TYPE_DYNAMIC_SECRET_RESPONSE:
336+
case DYNAMIC_SECRET_RESPONSE:
337337
getDynamicSecretValue := akeyless.NewGetDynamicSecretValue(secretName)
338338
getDynamicSecretValue.SetToken(a.token)
339339
secretRespMap, _, apiErr := a.v2.GetDynamicSecretValue(context.Background()).Body(*getDynamicSecretValue).Execute()
@@ -366,7 +366,7 @@ func (a *akeylessSecretStore) GetSingleSecretValue(secretName string, secretType
366366
// Return the value field directly (already a JSON string with credentials)
367367
secretValue = dynamicSecretResp.Value
368368

369-
case AKEYLESS_SECRET_TYPE_ROTATED_SECRET_RESPONSE:
369+
case ROTATED_SECRET_RESPONSE:
370370
getRotatedSecretValue := akeyless.NewGetRotatedSecretValue(secretName)
371371
getRotatedSecretValue.SetToken(a.token)
372372
secretRespMap, _, apiErr := a.v2.GetRotatedSecretValue(context.Background()).Body(*getRotatedSecretValue).Execute()
@@ -418,7 +418,7 @@ func (a *akeylessSecretStore) listItemsRecursively(path string) ([]akeyless.Item
418418
listItems.SetToken(a.token)
419419
listItems.SetPath(path)
420420
listItems.SetAutoPagination("enabled")
421-
listItems.SetType([]string{AKEYLESS_SECRET_TYPE_STATIC, AKEYLESS_SECRET_TYPE_DYNAMIC, AKEYLESS_SECRET_TYPE_ROTATED})
421+
listItems.SetType(SUPPORTED_SECRET_TYPES)
422422

423423
// Execute the list items request
424424
a.logger.Debugf("listing items from path '%s'...", path)
@@ -462,18 +462,18 @@ func (a *akeylessSecretStore) Authenticate(metadata *akeylessMetadata) error {
462462
// Depending on the access type we set the appropriate authentication method
463463
switch accessType {
464464
// If access type is AWS IAM we use the cloud ID
465-
case AKEYLESS_AUTH_ACCESS_IAM:
465+
case AUTH_IAM:
466466
id, err := aws.GetCloudId()
467467
if err != nil {
468468
return errors.New("unable to get cloud ID")
469469
}
470470
authRequest.SetCloudId(id)
471-
case AKEYLESS_AUTH_ACCESS_JWT:
471+
case AUTH_JWT:
472472
authRequest.SetJwt(metadata.JWT)
473-
case AKEYLESS_AUTH_DEFAULT_ACCESS_TYPE:
473+
case DEFAULT_AUTH_TYPE:
474474
a.logger.Debug("authenticating using access key...")
475475
authRequest.SetAccessKey(metadata.AccessKey)
476-
case AKEYLESS_AUTH_ACCESS_K8S:
476+
case AUTH_K8S:
477477
a.logger.Debug("authenticating using k8s...")
478478
err := setK8SAuthConfiguration(*metadata, authRequest, a)
479479
if err != nil {
@@ -489,8 +489,8 @@ func (a *akeylessSecretStore) Authenticate(metadata *akeylessMetadata) error {
489489
URL: metadata.GatewayURL,
490490
},
491491
}
492-
config.UserAgent = AKEYLESS_USER_AGENT
493-
config.AddDefaultHeader("akeylessclienttype", AKEYLESS_USER_AGENT)
492+
config.UserAgent = USER_AGENT
493+
config.AddDefaultHeader("akeylessclienttype", USER_AGENT)
494494

495495
a.v2 = akeyless.NewAPIClient(config).V2Api
496496

@@ -514,11 +514,11 @@ func (a *akeylessSecretStore) separateItemsByType(items []akeyless.Item) ([]akey
514514
itemType := *item.ItemType
515515

516516
switch itemType {
517-
case AKEYLESS_SECRET_TYPE_STATIC_SECRET_RESPONSE:
517+
case STATIC_SECRET_RESPONSE:
518518
staticItems = append(staticItems, item)
519-
case AKEYLESS_SECRET_TYPE_DYNAMIC_SECRET_RESPONSE:
519+
case DYNAMIC_SECRET_RESPONSE:
520520
dynamicItems = append(dynamicItems, item)
521-
case AKEYLESS_SECRET_TYPE_ROTATED_SECRET_RESPONSE:
521+
case ROTATED_SECRET_RESPONSE:
522522
rotatedItems = append(rotatedItems, item)
523523
}
524524
}

secretstores/akeyless/akeyless_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var (
3939
mockDynamicSecretItemName = "/dynamic-secret-test"
4040
mockRotatedSecretItemName = "/rotated-secret-test"
4141
mockDescribeStaticSecretName = fmt.Sprintf("/path/to/akeyless%s", mockStaticSecretItem)
42-
mockDescribeStaticSecretType = AKEYLESS_SECRET_TYPE_STATIC_SECRET_RESPONSE
42+
mockDescribeStaticSecretType = STATIC_SECRET_RESPONSE
4343
mockDescribeStaticSecretItemResponse = akeyless.Item{
4444
ItemName: &mockDescribeStaticSecretName,
4545
ItemType: &mockDescribeStaticSecretType,
@@ -64,7 +64,7 @@ var (
6464
},
6565
}
6666
mockDescribeDynamicSecretName = fmt.Sprintf("/path/to/akeyless%s", mockDynamicSecretItemName)
67-
mockDescribeDynamicSecretType = AKEYLESS_SECRET_TYPE_DYNAMIC_SECRET_RESPONSE
67+
mockDescribeDynamicSecretType = DYNAMIC_SECRET_RESPONSE
6868
mockDescribeDynamicSecretItemResponse = akeyless.Item{
6969
ItemName: &mockDescribeDynamicSecretName,
7070
ItemType: &mockDescribeDynamicSecretType,
@@ -80,7 +80,7 @@ var (
8080
"error": "",
8181
}
8282
mockDescribeRotatedSecretName = fmt.Sprintf("/path/to/akeyless%s", mockRotatedSecretItemName)
83-
mockDescribeRotatedSecretType = AKEYLESS_SECRET_TYPE_ROTATED_SECRET_RESPONSE
83+
mockDescribeRotatedSecretType = ROTATED_SECRET_RESPONSE
8484
mockDescribeRotatedSecretItemResponse = akeyless.Item{
8585
ItemName: &mockDescribeRotatedSecretName,
8686
ItemType: &mockDescribeRotatedSecretType,
@@ -119,13 +119,13 @@ func mockAuthenticate(metadata *akeylessMetadata, akeylessSecretStore *akeylessS
119119
// Depending on the access type we set the appropriate authentication method
120120
switch metadata.AccessType {
121121
// If access type is AWS IAM we use the mock cloud ID
122-
case AKEYLESS_AUTH_ACCESS_IAM:
122+
case AUTH_IAM:
123123
akeylessSecretStore.logger.Debug("Using mock cloud ID for AWS IAM...")
124124
authRequest.SetCloudId(mockCloudID)
125-
case AKEYLESS_AUTH_ACCESS_JWT:
125+
case AUTH_JWT:
126126
akeylessSecretStore.logger.Debug("Setting JWT for authentication...")
127127
authRequest.SetJwt(metadata.JWT)
128-
case AKEYLESS_AUTH_DEFAULT_ACCESS_TYPE:
128+
case DEFAULT_AUTH_TYPE:
129129
akeylessSecretStore.logger.Debug("Setting access key for authentication...")
130130
authRequest.SetAccessKey(metadata.AccessKey)
131131
}
@@ -136,8 +136,8 @@ func mockAuthenticate(metadata *akeylessMetadata, akeylessSecretStore *akeylessS
136136
URL: metadata.GatewayURL,
137137
},
138138
}
139-
config.UserAgent = AKEYLESS_USER_AGENT
140-
config.AddDefaultHeader("akeylessclienttype", AKEYLESS_USER_AGENT)
139+
config.UserAgent = USER_AGENT
140+
config.AddDefaultHeader("akeylessclienttype", USER_AGENT)
141141

142142
akeylessSecretStore.v2 = akeyless.NewAPIClient(config).V2Api
143143

@@ -319,7 +319,7 @@ func TestParseMetadata(t *testing.T) {
319319
expected: &akeylessMetadata{
320320
AccessID: testAccessIdKey,
321321
AccessKey: testAccessKey,
322-
AccessType: AKEYLESS_AUTH_DEFAULT_ACCESS_TYPE,
322+
AccessType: DEFAULT_AUTH_TYPE,
323323
GatewayURL: "https://api.akeyless.io", // Default gateway URL
324324
},
325325
},
@@ -334,7 +334,7 @@ func TestParseMetadata(t *testing.T) {
334334
expected: &akeylessMetadata{
335335
AccessID: testAccessIdJwt,
336336
JWT: testJWT,
337-
AccessType: AKEYLESS_AUTH_ACCESS_JWT,
337+
AccessType: AUTH_JWT,
338338
GatewayURL: mockGateway.URL,
339339
},
340340
},
@@ -347,7 +347,7 @@ func TestParseMetadata(t *testing.T) {
347347
expectError: false,
348348
expected: &akeylessMetadata{
349349
AccessID: testAccessIdIAM,
350-
AccessType: AKEYLESS_AUTH_ACCESS_IAM,
350+
AccessType: AUTH_IAM,
351351
GatewayURL: mockGateway.URL,
352352
},
353353
},
@@ -442,7 +442,7 @@ func TestMockAWSCloudID(t *testing.T) {
442442
// Parse metadata first
443443
m, err := store.parseMetadata(meta)
444444
require.NoError(t, err)
445-
assert.Equal(t, AKEYLESS_AUTH_ACCESS_IAM, m.AccessType)
445+
assert.Equal(t, AUTH_IAM, m.AccessType)
446446

447447
// Use mock authentication with mock cloud ID
448448
err = mockAuthenticate(m, store)
@@ -647,7 +647,7 @@ func TestGetSecretType(t *testing.T) {
647647

648648
secretType, err := store.GetSecretType(mockDescribeStaticSecretName)
649649
assert.NoError(t, err)
650-
assert.Equal(t, AKEYLESS_SECRET_TYPE_STATIC_SECRET_RESPONSE, secretType)
650+
assert.Equal(t, STATIC_SECRET_RESPONSE, secretType)
651651
}
652652

653653
func TestGetSingleDynamicSecret(t *testing.T) {
@@ -695,7 +695,7 @@ func TestGetSingleDynamicSecret(t *testing.T) {
695695
err := store.Init(context.Background(), meta)
696696
require.NoError(t, err)
697697

698-
secretValue, err := store.GetSingleSecretValue(mockDescribeDynamicSecretName, AKEYLESS_SECRET_TYPE_DYNAMIC_SECRET_RESPONSE)
698+
secretValue, err := store.GetSingleSecretValue(mockDescribeDynamicSecretName, DYNAMIC_SECRET_RESPONSE)
699699
assert.NoError(t, err)
700700
assert.Equal(t, "{\"user\":\"generated_username\",\"password\":\"generated_password\",\"ttl_in_minutes\":\"60\",\"id\":\"username\"}", secretValue)
701701

@@ -747,7 +747,7 @@ func TestGetSingleRotatedSecret(t *testing.T) {
747747
err := store.Init(context.Background(), meta)
748748
require.NoError(t, err)
749749

750-
secretValue, err := store.GetSingleSecretValue(mockDescribeRotatedSecretName, AKEYLESS_SECRET_TYPE_ROTATED_SECRET_RESPONSE)
750+
secretValue, err := store.GetSingleSecretValue(mockDescribeRotatedSecretName, ROTATED_SECRET_RESPONSE)
751751
assert.NoError(t, err)
752752
assert.Equal(t, "{\"value\":{\"application_id\":\"1234567890\",\"password\":\"r3vE4L3D\",\"username\":\"abcdefghijklmnopqrstuvwxyz\"}}", secretValue)
753753

secretstores/akeyless/utils.go

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@ import (
1515

1616
// Define constants for the access types. These are equivalent to the TypeScript consts.
1717
const (
18-
AKEYLESS_AUTH_ACCESS_JWT = "jwt"
19-
AKEYLESS_AUTH_DEFAULT_ACCESS_TYPE = "access_key"
20-
AKEYLESS_AUTH_ACCESS_IAM = "aws_iam"
21-
AKEYLESS_AUTH_ACCESS_K8S = "k8s"
22-
AKEYLESS_PUBLIC_GATEWAY_URL = "https://api.akeyless.io"
23-
AKEYLESS_USER_AGENT = "dapr.io/akeyless-secret-store"
24-
AKEYLESS_SECRET_TYPE_STATIC = "static-secret"
25-
AKEYLESS_SECRET_TYPE_DYNAMIC = "dynamic-secret"
26-
AKEYLESS_SECRET_TYPE_ROTATED = "rotated-secret"
27-
AKEYLESS_SECRET_TYPE_STATIC_SECRET_RESPONSE = "STATIC_SECRET"
28-
AKEYLESS_SECRET_TYPE_DYNAMIC_SECRET_RESPONSE = "DYNAMIC_SECRET"
29-
AKEYLESS_SECRET_TYPE_ROTATED_SECRET_RESPONSE = "ROTATED_SECRET"
18+
AUTH_JWT = "jwt"
19+
DEFAULT_AUTH_TYPE = "access_key"
20+
AUTH_IAM = "aws_iam"
21+
AUTH_K8S = "k8s"
22+
PUBLIC_GATEWAY_URL = "https://api.akeyless.io"
23+
USER_AGENT = "dapr.io/akeyless-secret-store"
24+
STATIC_SECRET_RESPONSE = "STATIC_SECRET"
25+
DYNAMIC_SECRET_RESPONSE = "DYNAMIC_SECRET"
26+
ROTATED_SECRET_RESPONSE = "ROTATED_SECRET"
3027
)
3128

29+
var SUPPORTED_SECRET_TYPES = []string{"static-secret", "dynamic-secret", "rotated-secret"}
30+
3231
// AccessTypeCharMap maps single-character access types to their display names.
3332
var AccessTypeCharMap = map[string]string{
34-
"a": AKEYLESS_AUTH_DEFAULT_ACCESS_TYPE,
35-
"o": AKEYLESS_AUTH_ACCESS_JWT,
36-
"w": AKEYLESS_AUTH_ACCESS_IAM,
37-
"k": AKEYLESS_AUTH_ACCESS_K8S,
33+
"a": DEFAULT_AUTH_TYPE,
34+
"o": AUTH_JWT,
35+
"w": AUTH_IAM,
36+
"k": AUTH_K8S,
3837
}
3938

4039
// AccessIdRegex is the compiled regular expression for validating Akeyless Access IDs.
@@ -148,10 +147,10 @@ func isSecretActive(secret akeyless.Item, logger logger.Logger) bool {
148147
}
149148

150149
switch *secret.ItemType {
151-
case AKEYLESS_SECRET_TYPE_STATIC_SECRET_RESPONSE:
150+
case STATIC_SECRET_RESPONSE:
152151
logger.Debugf("static secret '%s' is active", *secret.ItemName)
153152
isActive = true
154-
case AKEYLESS_SECRET_TYPE_DYNAMIC_SECRET_RESPONSE:
153+
case DYNAMIC_SECRET_RESPONSE:
155154
// Check if ItemGeneralInfo is available, if not, include the secret
156155
if secret.ItemGeneralInfo != nil &&
157156
secret.ItemGeneralInfo.DynamicSecretProducerDetails != nil &&
@@ -168,7 +167,7 @@ func isSecretActive(secret akeyless.Item, logger logger.Logger) bool {
168167
logger.Debugf("dynamic secret '%s' is missing detailed info. adding to filtered secrets...", *secret.ItemName)
169168
isActive = true
170169
}
171-
case AKEYLESS_SECRET_TYPE_ROTATED_SECRET_RESPONSE:
170+
case ROTATED_SECRET_RESPONSE:
172171
// Check if ItemGeneralInfo is available, if not, include the secret
173172
if secret.ItemGeneralInfo != nil &&
174173
secret.ItemGeneralInfo.RotatedSecretDetails != nil &&

0 commit comments

Comments
 (0)