Skip to content

Commit

Permalink
fix: lowercase URI secret name; abbreviated IPv6 address
Browse files Browse the repository at this point in the history
Signed-off-by: huyinhou <[email protected]>
  • Loading branch information
huyinhou committed Sep 12, 2023
1 parent a682eee commit 128644c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions util/db/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ func Test_URIToSecretName(t *testing.T) {

name, err = URIToSecretName("cluster", "http://[fe80::1ff:fe23:4567:890a]")
assert.NoError(t, err)
assert.Equal(t, "cluster-fe80-0000-0000-0000-01ff-fe23-4567-890a-3877258831", name)
assert.Equal(t, "cluster-fe80--1ff-fe23-4567-890a-3877258831", name)

name, err = URIToSecretName("cluster", "http://[fe80::1ff:fe23:4567:890a]:8000")
assert.NoError(t, err)
assert.Equal(t, "cluster-fe80-0000-0000-0000-01ff-fe23-4567-890a-664858999", name)
assert.Equal(t, "cluster-fe80--1ff-fe23-4567-890a-664858999", name)

name, err = URIToSecretName("cluster", "http://[FE80::1FF:FE23:4567:890A]:8000")
assert.NoError(t, err)
assert.Equal(t, "cluster-fe80--1ff-fe23-4567-890a-682802007", name)

name, err = URIToSecretName("cluster", "http://:/abc")
assert.NoError(t, err)
Expand Down
3 changes: 2 additions & 1 deletion util/db/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func URIToSecretName(uriType, uri string) (string, error) {
if err != nil {
return "", err
}
host = strings.ReplaceAll(addr.StringExpanded(), ":", "-")
host = strings.ReplaceAll(addr.String(), ":", "-")
}
} else {
last := strings.Index(host, ":")
Expand All @@ -175,5 +175,6 @@ func URIToSecretName(uriType, uri string) (string, error) {
}
h := fnv.New32a()
_, _ = h.Write([]byte(uri))
host = strings.ToLower(host)
return fmt.Sprintf("%s-%s-%v", uriType, host, h.Sum32()), nil
}

0 comments on commit 128644c

Please sign in to comment.