Skip to content

Commit

Permalink
attempting to write config file on client creation
Browse files Browse the repository at this point in the history
  • Loading branch information
abiswal2001 committed Oct 20, 2023
1 parent 23b14c9 commit 654ca94
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
32 changes: 32 additions & 0 deletions skyplane/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from skyplane.api.config import TransferConfig
from skyplane.api.provisioner import Provisioner
from skyplane.api.obj_store import ObjectStore
from skyplane.config_paths import config_path
from skyplane.obj_store.object_store_interface import ObjectStoreInterface
from skyplane.obj_store.storage_interface import StorageInterface
from skyplane.api.usage import get_clientid
Expand Down Expand Up @@ -79,6 +80,37 @@ def __init__(
disable_ibm=disable_ibm
)

self.config = SkyplaneConfig()
if not disable_aws:
self.config.aws_enabled = True
if aws_config:
self.config.aws_access_key = aws_config.aws_access_key
self.config.aws_secret_key = aws_config.aws_secret_key
if not disable_azure:
self.config.azure_enabled = True
if azure_config:
self.config.azure_subscription_id=azure_config.azure_subscription_id
self.config.azure_resource_group=azure_config.azure_resource_group
self.config.azure_principal_id=azure_config.azure_umi_id
self.config.azure_umi_name=azure_config.azure_umi_name
self.config.azure_client_id=azure_config.azure_umi_client_id
if not disable_gcp:
self.config.gcp_enabled = True
if gcp_config:
self.config.gcp_project_id=gcp_config.gcp_project_id
if not disable_ibm:
self.config.ibm_enabled = True
if ibm_config:
self.config.ibmcloud_access_id=ibm_config.ibmcloud_access_id
self.config.ibmcloud_secret_key=ibm_config.ibmcloud_secret_key
self.config.ibmcloud_iam_key=ibm_config.ibmcloud_iam_key
self.config.ibmcloud_iam_endpoint=ibm_config.ibmcloud_iam_endpoint
self.config.ibmcloud_useragent=ibm_config.ibmcloud_useragent
self.config.ibmcloud_resource_group_id=ibm_config.ibmcloud_resource_group_id

self.config.to_config_file(config_path)
typer.secho(f"\nConfig file saved to {config_path}", fg="green")

def pipeline(self, planning_algorithm: Optional[str] = "direct", max_instances: Optional[int] = 1, src_iface: Optional[ObjectStoreInterface] = None, dst_ifaces: Optional[List[ObjectStoreInterface]] = None, debug=False):
"""Create a pipeline object to queue jobs"""
return Pipeline(
Expand Down
12 changes: 12 additions & 0 deletions skyplane/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ class SkyplaneConfig:
cloudflare_enabled: bool
ibmcloud_enabled: bool
anon_clientid: str
aws_access_key: Optional[str] = None
aws_secret_key: Optional[str] = None
azure_principal_id: Optional[str] = None
azure_subscription_id: Optional[str] = None
azure_resource_group: Optional[str] = None
Expand Down Expand Up @@ -151,6 +153,10 @@ def load_config(cls, path) -> "SkyplaneConfig":
if "aws" in config:
if "aws_enabled" in config["aws"]:
aws_enabled = config.getboolean("aws", "aws_enabled")
if "aws_access_key" in config["aws"]:
aws_access_key = config.get("aws", "aws_access_key")
if "aws_secret_key" in config["aws"]:
aws_secret_key = config.getboolean("aws", "aws_secret_key")

azure_enabled = False
azure_subscription_id = None
Expand Down Expand Up @@ -215,6 +221,8 @@ def load_config(cls, path) -> "SkyplaneConfig":
gcp_enabled=gcp_enabled,
ibmcloud_enabled=ibmcloud_enabled,
cloudflare_enabled=cloudflare_enabled,
aws_access_key=aws_access_key,
aws_secret_key=aws_secret_key,
anon_clientid=anon_clientid,
azure_principal_id=azure_principal_id,
azure_subscription_id=azure_subscription_id,
Expand Down Expand Up @@ -248,6 +256,10 @@ def to_config_file(self, path):
if "aws" not in config:
config.add_section("aws")
config.set("aws", "aws_enabled", str(self.aws_enabled))
if self.aws_access_key:
config.set("aws", "aws_access_key", self.aws_access_key)
if self.aws_secret_key:
config.set("aws", "aws_secret_key", self.aws_secret_key)

if "ibmcloud" not in config:
config.add_section("ibmcloud")
Expand Down

0 comments on commit 654ca94

Please sign in to comment.