Skip to content

Commit d351516

Browse files
committed
fix: token lookup in services
1 parent 589b005 commit d351516

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
OWNER := dnitsch
33
NAME := configmanager
44
GIT_TAG := "0.0.0"
5-
VERSION := "v$(shell git describe --tags --abbrev=0)"
5+
VERSION := "v0.9.2"
6+
# VERSION := "$(shell git describe --tags --abbrev=0)"
67
REVISION := $(shell git rev-parse --short HEAD)
78

89
LDFLAGS := -ldflags="-s -w -X \"github.com/$(OWNER)/$(NAME)/cmd/configmanager.Version=$(VERSION)\" -X \"github.com/$(OWNER)/$(NAME)/cmd/configmanager.Revision=$(REVISION)\" -extldflags -static"

pkg/generator/generator.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func (c *GenVars) retrieveSpecific(prefix, in string) (string, error) {
155155
c.setToken(in)
156156
return c.getTokenValue()
157157
case AzKeyVaultPrefix:
158-
azKv, err := NewKvStoreWithToken(c.ctx, in, c.config.tokenSeparator)
158+
azKv, err := NewKvStoreWithToken(c.ctx, in, c.config.tokenSeparator, c.config.keySeparator)
159159
if err != nil {
160160
return "", err
161161
}
@@ -259,11 +259,13 @@ func (c *GenVars) normalizeKey(k string) string {
259259
}
260260

261261
func (c *GenVars) stripPrefix(in, prefix string) string {
262-
return stripPrefix(in, prefix, c.config.tokenSeparator)
262+
return stripPrefix(in, prefix, c.config.tokenSeparator, c.config.keySeparator)
263263
}
264264

265-
func stripPrefix(in, prefix, tokenSeparator string) string {
266-
return strings.Replace(in, fmt.Sprintf("%s%s", prefix, tokenSeparator), "", 1)
265+
func stripPrefix(in, prefix, tokenSeparator, keySeparator string) string {
266+
t := in
267+
b := regexp.MustCompile(`[|].*`).ReplaceAll([]byte(t), []byte(""))
268+
return strings.Replace(string(b), fmt.Sprintf("%s%s", prefix, tokenSeparator), "", 1)
267269
}
268270

269271
// FlushToFile saves contents to file provided

pkg/generator/keyvault.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ func NewKvStore(ctx context.Context) (*KvStore, error) {
4040

4141
// NewKvStore returns a KvStore
4242
// requires `AZURE_SUBSCRIPTION_ID` environment variable to be present to successfuly work
43-
func NewKvStoreWithToken(ctx context.Context, token, tokenSeparator string) (*KvStore, error) {
43+
func NewKvStoreWithToken(ctx context.Context, token, tokenSeparator, keySeparator string) (*KvStore, error) {
4444

4545
//
46-
conf := azSplitToken(stripPrefix(token, AzKeyVaultPrefix, tokenSeparator))
46+
conf := azSplitToken(stripPrefix(token, AzKeyVaultPrefix, tokenSeparator, keySeparator))
4747

4848
cred, err := azidentity.NewDefaultAzureCredential(nil)
4949
if err != nil {

0 commit comments

Comments
 (0)