-
Notifications
You must be signed in to change notification settings - Fork 69
NAS-3868 extend user and organisation service #108
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
68 changes: 42 additions & 26 deletions
68
gooddata-sdk/gooddata_sdk/catalog/organization/entity_model/organization.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,33 +1,49 @@ | ||
| # (C) 2022 GoodData Corporation | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Any | ||
| from typing import List, Optional, Type | ||
|
|
||
| import attr | ||
|
|
||
| from gooddata_metadata_client.model.json_api_organization_in import JsonApiOrganizationIn | ||
| from gooddata_metadata_client.model.json_api_organization_in_attributes import JsonApiOrganizationInAttributes | ||
| from gooddata_metadata_client.model.json_api_organization_in_document import JsonApiOrganizationInDocument | ||
| from gooddata_sdk.catalog.entity import CatalogNameEntity | ||
|
|
||
|
|
||
| class CatalogOrganization(CatalogNameEntity): | ||
| def __init__(self, organization_id: str, name: str, hostname: str) -> None: | ||
| super(CatalogOrganization, self).__init__(organization_id, name) | ||
| self.hostname = hostname | ||
|
|
||
| @classmethod | ||
| def from_api(cls, entity: dict[str, Any]) -> CatalogOrganization: | ||
| ea = entity["attributes"] | ||
| return cls(organization_id=entity["id"], name=ea["name"], hostname=ea["hostname"]) | ||
|
|
||
| def to_api(self) -> JsonApiOrganizationInDocument: | ||
| return JsonApiOrganizationInDocument( | ||
| data=JsonApiOrganizationIn( | ||
| id=self.id, | ||
| attributes=JsonApiOrganizationInAttributes(name=self.name, hostname=self.hostname), | ||
| ) | ||
| ) | ||
|
|
||
| def __eq__(self, other: object) -> bool: | ||
| if not isinstance(other, CatalogOrganization): | ||
| return False | ||
| return self.id == other.id and self.name == other.name and self.hostname == other.hostname | ||
| from gooddata_sdk.catalog.base import Base | ||
|
|
||
|
|
||
| @attr.s(auto_attribs=True, kw_only=True) | ||
| class CatalogOrganizationDocument(Base): | ||
| data: CatalogOrganization | ||
|
|
||
| @staticmethod | ||
| def client_class() -> Type[JsonApiOrganizationInDocument]: | ||
| return JsonApiOrganizationInDocument | ||
|
|
||
| def to_api(self, oauth_client_secret: Optional[str] = None) -> JsonApiOrganizationInDocument: | ||
| dictionary = self._get_snake_dict() | ||
| if oauth_client_secret is not None: | ||
| dictionary["data"]["attributes"]["oauth_client_secret"] = oauth_client_secret | ||
| return self.client_class().from_dict(dictionary, camel_case=False) | ||
|
|
||
|
|
||
| @attr.s(auto_attribs=True, kw_only=True) | ||
| class CatalogOrganization(Base): | ||
| id: str | ||
| attributes: CatalogOrganizationAttributes | ||
|
|
||
| @staticmethod | ||
| def client_class() -> Type[JsonApiOrganizationIn]: | ||
| return JsonApiOrganizationIn | ||
|
|
||
|
|
||
| @attr.s(auto_attribs=True, kw_only=True) | ||
| class CatalogOrganizationAttributes(Base): | ||
| name: Optional[str] = None | ||
| hostname: Optional[str] = None | ||
| allowed_origins: Optional[List[str]] = None | ||
| oauth_issuer_location: Optional[str] = None | ||
| oauth_client_id: Optional[str] = None | ||
|
|
||
| @staticmethod | ||
| def client_class() -> Type[JsonApiOrganizationInAttributes]: | ||
| return JsonApiOrganizationInAttributes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,36 @@ | ||
| # (C) 2022 GoodData Corporation | ||
| from __future__ import annotations | ||
|
|
||
| from typing import Optional | ||
|
|
||
| from gooddata_sdk.catalog.catalog_service_base import CatalogServiceBase | ||
| from gooddata_sdk.catalog.organization.entity_model.organization import CatalogOrganizationDocument | ||
| from gooddata_sdk.client import GoodDataApiClient | ||
|
|
||
|
|
||
| class CatalogOrganizationService(CatalogServiceBase): | ||
| def __init__(self, api_client: GoodDataApiClient) -> None: | ||
| super(CatalogOrganizationService, self).__init__(api_client) | ||
|
|
||
| def update_oidc_parameters( | ||
| self, | ||
| oauth_issuer_location: Optional[str] = None, | ||
| oauth_client_id: Optional[str] = None, | ||
| oauth_client_secret: Optional[str] = None, | ||
| ) -> None: | ||
| parameters = [oauth_issuer_location, oauth_client_id, oauth_client_secret] | ||
| if not all(p is not None for p in parameters) and any(p is not None for p in parameters): | ||
| raise ValueError("All parameters have to be set to None or all parameters has to be string.") | ||
| organization = self.get_organization() | ||
| organization.attributes.oauth_issuer_location = oauth_issuer_location | ||
| organization.attributes.oauth_client_id = oauth_client_id | ||
| organization_document = CatalogOrganizationDocument(data=organization) | ||
| self._entities_api.update_entity_organizations( | ||
| organization.id, organization_document.to_api(oauth_client_secret=oauth_client_secret) | ||
| ) | ||
|
|
||
| def update_name(self, name: str) -> None: | ||
| organization = self.get_organization() | ||
| organization.attributes.name = name | ||
| organization_document = CatalogOrganizationDocument(data=organization) | ||
| self._entities_api.update_entity_organizations(organization.id, organization_document.to_api()) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.