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
1 change: 1 addition & 0 deletions docs/stackit_observability.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ stackit observability [flags]
### SEE ALSO

* [stackit](./stackit.md) - Manage STACKIT resources using the command line
* [stackit observability acl](./stackit_observability_acl.md) - Provides functionality for ACLs of Observability instances
* [stackit observability credentials](./stackit_observability_credentials.md) - Provides functionality for Observability credentials
* [stackit observability grafana](./stackit_observability_grafana.md) - Provides functionality for the Grafana configuration of Observability instances
* [stackit observability instance](./stackit_observability_instance.md) - Provides functionality for Observability instances
Expand Down
35 changes: 35 additions & 0 deletions docs/stackit_observability_acl.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## stackit observability acl

Provides functionality for ACLs of Observability instances

### Synopsis

Provides functionality for access control lists (ACLs) of Observability instances.

```
stackit observability acl [flags]
```

### Options

```
-h, --help Help for "stackit observability acl"
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
```

### SEE ALSO

* [stackit observability](./stackit_observability.md) - Provides functionality for Observability
* [stackit observability acl list](./stackit_observability_acl_list.md) - Lists all ACLs of an Observability instance
* [stackit observability acl update](./stackit_observability_acl_update.md) - Updates the ACLs of an Observability instance

48 changes: 48 additions & 0 deletions docs/stackit_observability_acl_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
## stackit observability acl list

Lists all ACLs of an Observability instance

### Synopsis

Lists all IP networks in CIDR notation which are allowed to access an Observability instance.

```
stackit observability acl list [flags]
```

### Examples

```
List all ACLs of Observability instance "xxx"
$ stackit observability acl list --instance-id xxx

List all ACLs of Observability instance "xxx" in JSON format
$ stackit observability acl list --instance-id xxx --output-format json

List up to 10 ACLs of Observability instance "xxx"
$ stackit observability acl list --instance-id xxx --limit 10
```

### Options

```
-h, --help Help for "stackit observability acl list"
--instance-id string Instance ID
--limit int Maximum number of entries to list
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
```

### SEE ALSO

* [stackit observability acl](./stackit_observability_acl.md) - Provides functionality for ACLs of Observability instances

45 changes: 45 additions & 0 deletions docs/stackit_observability_acl_update.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## stackit observability acl update

Updates the ACLs of an Observability instance

### Synopsis

Updates the ACLs of an Observability instance.

```
stackit observability acl update [flags]
```

### Examples

```
Set the ACLs of Observability instance "xxx" to the IP networks "1.2.3.0/24" and "5.6.7.8/32"
$ stackit observability acl update --instance-id xxx --acl 1.2.3.0/24,5.6.7.8/32

Remove all ACLs of Observability instance "xxx"
$ stackit observability acl update --instance-id xxx --acl ""
```

### Options

```
--acl strings List of IP networks in CIDR notation which are allowed to access the instance. Replaces all existing ACLs, an empty value removes all ACLs (default [])
-h, --help Help for "stackit observability acl update"
--instance-id string Instance ID
```

### Options inherited from parent commands

```
-y, --assume-yes If set, skips all confirmation prompts
--async If set, runs the command asynchronously
-o, --output-format string Output format, (one of: [json, pretty, none, yaml])
-p, --project-id string Project ID
--region string Target region for region-specific requests
--verbosity string Verbosity of the CLI, (one of: [debug, info, warning, error]) (default "info")
```

### SEE ALSO

* [stackit observability acl](./stackit_observability_acl.md) - Provides functionality for ACLs of Observability instances

28 changes: 28 additions & 0 deletions internal/cmd/observability/acl/acl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package acl

import (
"github.com/stackitcloud/stackit-cli/internal/cmd/observability/acl/list"
"github.com/stackitcloud/stackit-cli/internal/cmd/observability/acl/update"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/types"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
)

func NewCmd(params *types.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: "acl",
Short: "Provides functionality for ACLs of Observability instances",
Long: "Provides functionality for access control lists (ACLs) of Observability instances.",
Args: args.NoArgs,
Run: utils.CmdHelp,
}
addSubcommands(cmd, params)
return cmd
}

func addSubcommands(cmd *cobra.Command, params *types.CmdParams) {
cmd.AddCommand(list.NewCmd(params))
cmd.AddCommand(update.NewCmd(params))
}
148 changes: 148 additions & 0 deletions internal/cmd/observability/acl/list/list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package list

import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/types"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/flags"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/print"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/tables"

observabilityUtils "github.com/stackitcloud/stackit-cli/internal/pkg/services/observability/utils"

"github.com/spf13/cobra"
observability "github.com/stackitcloud/stackit-sdk-go/services/observability/v1api"
)

const (
limitFlag = "limit"
instanceIdFlag = "instance-id"
)

type inputModel struct {
*globalflags.GlobalFlagModel
Limit *int64
InstanceId string
}

func NewCmd(params *types.CmdParams) *cobra.Command {
cmd := &cobra.Command{
Use: "list",
Short: "Lists all ACLs of an Observability instance",
Long: "Lists all IP networks in CIDR notation which are allowed to access an Observability instance.",
Args: args.NoArgs,
Example: examples.Build(
examples.NewExample(
`List all ACLs of Observability instance "xxx"`,
"$ stackit observability acl list --instance-id xxx"),
examples.NewExample(
`List all ACLs of Observability instance "xxx" in JSON format`,
"$ stackit observability acl list --instance-id xxx --output-format json"),
examples.NewExample(
`List up to 10 ACLs of Observability instance "xxx"`,
"$ stackit observability acl list --instance-id xxx --limit 10"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
model, err := parseInput(params.Printer, cmd, args)
if err != nil {
return err
}

// Configure API client
apiClient, err := client.ConfigureClient(params.Printer, params.CliVersion)
if err != nil {
return err
}

// Call API
req := buildRequest(ctx, model, apiClient.DefaultAPI)
resp, err := req.Execute()
if err != nil {
return fmt.Errorf("get Observability instance ACLs: %w", err)
}

acls := resp.GetAcl()

instanceLabel, err := observabilityUtils.GetInstanceName(ctx, apiClient.DefaultAPI, model.InstanceId, model.ProjectId)
if err != nil || instanceLabel == "" {
params.Printer.Debug(print.ErrorLevel, "get instance name: %v", err)
instanceLabel = model.InstanceId
}

// Truncate output
if model.Limit != nil && len(acls) > int(*model.Limit) {
acls = acls[:*model.Limit]
}

return outputResult(params.Printer, model.OutputFormat, instanceLabel, acls)
},
}

configureFlags(cmd)
return cmd
}

func configureFlags(cmd *cobra.Command) {
cmd.Flags().Int64(limitFlag, 0, "Maximum number of entries to list")
cmd.Flags().Var(flags.UUIDFlag(), instanceIdFlag, "Instance ID")

err := flags.MarkFlagsRequired(cmd, instanceIdFlag)
cobra.CheckErr(err)
}

func parseInput(p *print.Printer, cmd *cobra.Command, _ []string) (*inputModel, error) {
globalFlags := globalflags.Parse(p, cmd)
if globalFlags.ProjectId == "" {
return nil, &errors.ProjectIdError{}
}

limit := flags.FlagToInt64Pointer(p, cmd, limitFlag)
if limit != nil && *limit < 1 {
return nil, &errors.FlagValidationError{
Flag: limitFlag,
Details: "must be greater than 0",
}
}

model := inputModel{
GlobalFlagModel: globalFlags,
Limit: limit,
InstanceId: flags.FlagToStringValue(p, cmd, instanceIdFlag),
}

p.DebugInputModel(model)
return &model, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient observability.DefaultAPI) observability.ApiListACLRequest {
req := apiClient.ListACL(ctx, model.InstanceId, model.ProjectId)
return req
}

func outputResult(p *print.Printer, outputFormat, instanceLabel string, acls []string) error {
return p.OutputResult(outputFormat, acls, func() error {
if len(acls) == 0 {
p.Outputf("No ACLs found for instance %q\n", instanceLabel)
return nil
}
table := tables.NewTable()
table.SetHeader("CIDR")
for _, acl := range acls {
table.AddRow(acl)
}
err := table.Display(p)
if err != nil {
return fmt.Errorf("render table: %w", err)
}

return nil
})
}
Loading
Loading