Machine ID: Bot instance management in tctl bots instances#46998
Machine ID: Bot instance management in tctl bots instances#46998timothyb89 merged 6 commits intomasterfrom
tctl bots instances#46998Conversation
This adds new new subcommands to `tctl` to manage bot instances: - `tctl bots instances list` lists bot instances - `tctl bots instances show` shows a specific bot instance - `tctl bots instances add` adds a new instance to an existing bot This also adds help text to guide users between the new commands. It also adds a few aliases for common alternate command names.
| c.botsUpdate.Flag("set-logins", "Sets the bot's logins to the given comma-separated list, replacing any existing logins.").StringVar(&c.setLogins) | ||
| c.botsUpdate.Flag("add-logins", "Adds a comma-separated list of logins to an existing bot.").StringVar(&c.addLogins) | ||
|
|
||
| c.botsInstance = bots.Command("instance", "Manage bot instances.").Alias("instances") |
There was a problem hiding this comment.
For tctl bots the plural version is the actual command and the singular version is an alias, but for tctl bots instance we do the reverse.
Not a big deal but might as well be consistent, no?
| if err := client.UpsertToken(ctx, token); err != nil { | ||
| return trace.Wrap(err) | ||
| } | ||
| } else { |
There was a problem hiding this comment.
Do we need the else or have all possible code paths in the if been exhausted?
There was a problem hiding this comment.
I can dedent this branch, sure.
| addr := proxies[0].GetPublicAddr() | ||
| if addr == "" { | ||
| addr = proxies[0].GetAddr() | ||
| } |
|
|
||
| // parseInstanceID converts an instance ID string in the form of | ||
| // '[bot name]/[uuid]' to separate bot name and UUID strings. | ||
| func parseInstanceID(s string) (string, string, error) { |
There was a problem hiding this comment.
| func parseInstanceID(s string) (string, string, error) { | |
| func parseInstanceID(s string) (name string, uuid string, err error) { |
| parts := strings.Split(s, "/") | ||
|
|
||
| if len(parts) != 2 { | ||
| return "", "", trace.BadParameter("invalid bot instance syntax, must be: [bot name]/[uuid]") | ||
| } | ||
|
|
||
| return parts[0], parts[1], nil |
There was a problem hiding this comment.
Consider using strings.Cut here:
botName, botUUID, ok := strings.Cut(s, "/")
if !ok { /* return bad parameter /* }
return botName, botUUID, nil
strideynet
left a comment
There was a problem hiding this comment.
Looks really good! Gives us a good basis for what should show in the Bot Instance UI when that gets added.
|
|
||
| // AddBotInstance begins onboarding a new instance of an existing bot. | ||
| func (c *BotsCommand) AddBotInstance(ctx context.Context, client *authclient.Client) error { | ||
| // A bit of a misnomer but makes the terminology a bit more consistent. This |
There was a problem hiding this comment.
I tried to think of something better than "tctl bots instances add" but I think it's close enough and not too confusing. I figure the fact that it basically just outputs an example command for delegated join methods makes sense in those scenarios.
There was a problem hiding this comment.
Yep, I don't love it but I think it's memorable and at least conceptually similar to existing commands in tctl.
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
|
@timothyb89 See the table below for backport results.
|
This adds new new subcommands to
tctlto manage bot instances:tctl bots instances listlists bot instancestctl bots instances showshows a specific bot instancetctl bots instances addadds a new instance to an existing botThis also adds help text to guide users between the new commands, along with a few aliases for common alternate command names.
changelog: Add new
tctlsubcommands to manage bot instances