Skip to content

Commit 9be258d

Browse files
committed
chore: turn some user-facing string literals into constants
1 parent e34bf0b commit 9be258d

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

authorization/hasher.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ type AuthorizationHasher struct {
2727
const (
2828
DefaultHashVariant = influxdb2_algo.VariantSHA256
2929
DefaultHashVariantName = influxdb2_algo.VariantIdentifierSHA256
30+
31+
// HashVariantNameUnknown is the placeholder name used for unknown or unsupported hash variants.
32+
HashVariantNameUnknown = "N/A"
3033
)
3134

3235
type authorizationHasherOptions struct {
@@ -113,7 +116,7 @@ func (h *AuthorizationHasher) AllHashes(token string) ([]string, error) {
113116
for idx, hasher := range h.allHashers {
114117
digest, err := hasher.Hash(token)
115118
if err != nil {
116-
variantName := "N/A"
119+
variantName := HashVariantNameUnknown
117120
if influxdb_hasher, ok := hasher.(*influxdb2_algo.Hasher); ok {
118121
variantName = influxdb_hasher.Variant().Prefix()
119122
}

authorization/storage.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,14 @@ token value. Raw token values are returned as in previous versions.
106106
107107
---*/
108108

109+
const (
110+
// TokenRedactedMessage is the user facing message used when a hashed token is redacted.
111+
TokenRedactedMessage = "REDACTED"
112+
113+
// TokenNotAvailableMessage is the user facing message when no token is available, plaintext or hashed.
114+
TokenNotAvailableMessage = "N/A"
115+
)
116+
109117
const MaxIDGenerationN = 100
110118
const ReservedIDs = 1000
111119

authorization/storage_authorization.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ func (s *Store) encodeAuthorization(a *influxdb.Authorization) ([]byte, error) {
6565
// raw tokens if hashing is enabled.
6666
if s.useHashedTokens {
6767
// Redact a copy, not the original. The raw Token value is still needed by the caller in some cases.
68+
// Note that this is an empty string, not TokenRedactedMessage. TokenRedactedMessage is only used for
69+
// user-facing output. The empty string signals that the plaintext token is not available and that
70+
// the hashed token should be used instead.
6871
redactedAuth := *a
6972
redactedAuth.Token = ""
7073
a = &redactedAuth

cmd/influxd/recovery/auth/auth.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,9 +221,9 @@ func PrintAuth(ctx context.Context, w io.Writer, v []*influxdb.Authorization, us
221221
if t.Token != "" {
222222
token = t.Token
223223
} else if t.HashedToken != "" {
224-
token = "REDACTED"
224+
token = authorization.TokenRedactedMessage
225225
} else {
226-
token = "N/A"
226+
token = authorization.TokenNotAvailableMessage
227227
}
228228
row := map[string]interface{}{
229229
"ID": t.ID,

0 commit comments

Comments
 (0)