Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(object): disable command in console #4151

Merged
merged 5 commits into from
Oct 9, 2024
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
65 changes: 31 additions & 34 deletions internal/namespaces/object/v1/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,46 +7,43 @@ import (
)

func GetCommands() *core.Commands {
cmds := core.NewCommands()

human.RegisterMarshalerFunc(BucketResponse{}, bucketResponseMarshalerFunc)
human.RegisterMarshalerFunc(bucketInfo{}, bucketInfoMarshalerFunc)
human.RegisterMarshalerFunc(BucketGetResult{}, bucketGetResultMarshalerFunc)
human.RegisterMarshalerFunc(s3.ListBucketsOutput{}.Buckets, bucketMarshalerFunc)

return core.NewCommands(
objectRoot(),
objectConfig(),
objectBucket(),
bucketCreateCommand(),
bucketDeleteCommand(),
bucketGetCommand(),
bucketListCommand(),
bucketUpdateCommand(),
configGetCommand(),
configInstallCommand(),
)
}

func objectRoot() *core.Command {
return &core.Command{
Short: `Object-storage utils`,
Namespace: "object",
if cmdObjectRoot := objectRoot(); cmdObjectRoot != nil {
cmds.Add(cmdObjectRoot)
}
}

func objectConfig() *core.Command {
return &core.Command{
Short: `Manage configuration files for popular S3 tools`,
Long: `Configuration generation for S3 tools.`,
Namespace: "object",
Resource: `config`,
if cmdObjectConfig := objectConfig(); cmdObjectConfig != nil {
cmds.Add(cmdObjectConfig)
}
}

func objectBucket() *core.Command {
return &core.Command{
Short: `Manage S3 buckets`,
Long: `Manage S3 buckets creation, deletion and updates to properties like tags, ACL and versioning.`,
Namespace: "object",
Resource: `bucket`,
if cmdObjectBucket := objectBucket(); cmdObjectBucket != nil {
cmds.Add(cmdObjectBucket)
}
if cmdBucketCreate := bucketCreateCommand(); cmdBucketCreate != nil {
cmds.Add(cmdBucketCreate)
}
if cmdBucketDelete := bucketDeleteCommand(); cmdBucketDelete != nil {
cmds.Add(cmdBucketDelete)
}
if cmdBucketGet := bucketGetCommand(); cmdBucketGet != nil {
cmds.Add(cmdBucketGet)
}
if cmdBucketList := bucketListCommand(); cmdBucketList != nil {
cmds.Add(cmdBucketList)
}
if cmdBucketUpdate := bucketUpdateCommand(); cmdBucketUpdate != nil {
cmds.Add(cmdBucketUpdate)
}
if cmdConfigGet := configGetCommand(); cmdConfigGet != nil {
cmds.Add(cmdConfigGet)
}
if cmdConfigInstall := configInstallCommand(); cmdConfigInstall != nil {
cmds.Add(cmdConfigInstall)
}

return cmds
}
112 changes: 2 additions & 110 deletions internal/namespaces/object/v1/custom_bucket.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build darwin || linux || windows

package object

import (
Expand All @@ -11,66 +13,9 @@ import (
"github.com/aws/aws-sdk-go-v2/service/s3"
"github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/scaleway/scaleway-cli/v2/core"
"github.com/scaleway/scaleway-cli/v2/internal/human"
"github.com/scaleway/scaleway-sdk-go/scw"
)

type bucketInfo struct {
ID string
Region scw.Region
APIEndpoint string
BucketEndpoint string
EnableVersioning bool
Tags []types.Tag
ACL []CustomS3ACLGrant
Owner string
}

func bucketInfoMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
// To avoid recursion of human.Marshal we create a dummy type
type tmp bucketInfo
info := tmp(i.(bucketInfo))

opt.Sections = []*human.MarshalSection{
{
FieldName: "Tags",
HideIfEmpty: true,
},
{
FieldName: "ACL",
HideIfEmpty: true,
},
}
str, err := human.Marshal(info, opt)
if err != nil {
return "", err
}
return str, nil
}

type BucketResponse struct {
SuccessResult *core.SuccessResult
BucketInfo *bucketInfo
}

func bucketResponseMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
resp := i.(BucketResponse)

messageStr, err := resp.SuccessResult.MarshalHuman()
if err != nil {
return "", err
}
bucketStr, err := bucketInfoMarshalerFunc(*resp.BucketInfo, opt)
if err != nil {
return "", err
}

return strings.Join([]string{
messageStr,
bucketStr,
}, "\n"), nil
}

type bucketConfigArgs struct {
Region scw.Region
Name string
Expand Down Expand Up @@ -205,59 +150,6 @@ func bucketDeleteCommand() *core.Command {
}
}

type bucketGetArgs struct {
Region scw.Region
Name string
WithSize bool `json:"with-size"`
}

type BucketGetResult struct {
*bucketInfo
Size *scw.Size
NbObjects *int64
NbParts *int64
}

func bucketGetResultMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
type tmp BucketGetResult
result := tmp(i.(BucketGetResult))
opt.Sections = []*human.MarshalSection{
{
FieldName: "Tags",
HideIfEmpty: true,
},
{
FieldName: "ACL",
HideIfEmpty: true,
},
}
str, err := human.Marshal(result, opt)
if err != nil {
return "", err
}
return str, nil
}

func bucketMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
type tmp []types.Bucket
result := tmp(i.([]types.Bucket))
opt.Fields = []*human.MarshalFieldOpt{
{
FieldName: "Name",
Label: "Name",
},
{
FieldName: "CreationDate",
Label: "Creation Date",
},
}
str, err := human.Marshal(result, opt)
if err != nil {
return "", err
}
return str, nil
}

func bucketGetCommand() *core.Command {
return &core.Command{
Namespace: "object",
Expand Down
30 changes: 30 additions & 0 deletions internal/namespaces/object/v1/custom_command.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//go:build darwin || linux || windows

package object

import "github.com/scaleway/scaleway-cli/v2/core"

func objectRoot() *core.Command {
return &core.Command{
Short: `Object-storage utils`,
Namespace: "object",
}
}

func objectConfig() *core.Command {
return &core.Command{
Short: `Manage configuration files for popular S3 tools`,
Long: `Configuration generation for S3 tools.`,
Namespace: "object",
Resource: `config`,
}
}

func objectBucket() *core.Command {
return &core.Command{
Short: `Manage S3 buckets`,
Long: `Manage S3 buckets creation, deletion and updates to properties like tags, ACL and versioning.`,
Namespace: "object",
Resource: `bucket`,
}
}
2 changes: 2 additions & 0 deletions internal/namespaces/object/v1/custom_config_get.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build darwin || linux || windows

package object

import (
Expand Down
2 changes: 2 additions & 0 deletions internal/namespaces/object/v1/custom_config_install.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build darwin || linux || windows

package object

import (
Expand Down
45 changes: 45 additions & 0 deletions internal/namespaces/object/v1/custom_disabled.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
//go:build !(darwin || linux || windows)

package object

import "github.com/scaleway/scaleway-cli/v2/core"

func objectRoot() *core.Command {
return nil
}

func objectConfig() *core.Command {
return nil
}

func objectBucket() *core.Command {
return nil
}

func bucketCreateCommand() *core.Command {
return nil
}

func bucketDeleteCommand() *core.Command {
return nil
}

func bucketListCommand() *core.Command {
return nil
}

func bucketGetCommand() *core.Command {
return nil
}

func bucketUpdateCommand() *core.Command {
return nil
}

func configGetCommand() *core.Command {
return nil
}

func configInstallCommand() *core.Command {
return nil
}
Loading
Loading