Skip to content
Open
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
Empty file added .eirctl/.gitkeep
Empty file.
5 changes: 5 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
* text eol=lf
*.jpg binary
*.jpeg binary
*.png binary
*.gif binary
17 changes: 12 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ permissions:

jobs:
set-version:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
container:
image: mcr.microsoft.com/dotnet/sdk:6.0
image: mcr.microsoft.com/dotnet/sdk:10.0
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
Expand All @@ -29,10 +29,12 @@ jobs:
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@v3.0.0
with:
versionSpec: "5.x"

- name: Set SemVer Version
uses: gittools/actions/gitversion/execute@v3.0.0
id: gitversion
Expand All @@ -43,7 +45,7 @@ jobs:
echo "VERSION -> $GITVERSION_SEMVER"

test:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: set-version
env:
SEMVER: ${{ needs.set-version.outputs.semVer }}
Expand All @@ -52,17 +54,22 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 1
fetch-depth: 0

- name: Install Eirctl
uses: ensono/actions/eirctl-setup@v0.3.1
with:
version: 0.9.3
version: 0.11.2
isPrerelease: false

- name: Run Commit Lint
run: |
eirctl commit-lint

- name: Run Lint
run: |
eirctl run pipeline lints

- name: Run Tests
run: |
eirctl run pipeline gha:unit:test
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ permissions:

jobs:
set-version:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
if: ${{ github.event.workflow_run.head_branch == 'master' && github.event.workflow_run.conclusion == 'success' }}
container:
image: mcr.microsoft.com/dotnet/sdk:6.0
image: mcr.microsoft.com/dotnet/sdk:10.0
outputs:
semVer: ${{ steps.gitversion.outputs.semVer }}
steps:
Expand All @@ -39,7 +39,7 @@ jobs:
id: gitversion

release:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: set-version
env:
SEMVER: ${{ needs.set-version.outputs.semVer }}
Expand All @@ -50,7 +50,7 @@ jobs:

- name: Install Eirctl
uses: ensono/actions/eirctl-setup@v0.3.1
with:
with:
version: 0.7.6
isPrerelease: false

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/release_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ on:
workflows: ['Lint and Test']
types:
- completed
branches:
branches:
- main

permissions:
contents: write
packages: write
packages: write

jobs:
set-version-tag:
Expand All @@ -33,7 +33,7 @@ jobs:
id: gitversion

build-and-push:
runs-on: ubuntu-latest
runs-on: ubuntu-24.04
needs: set-version-tag
env:
SEMVER: ${{ needs.set-version-tag.outputs.semVer }}
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ dist

# local testers and
local/

# Eirctl
eirctl.env
.eirctl/*
!.eirctl/.gitkeep
9 changes: 9 additions & 0 deletions GitVersion.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Conventional Commits versioning rules:
# Major: any type with ! (e.g. feat!:, fix(scope)!:) or BREAKING CHANGE in commit footer
# Minor: feat: or feat(scope):
# Patch: all other types (fix:, refactor:, debug:, chore:, etc.)
mode: Mainline
commit-message-incrementing: Enabled
major-version-bump-message: '^(\w+)(\(\w+\))?!:|BREAKING CHANGE'
minor-version-bump-message: '^feat(\(\w+\))?:'
patch-version-bump-message: '^(\w+)(\(\w+\))?:'
9 changes: 6 additions & 3 deletions cmd/configmanager/configmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var (

type rootCmdFlags struct {
verbose bool
strict bool
tokenSeparator string
keySeparator string
enableEnvSubst bool
Expand All @@ -38,14 +39,16 @@ func NewRootCmd(logger log.ILogger) *Root { //channelOut, channelErr io.Writer
Short: fmt.Sprintf("%s CLI for retrieving and inserting config or secret variables", config.SELF_NAME),
Long: fmt.Sprintf(`%s CLI for retrieving config or secret variables.
Using a specific tokens as an array item`, config.SELF_NAME),
SilenceUsage: true,
Version: fmt.Sprintf("%s-%s", Version, Revision),
SilenceUsage: true,
SilenceErrors: true,
Version: fmt.Sprintf("%s-%s", Version, Revision),
},
logger: logger,
rootFlags: &rootCmdFlags{},
}

rc.Cmd.PersistentFlags().BoolVarP(&rc.rootFlags.verbose, "verbose", "v", false, "Verbosity level")
rc.Cmd.PersistentFlags().BoolVar(&rc.rootFlags.strict, "strict", false, "Exit with a non-zero exit code if any provider fails")
rc.Cmd.PersistentFlags().StringVarP(&rc.rootFlags.tokenSeparator, "token-separator", "s", "#", "Separator to use to mark concrete store and the key within it")
rc.Cmd.PersistentFlags().StringVarP(&rc.rootFlags.keySeparator, "key-separator", "k", "|", "Separator to use to mark a key look up in a map. e.g. AWSSECRETS#/token/map|key1")
rc.Cmd.PersistentFlags().BoolVarP(&rc.rootFlags.enableEnvSubst, "enable-envsubst", "e", false, "Enable envsubst on input. This will fail on any unset or empty variables")
Expand All @@ -72,7 +75,7 @@ func cmdutilsInit(rootCmd *Root, cmd *cobra.Command, path string) (*cmdutils.Cmd
}

cm := configmanager.New(cmd.Context())
cm.Config.WithTokenSeparator(rootCmd.rootFlags.tokenSeparator).WithOutputPath(path).WithKeySeparator(rootCmd.rootFlags.keySeparator).WithEnvSubst(rootCmd.rootFlags.enableEnvSubst)
cm.Config.WithTokenSeparator(rootCmd.rootFlags.tokenSeparator).WithOutputPath(path).WithKeySeparator(rootCmd.rootFlags.keySeparator).WithEnvSubst(rootCmd.rootFlags.enableEnvSubst).WithStrict(rootCmd.rootFlags.strict)
gnrtr := generator.NewGenerator(cmd.Context(), func(gv *generator.GenVars) {
if rootCmd.rootFlags.verbose {
rootCmd.logger.SetLevel(log.DebugLvl)
Expand Down
12 changes: 10 additions & 2 deletions cmd/configmanager/fromfileinput.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package cmd

import (
"fmt"
"os"

"github.com/DevLabFoundry/configmanager/v2/internal/cmdutils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -30,9 +31,16 @@ func newFromStrCmd(rootCmd *Root) {
if err != nil {
return err
}
defer outputWriter.Close()

return cu.GenerateStrOut(inputReader, f.input == f.path)
err = cu.GenerateStrOut(inputReader, f.input == f.path)
outputWriter.Close()
if err != nil {
if rootCmd.rootFlags.strict && f.path != "stdout" {
os.Remove(f.path)
}
return err
}
return nil
},
PreRunE: func(cmd *cobra.Command, args []string) error {
if len(f.input) < 1 {
Expand Down
4 changes: 4 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package main

import (
"context"
"fmt"
"os"

cfgmgr "github.com/DevLabFoundry/configmanager/v2/cmd/configmanager"
"github.com/DevLabFoundry/configmanager/v2/internal/log"
)

const redTerminal = "\x1b[31m%s\x1b[0m"

func main() {
logger := log.New(os.Stderr)
cmd := cfgmgr.NewRootCmd(logger)
if err := cmd.Execute(context.Background()); err != nil {
fmt.Fprintf(os.Stderr, redTerminal+"\n", err)
os.Exit(1)
}
}
10 changes: 10 additions & 0 deletions committed.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# committed.toml
# Enforces Conventional Commits format: type(scope)?!?: subject
# Versioning impact (configured in GitVersion.yaml):
# Major: any type with ! suffix (e.g. feat!:, fix(scope)!:) or BREAKING CHANGE in footer
# Minor: feat: or feat(scope):
# Patch: all other types (fix:, refactor:, debug:, chore:, etc.)

style = "conventional"
subject_capitalized = false
imperative_subject = false
34 changes: 31 additions & 3 deletions eirctl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,18 @@ contexts:
container:
name: mirror.gcr.io/bash:5.0.18-alpine3.22

committed:
container:
name: alpine:3
shell: /bin/sh
shell_args: ["-c"]

pipelines:
commit-lint:
- task: lint:commits

gha:unit:test:
- pipeline: test:unit
- pipeline: test:unit
env:
ROOT_PKG_NAME: github.com/DevLabFoundry
- task: sonar:coverage:prep
Expand All @@ -30,6 +39,26 @@ pipelines:
depends_on: clean

tasks:
lint:commits:
context: committed
description: Lint commit messages against Conventional Commits using committed
command:
- |
apk add --no-cache git
git config --global safe.directory '*'
if [ ! -f /eirctl/.eirctl/committed ]; then
echo "Downloading committed binary..."
wget -qO- https://github.com/crate-ci/committed/releases/download/v1.1.11/committed-v1.1.11-x86_64-unknown-linux-musl.tar.gz \
| tar xz -C /tmp
install -m 755 /tmp/committed /eirctl/.eirctl/committed
fi
if [ -n "$GITHUB_BASE_REF" ]; then
RANGE="HEAD^1..HEAD^2"
else
RANGE="origin/main..HEAD"
fi
/eirctl/.eirctl/committed $RANGE --no-merge-commit

show:coverage:
description: Opens the current coverage viewer for the the configmanager utility.
command: go tool cover -html=.coverage/out
Expand All @@ -39,7 +68,6 @@ tasks:
Opens a webview with godoc running
Already filters the packages to this one and enables
internal/private package documentation
# go install golang.org/x/tools/cmd/godoc@latest
command: |
open http://localhost:6060/pkg/github.com/DevLabFoundry/configmanager/v2/?m=all
godoc -notes "BUG|TODO" -play -http=:6060
Expand Down Expand Up @@ -90,7 +118,7 @@ tasks:
sonar:coverage:prep:
context: bash
command:
- |
- |
sed -i 's|github.com/DevLabFoundry/configmanager/v2/||g' .coverage/out
echo "Coverage file first 20 lines after conversion:"
head -20 .coverage/out
Expand Down
3 changes: 2 additions & 1 deletion internal/cmdutils/cmdutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ func (c *CmdUtils) generateFromToken(tokens []string) error {
pm, err := c.configManager.Retrieve(tokens)
if err != nil {
// return full error to terminal if no tokens were parsed
if len(pm) < 1 {
// or if strict mode is enabled
if len(pm) < 1 || c.configManager.GeneratorConfig().Strict() {
return err
}
c.logger.Error("%v", err)
Expand Down
12 changes: 12 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ type GenVarsConfig struct {
tokenSeparator string
keySeparator string
enableEnvSubst bool
strict bool
// parseAdditionalVars func(token string) TokenConfigVars
}

Expand Down Expand Up @@ -94,6 +95,12 @@ func (c *GenVarsConfig) WithEnvSubst(enabled bool) *GenVarsConfig {
return c
}

// WithStrict sets strict mode - errors from any provider will be returned
func (c *GenVarsConfig) WithStrict(strict bool) *GenVarsConfig {
c.strict = strict
return c
}

// OutputPath returns the outpath set in the config
func (c *GenVarsConfig) OutputPath() string {
return c.outpath
Expand All @@ -114,6 +121,11 @@ func (c *GenVarsConfig) EnvSubstEnabled() bool {
return c.enableEnvSubst
}

// Strict returns whether strict mode is enabled
func (c *GenVarsConfig) Strict() bool {
return c.strict
}

// Config returns the derefed value
func (c *GenVarsConfig) Config() GenVarsConfig {
cc := *c
Expand Down
2 changes: 1 addition & 1 deletion internal/strategy/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func Test_SelectImpl_With(t *testing.T) {
},
"success GCPSECRETS": {
func() func() {
cf, _ := os.CreateTemp(".", "*")
cf, _ := os.CreateTemp(os.TempDir(), "gcp-creds*")
cf.Write(TEST_GCP_CREDS)
os.Setenv("GOOGLE_APPLICATION_CREDENTIALS", cf.Name())
return func() {
Expand Down
Loading
Loading