Skip to content

Commit 1d1582e

Browse files
authored
Merge pull request #38 from AmedeeBulle/session-token
feat: ✨ manage-dt: support for token auth.
2 parents 10c9916 + ec2ccb6 commit 1d1582e

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

samples/python/manage-dt/manage_dt/cli.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ def validate_digital_twin(
7777
)
7878
@click.option(
7979
"--auth",
80-
type=click.Choice(["api_key", "instance_principal", "resource_principal"]),
80+
type=click.Choice(
81+
["api_key", "instance_principal", "resource_principal", "security_token"]
82+
),
8183
help="The type of auth to use for the API request.",
8284
default=os.getenv("OCI_CLI_AUTH", "api_key"),
8385
show_default=True,

samples/python/manage-dt/manage_dt/mdt_oci.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from typing import Tuple
1414

1515
from oci import config as oci_config
16+
from oci import signer as oci_signer
1617
from oci.auth import signers as oci_auth_signers
1718

1819

@@ -79,6 +80,20 @@ def get_oci_config(
7980
"signer": oci_auth_signers.get_resource_principals_signer(),
8081
}
8182
config = {}
83+
case "security_token":
84+
logger.debug("OCI authentication: Session Token")
85+
config = oci_config.from_file(profile_name=profile)
86+
if os.getenv("OCI_CLI_TENANCY"):
87+
logger.debug("Overriding tenancy OCID")
88+
config["tenancy"] = os.getenv("OCI_CLI_TENANCY")
89+
token_file = config["security_token_file"]
90+
token = None
91+
with open(token_file, "r") as f:
92+
token = f.read()
93+
private_key = oci_signer.load_private_key_from_file(config["key_file"])
94+
signer = {
95+
"signer": oci_auth_signers.SecurityTokenSigner(token, private_key),
96+
}
8297
case _:
8398
raise ValueError(f"unsupported auth scheme {auth}")
8499
return config, signer

samples/python/manage-dt/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
setup(
2222
name="manage_dt",
23-
version="0.0.2",
23+
version="0.0.3",
2424
description="Manage Digital Twins sample script",
2525
long_description=long_description,
2626
long_description_content_type="text/markdown",

0 commit comments

Comments
 (0)