File tree Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Expand file tree Collapse file tree 2 files changed +18
-4
lines changed Original file line number Diff line number Diff line change @@ -125,11 +125,12 @@ export class BaseService {
125125      options , 
126126      _options 
127127    ) ; 
128-      if  ( options . iam_apikey  ||  options . iam_access_token )  { 
128+ 
129+     if  ( _options . iam_apikey  ||  _options . iam_access_token )  { 
129130      this . tokenManager  =  new  IamTokenManagerV1 ( { 
130-         iamApikey : options . iam_apikey , 
131-         iamAccessToken : options . iam_access_token , 
132-         iamUrl : options . iam_url 
131+         iamApikey : _options . iam_apikey , 
132+         iamAccessToken : _options . iam_access_token , 
133+         iamUrl : _options . iam_url 
133134      } ) ; 
134135    }  else  { 
135136      this . tokenManager  =  null ; 
Original file line number Diff line number Diff line change @@ -112,6 +112,7 @@ describe('BaseService', function() {
112112      url : 'https://gateway.watsonplatform.net/test/api' , 
113113    } ; 
114114    assert . deepEqual ( actual ,  expected ) ; 
115+     assert . notEqual ( instance . tokenManager ,  null ) ; 
115116  } ) ; 
116117
117118  it ( 'should prefer hard-coded credentials over environment properties' ,  function ( )  { 
@@ -218,4 +219,16 @@ describe('BaseService', function() {
218219    instance . setAccessToken ( 'abcd-1234' ) ; 
219220    assert . notEqual ( instance . tokenManager ,  null ) ; 
220221  } ) ; 
222+ 
223+   it ( 'should create a token manager instance if env variables specify iam credentials' ,  function ( )  { 
224+     process . env . TEST_IAM_APIKEY  =  'test1234' ; 
225+     const  instance  =  new  TestService ( ) ; 
226+     const  actual  =  instance . getCredentials ( ) ; 
227+     const  expected  =  { 
228+       iam_apikey : 'test1234' , 
229+       url : 'https://gateway.watsonplatform.net/test/api' , 
230+     } ; 
231+     assert . deepEqual ( actual ,  expected ) ; 
232+     assert . notEqual ( instance . tokenManager ,  null ) ; 
233+   } ) ; 
221234} ) ; 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments