Skip to content

Commit

Permalink
Add test bucket endpoints (IBM-Cloud#5636)
Browse files Browse the repository at this point in the history
* add changes for test bucket endpoints

* update code

---------

Co-authored-by: Deeksha Sharma <deekshasharma@Deekshas-MacBook-Pro.local>
  • Loading branch information
2 people authored and Ramya-c4 committed Sep 27, 2024
1 parent f832fd2 commit 8daf0df
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 29 deletions.
3 changes: 2 additions & 1 deletion ibm/service/cos/data_source_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error
apiEndpoint = SelectSatlocCosApi(bucketType, serviceID, satlc_id)

} else {
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion)
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, false)
visibility = endpointType
if endpointType == "private" {
apiEndpoint = apiEndpointPrivate
Expand Down Expand Up @@ -718,6 +718,7 @@ func dataSourceIBMCosBucketRead(d *schema.ResourceData, meta interface{}) error
bucketCRN := fmt.Sprintf("%s:%s:%s", strings.Replace(serviceID, "::", "", -1), "bucket", bucketName)
d.Set("crn", bucketCRN)
d.Set("resource_instance_id", serviceID)
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(bucketLocationConvert(bucketType), bucketRegion, strings.Contains(apiEndpoint, "test"))
d.Set("s3_endpoint_public", apiEndpoint)
d.Set("s3_endpoint_private", apiEndpointPrivate)
d.Set("s3_endpoint_direct", directApiEndpoint)
Expand Down
28 changes: 15 additions & 13 deletions ibm/service/cos/resource_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ func resourceIBMCOSBucketUpdate(d *schema.ResourceData, meta interface{}) error
if apiType == "sl" {
apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation)
} else {
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation)
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false)
visibility = endpointType
if endpointType == "private" {
apiEndpoint = apiEndpointPrivate
Expand Down Expand Up @@ -1108,13 +1108,12 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error {
bucketsatcrn := satloc_guid[0]
serviceID = bucketsatcrn
}

var apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint, visibility string
visibility = endpointType
if apiType == "sl" {
apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation)
} else {
apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation)
apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false)
apiEndpoint = apiEndpointPublic
if endpointType == "private" {
apiEndpoint = apiEndpointPrivate
Expand Down Expand Up @@ -1202,6 +1201,8 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error {
d.Set("crn", bucketCRN)
d.Set("resource_instance_id", serviceID)
d.Set("bucket_name", bucketName)

apiEndpointPublic, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, strings.Contains(apiEndpoint, "test"))
d.Set("s3_endpoint_public", apiEndpointPublic)
d.Set("s3_endpoint_private", apiEndpointPrivate)
d.Set("s3_endpoint_direct", directApiEndpoint)
Expand Down Expand Up @@ -1401,13 +1402,12 @@ func resourceIBMCOSBucketCreate(d *schema.ResourceData, meta interface{}) error
lConstraint := fmt.Sprintf("%s-%s", bLocation, storageClass)

var endpointType = d.Get("endpoint_type").(string)

var apiEndpoint, privateApiEndpoint, directApiEndpoint, visibility string
if apiType == "sl" {
apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation)

} else {
apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation)
apiEndpoint, privateApiEndpoint, directApiEndpoint = SelectCosApi(apiType, bLocation, false)
visibility = endpointType
if endpointType == "private" {
apiEndpoint = privateApiEndpoint
Expand Down Expand Up @@ -1527,13 +1527,12 @@ func resourceIBMCOSBucketDelete(d *schema.ResourceData, meta interface{}) error
endpointType = d.Get("endpoint_type").(string)
}
var apiEndpoint, apiEndpointPrivate, directApiEndpoint, visibility string

if apiType == "sl" {

apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation)

} else {
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation)
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false)
visibility = endpointType
if endpointType == "private" {
apiEndpoint = apiEndpointPrivate
Expand Down Expand Up @@ -1662,13 +1661,12 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool,
}

var apiEndpoint, apiEndpointPrivate, directApiEndpoint string

if apiType == "sl" {

apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation)

} else {
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation)
apiEndpoint, apiEndpointPrivate, directApiEndpoint = SelectCosApi(apiType, bLocation, false)
if endpointType == "private" {
apiEndpoint = apiEndpointPrivate
}
Expand Down Expand Up @@ -1722,15 +1720,19 @@ func resourceIBMCOSBucketExists(d *schema.ResourceData, meta interface{}) (bool,
return false, nil
}

func SelectCosApi(apiType string, bLocation string) (string, string, string) {
func SelectCosApi(apiType string, bLocation string, test bool) (string, string, string) {
hostUrl := "cloud-object-storage.appdomain.cloud"
if test {
hostUrl = "cloud-object-storage.test.appdomain.cloud"
}
if apiType == "crl" {
return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bLocation)
return fmt.Sprintf("s3.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.private.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.direct.%s.%s", bLocation, hostUrl)
}
if apiType == "rl" {
return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bLocation)
return fmt.Sprintf("s3.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.private.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.direct.%s.%s", bLocation, hostUrl)
}
if apiType == "ssl" {
return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bLocation), fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bLocation)
return fmt.Sprintf("s3.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.private.%s.%s", bLocation, hostUrl), fmt.Sprintf("s3.direct.%s.%s", bLocation, hostUrl)
}
return "", "", ""
}
Expand Down
17 changes: 10 additions & 7 deletions ibm/service/cos/resource_ibm_cos_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -476,17 +476,21 @@ func resourceIBMCOSBucketObjectDelete(ctx context.Context, d *schema.ResourceDat
return nil
}

func getCosEndpoint(bucketLocation string, endpointType string) string {
func getCosEndpoint(bucketLocation string, endpointType string, test bool) string {
if bucketLocation != "" {
hostUrl := "cloud-object-storage.appdomain.cloud"
if test {
hostUrl = "cloud-object-storage.test.appdomain.cloud"
}
switch endpointType {
case "public":
return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl)
case "private":
return fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.private.%s.%s", bucketLocation, hostUrl)
case "direct":
return fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.direct.%s.%s", bucketLocation, hostUrl)
default:
return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl)
}
}
return ""
Expand All @@ -498,8 +502,7 @@ func getS3Client(bxSession *bxsession.Session, bucketLocation string, endpointTy
if endpointType == "direct" {
visibility = "private"
}

apiEndpoint := getCosEndpoint(bucketLocation, endpointType)
apiEndpoint := getCosEndpoint(bucketLocation, endpointType, false)
apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint)
apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint)
if apiEndpoint == "" {
Expand Down
2 changes: 1 addition & 1 deletion ibm/service/cos/resource_ibm_cos_bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2242,7 +2242,7 @@ func testAccCheckIBMCosBucketExists(resource string, bucket string, regiontype s
rt = "crl"
}

apiEndpoint, _, _ := cos.SelectCosApi(rt, region)
apiEndpoint, _, _ := cos.SelectCosApi(rt, region, false)

rsContClient, err := acc.TestAccProvider.Meta().(conns.ClientSession).BluemixSession()
if err != nil {
Expand Down
19 changes: 12 additions & 7 deletions ibm/service/cos/resource_ibm_cos_replication_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,19 +334,25 @@ func parseBucketReplId(id string, info string) string {
return parseBucketId(bucketCRN, info)
}

func getCosEndpointType(bucketLocation string, endpointType string) string {
func getCosEndpointType(bucketLocation string, endpointType string, test bool) string {

if bucketLocation != "" {
hostUrl := "cloud-object-storage.appdomain.cloud"
if test {
hostUrl = "cloud-object-storage.test.appdomain.cloud"
}
switch endpointType {
case "public":
return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl)
case "private":
return fmt.Sprintf("s3.private.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.private.%s.%s", bucketLocation, hostUrl)
case "direct":
return fmt.Sprintf("s3.direct.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.direct.%s.%s", bucketLocation, hostUrl)
default:
return fmt.Sprintf("s3.%s.cloud-object-storage.appdomain.cloud", bucketLocation)
return fmt.Sprintf("s3.%s.%s", bucketLocation, hostUrl)
}
}

return ""
}

Expand All @@ -357,8 +363,7 @@ func getS3ClientSession(bxSession *bxsession.Session, bucketLocation string, end
if endpointType == "direct" {
visibility = "private"
}

apiEndpoint := getCosEndpointType(bucketLocation, endpointType)
apiEndpoint := getCosEndpointType(bucketLocation, endpointType, false)
apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint)
apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint)
if apiEndpoint == "" {
Expand Down

0 comments on commit 8daf0df

Please sign in to comment.