Skip to content

Commit 29a9397

Browse files
authored
Feat/v2 alpha0.0.1 (#28)
* BREAKING!: change the interface of configmanager +semver: feat +semver: feature * fix[breaking]: added post processor to cmd utils * fix: add strategy package into internal * fix: add store implementations * fix: ci updated * fix: add more tests * fix: unit tests * fix: ci definitions * fix: add additional tests TODO: still uncomment some not ported negative assertions * docs: update breaking change notice * fix: add more tests to cmdutils * fix: typo +semver: major +semver: breaking
1 parent da6a007 commit 29a9397

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+2918
-2317
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,21 @@ jobs:
1212
outputs:
1313
semVer: ${{ steps.gitversion.outputs.semVer }}
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
18+
- name: install deps
19+
run: |
20+
apt-get update && apt-get install -y jq git
21+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
22+
git config user.email ${{ github.actor }}-ci@gha.org
23+
git config user.name ${{ github.actor }}
1824
- name: Install GitVersion
19-
uses: gittools/actions/gitversion/setup@v0.9.15
25+
uses: gittools/actions/gitversion/setup@v1.1.1
2026
with:
2127
versionSpec: '5.x'
2228
- name: Set SemVer Version
23-
uses: gittools/actions/gitversion/execute@v0.9.15
29+
uses: gittools/actions/gitversion/execute@v1.1.1
2430
id: gitversion
2531

2632
- name: echo VERSIONS
@@ -30,14 +36,14 @@ jobs:
3036
test:
3137
runs-on: ubuntu-latest
3238
container:
33-
image: golang:1.19-bullseye
39+
image: golang:1.21-bullseye
3440
needs: set-version
3541
env:
3642
SEMVER: ${{ needs.set-version.outputs.semVer }}
3743
GIT_TAG: ${{ needs.set-version.outputs.semVer }}
3844
GOVCS: false
3945
steps:
40-
- uses: actions/checkout@v3
46+
- uses: actions/checkout@v4
4147
with:
4248
fetch-depth: 1
4349
- name: install deps
@@ -50,7 +56,7 @@ jobs:
5056
run: |
5157
make REVISION=$GITHUB_SHA test
5258
- name: Publish Junit style Test Report
53-
uses: mikepenz/action-junit-report@v3
59+
uses: mikepenz/action-junit-report@v4
5460
if: always() # always run even if the previous step fails
5561
with:
5662
report_paths: '**/.coverage/report-junit.xml'

.github/workflows/pr.yml

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,32 @@ jobs:
1212
outputs:
1313
semVer: ${{ steps.gitversion.outputs.semVer }}
1414
steps:
15-
- uses: actions/checkout@v3
15+
- uses: actions/checkout@v4
1616
with:
1717
fetch-depth: 0
18+
- name: install deps
19+
run: |
20+
apt-get update && apt-get install -y jq git
21+
git config --global --add safe.directory "$GITHUB_WORKSPACE"
22+
git config user.email ${{ github.actor }}-ci@gha.org
23+
git config user.name ${{ github.actor }}
1824
- name: Install GitVersion
19-
uses: gittools/actions/gitversion/setup@v0.9.15
25+
uses: gittools/actions/gitversion/setup@v1.1.1
2026
with:
2127
versionSpec: '5.x'
2228
- name: Set SemVer Version
23-
uses: gittools/actions/gitversion/execute@v0.9.15
29+
uses: gittools/actions/gitversion/execute@v1.1.1
2430
id: gitversion
2531
pr:
2632
runs-on: ubuntu-latest
2733
container:
28-
image: golang:1.19-bullseye
34+
image: golang:1.21-bullseye
2935
needs: set-version
3036
env:
3137
REVISION: $GITHUB_SHA
3238
SEMVER: ${{ needs.set-version.outputs.semVer }}
3339
steps:
34-
- uses: actions/checkout@v3
40+
- uses: actions/checkout@v4
3541
- name: install deps
3642
run: |
3743
apt-get update && apt-get install -y jq git
@@ -42,7 +48,7 @@ jobs:
4248
run: |
4349
make REVISION=$GITHUB_SHA test
4450
- name: Publish Junit style Test Report
45-
uses: mikepenz/action-junit-report@v3
51+
uses: mikepenz/action-junit-report@v4
4652
if: always() # always run even if the previous step fails
4753
with:
4854
report_paths: '**/report-junit.xml'

.github/workflows/release.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,15 @@ jobs:
1515
outputs:
1616
semVer: ${{ steps.gitversion.outputs.semVer }}
1717
steps:
18-
- uses: actions/checkout@v3
18+
- uses: actions/checkout@v4
1919
with:
2020
fetch-depth: 0
2121
- name: Install GitVersion
22-
uses: gittools/actions/gitversion/setup@v0.9.15
22+
uses: gittools/actions/gitversion/setup@v1.1.1
2323
with:
2424
versionSpec: '5.x'
2525
- name: Set SemVer Version
26-
uses: gittools/actions/gitversion/execute@v0.9.15
26+
uses: gittools/actions/gitversion/execute@v1.1.1
2727
id: gitversion
2828

2929
- name: echo VERSIONS
@@ -33,14 +33,14 @@ jobs:
3333
release:
3434
runs-on: ubuntu-latest
3535
container:
36-
image: golang:1.19-bullseye
36+
image: golang:1.21-bullseye
3737
env:
3838
FOO: Bar
3939
needs: set-version
4040
env:
4141
SEMVER: ${{ needs.set-version.outputs.semVer }}
4242
steps:
43-
- uses: actions/checkout@v3
43+
- uses: actions/checkout@v4
4444
with:
4545
fetch-depth: 1
4646
- name: install deps

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ LDFLAGS := -ldflags="-s -w -X \"github.com/$(OWNER)/$(NAME)/cmd/configmanager.Ve
1010
.PHONY: test test_ci tidy install cross-build
1111

1212
test: test_prereq
13-
go test `go list ./... | grep -v */generated/` -v -buildvcs=false -mod=readonly -coverprofile=.coverage/out ; \
14-
cat .coverage/out | go-junit-report > .coverage/report-junit.xml && \
13+
go test ./... -v -buildvcs=false -mod=readonly -coverprofile=.coverage/out > .coverage/unit ; \
14+
cat .coverage/unit | go-junit-report > .coverage/report-junit.xml && \
1515
gocov convert .coverage/out | gocov-xml > .coverage/report-cobertura.xml
1616

1717
test_ci:

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,19 @@ Where `configVar` can be either a parseable string `'som3#!S$CRet'` or a number
5353

5454
This can be leveraged from any application written in Go - on start up or at runtime. Secrets/Config items can be retrieved in "bulk" and parsed into a provided type, [see here for examples](./examples/examples.go).
5555

56+
> BREAKING CHANGE v2.x with the API (see [examples](./examples/examples.go))
57+
- `generator.NewConfig()` is no longer required.
58+
59+
```go
60+
// initialise new configmanager instance
61+
cm := configmanager.New(context.TODO())
62+
// add additional config to apply on your tokens
63+
cm.Config.WithTokenSeparator("://")
64+
pm, err := cm.Retrieve([]string{"IMPLEMENTATION://token1", "IMPLEMENTATION:// token2","ANOTHER_IMPL://token1"})
65+
```
66+
67+
- `RetrieveUnmarshalledFromYaml`|`RetrieveUnmarshalledFromJson`|`RetrieveMarshalledJson`|`RetrieveMarshalledYaml` methods are now on the ConfigManager struct, see `exampleRetrieveYamlMarshalled` or `exampleRetrieveYamlUnmarshalled` in [examples](./examples/examples.go)
68+
5669
- Kubernetes
5770

5871
Avoid storing overly large configmaps and especially using secrets objects to store actual secrets e.g. DB passwords, 3rd party API creds, etc... By only storing a config file or a script containing only the tokens e.g. `AWSSECRETS#/$ENV/service/db-config` it can be git committed without writing numerous shell scripts, only storing either some interpolation vars like `$ENV` in a configmap or the entire configmanager token for smaller use cases.

cmd/configmanager/fromfileinput.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package cmd
22

33
import (
4-
"context"
54
"fmt"
65

76
"github.com/dnitsch/configmanager"
87
"github.com/dnitsch/configmanager/internal/cmdutils"
9-
"github.com/dnitsch/configmanager/pkg/generator"
108
"github.com/spf13/cobra"
119
)
1210

@@ -43,8 +41,7 @@ unix style output only`)
4341
}
4442

4543
func retrieveFromStr(cmd *cobra.Command, args []string) error {
46-
conf := generator.NewConfig().WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
47-
gv := generator.NewGenerator().WithConfig(conf).WithContext(context.Background())
48-
configManager := &configmanager.ConfigManager{}
49-
return cmdutils.New(gv, configManager).GenerateStrOut(input, path)
44+
cm := configmanager.New(cmd.Context())
45+
cm.Config.WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
46+
return cmdutils.New(cm).GenerateStrOut(input, path)
5047
}

cmd/configmanager/retrieve.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package cmd
22

33
import (
4-
"context"
54
"fmt"
65

76
"github.com/dnitsch/configmanager"
87
"github.com/dnitsch/configmanager/internal/cmdutils"
9-
"github.com/dnitsch/configmanager/pkg/generator"
108
"github.com/spf13/cobra"
119
)
1210

@@ -39,8 +37,7 @@ func init() {
3937
}
4038

4139
func retrieveRun(cmd *cobra.Command, args []string) error {
42-
conf := generator.NewConfig().WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
43-
gv := generator.NewGenerator().WithConfig(conf).WithContext(context.Background())
44-
configManager := &configmanager.ConfigManager{}
45-
return cmdutils.New(gv, configManager).GenerateFromCmd(tokens, path)
40+
cm := configmanager.New(cmd.Context())
41+
cm.Config.WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
42+
return cmdutils.New(cm).GenerateFromCmd(tokens, path)
4643
}

cmd/configmanager/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package cmd
22

33
import (
4+
"context"
45
"fmt"
56
"os"
67

@@ -20,8 +21,8 @@ var (
2021
}
2122
)
2223

23-
func Execute() {
24-
if err := configmanagerCmd.Execute(); err != nil {
24+
func Execute(ctx context.Context) {
25+
if err := configmanagerCmd.ExecuteContext(ctx); err != nil {
2526
fmt.Errorf("cli error: %v", err)
2627
os.Exit(1)
2728
}

cmd/main.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
package main
22

3-
import cfgmgr "github.com/dnitsch/configmanager/cmd/configmanager"
3+
import (
4+
"context"
5+
6+
cfgmgr "github.com/dnitsch/configmanager/cmd/configmanager"
7+
)
48

59
func main() {
610
// init loggerHere or in init function
7-
cfgmgr.Execute()
11+
cfgmgr.Execute(context.Background())
812
}

0 commit comments

Comments
 (0)