Skip to content

Commit

Permalink
Clevos 94481 read from endpointsfile (#5517)
Browse files Browse the repository at this point in the history
* remove hardcoded values for private and direct cos config endpoint. Use defaults values when no env variables are set

* update code

* update code

* remove extra space

* update code

* update comment

* udpate documentation

* documentation update for issue #4819

* update doc

* read from endpoints file

---------

Co-authored-by: Deeksha Sharma <[email protected]>
  • Loading branch information
IBM-Deeksha and Deeksha Sharma authored Jul 18, 2024
1 parent 536f2ad commit 3e7a0d3
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
7 changes: 5 additions & 2 deletions ibm/service/cos/resource_ibm_cos_bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -1101,8 +1101,8 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error {
serviceID = bucketsatcrn
}

var apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint string

var apiEndpoint, apiEndpointPublic, apiEndpointPrivate, directApiEndpoint, visibility string
visibility = endpointType
if apiType == "sl" {
apiEndpoint = SelectSatlocCosApi(apiType, serviceID, bLocation)
} else {
Expand All @@ -1112,11 +1112,14 @@ func resourceIBMCOSBucketRead(d *schema.ResourceData, meta interface{}) error {
apiEndpoint = apiEndpointPrivate
}
if endpointType == "direct" {
// visibility type "direct" is not supported in endpoints file.
visibility = "private"
apiEndpoint = directApiEndpoint
}

}

apiEndpoint = conns.FileFallBack(rsConClient.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bLocation, apiEndpoint)
apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint)

authEndpoint, err := rsConClient.Config.EndpointLocator.IAMEndpoint()
Expand Down
5 changes: 5 additions & 0 deletions ibm/service/cos/resource_ibm_cos_bucket_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,13 @@ func getCosEndpoint(bucketLocation string, endpointType string) string {

func getS3Client(bxSession *bxsession.Session, bucketLocation string, endpointType string, instanceCRN string) (*s3.S3, error) {
var s3Conf *aws.Config
visibility := endpointType
if endpointType == "direct" {
visibility = "private"
}

apiEndpoint := getCosEndpoint(bucketLocation, endpointType)
apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint)
apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint)
if apiEndpoint == "" {
return nil, fmt.Errorf("the endpoint doesn't exists for given location %s and endpoint type %s", bucketLocation, endpointType)
Expand Down
6 changes: 6 additions & 0 deletions ibm/service/cos/resource_ibm_cos_replication_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,13 @@ func getCosEndpointType(bucketLocation string, endpointType string) string {
func getS3ClientSession(bxSession *bxsession.Session, bucketLocation string, endpointType string, instanceCRN string) (*s3.S3, error) {
var s3Conf *aws.Config

visibility := endpointType
if endpointType == "direct" {
visibility = "private"
}

apiEndpoint := getCosEndpointType(bucketLocation, endpointType)
apiEndpoint = conns.FileFallBack(bxSession.Config.EndpointsFile, visibility, "IBMCLOUD_COS_ENDPOINT", bucketLocation, apiEndpoint)
apiEndpoint = conns.EnvFallBack([]string{"IBMCLOUD_COS_ENDPOINT"}, apiEndpoint)
if apiEndpoint == "" {
return nil, fmt.Errorf("the endpoint doesn't exists for given location %s and endpoint type %s", bucketLocation, endpointType)
Expand Down

0 comments on commit 3e7a0d3

Please sign in to comment.