tctl edit: get the original resource name from the file (#20362)

This ensures we correctly detect attempts to rename even when
aliases are used for dynamic resources like `cap`.
This commit is contained in:
Zac Bergquist 2023-01-22 07:45:00 -07:00 committed by GitHub
parent 10045bd349
commit 6a2ed69567
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,6 +98,11 @@ func (e *EditCommand) TryRun(ctx context.Context, cmd string, client auth.Client
return true, trace.Wrap(err)
}
originalName, err := resourceName(f.Name())
if err != nil {
return true, trace.Wrap(err)
}
args := strings.Fields(editor())
editorCmd := exec.CommandContext(ctx, args[0], append(args[1:], f.Name())...)
editorCmd.Stdin = os.Stdin
@ -126,7 +131,7 @@ func (e *EditCommand) TryRun(ctx context.Context, cmd string, client auth.Client
return true, trace.Wrap(err)
}
if e.ref.Name != newName {
if originalName != newName {
return true, trace.NotImplemented("renaming resources is not supported with tctl edit")
}