Skip to content
Merged
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: 2 additions & 2 deletions docs/stackit_load-balancer_observability-credentials_add.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ stackit load-balancer observability-credentials add [flags]
### Options

```
--display-name string Credentials name
--display-name string Credentials display name
-h, --help Help for "stackit load-balancer observability-credentials add"
--password string Password
--password string Password. Can be a string or a file path, if prefixed with "@" (example: @./password.txt).
--username string Username
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ stackit load-balancer observability-credentials update [flags]
```
--display-name string Credentials name
-h, --help Help for "stackit load-balancer observability-credentials update"
--password string Password
--password string Password. Can be a string or a file path, if prefixed with "@" (example: @./password.txt).
--username string Username
```

Expand Down
15 changes: 8 additions & 7 deletions docs/stackit_load-balancer_target-pool_add-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,26 @@ Adds a target to a target pool
### Synopsis

Adds a target to a target pool.
The target IP must by unique within a target pool and must be a valid IPv4 or IPv6.

```
stackit load-balancer target-pool add-target TARGET_POOL_NAME [flags]
stackit load-balancer target-pool add-target TARGET_IP [flags]
```

### Examples

```
Add a target to target pool "my-target-pool" of load balancer with name "my-load-balancer"
$ stackit load-balancer target-pool add-target my-target-pool --lb-name my-load-balancer --target-name my-new-target --ip 1.2.3.4
Add a target with IP 1.2.3.4 and name "my-new-target" to target pool "my-target-pool" of load balancer with name "my-load-balancer"
$ stackit load-balancer target-pool add-target 1.2.3.4 --target-name my-new-target --target-pool-name my-target-pool --lb-name my-load-balancer
```

### Options

```
-h, --help Help for "stackit load-balancer target-pool add-target"
--ip string Target IP. Must by unique within a target pool. Must be a valid IPv4 or IPv6
--lb-name string Load balancer name
-n, --target-name string Target name
-h, --help Help for "stackit load-balancer target-pool add-target"
--lb-name string Load balancer name
-n, --target-name string Target name
--target-pool-name string Target pool name
```

### Options inherited from parent commands
Expand Down
10 changes: 5 additions & 5 deletions docs/stackit_load-balancer_target-pool_remove-target.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,22 @@ Removes a target from a target pool
Removes a target from a target pool.

```
stackit load-balancer target-pool remove-target TARGET_POOL_NAME [flags]
stackit load-balancer target-pool remove-target TARGET_IP [flags]
```

### Examples

```
Remove target with IP 1.2.3.4 from target pool "my-target-pool" of load balancer with name "my-load-balancer"
$ stackit load-balancer target-pool remove-target my-target-pool --lb-name my-load-balancer --ip 1.2.3.4
$ stackit load-balancer target-pool remove-target 1.2.3.4 --target-pool-name my-target-pool --lb-name my-load-balancer
```

### Options

```
-h, --help Help for "stackit load-balancer target-pool remove-target"
--ip string Target IP of the target to remove. Must be a valid IPv4 or IPv6
--lb-name string Load balancer name
-h, --help Help for "stackit load-balancer target-pool remove-target"
--lb-name string Load balancer name
--target-pool-name string Target IP of the target to remove. Must be a valid IPv4 or IPv6
```

### Options inherited from parent commands
Expand Down
12 changes: 12 additions & 0 deletions internal/cmd/load-balancer/describe/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
"strings"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
Expand Down Expand Up @@ -153,11 +154,22 @@ func renderLoadBalancer(loadBalancer *loadbalancer.LoadBalancer) string {
externalAdress = *loadBalancer.ExternalAddress
}

errorDescriptions := []string{}
if loadBalancer.Errors != nil && len((*loadBalancer.Errors)) > 0 {
for _, err := range *loadBalancer.Errors {
errorDescriptions = append(errorDescriptions, *err.Description)
}
}

table := tables.NewTable()
table.AddRow("NAME", *loadBalancer.Name)
table.AddSeparator()
table.AddRow("STATE", *loadBalancer.Status)
table.AddSeparator()
if len(errorDescriptions) > 0 {
table.AddRow("ERROR DESCRIPTIONS", strings.Join(errorDescriptions, "\n"))
table.AddSeparator()
}
table.AddRow("PRIVATE ACCESS ONLY", privateAccessOnly)
table.AddSeparator()
table.AddRow("ATTACHED PUBLIC IP", externalAdress)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ func NewCmd(p *print.Printer) *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(displayNameFlag, "", "Credentials name")
cmd.Flags().String(displayNameFlag, "", "Credentials display name")
cmd.Flags().String(usernameFlag, "", "Username")
cmd.Flags().String(passwordFlag, "", "Password")
cmd.Flags().Var(flags.ReadFromFileFlag(), passwordFlag, `Password. Can be a string or a file path, if prefixed with "@" (example: @./password.txt).`)

err := flags.MarkFlagsRequired(cmd, displayNameFlag, usernameFlag)
cobra.CheckErr(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,6 @@ func NewCmd(p *print.Printer) *cobra.Command {
credentialsLabel = model.CredentialsRef
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to update observability credentials %q for Load Balancer on project %q?", credentialsLabel, projectLabel)
err = p.PromptForConfirmation(prompt)
if err != nil {
return err
}
}

// Prompt for password if not passed in as a flag
if model.Password == nil {
pwd, err := p.PromptForPassword("Enter new password: ")
Expand All @@ -94,6 +86,14 @@ func NewCmd(p *print.Printer) *cobra.Command {
model.Password = utils.Ptr(pwd)
}

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to update observability credentials %q for Load Balancer on project %q?", credentialsLabel, projectLabel)
err = p.PromptForConfirmation(prompt)
if err != nil {
return err
}
}

// Call API
req, err := buildRequest(ctx, model, apiClient)
if err != nil {
Expand All @@ -116,7 +116,7 @@ func NewCmd(p *print.Printer) *cobra.Command {
func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(displayNameFlag, "", "Credentials name")
cmd.Flags().String(usernameFlag, "", "Username")
cmd.Flags().String(passwordFlag, "", "Password")
cmd.Flags().Var(flags.ReadFromFileFlag(), passwordFlag, `Password. Can be a string or a file path, if prefixed with "@" (example: @./password.txt).`)
}

func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
Expand Down
32 changes: 17 additions & 15 deletions internal/cmd/load-balancer/target-pool/add-target/add_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
)

const (
targetPoolNameArg = "TARGET_POOL_NAME"
ipArg = "TARGET_IP"

lbNameFlag = "lb-name"
targetNameFlag = "target-name"
ipFlag = "ip"
lbNameFlag = "lb-name"
targetNameFlag = "target-name"
targetPoolNameFlag = "target-pool-name"
)

type inputModel struct {
Expand All @@ -36,14 +36,16 @@ type inputModel struct {

func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("add-target %s", targetPoolNameArg),
Use: fmt.Sprintf("add-target %s", ipArg),
Short: "Adds a target to a target pool",
Long: "Adds a target to a target pool.",
Args: args.SingleArg(targetPoolNameArg, nil),
Long: fmt.Sprintf("%s\n%s",
"Adds a target to a target pool.",
"The target IP must by unique within a target pool and must be a valid IPv4 or IPv6."),
Args: args.SingleArg(ipArg, nil),
Example: examples.Build(
examples.NewExample(
`Add a target to target pool "my-target-pool" of load balancer with name "my-load-balancer"`,
"$ stackit load-balancer target-pool add-target my-target-pool --lb-name my-load-balancer --target-name my-new-target --ip 1.2.3.4"),
`Add a target with IP 1.2.3.4 and name "my-new-target" to target pool "my-target-pool" of load balancer with name "my-load-balancer"`,
"$ stackit load-balancer target-pool add-target 1.2.3.4 --target-name my-new-target --target-pool-name my-target-pool --lb-name my-load-balancer"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down Expand Up @@ -85,16 +87,16 @@ func NewCmd(p *print.Printer) *cobra.Command {
}

func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(lbNameFlag, "", "Load balancer name")
cmd.Flags().StringP(targetNameFlag, "n", "", "Target name")
cmd.Flags().String(ipFlag, "", "Target IP. Must by unique within a target pool. Must be a valid IPv4 or IPv6")
cmd.Flags().String(targetPoolNameFlag, "", "Target pool name")
cmd.Flags().String(lbNameFlag, "", "Load balancer name")

err := flags.MarkFlagsRequired(cmd, lbNameFlag, targetNameFlag, ipFlag)
err := flags.MarkFlagsRequired(cmd, lbNameFlag, targetNameFlag, targetPoolNameFlag)
cobra.CheckErr(err)
}

func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
targetPoolName := inputArgs[0]
ip := inputArgs[0]

globalFlags := globalflags.Parse(p, cmd)
if globalFlags.ProjectId == "" {
Expand All @@ -103,10 +105,10 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu

model := inputModel{
GlobalFlagModel: globalFlags,
TargetPoolName: targetPoolName,
TargetPoolName: cmd.Flag(targetPoolNameFlag).Value.String(),
LBName: cmd.Flag(lbNameFlag).Value.String(),
TargetName: cmd.Flag(targetNameFlag).Value.String(),
IP: cmd.Flag(ipFlag).Value.String(),
IP: ip,
}

if p.IsVerbosityDebug() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const (
testLBName = "my-load-balancer"
testTargetPoolName = "target-pool-1"
testTargetName = "my-target"
testIP = "1.2.3.4"
testIP = "1.1.1.1"
)

type loadBalancerClientMocked struct {
Expand Down Expand Up @@ -59,7 +59,7 @@ func (m *loadBalancerClientMocked) UpdateTargetPool(ctx context.Context, project

func fixtureArgValues(mods ...func(argValues []string)) []string {
argValues := []string{
testTargetPoolName,
testIP,
}
for _, mod := range mods {
mod(argValues)
Expand All @@ -69,10 +69,10 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
lbNameFlag: testLBName,
targetNameFlag: testTargetName,
ipFlag: testIP,
projectIdFlag: testProjectId,
lbNameFlag: testLBName,
targetNameFlag: testTargetName,
targetPoolNameFlag: testTargetPoolName,
}
for _, mod := range mods {
mod(flagValues)
Expand Down Expand Up @@ -221,7 +221,7 @@ func TestParseInput(t *testing.T) {
isValid: false,
},
{
description: "target pool name missing",
description: "ip missing",
argValues: []string{""},
flagValues: fixtureFlagValues(),
isValid: false,
Expand All @@ -243,10 +243,10 @@ func TestParseInput(t *testing.T) {
isValid: false,
},
{
description: "ip missing",
description: "target pool name missing",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, ipFlag)
delete(flagValues, targetPoolNameFlag)
}),
isValid: false,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import (
)

const (
targetPoolNameArg = "TARGET_POOL_NAME"
ipArg = "TARGET_IP"

lbNameFlag = "lb-name"
ipFlag = "ip"
lbNameFlag = "lb-name"
targetPoolNameFlag = "target-pool-name"
)

type inputModel struct {
Expand All @@ -34,14 +34,14 @@ type inputModel struct {

func NewCmd(p *print.Printer) *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("remove-target %s", targetPoolNameArg),
Use: fmt.Sprintf("remove-target %s", ipArg),
Short: "Removes a target from a target pool",
Long: "Removes a target from a target pool.",
Args: args.SingleArg(targetPoolNameArg, nil),
Args: args.SingleArg(ipArg, nil),
Example: examples.Build(
examples.NewExample(
`Remove target with IP 1.2.3.4 from target pool "my-target-pool" of load balancer with name "my-load-balancer"`,
"$ stackit load-balancer target-pool remove-target my-target-pool --lb-name my-load-balancer --ip 1.2.3.4"),
"$ stackit load-balancer target-pool remove-target 1.2.3.4 --target-pool-name my-target-pool --lb-name my-load-balancer"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
Expand Down Expand Up @@ -90,14 +90,14 @@ func NewCmd(p *print.Printer) *cobra.Command {

func configureFlags(cmd *cobra.Command) {
cmd.Flags().String(lbNameFlag, "", "Load balancer name")
cmd.Flags().String(ipFlag, "", "Target IP of the target to remove. Must be a valid IPv4 or IPv6")
cmd.Flags().String(targetPoolNameFlag, "", "Target IP of the target to remove. Must be a valid IPv4 or IPv6")

err := flags.MarkFlagsRequired(cmd, lbNameFlag, ipFlag)
err := flags.MarkFlagsRequired(cmd, lbNameFlag, targetPoolNameFlag)
cobra.CheckErr(err)
}

func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
targetPoolName := inputArgs[0]
ip := inputArgs[0]

globalFlags := globalflags.Parse(p, cmd)
if globalFlags.ProjectId == "" {
Expand All @@ -106,9 +106,9 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu

model := inputModel{
GlobalFlagModel: globalFlags,
TargetPoolName: targetPoolName,
TargetPoolName: cmd.Flag(targetPoolNameFlag).Value.String(),
LBName: cmd.Flag(lbNameFlag).Value.String(),
IP: cmd.Flag(ipFlag).Value.String(),
IP: ip,
}

if p.IsVerbosityDebug() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func (m *loadBalancerClientMocked) UpdateTargetPool(ctx context.Context, project

func fixtureArgValues(mods ...func(argValues []string)) []string {
argValues := []string{
testTargetPoolName,
testIP,
}
for _, mod := range mods {
mod(argValues)
Expand All @@ -69,9 +69,9 @@ func fixtureArgValues(mods ...func(argValues []string)) []string {

func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
flagValues := map[string]string{
projectIdFlag: testProjectId,
lbNameFlag: testLBName,
ipFlag: testIP,
projectIdFlag: testProjectId,
lbNameFlag: testLBName,
targetPoolNameFlag: testTargetPoolName,
}
for _, mod := range mods {
mod(flagValues)
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestParseInput(t *testing.T) {
isValid: false,
},
{
description: "target pool name missing",
description: "ip missing",
argValues: []string{""},
flagValues: fixtureFlagValues(),
isValid: false,
Expand All @@ -233,10 +233,10 @@ func TestParseInput(t *testing.T) {
isValid: false,
},
{
description: "ip missing",
description: "target pool name missing",
argValues: fixtureArgValues(),
flagValues: fixtureFlagValues(func(flagValues map[string]string) {
delete(flagValues, ipFlag)
delete(flagValues, targetPoolNameFlag)
}),
isValid: false,
},
Expand Down