diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 3ab426e..194ee5a 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -29,7 +29,6 @@ RUN yum install -y \ chmod 0440 /etc/sudoers.d/$USERNAME && \ python3 -m pip install \ pylint \ - cx_Oracle \ --upgrade USER ${USERNAME} \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 10b92f7..1d23248 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -15,6 +15,9 @@ // Uncomment the next line to use Docker from inside the container. See https://aka.ms/vscode-remote/samples/docker-in-docker for details. // "-v","/var/run/docker.sock:/var/run/docker.sock", + // Uncomment the next line to mount the user's .oci directory that contains the OCI API key and config files. + // "-v", "${env:HOME}${env:USERPROFILE}/.oci:/home/vscode/.oci", + // Uncomment the next line if you will be using a ptrace-based debugger like C++, Go, and Rust. // "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" @@ -40,7 +43,7 @@ }, // Installs any dependencies if "requirements.txt" exists in workspace root. - "postCreateCommand": "if [[ -f requirements.txt ]]; then python3 -m pip install -r requirements.txt; fi;", + "postCreateCommand": "if [[ -f requirements.txt ]]; then sudo python3 -m pip install -r requirements.txt; fi;", // Add the IDs of any extensions you want installed in the array below. "extensions": [ "ms-python.python" ] diff --git a/.gitignore b/.gitignore index 3be041e..cf28cc0 100644 --- a/.gitignore +++ b/.gitignore @@ -211,4 +211,5 @@ $RECYCLE.BIN/ # End of https://www.gitignore.io/api/node,java,linux,macos,maven,windows,visualstudiocode *.ora -.wallets \ No newline at end of file +.wallets +.oci \ No newline at end of file diff --git a/README.md b/README.md index 7a86a77..92d48e6 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,7 @@ The starter kit runs a Docker container with the following components for Python * Oracle SQL*Plus * Python 3.x * [cx_Oracle](https://oracle.github.io/python-cx_Oracle/) +* [Oracle Cloud Infrastructure](https://cloud.oracle.com) (OCI) [Python SDK](https://oracle-cloud-infrastructure-python-sdk.readthedocs.io) * Git * Microsoft's [Python extension for VS Code](https://marketplace.visualstudio.com/items?itemName=ms-python.python) * [pylint](https://www.pylint.org/) @@ -70,6 +71,10 @@ A debug configuration has been created. See [`launch.json`](.vscode/launch.json) Developers are encouraged to store database credentials safely in encrypted Oracle Wallets, as oppose to storing them in plaintext either within the Python script or as environment variables. Follow the [*Oracle Database Connection with Oracle Wallet*](docs/oracle-database-connection-with-oracle-wallet.md) guide. +### Support for Oracle Cloud Infrastructure + +See [*Support for Oracle Cloud Infrasturcture Guide*](docs/support-for-oci.md). + ## Credits The beauty of [Open Source](https://opensource.org/) is that we can learn and build on top of previous knowledge shared by others. I wish to thank the following projects that have guided the creation of this starter kit: diff --git a/docs/support-for-oci.md b/docs/support-for-oci.md new file mode 100644 index 0000000..1393eee --- /dev/null +++ b/docs/support-for-oci.md @@ -0,0 +1,21 @@ +# Support for Oracle Cloud Infrastructure + +The starter kit now comes with the [Oracle Cloud Infrastructure](https://cloud.oracle.com) (OCI) [Python SDK](https://oracle-cloud-infrastructure-python-sdk.readthedocs.io) preinstalled. + +1. Follow the instructions on OCI's [Tools Configuration](https://docs.cloud.oracle.com/iaas/Content/ToolsConfig.htm) page to generate, upload the API key and configure the SDK. +1. Place the API key and `config` file in a subdirectory `.oci`, under the home directory of the user. In Mac and Linux, the home directory is expressed by the environment variable `$HOME`, and in Windows, `%USERPROFILE%`. +1. Uncomment the following line in [devcontainer.json](../.devcontainer/devcontainer.json): + ```json + "-v", "${env:HOME}${env:USERPROFILE}/.oci:/home/vscode/.oci", + ``` + +Running the following Python code should return the user object if the SDK is configured correctly: + +```python +import oci + +config=oci.config.from_file("~/.oci/config", "DEFAULT") +identity = oci.identity.IdentityClient(config) +user = identity.get_user(config["user"]).data +print(user) +``` \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 343e57d..760e3f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,3 @@ -# Place any additional Python libraries required that can be found on the [Python Package Index](https://pypi.org/) \ No newline at end of file +cx_oracle +oci +# Place any additional Python libraries required that can be found on the [Python Package Index](https://pypi.org/) below this line. \ No newline at end of file