Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,21 @@ jobs:
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: install deps
run: |
apt-get update && apt-get install -y jq git
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config user.email ${{ github.actor }}-ci@gha.org
git config user.name ${{ github.actor }}
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: '5.x'
- name: Set SemVer Version
uses: gittools/actions/gitversion/execute@v0.9.15
uses: gittools/actions/gitversion/execute@v1.1.1
id: gitversion

- name: echo VERSIONS
Expand All @@ -30,14 +36,14 @@ jobs:
test:
runs-on: ubuntu-latest
container:
image: golang:1.19-bullseye
image: golang:1.21-bullseye
needs: set-version
env:
SEMVER: ${{ needs.set-version.outputs.semVer }}
GIT_TAG: ${{ needs.set-version.outputs.semVer }}
GOVCS: false
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: install deps
Expand All @@ -50,7 +56,7 @@ jobs:
run: |
make REVISION=$GITHUB_SHA test
- name: Publish Junit style Test Report
uses: mikepenz/action-junit-report@v3
uses: mikepenz/action-junit-report@v4
if: always() # always run even if the previous step fails
with:
report_paths: '**/.coverage/report-junit.xml'
Expand Down
18 changes: 12 additions & 6 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,32 @@ jobs:
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: install deps
run: |
apt-get update && apt-get install -y jq git
git config --global --add safe.directory "$GITHUB_WORKSPACE"
git config user.email ${{ github.actor }}-ci@gha.org
git config user.name ${{ github.actor }}
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: '5.x'
- name: Set SemVer Version
uses: gittools/actions/gitversion/execute@v0.9.15
uses: gittools/actions/gitversion/execute@v1.1.1
id: gitversion
pr:
runs-on: ubuntu-latest
container:
image: golang:1.19-bullseye
image: golang:1.21-bullseye
needs: set-version
env:
REVISION: $GITHUB_SHA
SEMVER: ${{ needs.set-version.outputs.semVer }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: install deps
run: |
apt-get update && apt-get install -y jq git
Expand All @@ -42,7 +48,7 @@ jobs:
run: |
make REVISION=$GITHUB_SHA test
- name: Publish Junit style Test Report
uses: mikepenz/action-junit-report@v3
uses: mikepenz/action-junit-report@v4
if: always() # always run even if the previous step fails
with:
report_paths: '**/report-junit.xml'
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ jobs:
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v0.9.15
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: '5.x'
- name: Set SemVer Version
uses: gittools/actions/gitversion/execute@v0.9.15
uses: gittools/actions/gitversion/execute@v1.1.1
id: gitversion

- name: echo VERSIONS
Expand All @@ -33,14 +33,14 @@ jobs:
release:
runs-on: ubuntu-latest
container:
image: golang:1.19-bullseye
image: golang:1.21-bullseye
env:
FOO: Bar
needs: set-version
env:
SEMVER: ${{ needs.set-version.outputs.semVer }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
fetch-depth: 1
- name: install deps
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ LDFLAGS := -ldflags="-s -w -X \"github.com/$(OWNER)/$(NAME)/cmd/configmanager.Ve
.PHONY: test test_ci tidy install cross-build

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

test_ci:
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ Where `configVar` can be either a parseable string `'som3#!S$CRet'` or a number

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).

> BREAKING CHANGE v2.x with the API (see [examples](./examples/examples.go))
- `generator.NewConfig()` is no longer required.

```go
// initialise new configmanager instance
cm := configmanager.New(context.TODO())
// add additional config to apply on your tokens
cm.Config.WithTokenSeparator("://")
pm, err := cm.Retrieve([]string{"IMPLEMENTATION://token1", "IMPLEMENTATION:// token2","ANOTHER_IMPL://token1"})
```

- `RetrieveUnmarshalledFromYaml`|`RetrieveUnmarshalledFromJson`|`RetrieveMarshalledJson`|`RetrieveMarshalledYaml` methods are now on the ConfigManager struct, see `exampleRetrieveYamlMarshalled` or `exampleRetrieveYamlUnmarshalled` in [examples](./examples/examples.go)

- Kubernetes

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.
Expand Down
9 changes: 3 additions & 6 deletions cmd/configmanager/fromfileinput.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cmd

import (
"context"
"fmt"

"github.com/dnitsch/configmanager"
"github.com/dnitsch/configmanager/internal/cmdutils"
"github.com/dnitsch/configmanager/pkg/generator"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -43,8 +41,7 @@ unix style output only`)
}

func retrieveFromStr(cmd *cobra.Command, args []string) error {
conf := generator.NewConfig().WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
gv := generator.NewGenerator().WithConfig(conf).WithContext(context.Background())
configManager := &configmanager.ConfigManager{}
return cmdutils.New(gv, configManager).GenerateStrOut(input, path)
cm := configmanager.New(cmd.Context())
cm.Config.WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
return cmdutils.New(cm).GenerateStrOut(input, path)
}
9 changes: 3 additions & 6 deletions cmd/configmanager/retrieve.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package cmd

import (
"context"
"fmt"

"github.com/dnitsch/configmanager"
"github.com/dnitsch/configmanager/internal/cmdutils"
"github.com/dnitsch/configmanager/pkg/generator"
"github.com/spf13/cobra"
)

Expand Down Expand Up @@ -39,8 +37,7 @@ func init() {
}

func retrieveRun(cmd *cobra.Command, args []string) error {
conf := generator.NewConfig().WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
gv := generator.NewGenerator().WithConfig(conf).WithContext(context.Background())
configManager := &configmanager.ConfigManager{}
return cmdutils.New(gv, configManager).GenerateFromCmd(tokens, path)
cm := configmanager.New(cmd.Context())
cm.Config.WithTokenSeparator(tokenSeparator).WithOutputPath(path).WithKeySeparator(keySeparator)
return cmdutils.New(cm).GenerateFromCmd(tokens, path)
}
5 changes: 3 additions & 2 deletions cmd/configmanager/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"context"
"fmt"
"os"

Expand All @@ -20,8 +21,8 @@ var (
}
)

func Execute() {
if err := configmanagerCmd.Execute(); err != nil {
func Execute(ctx context.Context) {
if err := configmanagerCmd.ExecuteContext(ctx); err != nil {
fmt.Errorf("cli error: %v", err)
os.Exit(1)
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package main

import cfgmgr "github.com/dnitsch/configmanager/cmd/configmanager"
import (
"context"

cfgmgr "github.com/dnitsch/configmanager/cmd/configmanager"
)

func main() {
// init loggerHere or in init function
cfgmgr.Execute()
cfgmgr.Execute(context.Background())
}
Loading