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

* [stackit](./stackit.md) - Manage STACKIT resources using the command line
* [stackit object-storage bucket](./stackit_object-storage_bucket.md) - Provides functionality for Object Storage buckets
* [stackit object-storage disable](./stackit_object-storage_disable.md) - Disables Object Storage for a project
* [stackit object-storage enable](./stackit_object-storage_enable.md) - Enables Object Storage for a project

35 changes: 35 additions & 0 deletions docs/stackit_object-storage_bucket.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## stackit object-storage bucket

Provides functionality for Object Storage buckets

### Synopsis

Provides functionality for Object Storage buckets.

```
stackit object-storage bucket [flags]
```

### Options

```
-h, --help Help for "stackit object-storage bucket"
```

### 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"]
-p, --project-id string Project ID
```

### SEE ALSO

* [stackit object-storage](./stackit_object-storage.md) - Provides functionality regarding Object Storage
* [stackit object-storage bucket create](./stackit_object-storage_bucket_create.md) - Creates an Object Storage bucket
* [stackit object-storage bucket delete](./stackit_object-storage_bucket_delete.md) - Deletes an Object Storage bucket
* [stackit object-storage bucket describe](./stackit_object-storage_bucket_describe.md) - Shows details of an Object Storage bucket
* [stackit object-storage bucket list](./stackit_object-storage_bucket_list.md) - Lists all Object Storage buckets

38 changes: 38 additions & 0 deletions docs/stackit_object-storage_bucket_create.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## stackit object-storage bucket create

Creates an Object Storage bucket

### Synopsis

Creates an Object Storage bucket.

```
stackit object-storage bucket create BUCKET_NAME [flags]
```

### Examples

```
Create an Object Storage bucket with name "my-bucket"
$ stackit object-storage bucket create my-bucket
```

### Options

```
-h, --help Help for "stackit object-storage bucket create"
```

### 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"]
-p, --project-id string Project ID
```

### SEE ALSO

* [stackit object-storage bucket](./stackit_object-storage_bucket.md) - Provides functionality for Object Storage buckets

38 changes: 38 additions & 0 deletions docs/stackit_object-storage_bucket_delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## stackit object-storage bucket delete

Deletes an Object Storage bucket

### Synopsis

Deletes an Object Storage bucket.

```
stackit object-storage bucket delete BUCKET_NAME [flags]
```

### Examples

```
Delete an Object Storage bucket with name "my-bucket"
$ stackit object-storage bucket delete my-bucket
```

### Options

```
-h, --help Help for "stackit object-storage bucket delete"
```

### 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"]
-p, --project-id string Project ID
```

### SEE ALSO

* [stackit object-storage bucket](./stackit_object-storage_bucket.md) - Provides functionality for Object Storage buckets

41 changes: 41 additions & 0 deletions docs/stackit_object-storage_bucket_describe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
## stackit object-storage bucket describe

Shows details of an Object Storage bucket

### Synopsis

Shows details of an Object Storage bucket.

```
stackit object-storage bucket describe BUCKET_NAME [flags]
```

### Examples

```
Get details of an Object Storage bucket with name "my-bucket"
$ stackit object-storage bucket describe my-bucket

Get details of an Object Storage bucket with name "my-bucket" in a table format
$ stackit object-storage bucket describe my-bucket --output-format pretty
```

### Options

```
-h, --help Help for "stackit object-storage bucket describe"
```

### 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"]
-p, --project-id string Project ID
```

### SEE ALSO

* [stackit object-storage bucket](./stackit_object-storage_bucket.md) - Provides functionality for Object Storage buckets

45 changes: 45 additions & 0 deletions docs/stackit_object-storage_bucket_list.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## stackit object-storage bucket list

Lists all Object Storage buckets

### Synopsis

Lists all Object Storage buckets.

```
stackit object-storage bucket list [flags]
```

### Examples

```
List all Object Storage buckets
$ stackit object-storage bucket list

List all Object Storage buckets in JSON format
$ stackit object-storage bucket list --output-format json

List up to 10 Object Storage buckets
$ stackit object-storage bucket list --limit 10
```

### Options

```
-h, --help Help for "stackit object-storage bucket list"
--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"]
-p, --project-id string Project ID
```

### SEE ALSO

* [stackit object-storage bucket](./stackit_object-storage_bucket.md) - Provides functionality for Object Storage buckets

31 changes: 31 additions & 0 deletions internal/cmd/object-storage/bucket/bucket.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package bucket

import (
"github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/bucket/create"
"github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/bucket/delete"
"github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/bucket/describe"
"github.com/stackitcloud/stackit-cli/internal/cmd/object-storage/bucket/list"
"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/utils"

"github.com/spf13/cobra"
)

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bucket",
Short: "Provides functionality for Object Storage buckets",
Long: "Provides functionality for Object Storage buckets.",
Args: args.NoArgs,
Run: utils.CmdHelp,
}
addSubcommands(cmd)
return cmd
}

func addSubcommands(cmd *cobra.Command) {
cmd.AddCommand(delete.NewCmd())
cmd.AddCommand(describe.NewCmd())
cmd.AddCommand(create.NewCmd())
cmd.AddCommand(list.NewCmd())
}
107 changes: 107 additions & 0 deletions internal/cmd/object-storage/bucket/create/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package create

import (
"context"
"fmt"

"github.com/stackitcloud/stackit-cli/internal/pkg/args"
"github.com/stackitcloud/stackit-cli/internal/pkg/confirm"
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
"github.com/stackitcloud/stackit-cli/internal/pkg/examples"
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
"github.com/stackitcloud/stackit-cli/internal/pkg/services/object-storage/client"
"github.com/stackitcloud/stackit-cli/internal/pkg/spinner"

"github.com/spf13/cobra"
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
"github.com/stackitcloud/stackit-sdk-go/services/objectstorage/wait"
)

const (
bucketNameArg = "BUCKET_NAME"
)

type inputModel struct {
*globalflags.GlobalFlagModel
BucketName string
}

func NewCmd() *cobra.Command {
cmd := &cobra.Command{
Use: fmt.Sprintf("create %s", bucketNameArg),
Short: "Creates an Object Storage bucket",
Long: "Creates an Object Storage bucket.",
Args: args.SingleArg(bucketNameArg, nil),
Example: examples.Build(
examples.NewExample(
`Create an Object Storage bucket with name "my-bucket"`,
"$ stackit object-storage bucket create my-bucket"),
),
RunE: func(cmd *cobra.Command, args []string) error {
ctx := context.Background()
model, err := parseInput(cmd, args)
if err != nil {
return err
}

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

if !model.AssumeYes {
prompt := fmt.Sprintf("Are you sure you want to create bucket %s? (This cannot be undone)", model.BucketName)
err = confirm.PromptForConfirmation(cmd, prompt)
if err != nil {
return err
}
}

// Call API
req := buildRequest(ctx, model, apiClient)
_, err = req.Execute()
if err != nil {
return fmt.Errorf("create Object Storage bucket: %w", err)
}

// Wait for async operation, if async mode not enabled
if !model.Async {
s := spinner.New(cmd)
s.Start("Creating bucket")
_, err = wait.CreateBucketWaitHandler(ctx, apiClient, model.ProjectId, model.BucketName).WaitWithContext(ctx)
if err != nil {
return fmt.Errorf("wait for Object Storage bucket creation: %w", err)
}
s.Stop()
}

operationState := "Created"
if model.Async {
operationState = "Triggered creation of"
}
cmd.Printf("%s bucket %s\n", operationState, model.BucketName)
return nil
},
}
return cmd
}

func parseInput(cmd *cobra.Command, inputArgs []string) (*inputModel, error) {
bucketName := inputArgs[0]

globalFlags := globalflags.Parse(cmd)
if globalFlags.ProjectId == "" {
return nil, &errors.ProjectIdError{}
}

return &inputModel{
GlobalFlagModel: globalFlags,
BucketName: bucketName,
}, nil
}

func buildRequest(ctx context.Context, model *inputModel, apiClient *objectstorage.APIClient) objectstorage.ApiCreateBucketRequest {
req := apiClient.CreateBucket(ctx, model.ProjectId, model.BucketName)
return req
}
Loading