Merge pull request #212 from foomo/feature/sesamy-cli-0.24.0

feature: sesamy cli 0.24.0
This commit is contained in:
Kevin Franklin Kim 2025-06-05 12:13:49 +02:00 committed by GitHub
commit cd5826e85c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
17 changed files with 209 additions and 4 deletions

15
.husky.yaml Normal file
View File

@ -0,0 +1,15 @@
hooks:
pre-commit:
- golangci-lint run --fast
- husky lint-staged
commit-msg:
# only execute if not in a merge
- if [[ -z $(git rev-parse -q --verify MERGE_HEAD) ]]; then husky lint-commit; fi
lint-staged:
'*.go':
- golangci-lint fmt
lint-commit:
types: '^(feat|fix|build|chore|docs|perf|refactor|revert|style|test|wip)$'
header: '^(?P<type>\w+)(\((?P<scope>[\w/.-]+)\))?(?P<breaking>!)?:( +)?(?P<header>.+)'

3
.husky/applypatch-msg Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/commit-msg Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/fsmonitor-watchman Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/post-update Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-applypatch Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-commit Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-merge-commit Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-push Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-rebase Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/pre-receive Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/prepare-commit-msg Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/push-to-checkout Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/sendemail-validate Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

3
.husky/update Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
husky hook $(basename "$0") $*

View File

@ -1,6 +1,21 @@
.DEFAULT_GOAL:=help
-include .makerc
# --- Targets -----------------------------------------------------------------
# This allows us to accept extra arguments
%: .husky
@:
.PHONY: .husky
# Configure git hooks for husky
.husky:
@if ! command -v husky &> /dev/null; then \
echo "ERROR: missing executeable 'husky', please run:"; \
echo "\n$ go install github.com/go-courier/husky/cmd/husky@latest\n"; \
fi
@git config core.hooksPath .husky
## === Tasks ===
.PHONY: tidy
@ -63,8 +78,8 @@ outdated:
.PHONY: test
## Run tests
test:
@GO_TEST_TAGS=-skip go test -coverprofile=coverage.out -race ./...
#@GO_TEST_TAGS=-skip go test -coverprofile=coverage.out -race -json ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
@GO_TEST_TAGS=-skip go test -coverprofile=coverage.out --tags=safe -race ./...
#@GO_TEST_TAGS=-skip go test -coverprofile=coverage.out --tags=safe -race -json ./... 2>&1 | tee /tmp/gotest.log | gotestfmt
.PHONY: lint.fix
## Fix lint violations

View File

@ -109,6 +109,25 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
Flags: flags,
Execute: inst.typescript,
},
{
Name: "open",
Description: "Open links in the browser",
Args: tree.Args{
{
Name: "name",
Description: "Name of the target",
Suggest: func(ctx context.Context, t tree.Root, r *readline.Readline) []goprompt.Suggest {
return []goprompt.Suggest{
{Text: "ga"},
{Text: "gtm-web"},
{Text: "gtm-server"},
}
},
},
configArg,
},
Execute: inst.open,
},
{
Name: "provision",
Description: "Provision Google Tag Manager",
@ -162,7 +181,6 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
{Text: "environments"},
{Text: "folders"},
{Text: "gtag-config"},
{Text: "status"},
{Text: "tags"},
{Text: "templates"},
{Text: "templates-data"},
@ -176,6 +194,10 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
},
configArg,
},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Default().Bool("raw", false, "print raw output")
return nil
},
Execute: inst.listWeb,
},
{
@ -206,10 +228,40 @@ func NewCommand(l log.Logger, op *onepassword.OnePassword, opts ...CommandOption
},
configArg,
},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Default().Bool("raw", false, "print raw output")
return nil
},
Execute: inst.listServer,
},
},
},
{
Name: "diff",
Description: "Print Google Tag Manager Status diff",
Nodes: tree.Nodes{
{
Name: "web",
Description: "Print Web Container Status diff",
Args: tree.Args{configArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Default().Bool("raw", false, "print raw output")
return nil
},
Execute: inst.diffWeb,
},
{
Name: "server",
Description: "Print Server Container Status diff",
Args: tree.Args{configArg},
Flags: func(ctx context.Context, r *readline.Readline, fs *readline.FlagSets) error {
fs.Default().Bool("raw", false, "print raw output")
return nil
},
Execute: inst.diffServer,
},
},
},
},
})
@ -334,6 +386,41 @@ func (c *Command) tags(ctx context.Context, r *readline.Readline) error {
return nil
}
func (c *Command) open(ctx context.Context, r *readline.Readline) error {
var paths []string
if r.Args().HasIndex(2) {
paths = []string{r.Args().At(2)}
} else {
paths = c.paths(ctx)
}
c.l.Info("Running sesamy open ...")
for _, value := range paths {
c.l.Info("└ " + value)
b, err := c.merge(ctx, value)
if err != nil {
return errors.Wrap(err, "failed to merge config")
}
out, err := c.op.Render(ctx, string(b))
if err != nil {
pterm.Error.Println(string(b))
return errors.Wrap(err, "failed to render secrets")
}
if err := shell.New(ctx, c.l, "sesamy", "open", r.Args().At(1)).
Args(r.Flags()...).
Args("--config", "-").
Args(r.AdditionalArgs()...).
Stdin(bytes.NewReader(out)).
Run(); err != nil {
return err
}
}
return nil
}
func (c *Command) typescript(ctx context.Context, r *readline.Readline) error {
var paths []string
if r.Args().HasIndex(1) {
@ -431,6 +518,7 @@ func (c *Command) listServer(ctx context.Context, r *readline.Readline) error {
}
func (c *Command) list(ctx context.Context, r *readline.Readline, cmd string) error {
fs := r.FlagSets().Default()
resource := r.Args().At(2)
var paths []string
@ -456,7 +544,52 @@ func (c *Command) list(ctx context.Context, r *readline.Readline, cmd string) er
}
if err := shell.New(ctx, c.l, "sesamy", "list", cmd, resource).
Args(r.Flags()...).
Args(fs.Visited().Args()...).
Args("--config", "-").
Args(r.AdditionalArgs()...).
Stdin(bytes.NewReader(out)).
Run(); err != nil {
return err
}
}
return nil
}
func (c *Command) diffWeb(ctx context.Context, r *readline.Readline) error {
return c.diff(ctx, r, "web")
}
func (c *Command) diffServer(ctx context.Context, r *readline.Readline) error {
return c.diff(ctx, r, "server")
}
func (c *Command) diff(ctx context.Context, r *readline.Readline, cmd string) error {
fs := r.FlagSets().Default()
var paths []string
if r.Args().HasIndex(2) {
paths = []string{r.Args().At(2)}
} else {
paths = c.paths(ctx)
}
c.l.Info("Running sesamy diff " + cmd + " ...")
for _, value := range paths {
c.l.Info("└ " + value)
b, err := c.merge(ctx, value)
if err != nil {
return errors.Wrap(err, "failed to merge config")
}
out, err := c.op.Render(ctx, string(b))
if err != nil {
pterm.Error.Println(string(b))
return errors.Wrap(err, "failed to render secrets")
}
if err := shell.New(ctx, c.l, "sesamy", "diff", cmd).
Args(fs.Visited().Args()...).
Args("--config", "-").
Args(r.AdditionalArgs()...).
Stdin(bytes.NewReader(out)).