@@ -117,7 +117,7 @@ def set_auth(
117117 >>> ads.set_auth("api_key", oci_config_location = "other_config_location") # use non-default oci_config_location
118118
119119 >>> ads.set_auth("api_key", client_kwargs={"timeout": 60}) # default signer with connection and read timeouts set to 60 seconds for the client.
120-
120+ >>> ads.set_auth("api_key", )
121121 >>> other_config = oci.config.from_file("other_config_location", "OTHER_PROFILE") # Create non-default config
122122 >>> ads.set_auth(config=other_config) # Set api keys type of authentication based on provided config
123123
@@ -157,7 +157,7 @@ def set_auth(
157157
158158 auth_state .oci_config = config
159159 auth_state .oci_key_profile = profile
160- if auth == AuthType .API_KEY and not signer and not signer_callable :
160+ if auth == AuthType .API_KEY and not signer and not signer_callable and not signer_kwargs :
161161 if os .path .exists (os .path .expanduser (oci_config_location )):
162162 auth_state .oci_config_path = oci_config_location
163163 else :
@@ -175,6 +175,7 @@ def api_keys(
175175 oci_config : str = os .path .join (os .path .expanduser ("~" ), ".oci" , "config" ),
176176 profile : str = DEFAULT_PROFILE ,
177177 client_kwargs : Dict = None ,
178+ kwargs : Dict = None
178179) -> Dict :
179180 """
180181 Prepares authentication and extra arguments necessary for creating clients for different OCI services using API
@@ -188,6 +189,15 @@ def api_keys(
188189 Profile name to select from the config file.
189190 client_kwargs: Optional[Dict], default None
190191 kwargs that are required to instantiate the Client if we need to override the defaults.
192+ kwargs:
193+ kwargs for API authentication signer.
194+ - user: OCID of the user calling the API.
195+ - tenancy: OCID of user's tenancy.
196+ - fingerprint: Fingerprint for the public key that was added to this user.
197+ - region: An Oracle Cloud Infrastructure region.
198+ - pass_phrase: Passphrase used for the key, if it is encrypted.
199+ - key_file: Full path and filename of the private key.
200+ - key_content: The private key as PEM string.
191201
192202 Returns
193203 -------
@@ -208,6 +218,7 @@ def api_keys(
208218 oci_config_location = oci_config ,
209219 oci_key_profile = profile ,
210220 client_kwargs = client_kwargs ,
221+ signer_kwargs = kwargs ,
211222 )
212223 signer_generator = AuthFactory ().signerGenerator (AuthType .API_KEY )
213224 return signer_generator (signer_args ).create_signer ()
@@ -316,6 +327,7 @@ def create_signer(
316327 oci_config_location = oci_config_location ,
317328 oci_key_profile = profile ,
318329 oci_config = config ,
330+ signer_kwargs = signer_kwargs ,
319331 client_kwargs = client_kwargs ,
320332 )
321333 if config :
@@ -386,6 +398,7 @@ def default_signer(client_kwargs: Optional[Dict] = None) -> Dict:
386398 oci_config_location = auth_state .oci_config_path ,
387399 oci_key_profile = auth_state .oci_key_profile ,
388400 oci_config = auth_state .oci_config ,
401+ signer_kwargs = auth_state .oci_signer_kwargs or {},
389402 client_kwargs = {
390403 ** (auth_state .oci_client_kwargs or {}),
391404 ** (client_kwargs or {}),
@@ -470,11 +483,13 @@ def __init__(self, args: Optional[Dict] = None):
470483 - oci_config_location - path to config file
471484 - oci_key_profile - the profile to load from config file
472485 - client_kwargs - optional parameters for OCI client creation in next steps
486+ - signer_kwargs - optional parameters for signer
473487 """
474488 self .oci_config = args .get ("oci_config" )
475489 self .oci_config_location = args .get ("oci_config_location" )
476490 self .oci_key_profile = args .get ("oci_key_profile" )
477491 self .client_kwargs = args .get ("client_kwargs" )
492+ self .signer_kwargs = args .get ("signer_kwargs" )
478493
479494 def create_signer (self ) -> Dict :
480495 """
@@ -503,18 +518,27 @@ def create_signer(self) -> Dict:
503518 if self .oci_config :
504519 configuration = ads .telemetry .update_oci_client_config (self .oci_config )
505520 else :
506- configuration = ads .telemetry .update_oci_client_config (
507- oci .config .from_file (self .oci_config_location , self .oci_key_profile )
508- )
521+ try :
522+ configuration = ads .telemetry .update_oci_client_config (
523+ oci .config .from_file (self .oci_config_location , self .oci_key_profile )
524+ )
525+ except :
526+ if not os .path .exists (os .path .expanduser (self .oci_config_location )):
527+ logger .info (f"Failed to get config from folder { self .oci_config_location } . Using 'signer_kwargs' instead." )
528+ configuration = ads .telemetry .update_oci_client_config (self .signer_kwargs )
529+ else :
530+ raise
531+
509532 logger .info (f"Using 'api_key' authentication." )
510533 return {
511534 "config" : configuration ,
512535 "signer" : oci .signer .Signer (
513- configuration [ "tenancy" ] ,
514- configuration [ "user" ] ,
515- configuration [ "fingerprint" ] ,
516- configuration [ "key_file" ] ,
536+ configuration . get ( "tenancy" ) ,
537+ configuration . get ( "user" ) ,
538+ configuration . get ( "fingerprint" ) ,
539+ configuration . get ( "key_file" ) ,
517540 configuration .get ("pass_phrase" ),
541+ configuration .get ("key_content" )
518542 ),
519543 "client_kwargs" : self .client_kwargs ,
520544 }
0 commit comments