Skip to content

Commit eb8432e

Browse files
authored
feat(ipfs): add list-pins command in scaleway cli (#3103)
1 parent ff568a1 commit eb8432e

File tree

3 files changed

+62
-67
lines changed

3 files changed

+62
-67
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ require (
2222
github.com/moby/buildkit v0.11.6
2323
github.com/opencontainers/go-digest v1.0.0
2424
github.com/pkg/errors v0.9.1
25-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16.0.20230425114903-9de7ce5b674f
25+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16.0.20230428130141-a5694ebc2375
2626
github.com/spf13/cobra v1.7.0
2727
github.com/spf13/pflag v1.0.5
2828
github.com/stretchr/testify v1.8.2

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,8 +274,8 @@ github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6L
274274
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
275275
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
276276
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
277-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16.0.20230425114903-9de7ce5b674f h1:h/skrTv7wKdxr88CjkD2cdVLaWqarBwXRQTE1XCraKg=
278-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16.0.20230425114903-9de7ce5b674f/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
277+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16.0.20230428130141-a5694ebc2375 h1:evSSWPPV1KO5/CmJ6BRdhHl0xxa9GwQWfQYTmsqSCfE=
278+
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.16.0.20230428130141-a5694ebc2375/go.mod h1:fCa7OJZ/9DRTnOKmxvT6pn+LPWUptQAmHF/SBJUGEcg=
279279
github.com/seccomp/libseccomp-golang v0.9.2-0.20220502022130-f33da4d89646/go.mod h1:JA8cRccbGaA1s33RQf7Y1+q9gHmZX1yB/z9WDN1C6fg=
280280
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
281281
github.com/sergi/go-diff v1.2.0 h1:XU+rvMAioB0UC3q1MFrIQy4Vo5/4VsRDQQXHsEya6xQ=

internal/namespaces/ipfs/v1alpha1/ipfs_cli.go

Lines changed: 59 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,16 +22,15 @@ func GetGeneratedCommands() *core.Commands {
2222
ipfsRoot(),
2323
ipfsIpfs(),
2424
ipfsVolume(),
25-
ipfsToken(),
2625
ipfsVolumeCreate(),
2726
ipfsVolumeGet(),
2827
ipfsVolumeList(),
2928
ipfsVolumeUpdate(),
3029
ipfsVolumeDelete(),
3130
ipfsIpfsAddURL(),
3231
ipfsIpfsAddCid(),
33-
ipfsIpfsAddFile(),
3432
ipfsIpfsGetPinID(),
33+
ipfsIpfsListPins(),
3534
ipfsIpfsRmPinID(),
3635
)
3736
}
@@ -45,8 +44,8 @@ func ipfsRoot() *core.Command {
4544

4645
func ipfsIpfs() *core.Command {
4746
return &core.Command{
48-
Short: `add content in s3 bucket`,
49-
Long: `add content in s3 bucket.`,
47+
Short: `add content by cid or url and manage pins`,
48+
Long: `add content by cid or url and manage pins.`,
5049
Namespace: "ipfs",
5150
Resource: "ipfs",
5251
}
@@ -61,19 +60,10 @@ func ipfsVolume() *core.Command {
6160
}
6261
}
6362

64-
func ipfsToken() *core.Command {
65-
return &core.Command{
66-
Short: `manage token in ipfs cli`,
67-
Long: `manage token in ipfs cli.`,
68-
Namespace: "ipfs",
69-
Resource: "token",
70-
}
71-
}
72-
7363
func ipfsVolumeCreate() *core.Command {
7464
return &core.Command{
75-
Short: `Create volume in S3 bucket`,
76-
Long: `Create volume in S3 bucket.`,
65+
Short: `Create volume`,
66+
Long: `Create volume.`,
7767
Namespace: "ipfs",
7868
Resource: "volume",
7969
Verb: "create",
@@ -212,8 +202,8 @@ func ipfsVolumeUpdate() *core.Command {
212202

213203
func ipfsVolumeDelete() *core.Command {
214204
return &core.Command{
215-
Short: `Delete volume in S3 bucket`,
216-
Long: `Delete volume in S3 bucket.`,
205+
Short: `Delete volume`,
206+
Long: `Delete volume.`,
217207
Namespace: "ipfs",
218208
Resource: "volume",
219209
Verb: "delete",
@@ -247,8 +237,8 @@ func ipfsVolumeDelete() *core.Command {
247237

248238
func ipfsIpfsAddURL() *core.Command {
249239
return &core.Command{
250-
Short: `Add content in s3 bucket`,
251-
Long: `Add content in s3 bucket.`,
240+
Short: `Add content in volume by url`,
241+
Long: `Add content in volume by url.`,
252242
Namespace: "ipfs",
253243
Resource: "ipfs",
254244
Verb: "add-url",
@@ -300,8 +290,8 @@ func ipfsIpfsAddURL() *core.Command {
300290

301291
func ipfsIpfsAddCid() *core.Command {
302292
return &core.Command{
303-
Short: `Add content in s3 bucket`,
304-
Long: `Add content in s3 bucket.`,
293+
Short: `Add content in volume by cid`,
294+
Long: `Add content in volume by cid.`,
305295
Namespace: "ipfs",
306296
Resource: "ipfs",
307297
Verb: "add-cid",
@@ -363,15 +353,15 @@ func ipfsIpfsAddCid() *core.Command {
363353
}
364354
}
365355

366-
func ipfsIpfsAddFile() *core.Command {
356+
func ipfsIpfsGetPinID() *core.Command {
367357
return &core.Command{
368-
Short: `Add content in s3 bucket`,
369-
Long: `Add content in s3 bucket.`,
358+
Short: `Get pin id in volume`,
359+
Long: `Get pin id in volume.`,
370360
Namespace: "ipfs",
371361
Resource: "ipfs",
372-
Verb: "add-file",
362+
Verb: "get-pin-id",
373363
// Deprecated: false,
374-
ArgsType: reflect.TypeOf(ipfs.CreatePinByRawRequest{}),
364+
ArgsType: reflect.TypeOf(ipfs.GetPinRequest{}),
375365
ArgSpecs: core.ArgSpecs{
376366
{
377367
Name: "volume-id",
@@ -380,57 +370,33 @@ func ipfsIpfsAddFile() *core.Command {
380370
Positional: false,
381371
},
382372
{
383-
Name: "content",
384-
Required: false,
385-
Deprecated: false,
386-
Positional: false,
387-
},
388-
{
389-
Name: "mime-type",
390-
Required: false,
391-
Deprecated: false,
392-
Positional: false,
393-
},
394-
{
395-
Name: "name",
396-
Required: false,
397-
Deprecated: false,
398-
Positional: false,
399-
},
400-
{
401-
Name: "pin-options.required-zones.{index}",
402-
Required: false,
403-
Deprecated: false,
404-
Positional: false,
405-
},
406-
{
407-
Name: "pin-options.replication-count",
408-
Required: false,
373+
Name: "pin-id",
374+
Required: true,
409375
Deprecated: false,
410376
Positional: false,
411377
},
412378
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
413379
},
414380
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
415-
request := args.(*ipfs.CreatePinByRawRequest)
381+
request := args.(*ipfs.GetPinRequest)
416382

417383
client := core.ExtractClient(ctx)
418384
api := ipfs.NewAPI(client)
419-
return api.CreatePinByRaw(request)
385+
return api.GetPin(request)
420386

421387
},
422388
}
423389
}
424390

425-
func ipfsIpfsGetPinID() *core.Command {
391+
func ipfsIpfsListPins() *core.Command {
426392
return &core.Command{
427-
Short: `Get pin id create when content is add in s3 bucket`,
428-
Long: `Get pin id create when content is add in s3 bucket.`,
393+
Short: `List pins in specific volume`,
394+
Long: `List pins in specific volume.`,
429395
Namespace: "ipfs",
430396
Resource: "ipfs",
431-
Verb: "get-pin-id",
397+
Verb: "list-pins",
432398
// Deprecated: false,
433-
ArgsType: reflect.TypeOf(ipfs.GetPinRequest{}),
399+
ArgsType: reflect.TypeOf(ipfs.ListPinsRequest{}),
434400
ArgSpecs: core.ArgSpecs{
435401
{
436402
Name: "volume-id",
@@ -439,19 +405,48 @@ func ipfsIpfsGetPinID() *core.Command {
439405
Positional: false,
440406
},
441407
{
442-
Name: "pin-id",
443-
Required: true,
408+
Name: "project-id",
409+
Required: false,
444410
Deprecated: false,
445411
Positional: false,
446412
},
447-
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw),
413+
{
414+
Name: "order-by",
415+
Required: false,
416+
Deprecated: false,
417+
Positional: false,
418+
EnumValues: []string{"created_at_asc", "created_at_desc"},
419+
},
420+
{
421+
Name: "status",
422+
Required: false,
423+
Deprecated: false,
424+
Positional: false,
425+
EnumValues: []string{"unknown_status", "queued", "pinning", "failed", "pinned"},
426+
},
427+
{
428+
Name: "organization-id",
429+
Required: false,
430+
Deprecated: false,
431+
Positional: false,
432+
},
433+
core.RegionArgSpec(scw.RegionFrPar, scw.RegionNlAms, scw.RegionPlWaw, scw.Region(core.AllLocalities)),
448434
},
449435
Run: func(ctx context.Context, args interface{}) (i interface{}, e error) {
450-
request := args.(*ipfs.GetPinRequest)
436+
request := args.(*ipfs.ListPinsRequest)
451437

452438
client := core.ExtractClient(ctx)
453439
api := ipfs.NewAPI(client)
454-
return api.GetPin(request)
440+
opts := []scw.RequestOption{scw.WithAllPages()}
441+
if request.Region == scw.Region(core.AllLocalities) {
442+
opts = append(opts, scw.WithRegions(api.Regions()...))
443+
request.Region = ""
444+
}
445+
resp, err := api.ListPins(request, opts...)
446+
if err != nil {
447+
return nil, err
448+
}
449+
return resp.Pins, nil
455450

456451
},
457452
}

0 commit comments

Comments
 (0)