-
Notifications
You must be signed in to change notification settings - Fork 6
fix(cli): move top-level command routing into folders #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ad05054
fix(cli): move top-level command routing into folders
Agent-Hellboy 39f11c4
refactor(cli): add shared runtime facade for command folders
Agent-Hellboy fa11c80
refactor(auth): move auth command logic into folder
Agent-Hellboy 2eef67a
refactor(cli): move command logic into folder packages
Agent-Hellboy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,12 +3,132 @@ package access | |
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| "go.uber.org/zap" | ||
|
|
||
| "mcp-runtime/internal/cli" | ||
| ) | ||
|
|
||
| const ( | ||
| grantResource = "mcpaccessgrant" | ||
| sessionResource = "mcpagentsession" | ||
| ) | ||
|
|
||
| // New returns the access command. | ||
| func New(logger *zap.Logger) *cobra.Command { | ||
| return cli.NewAccessCmd(logger) | ||
| func New(runtime *cli.Runtime) *cobra.Command { | ||
| return NewWithManager(runtime.AccessManager()) | ||
| } | ||
|
|
||
| // NewWithManager returns the access command using the provided manager. | ||
| func NewWithManager(mgr *cli.AccessManager) *cobra.Command { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| cmd := &cobra.Command{ | ||
| Use: "access", | ||
| Short: "Manage grants and agent sessions", | ||
| Long: `Commands for managing MCPAccessGrant and MCPAgentSession resources that feed the gateway policy layer. | ||
|
|
||
| With mcp-runtime auth login, commands use the platform API by default. Use --use-kube | ||
| to target the cluster with kubectl and a kubeconfig (cluster admin path).`, | ||
| } | ||
|
|
||
| mgr.BindUseKubeFlag(cmd) | ||
|
|
||
| cmd.AddCommand(newGrantCmd(mgr), newSessionCmd(mgr)) | ||
| return cmd | ||
| } | ||
|
|
||
| func newGrantCmd(mgr *cli.AccessManager) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "grant", | ||
| Short: "Manage MCPAccessGrant resources", | ||
| } | ||
| cmd.AddCommand(newListCmd(mgr, grantResource, "grants")) | ||
| cmd.AddCommand(newGetCmd(mgr, grantResource, "grant")) | ||
| cmd.AddCommand(newApplyCmd(mgr, "grant")) | ||
| cmd.AddCommand(newDeleteCmd(mgr, grantResource, "grant")) | ||
| cmd.AddCommand(newToggleCmd(mgr, grantResource, "disable", "Disable a grant", true)) | ||
| cmd.AddCommand(newToggleCmd(mgr, grantResource, "enable", "Enable a grant", false)) | ||
| return cmd | ||
| } | ||
|
|
||
| func newSessionCmd(mgr *cli.AccessManager) *cobra.Command { | ||
| cmd := &cobra.Command{ | ||
| Use: "session", | ||
| Short: "Manage MCPAgentSession resources", | ||
| } | ||
| cmd.AddCommand(newListCmd(mgr, sessionResource, "sessions")) | ||
| cmd.AddCommand(newGetCmd(mgr, sessionResource, "session")) | ||
| cmd.AddCommand(newApplyCmd(mgr, "session")) | ||
| cmd.AddCommand(newDeleteCmd(mgr, sessionResource, "session")) | ||
| cmd.AddCommand(newToggleCmd(mgr, sessionResource, "revoke", "Revoke an agent session", true)) | ||
| cmd.AddCommand(newToggleCmd(mgr, sessionResource, "unrevoke", "Clear the revoked flag on an agent session", false)) | ||
| return cmd | ||
| } | ||
|
|
||
| func newListCmd(mgr *cli.AccessManager, resource, label string) *cobra.Command { | ||
| var namespace string | ||
| var allNamespaces bool | ||
| cmd := &cobra.Command{ | ||
| Use: "list", | ||
| Short: "List access " + label, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return mgr.ListAccessResources(resource, namespace, allNamespaces) | ||
| }, | ||
| } | ||
| cmd.Flags().StringVar(&namespace, "namespace", "", "Namespace to inspect") | ||
| cmd.Flags().BoolVar(&allNamespaces, "all-namespaces", true, "List resources across all namespaces when no namespace is specified") | ||
| return cmd | ||
| } | ||
|
|
||
| func newGetCmd(mgr *cli.AccessManager, resource, label string) *cobra.Command { | ||
| var namespace string | ||
| cmd := &cobra.Command{ | ||
| Use: "get [name]", | ||
| Short: "Get an access " + label, | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return mgr.GetAccessResource(resource, args[0], namespace) | ||
| }, | ||
| } | ||
| cmd.Flags().StringVar(&namespace, "namespace", cli.NamespaceMCPServers, "Namespace") | ||
| return cmd | ||
| } | ||
|
|
||
| func newApplyCmd(mgr *cli.AccessManager, label string) *cobra.Command { | ||
| var file string | ||
| cmd := &cobra.Command{ | ||
| Use: "apply", | ||
| Short: "Apply a " + label + " manifest", | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return mgr.ApplyAccessResource(file) | ||
| }, | ||
| } | ||
| cmd.Flags().StringVar(&file, "file", "", "Manifest file to apply") | ||
| _ = cmd.MarkFlagRequired("file") | ||
| return cmd | ||
| } | ||
|
|
||
| func newDeleteCmd(mgr *cli.AccessManager, resource, label string) *cobra.Command { | ||
| var namespace string | ||
| cmd := &cobra.Command{ | ||
| Use: "delete [name]", | ||
| Short: "Delete an access " + label, | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return mgr.DeleteAccessResource(resource, args[0], namespace) | ||
| }, | ||
| } | ||
| cmd.Flags().StringVar(&namespace, "namespace", cli.NamespaceMCPServers, "Namespace") | ||
| return cmd | ||
| } | ||
|
|
||
| func newToggleCmd(mgr *cli.AccessManager, resource, use, short string, value bool) *cobra.Command { | ||
| var namespace string | ||
| cmd := &cobra.Command{ | ||
| Use: use + " [name]", | ||
| Short: short, | ||
| Args: cobra.ExactArgs(1), | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| return mgr.ToggleAccessResource(resource, args[0], namespace, value) | ||
| }, | ||
| } | ||
| cmd.Flags().StringVar(&namespace, "namespace", cli.NamespaceMCPServers, "Namespace") | ||
| return cmd | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These resource name constants are duplicated from
internal/cli/access.go. To ensure consistency and avoid potential runtime errors if the strings diverge, consider exporting the constants from theclipackage (e.g.,AccessGrantResource) and referencing them here.