/
resource_ibm_cos_bucket.go
645 lines (588 loc) · 21.7 KB
/
resource_ibm_cos_bucket.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
package ibm
import (
"fmt"
"regexp"
"strings"
"time"
"github.com/IBM/ibm-cos-sdk-go-config/resourceconfigurationv1"
"github.com/IBM/ibm-cos-sdk-go/aws"
"github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam"
token "github.com/IBM/ibm-cos-sdk-go/aws/credentials/ibmiam/token"
"github.com/IBM/ibm-cos-sdk-go/aws/session"
"github.com/IBM/ibm-cos-sdk-go/service/s3"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
)
var singleSiteLocation = []string{
"ams03", "che01", "hkg02", "mel01", "mex01",
"mil01", "mon01", "osl01", "sjc04", "sao01",
"seo01", "tor01",
}
var regionLocation = []string{
"au-syd", "eu-de", "eu-gb", "jp-tok", "us-east", "us-south",
}
var crossRegionLocation = []string{
"us", "eu", "ap",
}
var storageClass = []string{
"standard", "vault", "cold", "flex", "smart",
}
const (
keyAlgorithm = "AES256"
)
func resourceIBMCOS() *schema.Resource {
return &schema.Resource{
Read: resourceIBMCOSRead,
Create: resourceIBMCOSCreate,
Update: resourceIBMCOSUpdate,
Delete: resourceIBMCOSDelete,
Exists: resourceIBMCOSExists,
Importer: &schema.ResourceImporter{},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(60 * time.Minute),
Update: schema.DefaultTimeout(20 * time.Minute),
Delete: schema.DefaultTimeout(10 * time.Minute),
},
Schema: map[string]*schema.Schema{
"bucket_name": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "COS Bucket name",
},
"resource_instance_id": &schema.Schema{
Type: schema.TypeString,
Required: true,
ForceNew: true,
Description: "resource instance ID",
},
"crn": {
Type: schema.TypeString,
Computed: true,
Description: "CRN of resource instance",
},
"key_protect": {
Type: schema.TypeString,
DiffSuppressFunc: applyOnce,
Optional: true,
Description: "CRN of the key you want to use data at rest encryption",
},
"single_site_location": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAllowedStringValue(singleSiteLocation),
ForceNew: true,
ConflictsWith: []string{"region_location", "cross_region_location"},
Description: "single site location info",
},
"region_location": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAllowedStringValue(regionLocation),
ForceNew: true,
ConflictsWith: []string{"cross_region_location", "single_site_location"},
Description: "Region Location info.",
},
"cross_region_location": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ValidateFunc: validateAllowedStringValue(crossRegionLocation),
ForceNew: true,
ConflictsWith: []string{"region_location", "single_site_location"},
Description: "Cros region location info",
},
"storage_class": &schema.Schema{
Type: schema.TypeString,
Required: true,
ValidateFunc: validateAllowedStringValue(storageClass),
ForceNew: true,
Description: "Storage class info",
},
"s3_endpoint_public": {
Type: schema.TypeString,
Computed: true,
Description: "Public endpoint for the COS bucket",
},
"s3_endpoint_private": {
Type: schema.TypeString,
Computed: true,
Description: "Private endpoint for the COS bucket",
},
"allowed_ip": {
Type: schema.TypeList,
Optional: true,
ForceNew: false,
Elem: &schema.Schema{Type: schema.TypeString},
Description: "List of IPv4 or IPv6 addresses ",
},
"activity_tracking": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Enables sending log data to Activity Tracker and LogDNA to provide visibility into object read and write events",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"read_data_events": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If set to true, all object read events will be sent to Activity Tracker.",
},
"write_data_events": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "If set to true, all object write events will be sent to Activity Tracker.",
},
"activity_tracker_crn": {
Type: schema.TypeString,
Required: true,
Description: "The instance of Activity Tracker that will receive object event data",
},
},
},
},
"metrics_monitoring": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Description: "Enables sending metrics to IBM Cloud Monitoring.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"usage_metrics_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
Description: "Usage metrics will be sent to the monitoring service.",
},
"metrics_monitoring_crn": {
Type: schema.TypeString,
Required: true,
Description: "Instance of IBM Cloud Monitoring that will receive the bucket metrics.",
},
},
},
},
},
}
}
func resourceIBMCOSUpdate(d *schema.ResourceData, meta interface{}) error {
sess, err := meta.(ClientSession).CosConfigV1API()
if err != nil {
return err
}
hasChanged := false
updateBucketConfigOptions := &resourceconfigurationv1.UpdateBucketConfigOptions{}
//BucketName
bucketName := d.Get("bucket_name").(string)
updateBucketConfigOptions.Bucket = &bucketName
if d.HasChange("allowed_ip") {
firewall := &resourceconfigurationv1.Firewall{}
var ips = make([]string, 0)
if ip, ok := d.GetOk("allowed_ip"); ok && ip != nil {
for _, i := range ip.([]interface{}) {
ips = append(ips, i.(string))
}
firewall.AllowedIp = ips
}
hasChanged = true
updateBucketConfigOptions.Firewall = firewall
}
if d.HasChange("activity_tracking") {
activityTracker := &resourceconfigurationv1.ActivityTracking{}
if activity, ok := d.GetOk("activity_tracking"); ok {
activitylist := activity.([]interface{})
for _, l := range activitylist {
activityMap, _ := l.(map[string]interface{})
//Read event - as its optional check for existence
if readEvent := activityMap["read_data_events"]; readEvent != nil {
readSet := readEvent.(bool)
activityTracker.ReadDataEvents = &readSet
}
//Write Event - as its optional check for existence
if writeEvent := activityMap["write_data_events"]; writeEvent != nil {
writeSet := writeEvent.(bool)
activityTracker.WriteDataEvents = &writeSet
}
//crn - Required field
crn := activityMap["activity_tracker_crn"].(string)
activityTracker.ActivityTrackerCrn = &crn
}
}
hasChanged = true
updateBucketConfigOptions.ActivityTracking = activityTracker
}
if d.HasChange("metrics_monitoring") {
metricsMonitor := &resourceconfigurationv1.MetricsMonitoring{}
if metrics, ok := d.GetOk("metrics_monitoring"); ok {
metricslist := metrics.([]interface{})
for _, l := range metricslist {
metricsMap, _ := l.(map[string]interface{})
//metrics enabled - as its optional check for existence
if metricsSet := metricsMap["usage_metrics_enabled"]; metricsSet != nil {
metrics := metricsSet.(bool)
metricsMonitor.UsageMetricsEnabled = &metrics
}
//crn - Required field
crn := metricsMap["metrics_monitoring_crn"].(string)
metricsMonitor.MetricsMonitoringCrn = &crn
}
}
hasChanged = true
updateBucketConfigOptions.MetricsMonitoring = metricsMonitor
}
if hasChanged {
response, err := sess.UpdateBucketConfig(updateBucketConfigOptions)
if err != nil {
return fmt.Errorf("Error Update COS Bucket: %s\n%s", err, response)
}
}
return resourceIBMCOSRead(d, meta)
}
func resourceIBMCOSRead(d *schema.ResourceData, meta interface{}) error {
var s3Conf *aws.Config
rsConClient, err := meta.(ClientSession).BluemixSession()
if err != nil {
return err
}
bucketName := parseBucketId(d.Id(), "bucketName")
serviceID := parseBucketId(d.Id(), "serviceID")
apiEndpoint, apiEndpointPrivate := selectCosApi(parseBucketId(d.Id(), "apiType"), parseBucketId(d.Id(), "bLocation"))
authEndpoint, err := rsConClient.Config.EndpointLocator.IAMEndpoint()
if err != nil {
return err
}
authEndpointPath := fmt.Sprintf("%s%s", authEndpoint, "/identity/token")
apiKey := rsConClient.Config.BluemixAPIKey
if apiKey != "" {
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewStaticCredentials(aws.NewConfig(), authEndpointPath, apiKey, serviceID)).WithS3ForcePathStyle(true)
}
iamAccessToken := rsConClient.Config.IAMAccessToken
if iamAccessToken != "" {
initFunc := func() (*token.Token, error) {
return &token.Token{
AccessToken: rsConClient.Config.IAMAccessToken,
RefreshToken: rsConClient.Config.IAMRefreshToken,
TokenType: "Bearer",
ExpiresIn: int64((time.Hour * 248).Seconds()) * -1,
Expiration: time.Now().Add(-1 * time.Hour).Unix(),
}, nil
}
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewCustomInitFuncCredentials(aws.NewConfig(), initFunc, authEndpointPath, serviceID)).WithS3ForcePathStyle(true)
}
s3Sess := session.Must(session.NewSession())
s3Client := s3.New(s3Sess, s3Conf)
headInput := &s3.HeadBucketInput{
Bucket: aws.String(bucketName),
}
err = s3Client.WaitUntilBucketExists(headInput)
if err != nil {
return fmt.Errorf("failed waiting for bucket %s to be created, %v",
bucketName, err)
}
bucketOutput, err := s3Client.ListBucketsExtended(&s3.ListBucketsExtendedInput{})
if err != nil {
return err
}
var bLocationConstraint string
for _, b := range bucketOutput.Buckets {
if *b.Name == bucketName {
bLocationConstraint = *b.LocationConstraint
}
}
singleSiteLocationRegex, err := regexp.Compile("^[a-z]{3}[0-9][0-9]-[a-z]{4,8}$")
if err != nil {
return err
}
regionLocationRegex, err := regexp.Compile("^[a-z]{2}-[a-z]{2,5}-[a-z]{4,8}$")
if err != nil {
return err
}
crossRegionLocationRegex, err := regexp.Compile("^[a-z]{2}-[a-z]{4,8}$")
if err != nil {
return err
}
if singleSiteLocationRegex.MatchString(bLocationConstraint) {
d.Set("single_site_location", strings.Split(bLocationConstraint, "-")[0])
d.Set("storage_class", strings.Split(bLocationConstraint, "-")[1])
}
if regionLocationRegex.MatchString(bLocationConstraint) {
d.Set("region_location", fmt.Sprintf("%s-%s", strings.Split(bLocationConstraint, "-")[0], strings.Split(bLocationConstraint, "-")[1]))
d.Set("storage_class", strings.Split(bLocationConstraint, "-")[2])
}
if crossRegionLocationRegex.MatchString(bLocationConstraint) {
d.Set("cross_region_location", strings.Split(bLocationConstraint, "-")[0])
d.Set("storage_class", strings.Split(bLocationConstraint, "-")[1])
}
bucketCRN := fmt.Sprintf("%s:%s:%s", strings.Replace(serviceID, "::", "", -1), "bucket", bucketName)
d.Set("crn", bucketCRN)
d.Set("resource_instance_id", serviceID)
d.Set("bucket_name", bucketName)
d.Set("s3_endpoint_public", apiEndpoint)
d.Set("s3_endpoint_private", apiEndpointPrivate)
getBucketConfigOptions := &resourceconfigurationv1.GetBucketConfigOptions{
Bucket: &bucketName,
}
sess, err := meta.(ClientSession).CosConfigV1API()
if err != nil {
return err
}
bucketPtr, response, err := sess.GetBucketConfig(getBucketConfigOptions)
if err != nil {
return fmt.Errorf("Error in getting bucket info rule: %s\n%s", err, response)
}
if bucketPtr != nil {
if bucketPtr.Firewall != nil {
d.Set("allowed_ip", flattenStringList(bucketPtr.Firewall.AllowedIp))
}
if bucketPtr.ActivityTracking != nil {
d.Set("activity_tracking", flattenActivityTrack(bucketPtr.ActivityTracking))
}
if bucketPtr.MetricsMonitoring != nil {
d.Set("metrics_monitoring", flattenMetricsMonitor(bucketPtr.MetricsMonitoring))
}
}
return nil
}
func resourceIBMCOSCreate(d *schema.ResourceData, meta interface{}) error {
var s3Conf *aws.Config
rsConClient, err := meta.(ClientSession).BluemixSession()
if err != nil {
return err
}
bucketName := d.Get("bucket_name").(string)
storageClass := d.Get("storage_class").(string)
var bLocation string
var apiType string
serviceID := d.Get("resource_instance_id").(string)
if bucketLocation, ok := d.GetOk("cross_region_location"); ok {
bLocation = bucketLocation.(string)
apiType = "crl"
}
if bucketLocation, ok := d.GetOk("region_location"); ok {
bLocation = bucketLocation.(string)
apiType = "rl"
}
if bucketLocation, ok := d.GetOk("single_site_location"); ok {
bLocation = bucketLocation.(string)
apiType = "ssl"
}
if bLocation == "" {
return fmt.Errorf("Provide either `cross_region_location` or `region_location` or `single_site_location`")
}
lConstraint := fmt.Sprintf("%s-%s", bLocation, storageClass)
apiEndpoint, _ := selectCosApi(apiType, bLocation)
create := &s3.CreateBucketInput{
Bucket: aws.String(bucketName),
CreateBucketConfiguration: &s3.CreateBucketConfiguration{
LocationConstraint: aws.String(lConstraint),
},
}
if keyprotect, ok := d.GetOk("key_protect"); ok {
create.IBMSSEKPCustomerRootKeyCrn = aws.String(keyprotect.(string))
create.IBMSSEKPEncryptionAlgorithm = aws.String(keyAlgorithm)
}
authEndpoint, err := rsConClient.Config.EndpointLocator.IAMEndpoint()
if err != nil {
return err
}
authEndpointPath := fmt.Sprintf("%s%s", authEndpoint, "/identity/token")
apiKey := rsConClient.Config.BluemixAPIKey
if apiKey != "" {
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewStaticCredentials(aws.NewConfig(), authEndpointPath, apiKey, serviceID)).WithS3ForcePathStyle(true)
}
iamAccessToken := rsConClient.Config.IAMAccessToken
if iamAccessToken != "" {
initFunc := func() (*token.Token, error) {
return &token.Token{
AccessToken: rsConClient.Config.IAMAccessToken,
RefreshToken: rsConClient.Config.IAMRefreshToken,
TokenType: "Bearer",
ExpiresIn: int64((time.Hour * 248).Seconds()) * -1,
Expiration: time.Now().Add(-1 * time.Hour).Unix(),
}, nil
}
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewCustomInitFuncCredentials(aws.NewConfig(), initFunc, authEndpointPath, serviceID)).WithS3ForcePathStyle(true)
}
s3Sess := session.Must(session.NewSession())
s3Client := s3.New(s3Sess, s3Conf)
_, err = s3Client.CreateBucket(create)
if err != nil {
return err
}
// Generating a fake id which contains every information about to get the bucket via s3 api
bucketID := fmt.Sprintf("%s:%s:%s:meta:%s:%s", strings.Replace(serviceID, "::", "", -1), "bucket", bucketName, apiType, bLocation)
d.SetId(bucketID)
return resourceIBMCOSUpdate(d, meta)
}
func resourceIBMCOSDelete(d *schema.ResourceData, meta interface{}) error {
var s3Conf *aws.Config
rsConClient, _ := meta.(ClientSession).BluemixSession()
bucketName := parseBucketId(d.Id(), "bucketName")
serviceID := d.Get("resource_instance_id").(string)
var bLocation string
var apiType string
if bucketLocation, ok := d.GetOk("cross_region_location"); ok {
bLocation = bucketLocation.(string)
apiType = "crl"
}
if bucketLocation, ok := d.GetOk("region_location"); ok {
bLocation = bucketLocation.(string)
apiType = "rl"
}
if bucketLocation, ok := d.GetOk("single_site_location"); ok {
bLocation = bucketLocation.(string)
apiType = "ssl"
}
apiEndpoint, _ := selectCosApi(apiType, bLocation)
authEndpoint, err := rsConClient.Config.EndpointLocator.IAMEndpoint()
if err != nil {
return err
}
authEndpointPath := fmt.Sprintf("%s%s", authEndpoint, "/identity/token")
apiKey := rsConClient.Config.BluemixAPIKey
if apiKey != "" {
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewStaticCredentials(aws.NewConfig(), authEndpointPath, apiKey, serviceID)).WithS3ForcePathStyle(true)
}
iamAccessToken := rsConClient.Config.IAMAccessToken
if iamAccessToken != "" {
initFunc := func() (*token.Token, error) {
return &token.Token{
AccessToken: rsConClient.Config.IAMAccessToken,
RefreshToken: rsConClient.Config.IAMRefreshToken,
TokenType: "Bearer",
ExpiresIn: int64((time.Hour * 248).Seconds()) * -1,
Expiration: time.Now().Add(-1 * time.Hour).Unix(),
}, nil
}
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewCustomInitFuncCredentials(aws.NewConfig(), initFunc, authEndpointPath, serviceID)).WithS3ForcePathStyle(true)
}
s3Sess := session.Must(session.NewSession())
s3Client := s3.New(s3Sess, s3Conf)
delete := &s3.DeleteBucketInput{
Bucket: aws.String(bucketName),
}
_, err = s3Client.DeleteBucket(delete)
if err != nil {
return err
}
d.SetId("")
return nil
}
func resourceIBMCOSExists(d *schema.ResourceData, meta interface{}) (bool, error) {
var s3Conf *aws.Config
rsConClient, err := meta.(ClientSession).BluemixSession()
if err != nil {
return false, err
}
bucketName := parseBucketId(d.Id(), "bucketName")
serviceID := parseBucketId(d.Id(), "serviceID")
apiEndpoint, _ := selectCosApi(parseBucketId(d.Id(), "apiType"), parseBucketId(d.Id(), "bLocation"))
authEndpoint, err := rsConClient.Config.EndpointLocator.IAMEndpoint()
if err != nil {
return false, err
}
authEndpointPath := fmt.Sprintf("%s%s", authEndpoint, "/identity/token")
apiKey := rsConClient.Config.BluemixAPIKey
if apiKey != "" {
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewStaticCredentials(aws.NewConfig(), authEndpointPath, apiKey, serviceID)).WithS3ForcePathStyle(true)
}
iamAccessToken := rsConClient.Config.IAMAccessToken
if iamAccessToken != "" {
initFunc := func() (*token.Token, error) {
return &token.Token{
AccessToken: rsConClient.Config.IAMAccessToken,
RefreshToken: rsConClient.Config.IAMRefreshToken,
TokenType: "Bearer",
ExpiresIn: int64((time.Hour * 248).Seconds()) * -1,
Expiration: time.Now().Add(-1 * time.Hour).Unix(),
}, nil
}
s3Conf = aws.NewConfig().WithEndpoint(apiEndpoint).WithCredentials(ibmiam.NewCustomInitFuncCredentials(aws.NewConfig(), initFunc, authEndpointPath, serviceID)).WithS3ForcePathStyle(true)
}
s3Sess := session.Must(session.NewSession())
s3Client := s3.New(s3Sess, s3Conf)
bucketList, err := s3Client.ListBuckets(&s3.ListBucketsInput{})
if err != nil {
return false, err
}
for _, bucket := range bucketList.Buckets {
if *bucket.Name == bucketName {
return true, nil
}
}
return false, nil
}
func selectCosApi(apiType string, bLocation string) (string, string) {
if apiType == "crl" {
switch bLocation {
case "eu":
return "s3.eu.cloud-object-storage.appdomain.cloud", "s3.private.eu.cloud-object-storage.appdomain.cloud"
case "ap":
return "s3.ap.cloud-object-storage.appdomain.cloud", "s3.private.ap.cloud-object-storage.appdomain.cloud"
case "us":
return "s3.us.cloud-object-storage.appdomain.cloud", "s3.private.us.cloud-object-storage.appdomain.cloud"
}
}
if apiType == "rl" {
switch bLocation {
case "au-syd":
return "s3.au-syd.cloud-object-storage.appdomain.cloud", "s3.private.au-syd.cloud-object-storage.appdomain.cloud"
case "eu-de":
return "s3.eu-de.cloud-object-storage.appdomain.cloud", "s3.private.eu-de.cloud-object-storage.appdomain.cloud"
case "eu-gb":
return "s3.eu-gb.cloud-object-storage.appdomain.cloud", "s3.private.eu-gb.cloud-object-storage.appdomain.cloud"
case "jp-tok":
return "s3.jp-tok.cloud-object-storage.appdomain.cloud", "s3.private.jp-tok.cloud-object-storage.appdomain.cloud"
case "us-east":
return "s3.us-east.cloud-object-storage.appdomain.cloud", "s3.private.us-east.cloud-object-storage.appdomain.cloud"
case "us-south":
return "s3.us-south.cloud-object-storage.appdomain.cloud", "s3.private.us-south.cloud-object-storage.appdomain.cloud"
}
}
if apiType == "ssl" {
switch bLocation {
case "ams03":
return "s3.ams03.cloud-object-storage.appdomain.cloud", "s3.private.ams03.cloud-object-storage.appdomain.cloud"
case "che01":
return "s3.che01.cloud-object-storage.appdomain.cloud", "s3.private.che01.cloud-object-storage.appdomain.cloud"
case "hkg02":
return "s3.hkg02.cloud-object-storage.appdomain.cloud", "s3.private.hkg02.cloud-object-storage.appdomain.cloud"
case "mel01":
return "s3.mel01.cloud-object-storage.appdomain.cloud", "s3.private.mel01.cloud-object-storage.appdomain.cloud"
case "mex01":
return "s3.mex01.cloud-object-storage.appdomain.cloud", "s3.private.mex01.cloud-object-storage.appdomain.cloud"
case "mil01":
return "s3.mil01.cloud-object-storage.appdomain.cloud", "s3.private.mil01.cloud-object-storage.appdomain.cloud"
case "mon01":
return "s3.mon01.cloud-object-storage.appdomain.cloud", "s3.private.mon01.cloud-object-storage.appdomain.cloud"
case "osl01":
return "s3.osl01.cloud-object-storage.appdomain.cloud", "s3.private.osl01.cloud-object-storage.appdomain.cloud"
case "sjc04":
return "s3.sjc04.cloud-object-storage.appdomain.cloud", "s3.private.sjc04.cloud-object-storage.appdomain.cloud"
case "sao01":
return "s3.sao01.cloud-object-storage.appdomain.cloud", "s3.private.sao01.cloud-object-storage.appdomain.cloud"
case "seo01":
return "s3.seo01.cloud-object-storage.appdomain.cloud", "s3.private.seo01.cloud-object-storage.appdomain.cloud"
case "tor01":
return "s3.tor01.cloud-object-storage.appdomain.cloud", "s3.private.tor01.cloud-object-storage.appdomain.cloud"
}
}
return "", ""
}
func parseBucketId(id string, info string) string {
crn := strings.Split(id, ":meta:")[0]
meta := strings.Split(id, ":meta:")[1]
if info == "bucketName" {
return strings.Split(crn, ":bucket:")[1]
}
if info == "serviceID" {
return fmt.Sprintf("%s::", strings.Split(crn, ":bucket:")[0])
}
if info == "apiType" {
return strings.Split(meta, ":")[0]
}
if info == "bLocation" {
return strings.Split(meta, ":")[1]
}
return ""
}