Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Commit 9bc4b77

Browse files
author
sfomuseumbot
committed
add credential string constants, ValidCredentials and ValidCredentialsString methods
1 parent 0fc1895 commit 9bc4b77

File tree

1 file changed

+42
-12
lines changed

1 file changed

+42
-12
lines changed

config.go

Lines changed: 42 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package auth
33
import (
44
"context"
55
"fmt"
6+
"log/slog"
67
"net/url"
78
"os/user"
89
"path/filepath"
9-
"sort"
10+
_ "sort"
1011
"strings"
1112

1213
"github.com/aws/aws-sdk-go-v2/aws"
@@ -17,20 +18,49 @@ import (
1718
// null_cfg is a placeholder to return in error contexts.
1819
var null_cfg aws.Config
1920

20-
// CredentialsStringPatterns() returns the list of valid credential strings patterns.
21-
func CredentialsStringPatterns() []string {
21+
const AnonymousCredentialsString string = "anon:"
22+
23+
const EnvironmentCredentialsString string = "env:"
24+
25+
const IAMCredentialsString string = "iam:"
26+
27+
const ProfileCredentialsTemplate string = "{profile}"
28+
29+
const ProfileFromPathCredentialsTemplate string = "{path}:{profile}"
30+
31+
const StaticCredentialsTemplate string = "static:{id}:{key}:{secret}"
32+
33+
const StaticCredentialsPrefix string = "static:"
34+
35+
const STSCredentialsPrefix string = "sts:"
2236

23-
patterns := []string{
24-
"anon:",
25-
"env:",
26-
"iam:",
27-
"{PROFILE}",
28-
"{PATH}:{PROFILE}",
29-
"static:{KEY}:{SECRET}:{TOKEN}",
37+
// ValidCredentials() returns the list of valid credential strings patterns.
38+
func ValidCredentials() []string {
39+
40+
valid := []string{
41+
AnonymousCredentialsString,
42+
EnvironmentCredentialsString,
43+
IAMCredentialsString,
44+
STSCredentialsPrefix,
45+
ProfileCredentialsTemplate,
46+
ProfileFromPathCredentialsTemplate,
47+
StaticCredentialsTemplate,
3048
}
3149

32-
sort.Strings(patterns)
33-
return patterns
50+
return valid
51+
}
52+
53+
func ValidCredentialsString() string {
54+
55+
valid := ValidCredentials()
56+
57+
return fmt.Sprintf("Valid credential flags are: %s", strings.Join(valid, ", "))
58+
}
59+
60+
// CredentialsStringPatterns() returns the list of valid credential strings patterns. DEPRECATED. Please use `ValidCredentials` instead.
61+
func CredentialsStringPatterns() []string {
62+
slog.Warn("CredentialsStringPatterns() is deprecated. Please call ValidCredentials() instead.")
63+
return ValidCredentials()
3464
}
3565

3666
// NewConfig() returns a new `aws.Config` derived from 'uri' which is expected to be configured

0 commit comments

Comments
 (0)