Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ GO_LDFLAGS=-X cloudamqp-cli/cmd.Version=$(VERSION) \
-X cloudamqp-cli/cmd.BuildDate=$(BUILD_DATE) \
-X cloudamqp-cli/cmd.GitCommit=$(GIT_COMMIT)


bin/cloudamqp:
$(MAKE) build BINARY_NAME="bin/cloudamqp"

# Default target
.PHONY: all
all: build
Expand Down
38 changes: 19 additions & 19 deletions cmd/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ func TestInstanceCommand(t *testing.T) {

assert.Contains(t, commandNames, "create")
assert.Contains(t, commandNames, "list")
assert.Contains(t, commandNames, "get --id <id>")
assert.Contains(t, commandNames, "update --id <id>")
assert.Contains(t, commandNames, "delete --id <id>")
assert.Contains(t, commandNames, "resize-disk --id <id>")
assert.Contains(t, commandNames, "get <id>")
assert.Contains(t, commandNames, "update <id>")
assert.Contains(t, commandNames, "delete <id>")
assert.Contains(t, commandNames, "resize-disk <id>")
}

func TestVPCCommand(t *testing.T) {
Expand All @@ -53,9 +53,9 @@ func TestVPCCommand(t *testing.T) {

assert.Contains(t, commandNames, "create")
assert.Contains(t, commandNames, "list")
assert.Contains(t, commandNames, "get --id <id>")
assert.Contains(t, commandNames, "update --id <id>")
assert.Contains(t, commandNames, "delete --id <id>")
assert.Contains(t, commandNames, "get <id>")
assert.Contains(t, commandNames, "update <id>")
assert.Contains(t, commandNames, "delete <id>")
}

func TestInstanceCreateCommand_Validation(t *testing.T) {
Expand Down Expand Up @@ -221,18 +221,18 @@ func TestInstanceActionsCommand(t *testing.T) {
}

expectedActions := []string{
"restart-rabbitmq --id <instance_id>",
"restart-cluster --id <instance_id>",
"restart-management --id <instance_id>",
"stop --id <instance_id>",
"start --id <instance_id>",
"reboot --id <instance_id>",
"stop-cluster --id <instance_id>",
"start-cluster --id <instance_id>",
"upgrade-erlang --id <instance_id>",
"upgrade-rabbitmq --id <instance_id>",
"upgrade-all --id <instance_id>",
"upgrade-versions --id <instance_id>",
"restart-rabbitmq <instance_id>",
"restart-cluster <instance_id>",
"restart-management <instance_id>",
"stop <instance_id>",
"start <instance_id>",
"reboot <instance_id>",
"stop-cluster <instance_id>",
"start-cluster <instance_id>",
"upgrade-erlang <instance_id>",
"upgrade-rabbitmq <instance_id>",
"upgrade-all <instance_id>",
"upgrade-versions <instance_id>",
}

for _, action := range expectedActions {
Expand Down
36 changes: 12 additions & 24 deletions cmd/instance_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,12 @@ var instanceAccountCmd = &cobra.Command{
}

var rotatePasswordCmd = &cobra.Command{
Use: "rotate-password --id <instance_id>",
Use: "rotate-password <instance_id>",
Short: "Rotate password",
Long: `Initiate rotation of the user password on your instance.`,
Example: ` cloudamqp instance account rotate-password --id 1234`,
Example: ` cloudamqp instance account rotate-password 1234`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
idFlag, _ := cmd.Flags().GetString("id")
if idFlag == "" {
return fmt.Errorf("instance ID is required. Use --id flag")
}

var err error
apiKey, err := getAPIKey()
if err != nil {
Expand All @@ -37,7 +33,7 @@ var rotatePasswordCmd = &cobra.Command{

c := client.New(apiKey, Version)

err = c.RotatePassword(idFlag)
err = c.RotatePassword(args[0])
if err != nil {
fmt.Printf("Error rotating password: %v\n", err)
return err
Expand All @@ -49,16 +45,12 @@ var rotatePasswordCmd = &cobra.Command{
}

var rotateInstanceAPIKeyCmd = &cobra.Command{
Use: "rotate-apikey --id <instance_id>",
Use: "rotate-apikey <instance_id>",
Short: "Rotate Instance API key",
Long: `Rotate the Instance API key.`,
Example: ` cloudamqp instance account rotate-apikey --id 1234`,
Example: ` cloudamqp instance account rotate-apikey 1234`,
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
idFlag, _ := cmd.Flags().GetString("id")
if idFlag == "" {
return fmt.Errorf("instance ID is required. Use --id flag")
}

var err error
apiKey, err := getAPIKey()
if err != nil {
Expand All @@ -67,26 +59,22 @@ var rotateInstanceAPIKeyCmd = &cobra.Command{

c := client.New(apiKey, Version)

err = c.RotateInstanceAPIKey(idFlag)
err = c.RotateInstanceAPIKey(args[0])
if err != nil {
fmt.Printf("Error rotating instance API key: %v\n", err)
return err
}

fmt.Println("Instance API key rotation initiated successfully.")
fmt.Printf("Warning: The local config for instance %s will need to be updated.\n", idFlag)
fmt.Printf("Run 'cloudamqp instance get --id %s' to retrieve and save the new API key.\n", idFlag)
fmt.Printf("Warning: The local config for instance %s will need to be updated.\n", args[0])
fmt.Printf("Run 'cloudamqp instance get %s' to retrieve and save the new API key.\n", args[0])
return nil
},
}

func init() {
// Add --id flag to both account commands
rotatePasswordCmd.Flags().StringP("id", "", "", "Instance ID (required)")
rotatePasswordCmd.MarkFlagRequired("id")

rotateInstanceAPIKeyCmd.Flags().StringP("id", "", "", "Instance ID (required)")
rotateInstanceAPIKeyCmd.MarkFlagRequired("id")
rotatePasswordCmd.ValidArgsFunction = completeInstances
rotateInstanceAPIKeyCmd.ValidArgsFunction = completeInstances

instanceAccountCmd.AddCommand(rotatePasswordCmd)
instanceAccountCmd.AddCommand(rotateInstanceAPIKeyCmd)
Expand Down
Loading
Loading