44 "context"
55 "fmt"
66
7+ "github.com/stackitcloud/stackit-cli/internal/pkg/flags"
78 "github.com/stackitcloud/stackit-cli/internal/pkg/types"
89
910 "github.com/stackitcloud/stackit-cli/internal/pkg/args"
@@ -21,12 +22,14 @@ import (
2122)
2223
2324const (
24- bucketNameArg = "BUCKET_NAME"
25+ bucketNameArg = "BUCKET_NAME"
26+ objectLockEnabledFlag = "object-lock-enabled"
2527)
2628
2729type inputModel struct {
2830 * globalflags.GlobalFlagModel
29- BucketName string
31+ BucketName string
32+ ObjectLockEnabled bool
3033}
3134
3235func NewCmd (params * types.CmdParams ) * cobra.Command {
@@ -39,6 +42,9 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
3942 examples .NewExample (
4043 `Create an Object Storage bucket with name "my-bucket"` ,
4144 "$ stackit object-storage bucket create my-bucket" ),
45+ examples .NewExample (
46+ `Create an Object Storage bucket with enabled object-lock` ,
47+ `$ stackit object-storage bucket create my-bucket --object-lock-enabled` ),
4248 ),
4349 RunE : func (cmd * cobra.Command , args []string ) error {
4450 ctx := context .Background ()
@@ -91,9 +97,14 @@ func NewCmd(params *types.CmdParams) *cobra.Command {
9197 return outputResult (params .Printer , model .OutputFormat , model .Async , model .BucketName , resp )
9298 },
9399 }
100+ configureFlags (cmd )
94101 return cmd
95102}
96103
104+ func configureFlags (cmd * cobra.Command ) {
105+ cmd .Flags ().Bool (objectLockEnabledFlag , false , "is the object-lock enabled for the bucket" )
106+ }
107+
97108func parseInput (p * print.Printer , cmd * cobra.Command , inputArgs []string ) (* inputModel , error ) {
98109 bucketName := inputArgs [0 ]
99110
@@ -103,16 +114,17 @@ func parseInput(p *print.Printer, cmd *cobra.Command, inputArgs []string) (*inpu
103114 }
104115
105116 model := inputModel {
106- GlobalFlagModel : globalFlags ,
107- BucketName : bucketName ,
117+ GlobalFlagModel : globalFlags ,
118+ BucketName : bucketName ,
119+ ObjectLockEnabled : flags .FlagToBoolValue (p , cmd , objectLockEnabledFlag ),
108120 }
109121
110122 p .DebugInputModel (model )
111123 return & model , nil
112124}
113125
114126func buildRequest (ctx context.Context , model * inputModel , apiClient * objectstorage.APIClient ) objectstorage.ApiCreateBucketRequest {
115- req := apiClient .DefaultAPI .CreateBucket (ctx , model .ProjectId , model .Region , model .BucketName )
127+ req := apiClient .DefaultAPI .CreateBucket (ctx , model .ProjectId , model .Region , model .BucketName ). ObjectLockEnabled ( model . ObjectLockEnabled )
116128 return req
117129}
118130
0 commit comments