Project: OCI CLI Testing

https://d33wubrfki0l68.cloudfront.net/1bc9a15458c7545e510b80c6f111bf5588c1356e/6e9bf/images/png-transparent-oracle-cloud.png

Traditional Setup

In general, when I am setting up Oracle OCI-CLI interface for the first time, I find it being time consuming. The documentation https://docs.cloud.oracle.com/en-us/iaas/Content/API/SDKDocs/cliconfigure.htm tells you to manually create a ~/.oci/config file by manually copying and pasting values from the Oracle Cloud Administration dashboard.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
~]$ oci setup config
    This command provides a walkthrough of creating a valid CLI config file.

    The following links explain where to find the information required by this
    script:

    User API Signing Key, OCID and Tenancy OCID:

        https://docs.cloud.oracle.com/Content/API/Concepts/apisigningkey.htm#Other

    Region:

        https://docs.cloud.oracle.com/Content/General/Concepts/regions.htm

    General config documentation:

        https://docs.cloud.oracle.com/Content/API/Concepts/sdkconfig.htm


Enter a location for your config [/Users/hiran.patel/.oci/config]:
Ugh..
This is not the way…

Boot strapping the config

I was planning on developing a simplified python script that would extract the data directly from Oracle Cloud Console. However, before embarking on further on the task, I reviewed their code https://github.com/oracle/oci-cli

Enter: ~]$ oci setup bootstrap

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
SETUP_BOOTSTRAP(1)         OCI CLI Command Reference        SETUP_BOOTSTRAP(1)



NAME
       setup_bootstrap -

DESCRIPTION
       Provides  an  interactive  process  to  create  a CLI config file using
       username / password  based  login  through  a  browser.   Also  handles
       generating   API   keys   and  uploading  them  to  your  Oracle  Cloud
       Infrastructure account.

       Note that port 8181 must be available in  order  for  this  command  to
       complete properly.

USAGE
          oci setup bootstrap [OPTIONS]

GLOBAL PARAMETERS
       Use oci --help for help on global parameters.

       --auth-purpose,  --auth,  --cert-bundle,  --cli-rc-file, --config-file,
       --debug,                  --defaults-file,                  --endpoint,
       --generate-full-command-json-input,        --generate-param-json-input,
       --help,    --latest-version,    --no-retry,    --opc-client-request-id,
       --opc-request-id, --output, --profile, --query, --raw-output, --region,
       --release-info, --request-id, --version, -?, -d, -h, -v

AUTHOR
       Oracle

COPYRIGHT
       2016, 2020, Oracle



2.12.13                          Sep 28, 2020               SETUP_BOOTSTRAP(1)

Step 1: Download and install OCI-CLI

Download and install the CLI: https://docs.cloud.oracle.com/en-us/iaas/Content/API/SDKDocs/climanualinst.htm

Step 2: Run the command

This will open a web browser with the Oracle Cloud Login. Login with your creditionals.

https://d33wubrfki0l68.cloudfront.net/5b464488848b509c85a3f245916345f08a2a2097/b91f3/images/oci-cli-2.png

After a successful login you will see this message.

https://d33wubrfki0l68.cloudfront.net/88b1d8432abc11a1bb4907a38ec355e196ef3692/6d2af/images/oci-cli-3.png

The config will be created for you and even uploading the PEM public key for you.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
(base) ~]$ oci setup bootstrap
Enter a region (e.g. ap-chiyoda-1, ap-chuncheon-1, ap-hyderabad-1, ap-melbourne-1, ap-mumbai-1, ap-osaka-1, ap-seoul-1, ap-sydney-1, ap-tokyo-1, ca-montreal-1, ca-toronto-1, eu-amsterdam-1, eu-frankfurt-1, eu-zurich-1, me-jeddah-1, sa-saopaulo-1, uk-gov-cardiff-1, uk-gov-london-1, uk-london-1, us-ashburn-1, us-gov-ashburn-1, us-gov-chicago-1, us-gov-phoenix-1, us-langley-1, us-luke-1, us-phoenix-1, us-sanjose-1): us-ashburn-1
    Please switch to newly opened browser window to log in!
    Completed browser authentication process!
Uploaded new API key with fingerprint: a9:49:72:d8:6a:2e:f8:f8:16:8a:6b:xx:xx:xx:xx:xx
Enter a passphrase for your private key (empty for no passphrase):
Config written to: /Users/hiran.patel/.oci/config

    Try out your newly registered credentials with the following example command:

    oci iam region list --config-file /Users/hiran.patel/.oci/config --profile DEFAULT

(base) ~]$ more ~/.oci/config


[DEFAULT]
user=ocid1.user.oc1..aaaaaaaafh3cqg3dtu5...
fingerprint=a9:49:72:d8:6a:2e:f8:f8:16:8a:6b:xx:xx:xx:xx:xx
key_file=/Users/hiran.patel/.oci/sessions/DEFAULT/oci_api_key.pem
tenancy=ocid1.tenancy.oc1..aaaaaaaadb4j...
region=us-ashburn-1

Fyi

Keep in Mind
  1. It will need access to port 8181 on our PC to work correctly. Since it runs a local websever using this URL: http://localhost:8181/#id_token=<LONG_TOKEN_KEY>&token_type=Security
  2. It doesn’t work in the Oracle Cloud Console. If filed the following git issue ER to implement it. https://github.com/oracle/oci-cli/issues/338