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
64 changes: 64 additions & 0 deletions .github/workflows/callable-test-krbctl.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
name: krbctl tests

on:
workflow_call:

permissions:
contents: read

jobs:
krbctl-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1

- name: Set up Golang
uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0
with:
go-version-file: test/suites/go.mod
cache: false

- name: Compute build cache key
id: build-cache-key
run: |
checksum=$(
{
cat go.mod
[ -f go.sum ] && cat go.sum
cat Makefile
find cmd/krbctl -type f -name '*.go' -print0 | sort -z | xargs -0 cat
cat test/suites/go.mod test/suites/go.sum
find test/suites/krbctl -type f -print0 | sort -z | xargs -0 cat
} | md5sum | awk '{print $1}'
)
echo "checksum=$checksum" >> "$GITHUB_OUTPUT"

- name: Cache Go module cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/go/pkg/mod
key: krbctl-test-go-mod-${{ runner.os }}-${{ hashFiles('test/suites/go.sum') }}

- name: Cache Go build cache
uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v6.1.0
with:
path: ~/.cache/go-build
key: krbctl-test-go-build-${{ runner.os }}-${{ steps.build-cache-key.outputs.checksum }}
restore-keys: |
krbctl-test-go-build-${{ runner.os }}-

- name: Build krbctl
run: make build/krbctl

- name: Run krbctl tests
run: make test/krbctl/json

- name: Publish krbctl test results
uses: dorny/test-reporter@a43b3a5f7366b97d083190328d2c652e1a8b6aa2 # v3.0.0
if: always()
with:
name: krbctl Tests
path: build/krbctl-test-output.json
reporter: golang-json
fail-on-error: "false"
4 changes: 4 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ jobs:
needs: image
uses: ./.github/workflows/callable-test-connector.yaml
secrets: inherit

krbctl-test:
uses: ./.github/workflows/callable-test-krbctl.yaml
secrets: inherit
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,15 @@ test/connector/json:
@mkdir -p build
@cd test/suites/connector && go test -v -json ./... -count=1 -failfast > $(CURDIR)/build/connector-test-output.json

test/krbctl: krbctl/build
$(call cecho,Running krbctl tests for Kerberos...,$(BOLD_YELLOW))
@cd test/suites/krbctl && KRBCTL_BIN=$(CURDIR)/build/krbctl go test -v ./... -count=1 -failfast

test/krbctl/json: krbctl/build
$(call cecho,Running krbctl tests for Kerberos...,$(BOLD_YELLOW))
@mkdir -p build
@cd test/suites/krbctl && KRBCTL_BIN=$(CURDIR)/build/krbctl go test -v -json ./... -count=1 -failfast > $(CURDIR)/build/krbctl-test-output.json

test/unit:
$(call cecho,Running unit tests for Kerberos...,$(BOLD_YELLOW))
@mkdir -p build
Expand Down
66 changes: 59 additions & 7 deletions cmd/krbctl/cmd/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ postgres, admin-connector, echo) can be included or skipped at each step.`,
}

cmd.Flags().StringP("output", "o", ".", "Output path where compose.yaml will be written.")
cmd.Flags().BoolP("non-interactive", "y", false,
"Skip prompts and build compose.yaml from flag values.")
cmd.Flags().Bool("echo", false, "Include the echo service. (non-interactive mode only)")
cmd.Flags().Bool("obs-stack", false,
"Include the observability stack. (non-interactive mode only)")
cmd.Flags().Bool("postgres", false,
"Use PostgreSQL as the persistence backend. (non-interactive mode only)")
cmd.Flags().Bool("connector", false,
"Include the admin-connector service. (non-interactive mode only)")

return cmd
}
Expand All @@ -43,8 +52,38 @@ func runCompose(cmd *cobra.Command, _ []string) error {
return err
}

nonInteractive, err := cmd.Flags().GetBool("non-interactive")
if err != nil {
return err
}

opts := &composeOptions{outputPath: output}

if nonInteractive {
if err := collectComposeFromFlags(cmd, opts); err != nil {
return err
}
} else if err := collectComposeInteractive(opts); err != nil {
return err
}

content := buildCompose(opts)

//nolint:gosec // welp
if err := os.WriteFile(
filepath.Join(opts.outputPath, "compose.yaml"), []byte(content), 0o644,
); err != nil {
return fmt.Errorf("failed to write compose file: %w", err)
}

fmt.Fprintf(os.Stdout, "\ncompose.yaml written to %s\n", opts.outputPath)

return nil
}

// collectComposeInteractive drives the interactive huh form, populating opts
// with the user's answers.
func collectComposeInteractive(opts *composeOptions) error {
form := huh.NewForm(
huh.NewGroup(
huh.NewConfirm().
Expand Down Expand Up @@ -76,16 +115,29 @@ func runCompose(cmd *cobra.Command, _ []string) error {
return fmt.Errorf("prompt cancelled: %w", err)
}

content := buildCompose(opts)
return nil
}

//nolint:gosec // welp
if err := os.WriteFile(
filepath.Join(opts.outputPath, "compose.yaml"), []byte(content), 0o644,
); err != nil {
return fmt.Errorf("failed to write compose file: %w", err)
// collectComposeFromFlags populates opts from the command's flag values for
// non-interactive runs.
func collectComposeFromFlags(cmd *cobra.Command, opts *composeOptions) error {
var err error

if opts.includeEcho, err = cmd.Flags().GetBool("echo"); err != nil {
return err
}

fmt.Fprintf(os.Stdout, "\ncompose.yaml written to %s\n", opts.outputPath)
if opts.includeObsStack, err = cmd.Flags().GetBool("obs-stack"); err != nil {
return err
}

if opts.includePostgres, err = cmd.Flags().GetBool("postgres"); err != nil {
return err
}

if opts.includeConnector, err = cmd.Flags().GetBool("connector"); err != nil {
return err
}

return nil
}
Expand Down
Loading