Skip to content
Open
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
76 changes: 38 additions & 38 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A command line interface for the CloudAMQP API that provides complete management

- **Unified API**: Single API key manages all operations through the customer API
- **Simple Configuration**: Plain text API key storage in `~/.cloudamqprc`
- **Flag-Based Commands**: Clean command structure with `--id` flags for instance operations
- **Positional IDs**: Clean command structure using positional IDs for instance and VPC operations
- **Copy Settings**: Clone configuration from existing instances (metrics, firewall, alarms, etc.)
- **Wait for Ready**: Optional `--wait` flag for long-running operations (create, resize-disk, upgrades)
- **User-Friendly**: Clear help messages, examples, and safety confirmations
Expand Down Expand Up @@ -85,7 +85,7 @@ exec zsh
After setup, you can test completion by typing:
```bash
cloudamqp instance <TAB> # Lists instance subcommands
cloudamqp instance get --id <TAB> # Lists your instance IDs
cloudamqp instance get <TAB> # Lists your instance IDs
cloudamqp instance create --plan <TAB> # Lists available plans
cloudamqp instance create --region <TAB> # Lists available regions
```
Expand Down Expand Up @@ -122,16 +122,16 @@ cloudamqp instance list
cloudamqp instance list --details

# Get instance details
cloudamqp instance get --id 1234
cloudamqp instance get 1234

# Update instance properties
cloudamqp instance update --id 1234 --name=new-name --plan=rabbit-1
cloudamqp instance update 1234 --name=new-name --plan=rabbit-1

# Resize instance disk
cloudamqp instance resize-disk --id 1234 --disk-size=100 --allow-downtime
cloudamqp instance resize-disk 1234 --disk-size=100 --allow-downtime

# Delete instance (with confirmation)
cloudamqp instance delete --id 1234
cloudamqp instance delete 1234
```

### VPC Management
Expand All @@ -146,76 +146,76 @@ cloudamqp vpc create --name=my-vpc --region=amazon-web-services::us-east-1 --sub
cloudamqp vpc list

# Get VPC details
cloudamqp vpc get --id 5678
cloudamqp vpc get 5678

# Update VPC
cloudamqp vpc update --id 5678 --name=new-vpc-name
cloudamqp vpc update 5678 --name=new-vpc-name

# Delete VPC (with confirmation)
cloudamqp vpc delete --id 5678
cloudamqp vpc delete 5678
```

### Instance-Specific Management

Manage specific instances using the unified API. All commands use `--id` flag to specify the instance.
Manage specific instances using the unified API. All commands take the instance ID as a positional argument.

#### Node Management

```bash
# List nodes in an instance
cloudamqp instance nodes list --id 1234
cloudamqp instance nodes list 1234

# Get available versions for upgrade
cloudamqp instance nodes versions --id 1234
cloudamqp instance nodes versions 1234
```

#### Plugin Management

```bash
# List available RabbitMQ plugins
cloudamqp instance plugins list --id 1234
cloudamqp instance plugins list 1234
```

#### RabbitMQ Configuration

```bash
# List all configuration settings
cloudamqp instance config list --id 1234
cloudamqp instance config list 1234

# Get specific configuration setting
cloudamqp instance config get --id 1234 --key tcp_listen_options
cloudamqp instance config get 1234 tcp_listen_options

# Set configuration setting
cloudamqp instance config set --id 1234 --key tcp_listen_options --value '[{"port": 5672}]'
cloudamqp instance config set 1234 tcp_listen_options '[{"port": 5672}]'
```

#### Instance Actions

```bash
# Restart RabbitMQ
cloudamqp instance restart-rabbitmq --id 1234
cloudamqp instance restart-rabbitmq --id 1234 --nodes=node1,node2
cloudamqp instance restart-rabbitmq 1234
cloudamqp instance restart-rabbitmq 1234 --nodes=node1,node2

# Cluster operations
cloudamqp instance restart-cluster --id 1234
cloudamqp instance stop-cluster --id 1234
cloudamqp instance start-cluster --id 1234
cloudamqp instance restart-cluster 1234
cloudamqp instance stop-cluster 1234
cloudamqp instance start-cluster 1234

# Instance lifecycle
cloudamqp instance stop --id 1234
cloudamqp instance start --id 1234
cloudamqp instance reboot --id 1234
cloudamqp instance stop 1234
cloudamqp instance start 1234
cloudamqp instance reboot 1234

# Management interface
cloudamqp instance restart-management --id 1234
cloudamqp instance restart-management 1234

# Upgrades (asynchronous operations)
cloudamqp instance upgrade-erlang --id 1234
cloudamqp instance upgrade-rabbitmq --id 1234 --version=3.10.7
cloudamqp instance upgrade-all --id 1234
cloudamqp instance upgrade-erlang 1234
cloudamqp instance upgrade-rabbitmq 1234 --version=3.10.7
cloudamqp instance upgrade-all 1234

# Get target upgrade versions
cloudamqp instance upgrade-versions --id 1234
cloudamqp instance upgrade-versions 1234

```

Expand Down Expand Up @@ -264,22 +264,22 @@ cloudamqp audit --timestamp=2024-01
cloudamqp instance create --name=production --plan=bunny-1 --region=amazon-web-services::us-east-1 --wait

# 2. Get instance details
cloudamqp instance get --id 1234
cloudamqp instance get 1234

# 3. Check instance nodes
cloudamqp instance nodes list --id 1234
cloudamqp instance nodes list 1234

# 4. List RabbitMQ configuration
cloudamqp instance config list --id 1234
cloudamqp instance config list 1234

# 5. Install plugins (if needed)
cloudamqp instance plugins list --id 1234
cloudamqp instance plugins list 1234

# 6. Restart RabbitMQ
cloudamqp instance restart-rabbitmq --id 1234
cloudamqp instance restart-rabbitmq 1234

# 7. Upgrade when needed
cloudamqp instance upgrade-all --id 1234
cloudamqp instance upgrade-all 1234
```

### Copy Settings Between Instances
Expand Down Expand Up @@ -371,13 +371,13 @@ RESULT=$(cloudamqp instance create --name=temp-instance --plan=lemming --region=
INSTANCE_ID=$(echo "$RESULT" | jq -r '.id')

# Get instance details
cloudamqp instance get --id "$INSTANCE_ID"
cloudamqp instance get "$INSTANCE_ID"

# Perform operations
cloudamqp instance restart-rabbitmq --id "$INSTANCE_ID"
cloudamqp instance restart-rabbitmq "$INSTANCE_ID"

# Cleanup
cloudamqp instance delete --id "$INSTANCE_ID" --force
cloudamqp instance delete "$INSTANCE_ID" --force
```

## Contributing
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