@@ -1357,7 +1357,7 @@ func (sess clientSession) GlobalCatalogV1API() (*globalcatalogv1.GlobalCatalogV1
13571357
13581358// ClientSession configures and returns a fully initialized ClientSession
13591359func (c * Config ) ClientSession () (interface {}, error ) {
1360- sess , err := newSession (c )
1360+ sess , fileMap , err := newSession (c )
13611361 if err != nil {
13621362 return nil , err
13631363 }
@@ -1488,22 +1488,7 @@ func (c *Config) ClientSession() (interface{}, error) {
14881488 session .functionClient , session .functionConfigErr = FunctionClient (sess .BluemixSession .Config )
14891489
14901490 BluemixRegion = sess .BluemixSession .Config .Region
1491- var fileMap map [string ]interface {}
1492- if f := EnvFallBack ([]string {"IBMCLOUD_ENDPOINTS_FILE_PATH" , "IC_ENDPOINTS_FILE_PATH" }, c .EndpointsFile ); f != "" {
1493- jsonFile , err := os .Open (f )
1494- if err != nil {
1495- log .Fatalf ("Unable to open Endpoints File %s" , err )
1496- }
1497- defer jsonFile .Close ()
1498- bytes , err := ioutil .ReadAll (jsonFile )
1499- if err != nil {
1500- log .Fatalf ("Unable to read Endpoints File %s" , err )
1501- }
1502- err = json .Unmarshal ([]byte (bytes ), & fileMap )
1503- if err != nil {
1504- log .Fatalf ("Unable to unmarshal Endpoints File %s" , err )
1505- }
1506- }
1491+
15071492 accv1API , err := accountv1 .New (sess .BluemixSession )
15081493 if err != nil {
15091494 session .accountV1ConfigErr = fmt .Errorf ("[ERROR] Error occured while configuring Bluemix Accountv1 Service: %q" , err )
@@ -3756,7 +3741,7 @@ func CreateVersionDate() *string {
37563741 return & version
37573742}
37583743
3759- func newSession (c * Config ) (* Session , error ) {
3744+ func newSession (c * Config ) (* Session , map [ string ] interface {}, error ) {
37603745 ibmSession := & Session {}
37613746
37623747 softlayerSession := & slsession.Session {
@@ -3784,7 +3769,34 @@ func newSession(c *Config) (*Session, error) {
37843769
37853770 var authenticator core.Authenticator
37863771 var err error
3772+ var fileMap map [string ]interface {}
3773+ if f := EnvFallBack ([]string {"IBMCLOUD_ENDPOINTS_FILE_PATH" , "IC_ENDPOINTS_FILE_PATH" }, c .EndpointsFile ); f != "" {
3774+ jsonFile , err := os .Open (f )
3775+ if err != nil {
3776+ log .Fatalf ("Unable to open Endpoints File %s" , err )
3777+ }
3778+ defer jsonFile .Close ()
3779+ bytes , err := ioutil .ReadAll (jsonFile )
3780+ if err != nil {
3781+ log .Fatalf ("Unable to read Endpoints File %s" , err )
3782+ }
3783+ err = json .Unmarshal ([]byte (bytes ), & fileMap )
3784+ if err != nil {
3785+ log .Fatalf ("Unable to unmarshal Endpoints File %s" , err )
3786+ }
3787+ }
37873788 iamURL := EnvFallBack ([]string {"IBMCLOUD_IAM_API_ENDPOINT" }, IAMURL )
3789+
3790+ if c .Visibility == "private" || c .Visibility == "public-and-private" {
3791+ if c .Region == "us-south" || c .Region == "us-east" {
3792+ iamURL = ContructEndpoint (fmt .Sprintf ("private.%s.iam" , c .Region ), cloudEndpoint )
3793+ } else {
3794+ iamURL = ContructEndpoint ("private.iam" , cloudEndpoint )
3795+ }
3796+ }
3797+ if fileMap != nil && c .Visibility != "public-and-private" {
3798+ iamURL = fileFallBack (fileMap , c .Visibility , "IBMCLOUD_IAM_API_ENDPOINT" , c .Region , iamURL )
3799+ }
37883800 if (c .BluemixAPIKey != "" ) && (c .IAMTrustedProfileID != "" || c .IAMTrustedProfileName != "" ) {
37893801 if c .IAMTrustedProfileID != "" {
37903802 log .Println ("Configuring Session with Trusted Profile ID" )
@@ -3859,11 +3871,11 @@ func newSession(c *Config) (*Session, error) {
38593871 }
38603872 sess , err = bxsession .New (bmxConfig )
38613873 if err != nil {
3862- return nil , err
3874+ return nil , fileMap , err
38633875 }
38643876 ibmSession .BluemixSession = sess
38653877
3866- return ibmSession , nil
3878+ return ibmSession , fileMap , err
38673879}
38683880
38693881/*func authenticateAPIKey(sess *bxsession.Session) error {
0 commit comments