Move alias CLI under a resource-alias command
Promote the trust-center alias subcommand to a top-level resource-alias command so aliases can be managed for any resource from the CLI. Signed-off-by: Bryan Frimin <bryan@probo.com>
This commit is contained in:
@@ -24,8 +24,8 @@ import (
|
||||
)
|
||||
|
||||
const removeMutation = `
|
||||
mutation($input: RemoveTrustCenterAliasInput!) {
|
||||
removeTrustCenterAlias(input: $input) {
|
||||
mutation($input: RemoveResourceAliasInput!) {
|
||||
removeResourceAlias(input: $input) {
|
||||
deletedResourceId
|
||||
}
|
||||
}
|
||||
@@ -36,7 +36,7 @@ func NewCmdRemove(f *cmdutil.Factory) *cobra.Command {
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "remove <resource-id>",
|
||||
Short: "Remove a trust center alias",
|
||||
Short: "Remove a resource alias",
|
||||
Args: cobra.ExactArgs(1),
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if !flagYes {
|
||||
@@ -12,19 +12,20 @@
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package alias
|
||||
package resourcealias
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"go.probo.inc/probo/pkg/cmd/cmdutil"
|
||||
"go.probo.inc/probo/pkg/cmd/trust-center/alias/remove"
|
||||
"go.probo.inc/probo/pkg/cmd/trust-center/alias/set"
|
||||
"go.probo.inc/probo/pkg/cmd/resource-alias/remove"
|
||||
"go.probo.inc/probo/pkg/cmd/resource-alias/set"
|
||||
)
|
||||
|
||||
func NewCmdAlias(f *cmdutil.Factory) *cobra.Command {
|
||||
func NewCmdResourceAlias(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd := &cobra.Command{
|
||||
Use: "alias <command>",
|
||||
Short: "Manage trust center aliases",
|
||||
Use: "resource-alias <command>",
|
||||
Short: "Manage resource aliases",
|
||||
Aliases: []string{"ra"},
|
||||
}
|
||||
|
||||
cmd.AddCommand(set.NewCmdSet(f))
|
||||
@@ -25,9 +25,9 @@ import (
|
||||
)
|
||||
|
||||
const setMutation = `
|
||||
mutation($input: SetTrustCenterAliasInput!) {
|
||||
setTrustCenterAlias(input: $input) {
|
||||
alias {
|
||||
mutation($input: SetResourceAliasInput!) {
|
||||
setResourceAlias(input: $input) {
|
||||
resourceAlias {
|
||||
resourceId
|
||||
alias
|
||||
}
|
||||
@@ -36,12 +36,12 @@ mutation($input: SetTrustCenterAliasInput!) {
|
||||
`
|
||||
|
||||
type setResponse struct {
|
||||
SetTrustCenterAlias struct {
|
||||
Alias struct {
|
||||
ResourceID string `json:"resourceId"`
|
||||
Alias string `json:"alias"`
|
||||
} `json:"alias"`
|
||||
} `json:"setTrustCenterAlias"`
|
||||
SetResourceAlias struct {
|
||||
ResourceAlias struct {
|
||||
ResourceID string `json:"resourceId"`
|
||||
Alias string `json:"alias"`
|
||||
} `json:"resourceAlias"`
|
||||
} `json:"setResourceAlias"`
|
||||
}
|
||||
|
||||
func NewCmdSet(f *cmdutil.Factory) *cobra.Command {
|
||||
@@ -52,12 +52,12 @@ func NewCmdSet(f *cmdutil.Factory) *cobra.Command {
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "set",
|
||||
Short: "Set a trust center alias",
|
||||
Short: "Set a resource alias",
|
||||
Example: ` # Set an alias interactively
|
||||
prb trust-center alias set --resource-id prbdoc_...
|
||||
prb resource-alias set --resource-id prbdoc_...
|
||||
|
||||
# Set an alias non-interactively
|
||||
prb trust-center alias set --resource-id prbdoc_... --alias privacy-policy`,
|
||||
prb resource-alias set --resource-id prbdoc_... --alias privacy-policy`,
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
cfg, err := f.Config()
|
||||
if err != nil {
|
||||
@@ -80,7 +80,7 @@ func NewCmdSet(f *cmdutil.Factory) *cobra.Command {
|
||||
if f.IOStreams.IsInteractive() {
|
||||
if flagResourceID == "" {
|
||||
err := huh.NewInput().
|
||||
Title("Resource ID (document, file, or audit)").
|
||||
Title("Resource ID").
|
||||
Value(&flagResourceID).
|
||||
Run()
|
||||
if err != nil {
|
||||
@@ -125,7 +125,7 @@ func NewCmdSet(f *cmdutil.Factory) *cobra.Command {
|
||||
return fmt.Errorf("cannot parse response: %w", err)
|
||||
}
|
||||
|
||||
a := resp.SetTrustCenterAlias.Alias
|
||||
a := resp.SetResourceAlias.ResourceAlias
|
||||
_, _ = fmt.Fprintf(
|
||||
f.IOStreams.Out,
|
||||
"Set alias %q for resource %s\n",
|
||||
@@ -137,7 +137,7 @@ func NewCmdSet(f *cmdutil.Factory) *cobra.Command {
|
||||
},
|
||||
}
|
||||
|
||||
cmd.Flags().StringVar(&flagResourceID, "resource-id", "", "Document, trust center file, or audit ID")
|
||||
cmd.Flags().StringVar(&flagResourceID, "resource-id", "", "ID of the resource to alias")
|
||||
cmd.Flags().StringVar(&flagAlias, "alias", "", "Human-readable alias slug")
|
||||
|
||||
return cmd
|
||||
@@ -41,6 +41,7 @@ import (
|
||||
"go.probo.inc/probo/pkg/cmd/obligation"
|
||||
"go.probo.inc/probo/pkg/cmd/org"
|
||||
processingactivity "go.probo.inc/probo/pkg/cmd/processing-activity"
|
||||
resourcealias "go.probo.inc/probo/pkg/cmd/resource-alias"
|
||||
rightsrequest "go.probo.inc/probo/pkg/cmd/rights-request"
|
||||
"go.probo.inc/probo/pkg/cmd/risk"
|
||||
riskassessment "go.probo.inc/probo/pkg/cmd/risk-assessment"
|
||||
@@ -118,6 +119,7 @@ func NewCmdRoot(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd.AddCommand(rightsrequest.NewCmdRightsRequest(f))
|
||||
cmd.AddCommand(risk.NewCmdRisk(f))
|
||||
cmd.AddCommand(riskassessment.NewCmdRiskAssessment(f))
|
||||
cmd.AddCommand(resourcealias.NewCmdResourceAlias(f))
|
||||
cmd.AddCommand(scim.NewCmdScim(f))
|
||||
cmd.AddCommand(soa.NewCmdSoa(f))
|
||||
cmd.AddCommand(task.NewCmdTask(f))
|
||||
|
||||
@@ -17,7 +17,6 @@ package trustcenter
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"go.probo.inc/probo/pkg/cmd/cmdutil"
|
||||
"go.probo.inc/probo/pkg/cmd/trust-center/alias"
|
||||
"go.probo.inc/probo/pkg/cmd/trust-center/file"
|
||||
"go.probo.inc/probo/pkg/cmd/trust-center/reference"
|
||||
"go.probo.inc/probo/pkg/cmd/trust-center/update"
|
||||
@@ -34,7 +33,6 @@ func NewCmdTrustCenter(f *cmdutil.Factory) *cobra.Command {
|
||||
cmd.AddCommand(view.NewCmdView(f))
|
||||
cmd.AddCommand(update.NewCmdUpdate(f))
|
||||
cmd.AddCommand(reference.NewCmdReference(f))
|
||||
cmd.AddCommand(alias.NewCmdAlias(f))
|
||||
cmd.AddCommand(file.NewCmdFile(f))
|
||||
|
||||
return cmd
|
||||
|
||||
Reference in New Issue
Block a user