-
Notifications
You must be signed in to change notification settings - Fork 110
feat(cli,sdk,manifests): credential name resolution + platform ingress NetworkPolicy #1566
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
base: main
Are you sure you want to change the base?
Changes from all commits
f416ffa
d3e8af6
9f7a581
744567d
a5ef660
23d8958
c02c788
023434e
67b00e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -9,6 +9,7 @@ import ( | |
| "github.com/ambient-code/platform/components/ambient-cli/pkg/config" | ||
| "github.com/ambient-code/platform/components/ambient-cli/pkg/connection" | ||
| "github.com/ambient-code/platform/components/ambient-cli/pkg/output" | ||
| sdkclient "github.com/ambient-code/platform/components/ambient-sdk/go-sdk/client" | ||
| sdktypes "github.com/ambient-code/platform/components/ambient-sdk/go-sdk/types" | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
@@ -103,7 +104,11 @@ var getCmd = &cobra.Command{ | |
| ctx, cancel := context.WithTimeout(context.Background(), cfg.GetRequestTimeout()) | ||
| defer cancel() | ||
|
|
||
| credential, err := client.Credentials().Get(ctx, args[0]) | ||
| credID, err := resolveCredentialID(ctx, client, args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| credential, err := client.Credentials().Get(ctx, credID) | ||
| if err != nil { | ||
| return fmt.Errorf("get credential %q: %w", args[0], err) | ||
| } | ||
|
|
@@ -187,7 +192,7 @@ var createCmd = &cobra.Command{ | |
| return fmt.Errorf("build credential: %w", err) | ||
| } | ||
|
|
||
| created, err := client.Credentials().Create(ctx, cred) | ||
| created, err := client.Credentials().CreateCompat(ctx, cred) | ||
| if err != nil { | ||
| return fmt.Errorf("create credential: %w", err) | ||
| } | ||
|
|
@@ -259,7 +264,11 @@ var updateCmd = &cobra.Command{ | |
| patch = patch.Annotations(updateArgs.annotations) | ||
| } | ||
|
|
||
| updated, err := client.Credentials().Update(ctx, args[0], patch.Build()) | ||
| credID, err := resolveCredentialID(ctx, client, args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| updated, err := client.Credentials().Update(ctx, credID, patch.Build()) | ||
| if err != nil { | ||
| return fmt.Errorf("update credential: %w", err) | ||
| } | ||
|
|
@@ -296,7 +305,11 @@ var deleteCmd = &cobra.Command{ | |
| ctx, cancel := context.WithTimeout(context.Background(), cfg.GetRequestTimeout()) | ||
| defer cancel() | ||
|
|
||
| if err := client.Credentials().Delete(ctx, args[0]); err != nil { | ||
| credID, err := resolveCredentialID(ctx, client, args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := client.Credentials().Delete(ctx, credID); err != nil { | ||
| return fmt.Errorf("delete credential: %w", err) | ||
| } | ||
|
|
||
|
|
@@ -329,7 +342,11 @@ var tokenCmd = &cobra.Command{ | |
| ctx, cancel := context.WithTimeout(context.Background(), cfg.GetRequestTimeout()) | ||
| defer cancel() | ||
|
|
||
| resp, err := client.Credentials().GetToken(ctx, args[0]) | ||
| credID, err := resolveCredentialID(ctx, client, args[0]) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| resp, err := client.Credentials().GetToken(ctx, credID) | ||
| if err != nil { | ||
| return fmt.Errorf("get token for credential %q: %w", args[0], err) | ||
| } | ||
|
|
@@ -451,6 +468,18 @@ func init() { | |
| bindCmd.Flags().StringVar(&bindArgs.project, "project", "", "Project to bind the credential to (required)") | ||
| } | ||
|
|
||
| func resolveCredentialID(ctx context.Context, client *sdkclient.Client, nameOrID string) (string, error) { | ||
| cred, err := client.Credentials().Get(ctx, nameOrID) | ||
| if err == nil { | ||
| return cred.ID, nil | ||
| } | ||
| cred, err = client.Credentials().FindByName(ctx, nameOrID) | ||
| if err != nil { | ||
| return "", fmt.Errorf("credential %q not found by ID or name", nameOrID) | ||
| } | ||
|
Comment on lines
+471
to
+479
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. Only fallback to name lookup on NotFound errors. Line 472 currently falls back to As per coding guidelines, “Handle errors and edge cases explicitly rather than ignoring them.” 🤖 Prompt for AI Agents |
||
| return cred.ID, nil | ||
| } | ||
|
|
||
| func printCredentialTable(printer *output.Printer, credentials []sdktypes.Credential) error { | ||
| columns := []output.Column{ | ||
| {Name: "ID", Width: 27}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -132,7 +132,11 @@ func run(cmd *cobra.Command, cmdArgs []string) error { | |
| return nil | ||
|
|
||
| case "credential", "credentials", "cred", "creds": | ||
| if err := client.Credentials().Delete(ctx, name); err != nil { | ||
| deleteID := name | ||
| if cred, findErr := client.Credentials().FindByName(ctx, name); findErr == nil { | ||
| deleteID = cred.ID | ||
| } | ||
| if err := client.Credentials().Delete(ctx, deleteID); err != nil { | ||
|
Comment on lines
+136
to
+139
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. Avoid silent fallback when name resolution fails. Line 136 ignores As per coding guidelines, “Handle errors and edge cases explicitly rather than ignoring them.” 🤖 Prompt for AI Agents |
||
| return fmt.Errorf("delete credential %q: %w", name, err) | ||
| } | ||
| fmt.Fprintf(cmd.OutOrStdout(), "credential/%s deleted\n", name) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -472,7 +472,10 @@ func getCredentials(ctx context.Context, client *sdkclient.Client, printer *outp | |
| if name != "" { | ||
| cred, err := client.Credentials().Get(ctx, name) | ||
| if err != nil { | ||
| return fmt.Errorf("get credential %q: %w", name, err) | ||
| cred, err = client.Credentials().FindByName(ctx, name) | ||
| if err != nil { | ||
| return fmt.Errorf("get credential %q: %w", name, err) | ||
| } | ||
|
Comment on lines
473
to
+478
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. Use not-found-aware fallback in Line 474 should not automatically switch to As per coding guidelines, “Handle errors and edge cases explicitly rather than ignoring them.” 🤖 Prompt for AI Agents |
||
| } | ||
| if printer.Format() == output.FormatJSON { | ||
| return printer.PrintJSON(cred) | ||
|
|
||
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.
Don’t treat every lookup error as create-miss.
Line 247 routes to create on any
FindByNameerror. This should only happen on not-found; otherwise transient/API failures are misclassified and can produce incorrect create behavior.As per coding guidelines, “Handle errors and edge cases explicitly rather than ignoring them.”
🤖 Prompt for AI Agents