Skip to content

Commit 5f05b15

Browse files
authored
fix(object): disable command in console (#4151)
1 parent 04916f2 commit 5f05b15

File tree

9 files changed

+240
-149
lines changed

9 files changed

+240
-149
lines changed

internal/namespaces/object/v1/custom.go

Lines changed: 31 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,43 @@ import (
77
)
88

99
func GetCommands() *core.Commands {
10+
cmds := core.NewCommands()
11+
1012
human.RegisterMarshalerFunc(BucketResponse{}, bucketResponseMarshalerFunc)
1113
human.RegisterMarshalerFunc(bucketInfo{}, bucketInfoMarshalerFunc)
1214
human.RegisterMarshalerFunc(BucketGetResult{}, bucketGetResultMarshalerFunc)
1315
human.RegisterMarshalerFunc(s3.ListBucketsOutput{}.Buckets, bucketMarshalerFunc)
1416

15-
return core.NewCommands(
16-
objectRoot(),
17-
objectConfig(),
18-
objectBucket(),
19-
bucketCreateCommand(),
20-
bucketDeleteCommand(),
21-
bucketGetCommand(),
22-
bucketListCommand(),
23-
bucketUpdateCommand(),
24-
configGetCommand(),
25-
configInstallCommand(),
26-
)
27-
}
28-
29-
func objectRoot() *core.Command {
30-
return &core.Command{
31-
Short: `Object-storage utils`,
32-
Namespace: "object",
17+
if cmdObjectRoot := objectRoot(); cmdObjectRoot != nil {
18+
cmds.Add(cmdObjectRoot)
3319
}
34-
}
35-
36-
func objectConfig() *core.Command {
37-
return &core.Command{
38-
Short: `Manage configuration files for popular S3 tools`,
39-
Long: `Configuration generation for S3 tools.`,
40-
Namespace: "object",
41-
Resource: `config`,
20+
if cmdObjectConfig := objectConfig(); cmdObjectConfig != nil {
21+
cmds.Add(cmdObjectConfig)
4222
}
43-
}
44-
45-
func objectBucket() *core.Command {
46-
return &core.Command{
47-
Short: `Manage S3 buckets`,
48-
Long: `Manage S3 buckets creation, deletion and updates to properties like tags, ACL and versioning.`,
49-
Namespace: "object",
50-
Resource: `bucket`,
23+
if cmdObjectBucket := objectBucket(); cmdObjectBucket != nil {
24+
cmds.Add(cmdObjectBucket)
25+
}
26+
if cmdBucketCreate := bucketCreateCommand(); cmdBucketCreate != nil {
27+
cmds.Add(cmdBucketCreate)
5128
}
29+
if cmdBucketDelete := bucketDeleteCommand(); cmdBucketDelete != nil {
30+
cmds.Add(cmdBucketDelete)
31+
}
32+
if cmdBucketGet := bucketGetCommand(); cmdBucketGet != nil {
33+
cmds.Add(cmdBucketGet)
34+
}
35+
if cmdBucketList := bucketListCommand(); cmdBucketList != nil {
36+
cmds.Add(cmdBucketList)
37+
}
38+
if cmdBucketUpdate := bucketUpdateCommand(); cmdBucketUpdate != nil {
39+
cmds.Add(cmdBucketUpdate)
40+
}
41+
if cmdConfigGet := configGetCommand(); cmdConfigGet != nil {
42+
cmds.Add(cmdConfigGet)
43+
}
44+
if cmdConfigInstall := configInstallCommand(); cmdConfigInstall != nil {
45+
cmds.Add(cmdConfigInstall)
46+
}
47+
48+
return cmds
5249
}

internal/namespaces/object/v1/custom_bucket.go

Lines changed: 2 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin || linux || windows
2+
13
package object
24

35
import (
@@ -11,66 +13,9 @@ import (
1113
"github.com/aws/aws-sdk-go-v2/service/s3"
1214
"github.com/aws/aws-sdk-go-v2/service/s3/types"
1315
"github.com/scaleway/scaleway-cli/v2/core"
14-
"github.com/scaleway/scaleway-cli/v2/internal/human"
1516
"github.com/scaleway/scaleway-sdk-go/scw"
1617
)
1718

18-
type bucketInfo struct {
19-
ID string
20-
Region scw.Region
21-
APIEndpoint string
22-
BucketEndpoint string
23-
EnableVersioning bool
24-
Tags []types.Tag
25-
ACL []CustomS3ACLGrant
26-
Owner string
27-
}
28-
29-
func bucketInfoMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
30-
// To avoid recursion of human.Marshal we create a dummy type
31-
type tmp bucketInfo
32-
info := tmp(i.(bucketInfo))
33-
34-
opt.Sections = []*human.MarshalSection{
35-
{
36-
FieldName: "Tags",
37-
HideIfEmpty: true,
38-
},
39-
{
40-
FieldName: "ACL",
41-
HideIfEmpty: true,
42-
},
43-
}
44-
str, err := human.Marshal(info, opt)
45-
if err != nil {
46-
return "", err
47-
}
48-
return str, nil
49-
}
50-
51-
type BucketResponse struct {
52-
SuccessResult *core.SuccessResult
53-
BucketInfo *bucketInfo
54-
}
55-
56-
func bucketResponseMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
57-
resp := i.(BucketResponse)
58-
59-
messageStr, err := resp.SuccessResult.MarshalHuman()
60-
if err != nil {
61-
return "", err
62-
}
63-
bucketStr, err := bucketInfoMarshalerFunc(*resp.BucketInfo, opt)
64-
if err != nil {
65-
return "", err
66-
}
67-
68-
return strings.Join([]string{
69-
messageStr,
70-
bucketStr,
71-
}, "\n"), nil
72-
}
73-
7419
type bucketConfigArgs struct {
7520
Region scw.Region
7621
Name string
@@ -205,59 +150,6 @@ func bucketDeleteCommand() *core.Command {
205150
}
206151
}
207152

208-
type bucketGetArgs struct {
209-
Region scw.Region
210-
Name string
211-
WithSize bool `json:"with-size"`
212-
}
213-
214-
type BucketGetResult struct {
215-
*bucketInfo
216-
Size *scw.Size
217-
NbObjects *int64
218-
NbParts *int64
219-
}
220-
221-
func bucketGetResultMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
222-
type tmp BucketGetResult
223-
result := tmp(i.(BucketGetResult))
224-
opt.Sections = []*human.MarshalSection{
225-
{
226-
FieldName: "Tags",
227-
HideIfEmpty: true,
228-
},
229-
{
230-
FieldName: "ACL",
231-
HideIfEmpty: true,
232-
},
233-
}
234-
str, err := human.Marshal(result, opt)
235-
if err != nil {
236-
return "", err
237-
}
238-
return str, nil
239-
}
240-
241-
func bucketMarshalerFunc(i interface{}, opt *human.MarshalOpt) (string, error) {
242-
type tmp []types.Bucket
243-
result := tmp(i.([]types.Bucket))
244-
opt.Fields = []*human.MarshalFieldOpt{
245-
{
246-
FieldName: "Name",
247-
Label: "Name",
248-
},
249-
{
250-
FieldName: "CreationDate",
251-
Label: "Creation Date",
252-
},
253-
}
254-
str, err := human.Marshal(result, opt)
255-
if err != nil {
256-
return "", err
257-
}
258-
return str, nil
259-
}
260-
261153
func bucketGetCommand() *core.Command {
262154
return &core.Command{
263155
Namespace: "object",
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//go:build darwin || linux || windows
2+
3+
package object
4+
5+
import "github.com/scaleway/scaleway-cli/v2/core"
6+
7+
func objectRoot() *core.Command {
8+
return &core.Command{
9+
Short: `Object-storage utils`,
10+
Namespace: "object",
11+
}
12+
}
13+
14+
func objectConfig() *core.Command {
15+
return &core.Command{
16+
Short: `Manage configuration files for popular S3 tools`,
17+
Long: `Configuration generation for S3 tools.`,
18+
Namespace: "object",
19+
Resource: `config`,
20+
}
21+
}
22+
23+
func objectBucket() *core.Command {
24+
return &core.Command{
25+
Short: `Manage S3 buckets`,
26+
Long: `Manage S3 buckets creation, deletion and updates to properties like tags, ACL and versioning.`,
27+
Namespace: "object",
28+
Resource: `bucket`,
29+
}
30+
}

internal/namespaces/object/v1/custom_config_get.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin || linux || windows
2+
13
package object
24

35
import (

internal/namespaces/object/v1/custom_config_install.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//go:build darwin || linux || windows
2+
13
package object
24

35
import (
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//go:build !(darwin || linux || windows)
2+
3+
package object
4+
5+
import "github.com/scaleway/scaleway-cli/v2/core"
6+
7+
func objectRoot() *core.Command {
8+
return nil
9+
}
10+
11+
func objectConfig() *core.Command {
12+
return nil
13+
}
14+
15+
func objectBucket() *core.Command {
16+
return nil
17+
}
18+
19+
func bucketCreateCommand() *core.Command {
20+
return nil
21+
}
22+
23+
func bucketDeleteCommand() *core.Command {
24+
return nil
25+
}
26+
27+
func bucketListCommand() *core.Command {
28+
return nil
29+
}
30+
31+
func bucketGetCommand() *core.Command {
32+
return nil
33+
}
34+
35+
func bucketUpdateCommand() *core.Command {
36+
return nil
37+
}
38+
39+
func configGetCommand() *core.Command {
40+
return nil
41+
}
42+
43+
func configInstallCommand() *core.Command {
44+
return nil
45+
}

0 commit comments

Comments
 (0)