Skip to content

feat: add microcks validate command for pre-flight config verification#495

Open
A-d-i-t-y wants to merge 2 commits into
microcks:masterfrom
A-d-i-t-y:feat/validate-command
Open

feat: add microcks validate command for pre-flight config verification#495
A-d-i-t-y wants to merge 2 commits into
microcks:masterfrom
A-d-i-t-y:feat/validate-command

Conversation

@A-d-i-t-y

Copy link
Copy Markdown

Fixes #470

Summary

Adds a microcks validate command that runs pre-flight checks before
running imports or tests, so users catch configuration problems early
instead of mid-execution.

What it checks

  • Config file is present and parses correctly
  • A context is configured and resolvable
  • Auth token is valid (refreshed automatically if needed)
  • The target Microcks server is reachable

Exits with code 0 if all checks pass, 1 if any check fails —
suitable for CI/CD pre-flight gating.

@A-d-i-t-y

Copy link
Copy Markdown
Author

Hi @Harsh4902 @Vaishnav88sk

I've opened a PR for this issue: #495

It adds a 'microcks validate' command that runs pre-flight checks
(config validity, context resolution, auth token, server reachability)
before running imports/tests, as described in the issue. Included unit
tests and manually verified the build and CLI output.

I'm applying for the LFX Mentorship (Term 3) and would really appreciate
your review whenever you get a chance. Happy to make any changes needed!

@Vaishnav88sk

Copy link
Copy Markdown

Hi @Harsh4902 @Vaishnav88sk

I've opened a PR for this issue: #495

It adds a 'microcks validate' command that runs pre-flight checks (config validity, context resolution, auth token, server reachability) before running imports/tests, as described in the issue. Included unit tests and manually verified the build and CLI output.

I'm applying for the LFX Mentorship (Term 3) and would really appreciate your review whenever you get a chance. Happy to make any changes needed!

Thanks for the PR.
We are not sure about Microcks' participation in Term 3.

@Vaishnav88sk Vaishnav88sk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass the DCO

Comment thread cmd/validate.go Outdated
Comment on lines +46 to +55
Run: func(cmd *cobra.Command, args []string) {
ok := true

// 1. Config file presence and parsing.
configFile := globalClientOpts.ConfigPath
localConfig, err := config.ReadLocalConfig(configFile)
if err != nil {
fmt.Printf("✗ Config file: invalid — %v\n", err)
os.Exit(1)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReadLocalConfig() can return (nil, nil) for a missing file, but we print ✓ Config file: parsed successfully before checking whether any config/context actually exists. Please restructure this so the success message is only printed when there is a real config to validate.

Comment thread cmd/validate.go Outdated
Comment on lines +64 to +83
ctx, err := localConfig.ResolveContext(globalClientOpts.Context)
if err != nil {
fmt.Printf("✗ Context resolution: %v\n", err)
os.Exit(1)
}
fmt.Printf("✓ Context resolved: %q (server: %s)\n", ctx.Name, ctx.Server.Server)

// 3. Build a client for this context. NewClient() attempts a token
// refresh internally, so a failure here reveals an expired or
// invalid credential.
mc, err := connectors.NewClient(*globalClientOpts)
if err != nil {
fmt.Printf("✗ Authentication: %v\n", err)
ok = false
} else {
fmt.Println("✓ Authentication: token is valid")
}

// 4. Server reachability check (also confirms Keycloak config
// endpoint responds, covering both plain connectivity and

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This currently only validates the local config/context path.

Please also consider the direct connection mode that other commands support via --microcksURL together with --keycloakClientId / --keycloakClientSecret. For CI/CD pre-flight checks, that mode is at least as important as local config validation.

Comment thread cmd/validate.go Outdated
Comment on lines +31 to +42

var validateCmd = &cobra.Command{

Use: "validate",
Short: "Validate current Microcks CLI configuration and connectivity",
Long: `Runs pre-flight checks on the active Microcks context:
- config file is present and parses correctly
- a context is configured and resolvable
- the auth token is valid (refreshed if needed)
- the target Microcks server is reachable

Exits with code 0 if all checks pass, or 1 if any check fails.`,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command contract in #470 is broader than what is currently implemented.

Right now this checks config/context/auth/server reachability, but it does not implement the proposed service-account permission check or Async Minion connectivity check. Please either extend the implementation to cover those, or narrow the issue/PR scope explicitly.

Comment thread cmd/validate_test.go

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests do not actually exercise NewValidateCommand() or the command output/exit behavior.

They mostly re-test config.ReadLocalConfig() and ResolveContext(), which are existing helpers. Please add command-level tests for the new behavior itself: success path, missing config/context, and a failing auth/reachability path if possible.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a copyright block

Signed-off-by: A-d-i-t-y <aaaditya1909@gmail.com>
@A-d-i-t-y
A-d-i-t-y force-pushed the feat/validate-command branch from 722bd05 to ea1e04c Compare July 26, 2026 15:37
…ection mode, rewrite tests

Signed-off-by: A-d-i-t-y <aaaditya1909@gmail.com>
@A-d-i-t-y

Copy link
Copy Markdown
Author

Thanks for the detailed review, @Vaishnav88sk! Pushed a new commit (df3dfde) addressing all the points:

  • Fixed the message-ordering bug (config check now happens before printing success)
  • Added CI/CD direct-connection mode (--microcksURL + keycloak client creds), following the same pattern as cmd/test.go
  • Rewrote the tests to exercise runValidate() directly (success, missing-config, invalid-config, unreachable-server, and direct-mode-fallback paths)
  • Added copyright header to the test file
  • Narrowed scope explicitly in --help text regarding service-account/Async Minion checks (replied inline with details)

Ready for another look whenever you get a chance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add microcks validate command for pre-flight config verification

2 participants