Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use oci_cli_rc file in Python SDK #561

Open
spareslant opened this issue Jul 31, 2023 · 8 comments
Open

How to use oci_cli_rc file in Python SDK #561

spareslant opened this issue Jul 31, 2023 · 8 comments
Labels
SDK Issue pertains to the SDK itself and not specific to any service

Comments

@spareslant
Copy link

Hi,
I could not find any example of using oci_cli_rc file using Python SDK. I looked at following page, but no reference for the use ofoci_cli_rc file.
https://docs.oracle.com/en-us/iaas/tools/python/2.108.0/api/config.html?highlight=config#module-oci.config

@adizohar
Copy link
Member

oci_cli_rc file only used by OCI cli and not by the OCI Python SDK

@KartikShrikantHegde KartikShrikantHegde added the SDK Issue pertains to the SDK itself and not specific to any service label Jul 31, 2023
@KartikShrikantHegde
Copy link

@spareslant Adi is right, the oci_cli_rc_file is CLI specific. Is there a specific reason you would want to use such as a file against Python SDK?

@spareslant
Copy link
Author

spareslant commented Aug 1, 2023

Hi @KartikShrikantHegde , we were testing oci session based authentication. i.e oci session authenticate . Our example ~/.oci/config is below

[PROD]
fingerprint=<fingerprint>
compartment-id=<OCID-1> 
key_file=<File>
tenancy=<Tenancy-1>
region=<Region-1>

[DEV]
fingerprint=<fingerprint>
compartment-id=<OCID-2> 
key_file=<File>
tenancy=<Tenancy-2>
region=<Region-2>

Please note an additional compartment-id in above config. As you know this section may have more keywords as well, that can act as default. But When using oci session authenticate it removes compartment-id and other non-required default keywords.
To mitigate this problem, we started using ~/.oci/oci_cli_rc file and moved some parts of these section there and oci-cli started working fine as cli was picking up extra parameters from oci_cli_rc file.

Before moving to session based auth, we were using following kind of code in our python scripts

    config = oci.config.from_file(config_file, profile)
    region = config["region"]
   compartment_id = config["compartment-id"]

After moving to session based auth, above code fails, as compartment-id has been removed from ~/.oci/config file. It would be good if above code could be written something like below to give a unified view of a section in one object.

config = oci.config.from_file(config_file, rc_file, profile)

@KartikShrikantHegde
Copy link

@spareslant I would like to understand the use case for needing such support. What is the need to use session auth with any config file? Session auth generates a new config file for that session right?

@spareslant
Copy link
Author

spareslant commented Aug 1, 2023

@KartikShrikantHegde , session auth is not creating any new config file at least thats what we saw. We observed that session auth is writing back to ~/.oci/config file and overwrites the existing profile section. As I mentioned above, it also removed non-required keys from the profile section. In our case it removed compartment-id. We mitigated this problem using oci_cli_rc file for bash scripts, but unfortunately OCI Python SDK is totally oblivious of the existence of this file. It would be great if both Bash scripts and Python scripts can use same set of config files and Python SDK can provide a unified view of a profile section in a single object. At the moment config object obtained from oci.config.from_file is not aware of non-required keys in profile section (which are in oci_cli_rc file)

@KartikShrikantHegde
Copy link

@spareslant We will investigate and reproduce the issue in CLI before we can determine if there is a bug at the CLI end. If it is indeed a bug in CLI, we would like to provide a fix rather than change how our SDKs work especially w.r.t to reading from the config file.

@spareslant
Copy link
Author

Are you saying that you are going to fix

  1. session auth will not remove non-required keywords in section ?
  2. session auth will create new file ?
  3. or both of above ?

@KartikShrikantHegde
Copy link

Hi @spareslant While using CLI, If you want to preserve any default values in the config, then keeping it in the ~/.oci/oci_cli_rc file is the right approach. And you seem to have done the same.

But in SDK, today we don't support reading from the oci_cli_rc file as it's only CLI specific file. So you would have to write your own implementation for it.

Having a unified file to read from for both CLI and Python SDK is a valid request and we will add it to our backlog for prioritization. Note that, we cannot promise when will we have it until we do the prioritization and pick it up to work on it. I will leave the issue open so that if others have the same request, they can upvote on it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
SDK Issue pertains to the SDK itself and not specific to any service
Projects
None yet
Development

No branches or pull requests

3 participants