forked from IBM/ibmcloud-cos-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobject_deletes.go
72 lines (60 loc) · 1.67 KB
/
object_deletes.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package functions
import (
"github.com/IBM/ibm-cos-sdk-go/service/s3"
"github.com/IBM/ibm-cos-sdk-go/service/s3/s3iface"
"github.com/IBM/ibmcloud-cos-cli/config/fields"
"github.com/IBM/ibmcloud-cos-cli/config/flags"
"github.com/IBM/ibmcloud-cos-cli/errors"
"github.com/IBM/ibmcloud-cos-cli/utils"
"github.com/urfave/cli"
)
const (
errorParsingDelete = "Error parsing parameter '--delete'"
)
// ObjectDeletes deletes multiple objects from a bucket.
// Parameter:
// CLI Context Application
// Returns:
// Error = zero or non-zero
func ObjectDeletes(c *cli.Context) (err error) {
// check the number of arguments
if c.NArg() > 0 {
err = &errors.CommandError{
CLIContext: c,
Cause: errors.InvalidNArg,
}
return
}
// Load COS Context
var cosContext *utils.CosContext
if cosContext, err = GetCosContext(c); err != nil {
return
}
// Set DeleteObjectInput
input := new(s3.DeleteObjectsInput)
// Required parameters for DeleteObjectsInput
mandatory := map[string]string{
fields.Bucket: flags.Bucket,
fields.Delete: flags.Delete,
}
// No optional parameters for DeleteObjectsInput
options := map[string]string{}
// Validate User Inputs
if err = MapToSDKInput(c, input, mandatory, options); err != nil {
return
}
// Setting client to do the call
var client s3iface.S3API
if client, err = cosContext.GetClient(c.String(flags.Region)); err != nil {
return
}
// DeleteObjects Op
var output *s3.DeleteObjectsOutput
if output, err = client.DeleteObjects(input); err != nil {
return
}
// Display either in JSON or text
err = cosContext.GetDisplay(c.String(flags.Output), c.Bool(flags.JSON)).Display(input, output, nil)
// Return
return
}