Skip to content

Commit 6374a88

Browse files
committed
sign API requests (#2)
Signed-off-by: Richard Gebhardt <[email protected]>
1 parent 6dc3bd7 commit 6374a88

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

oci_compute.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from logging import Logger
23

34
import oci
@@ -10,8 +11,17 @@
1011

1112
def get_compute_client():
1213
logger.info("entering get_compute_client")
13-
config = oci.config.from_file()
14-
return oci.core.ComputeClient(config)
14+
config = oci.config.from_file(
15+
profile_name=os.getenv("OCI_CONFIG_PROFILE", oci.config.DEFAULT_PROFILE)
16+
)
17+
18+
private_key = oci.signer.load_private_key_from_file(config["key_file"])
19+
token_file = config["security_token_file"]
20+
token = None
21+
with open(token_file, "r") as f:
22+
token = f.read()
23+
signer = oci.auth.signers.SecurityTokenSigner(token, private_key)
24+
return oci.core.ComputeClient(config, signer=signer)
1525

1626

1727
@mcp.tool

oci_networking.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import os
12
from logging import Logger
23

34
import oci
@@ -9,9 +10,16 @@
910

1011

1112
def get_networking_client():
12-
# Assumes you have ~/.oci/config with [DEFAULT] set up
13-
config = oci.config.from_file("~/.oci/config")
14-
return oci.core.VirtualNetworkClient(config)
13+
config = oci.config.from_file(
14+
profile_name=os.getenv("OCI_CONFIG_PROFILE", oci.config.DEFAULT_PROFILE)
15+
)
16+
private_key = oci.signer.load_private_key_from_file(config["key_file"])
17+
token_file = config["security_token_file"]
18+
token = None
19+
with open(token_file, "r") as f:
20+
token = f.read()
21+
signer = oci.auth.signers.SecurityTokenSigner(token, private_key)
22+
return oci.core.VirtualNetworkClient(config, signer=signer)
1523

1624

1725
@mcp.tool

0 commit comments

Comments
 (0)