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

fix(v2client): set organizationguid header by default #330

Merged
merged 1 commit into from
Jul 10, 2024
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
36 changes: 20 additions & 16 deletions riocli/v2client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,14 @@ def __init__(self, config, auth_token: str, project: Optional[str] = None):
self._project = project
self._token = 'Bearer {}'.format(auth_token)

def _get_auth_header(self: Client, with_org: bool = False, with_project: bool = True) -> dict:
def _get_auth_header(self: Client, with_project: bool = True) -> dict:
headers = dict(Authorization=self._token)

headers['organizationguid'] = self._config.organization_guid

if with_project and self._project is not None:
headers['project'] = self._project

if with_org:
headers['organizationguid'] = self._config.organization_guid

return headers

# Project APIs
Expand Down Expand Up @@ -120,6 +119,11 @@ def create_project(self, spec: dict) -> Munch:
"""
url = "{}/v2/projects/".format(self._host)
headers = self._get_auth_header(with_project=False)

# Set the organizationguid header
if spec['metadata'].get('organizationGUID'):
headers['organizationguid'] = spec['metadata'].get('organizationGUID')
pallabpain marked this conversation as resolved.
Show resolved Hide resolved

response = RestClient(url).method(HttpMethod.POST).headers(
headers).execute(payload=spec)

Expand Down Expand Up @@ -507,13 +511,13 @@ def update_secret(self, secret_name: str, spec: dict) -> Munch:
# ConfigTrees APIs
def list_config_trees(self) -> Munch:
url = "{}/v2/configtrees/".format(self._host)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
client = RestClient(url).method(HttpMethod.GET).headers(headers)
return self._walk_pages(client)

def create_config_tree(self, tree_spec: dict) -> Munch:
url = "{}/v2/configtrees/".format(self._host)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.POST).headers(
headers).execute(payload=tree_spec)
handle_server_errors(response)
Expand All @@ -527,7 +531,7 @@ def create_config_tree(self, tree_spec: dict) -> Munch:

def delete_config_tree(self, tree_name: str) -> Munch:
url = "{}/v2/configtrees/{}/".format(self._host, tree_name)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.DELETE).headers(
headers).execute()
handle_server_errors(response)
Expand All @@ -549,7 +553,7 @@ def get_config_tree(self, tree_name: str, rev_id: Optional[str] = None,
'keyPrefixes': filter_prefixes,
'revision': rev_id,
}
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.GET).headers(
headers).query_param(query).execute()
handle_server_errors(response)
Expand All @@ -563,7 +567,7 @@ def get_config_tree(self, tree_name: str, rev_id: Optional[str] = None,

def set_revision_config_tree(self, tree_name: str, spec: dict) -> Munch:
url = "{}/v2/configtrees/{}/".format(self._host, tree_name)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.PUT).headers(
headers).execute(payload=spec)
handle_server_errors(response)
Expand All @@ -577,13 +581,13 @@ def set_revision_config_tree(self, tree_name: str, spec: dict) -> Munch:

def list_config_tree_revisions(self, tree_name: str, labels: str = '') -> Munch:
url = "{}/v2/configtrees/{}/revisions/".format(self._host, tree_name)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
client = RestClient(url).method(HttpMethod.GET).headers(headers)
return self._walk_pages(client, params={'labelSelector': labels})

def initialize_config_tree_revision(self, tree_name: str) -> Munch:
url = "{}/v2/configtrees/{}/revisions/".format(self._host, tree_name)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.POST).headers(
headers).execute()
handle_server_errors(response)
Expand All @@ -597,7 +601,7 @@ def initialize_config_tree_revision(self, tree_name: str) -> Munch:

def commit_config_tree_revision(self, tree_name: str, rev_id: str, payload: dict) -> Munch:
url = "{}/v2/configtrees/{}/revisions/{}/".format(self._host, tree_name, rev_id)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.PATCH).headers(
headers).execute(payload=payload)
handle_server_errors(response)
Expand All @@ -611,7 +615,7 @@ def commit_config_tree_revision(self, tree_name: str, rev_id: str, payload: dict

def store_keys_in_revision(self, tree_name: str, rev_id: str, payload: Any) -> Munch:
url = "{}/v2/configtrees/{}/revisions/{}/".format(self._host, tree_name, rev_id)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.PUT).headers(
headers).execute(payload=payload)
handle_server_errors(response)
Expand All @@ -625,7 +629,7 @@ def store_keys_in_revision(self, tree_name: str, rev_id: str, payload: Any) -> M

def store_key_in_revision(self, tree_name: str, rev_id: str, key: str, value: str, perms: int = 644) -> Munch:
url = "{}/v2/configtrees/{}/revisions/{}/{}".format(self._host, tree_name, rev_id, key)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
headers['Content-Type'] = 'kv'
headers['X-Checksum'] = md5(str(value).encode('utf-8')).hexdigest()
headers['X-Permissions'] = str(perms)
Expand All @@ -648,7 +652,7 @@ def store_file_in_revision(self, tree_name: str, rev_id: str, key: str, file_pat
content_type = magic.from_file(file_path, mime=True)

url = "{}/v2/configtrees/{}/revisions/{}/{}".format(self._host, tree_name, rev_id, key)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
headers['Content-Type'] = content_type
headers['X-Permissions'] = perms

Expand All @@ -674,7 +678,7 @@ def store_file_in_revision(self, tree_name: str, rev_id: str, key: str, file_pat

def delete_key_in_revision(self, tree_name: str, rev_id: str, key: str) -> Munch:
url = "{}/v2/configtrees/{}/revisions/{}/{}".format(self._host, tree_name, rev_id, key)
headers = self._get_auth_header(with_org=True)
headers = self._get_auth_header()
response = RestClient(url).method(HttpMethod.DELETE).headers(headers).execute()
handle_server_errors(response)

Expand Down
Loading