-
Notifications
You must be signed in to change notification settings - Fork 19
/
storage_cors.go
59 lines (48 loc) · 1.61 KB
/
storage_cors.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
package cmd
import (
"github.com/aws/aws-sdk-go-v2/service/s3"
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
"github.com/spf13/cobra"
)
type storageCORSRule struct {
AllowedOrigins []string `json:"allowed_origins,omitempty"`
AllowedMethods []string `json:"allowed_methods,omitempty"`
AllowedHeaders []string `json:"allowed_headers,omitempty"`
}
// storageCORSRulesFromS3 converts a list of S3 CORS rules to a list of
// storageCORSRule.
func storageCORSRulesFromS3(v *s3.GetBucketCorsOutput) []storageCORSRule {
rules := make([]storageCORSRule, 0)
for _, rule := range v.CORSRules {
rules = append(rules, storageCORSRule{
AllowedOrigins: rule.AllowedOrigins,
AllowedMethods: rule.AllowedMethods,
AllowedHeaders: rule.AllowedHeaders,
})
}
return rules
}
// toS3 converts a storageCORSRule object to the S3 CORS rule format.
func (r *storageCORSRule) toS3() s3types.CORSRule {
return s3types.CORSRule{
AllowedOrigins: r.AllowedOrigins,
AllowedMethods: r.AllowedMethods,
AllowedHeaders: r.AllowedHeaders,
}
}
var storageCORSCmd = &cobra.Command{
Use: "cors",
Short: "Manage buckets CORS configuration",
Long: `These commands allow you to manage the CORS configuration of a bucket.
For more information on CORS, please refer to the Exoscale Storage
documentation:
https://community.exoscale.com/documentation/storage/cors/
Notes:
* It is not possible to edit a CORS configuration rule once it's been
created, nor to delete rules individually -- the whole configuration must
be reset using the "exo storage cors reset" command.
`,
}
func init() {
storageCmd.AddCommand(storageCORSCmd)
}