Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enable --endpoint #244

Merged
merged 1 commit into from
Feb 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions osc_sdk/sdk.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@ class ApiCall:
date: Optional[str] = field(default=None, init=False)
datestamp: Optional[str] = field(default=None, init=False)

endpoint: Optional[str] = None
method: str = DEFAULT_METHOD
endpoint: str = ""
host: str = ""
access_key: Optional[str] = None
secret_key: Optional[str] = None
Expand Down Expand Up @@ -242,7 +242,7 @@ def __post_init__(self):
if parsed_url.scheme:
self.host = parsed_url.netloc
else:
self.host = self.endpoint
self.host = str(self.endpoint)
self.endpoint = f"{self.protocol}://{self.endpoint}"

def check_authentication_options(self):
Expand All @@ -269,7 +269,7 @@ def set_datestamp(self):
def get_url(
self, call: str, encoded_request_params: EncodedCallParameters = None
) -> str:
value = self.endpoint
value = self.endpoint if self.endpoint else ""
if self.method == "GET":
value += f"?{encoded_request_params}"
return value
Expand Down Expand Up @@ -674,7 +674,7 @@ def get_canonical_uri(self, call: str) -> str:
def get_url(
self, call: str, encoded_request_params: EncodedCallParameters = None
) -> str:
return "/".join([self.endpoint, self.get_canonical_uri(call)])
return "/".join([str(self.endpoint), self.get_canonical_uri(call)])

def get_password_params(self) -> PasswordParams:
# Don't put any auth parameters in body
Expand Down Expand Up @@ -708,6 +708,12 @@ def build_headers(self, target: str, _) -> Headers:
return signed_headers, canonical_headers, headers


def patch_conf(conf: Configuration, endpoint: Optional[str] = None) -> Configuration:
if endpoint:
conf["endpoint"] = endpoint
return conf


def get_conf(profile: str) -> Configuration:
# Check which conf_path is used.
conf_path = next((path for path in CONF_PATHS if path.exists()), None)
Expand Down Expand Up @@ -747,6 +753,7 @@ def api_connect(
call: str,
profile: str = DEFAULT_PROFILE,
login: Optional[str] = None,
endpoint: Optional[str] = None,
password: Optional[str] = None,
authentication_method: Optional[str] = None,
bash_completion: bool = False,
Expand All @@ -764,8 +771,13 @@ def api_connect(
}

handler = calls[service](
profile, login, PASSWORD_ARG, authentication_method, **get_conf(profile)
profile,
login,
PASSWORD_ARG,
authentication_method,
**patch_conf(get_conf(profile), endpoint),
)

handler.make_request(call, **kwargs)
if handler.response:
print(json.dumps(handler.response, indent=4))
Expand Down