Skip to content

Commit

Permalink
feat: prefix versions with pound sign
Browse files Browse the repository at this point in the history
  • Loading branch information
busser committed Aug 8, 2022
1 parent 6beadb6 commit fb00c42
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 24 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Here are some examples:

- `azkv:example.vault.azure.net/secret-sauce` references the latest value of the
`secret-sauce` secret in the `example` Key Vault.
- `azkv:example.vault.azure.net/secret-sauce/5ddc29704c1c4429a4c53605b7949100`
- `azkv:example.vault.azure.net/secret-sauce#5ddc29704c1c4429a4c53605b7949100`
references a specific version of the `secret-sauce` secret in the `example`
Key Vault.

Expand All @@ -96,7 +96,7 @@ Here are some examples:

- `gcpsm:example/secret-sauce` references the latest value of the
`secret-sauce` secret in the `example` project.
- `gcpsm:example/secret-sauce/123` references a specific version of the
- `gcpsm:example/secret-sauce#123` references a specific version of the
- `secret-sauce` secret in the `example` project.

Whisper uses the environment's default credentials to authenticate to Google
Expand Down
25 changes: 17 additions & 8 deletions internal/clients/azkv/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,22 @@ func (c *client) createClientIfMissing(vault string) {
}

func parseRef(ref string) (vaultURL, name, version string, err error) {
parts := strings.SplitN(ref, "/", 3)
switch {
case len(parts) < 2:
return "", "", "", errors.New("not enough information")
case len(parts) < 3:
return parts[0], parts[1], "", nil
default:
return parts[0], parts[1], parts[2], nil
refParts := strings.SplitN(ref, "#", 2)
if len(refParts) < 1 {
return "", "", "", errors.New("invalid syntax")
}
fullname := refParts[0]
version = ""
if len(refParts) == 2 {
version = refParts[1]
}

fullnameParts := strings.SplitN(fullname, "/", 2)
if len(fullnameParts) < 2 {
return "", "", "", errors.New("invalid syntax")
}
vaultURL = fullnameParts[0]
name = fullnameParts[1]

return vaultURL, name, version, nil
}
8 changes: 4 additions & 4 deletions internal/clients/azkv/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ func TestClient(t *testing.T) {
wantErr: false,
},
{
ref: "whisper-alpha.vault.azure.net/secret-sauce/0c2fd54cde7e494faad53882524d358f",
ref: "whisper-alpha.vault.azure.net/secret-sauce#0c2fd54cde7e494faad53882524d358f",
wantVal: "szechuan",
wantErr: false,
},
{
ref: "whisper-alpha.vault.azure.net/secret-sauce/73f5e5ff35a44cdab53b7a34c18da367",
ref: "whisper-alpha.vault.azure.net/secret-sauce#73f5e5ff35a44cdab53b7a34c18da367",
wantVal: "ketchup",
wantErr: false,
},
Expand All @@ -54,12 +54,12 @@ func TestClient(t *testing.T) {
wantErr: false,
},
{
ref: "whisper-bravo.vault.azure.net/secret-sauce/b5f5287b95b24491a7ec5bb6a19ff341",
ref: "whisper-bravo.vault.azure.net/secret-sauce#b5f5287b95b24491a7ec5bb6a19ff341",
wantVal: "szechuan",
wantErr: false,
},
{
ref: "whisper-bravo.vault.azure.net/secret-sauce/03bb1bf7a5b44bb28508a6de043faf3c",
ref: "whisper-bravo.vault.azure.net/secret-sauce#03bb1bf7a5b44bb28508a6de043faf3c",
wantVal: "ketchup",
wantErr: false,
},
Expand Down
25 changes: 17 additions & 8 deletions internal/clients/gcpsm/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,22 @@ func (c *client) Close() error {
}

func parseRef(ref string) (project, name, version string, err error) {
parts := strings.SplitN(ref, "/", 3)
switch {
case len(parts) < 2:
return "", "", "", errors.New("not enough information")
case len(parts) < 3:
return parts[0], parts[1], "latest", nil
default:
return parts[0], parts[1], parts[2], nil
refParts := strings.SplitN(ref, "#", 2)
if len(refParts) < 1 {
return "", "", "", errors.New("invalid syntax")
}
fullname := refParts[0]
version = "latest"
if len(refParts) == 2 {
version = refParts[1]
}

fullnameParts := strings.SplitN(fullname, "/", 2)
if len(fullnameParts) < 2 {
return "", "", "", errors.New("invalid syntax")
}
project = fullnameParts[0]
name = fullnameParts[1]

return project, name, version, nil
}
4 changes: 2 additions & 2 deletions internal/clients/gcpsm/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ func TestClient(t *testing.T) {
wantErr: false,
},
{
ref: "whisper-tests/secret-sauce/4",
ref: "whisper-tests/secret-sauce#4",
wantVal: "szechuan",
wantErr: false,
},
{
ref: "whisper-tests/secret-sauce/3",
ref: "whisper-tests/secret-sauce#3",
wantVal: "ketchup",
wantErr: false,
},
Expand Down

0 comments on commit fb00c42

Please # to comment.