Skip to content

Commit

Permalink
sdk: use default conf instead of raising error on buggy/no conf file.
Browse files Browse the repository at this point in the history
This is so we can use osc-cli without conf file,
either for calls that doesn't need auth or using environement variables

Note that we don't support environement variables, but this is a good start

Signed-off-by: Matthias Gatto <matthias.gatto@outscale.com>
  • Loading branch information
outscale-mgo committed Jun 6, 2022
1 parent 45645ff commit b198082
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions osc_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,19 @@ class Configuration(TypedDict):
host: str


DEFAULT_CONF = cast(
Configuration,
{
"method": "POST",
"https": True,
"region_name": DEFAULT_REGION,
"ssl_verify": True,
"version": DEFAULT_VERSION,
"host": DEFAULT_HOST,
},
)


class PasswordParams(TypedDict, total=False):
AuthenticationMethod: str
Login: Optional[str]
Expand Down Expand Up @@ -689,7 +702,7 @@ def get_conf(profile: str) -> Configuration:
conf_path = next((path for path in CONF_PATHS if path.exists()), None)

if not conf_path:
raise RuntimeError("No configuration file found in home folder")
return DEFAULT_CONF

json_profiles = json.loads(conf_path.read_text())
# convert region to region_name in json to fit Mapping
Expand All @@ -711,7 +724,7 @@ def get_conf(profile: str) -> Configuration:
try:
return conf[profile]
except KeyError:
raise RuntimeError(f"Profile {profile} not found in configuration file")
return DEFAULT_CONF


def call_need_auth(service: str, call: str) -> bool:
Expand Down

0 comments on commit b198082

Please sign in to comment.