-
Notifications
You must be signed in to change notification settings - Fork 445
feat: support extensions api #1672
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
Open
jorwoods
wants to merge
9
commits into
tableau:development
Choose a base branch
from
jorwoods:jorwoods/extensions
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
499f4f4
feat: List server extension settings
jorwoods 7ba63c1
feat: support updating server extension settings
jorwoods ce43b3d
feat: enable retrieving site extension settings
jorwoods 4cc683b
feat: support updating site settings
jorwoods 83c25d8
feat: add support for new extension attributes
jorwoods 74ac0bc
chore: update to py3.10 syntax
jorwoods 0cdb28b
fix: copilot suggestions
jorwoods f74a714
fix: remove unused import
jorwoods c24b7ff
docs: reflect actual behavior
jorwoods 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| from typing import overload | ||
| from typing_extensions import Self | ||
|
|
||
| from defusedxml.ElementTree import fromstring | ||
|
|
||
| from tableauserverclient.models.property_decorators import property_is_boolean | ||
|
|
||
|
|
||
| class ExtensionsServer: | ||
| def __init__(self) -> None: | ||
| self._enabled: bool | None = None | ||
| self._block_list: list[str] | None = None | ||
|
|
||
| @property | ||
| def enabled(self) -> bool | None: | ||
| """Indicates whether the extensions server is enabled.""" | ||
| return self._enabled | ||
|
|
||
| @enabled.setter | ||
| @property_is_boolean | ||
| def enabled(self, value: bool | None) -> None: | ||
| self._enabled = value | ||
|
|
||
| @property | ||
| def block_list(self) -> list[str] | None: | ||
| """List of blocked extensions.""" | ||
| return self._block_list | ||
|
|
||
| @block_list.setter | ||
| def block_list(self, value: list[str] | None) -> None: | ||
| self._block_list = value | ||
|
|
||
| @classmethod | ||
| def from_response(cls: type[Self], response, ns) -> Self: | ||
| xml = fromstring(response) | ||
| obj = cls() | ||
| element = xml.find(".//t:extensionsServerSettings", namespaces=ns) | ||
| if element is None: | ||
| raise ValueError("Missing extensionsServerSettings element in response") | ||
|
|
||
| if (enabled_element := element.find("./t:extensionsGloballyEnabled", namespaces=ns)) is not None: | ||
| obj.enabled = string_to_bool(enabled_element.text) | ||
| obj.block_list = [e.text for e in element.findall("./t:blockList", namespaces=ns) if e.text is not None] | ||
|
|
||
| return obj | ||
|
|
||
|
|
||
| class SafeExtension: | ||
| def __init__( | ||
| self, url: str | None = None, full_data_allowed: bool | None = None, prompt_needed: bool | None = None | ||
| ) -> None: | ||
| self.url = url | ||
| self._full_data_allowed = full_data_allowed | ||
| self._prompt_needed = prompt_needed | ||
|
|
||
| @property | ||
| def full_data_allowed(self) -> bool | None: | ||
| return self._full_data_allowed | ||
|
|
||
| @full_data_allowed.setter | ||
| @property_is_boolean | ||
| def full_data_allowed(self, value: bool | None) -> None: | ||
| self._full_data_allowed = value | ||
|
|
||
| @property | ||
| def prompt_needed(self) -> bool | None: | ||
| return self._prompt_needed | ||
|
|
||
| @prompt_needed.setter | ||
| @property_is_boolean | ||
| def prompt_needed(self, value: bool | None) -> None: | ||
| self._prompt_needed = value | ||
|
|
||
|
|
||
| class ExtensionsSiteSettings: | ||
| def __init__(self) -> None: | ||
| self._enabled: bool | None = None | ||
| self._use_default_setting: bool | None = None | ||
| self.safe_list: list[SafeExtension] | None = None | ||
| self._allow_trusted: bool | None = None | ||
| self._include_tableau_built: bool | None = None | ||
| self._include_partner_built: bool | None = None | ||
| self._include_sandboxed: bool | None = None | ||
|
|
||
| @property | ||
| def enabled(self) -> bool | None: | ||
| return self._enabled | ||
|
|
||
| @enabled.setter | ||
| @property_is_boolean | ||
| def enabled(self, value: bool | None) -> None: | ||
| self._enabled = value | ||
|
|
||
| @property | ||
| def use_default_setting(self) -> bool | None: | ||
| return self._use_default_setting | ||
|
|
||
| @use_default_setting.setter | ||
| @property_is_boolean | ||
| def use_default_setting(self, value: bool | None) -> None: | ||
| self._use_default_setting = value | ||
|
|
||
| @property | ||
| def allow_trusted(self) -> bool | None: | ||
| return self._allow_trusted | ||
|
|
||
| @allow_trusted.setter | ||
| @property_is_boolean | ||
| def allow_trusted(self, value: bool | None) -> None: | ||
| self._allow_trusted = value | ||
|
|
||
| @property | ||
| def include_tableau_built(self) -> bool | None: | ||
| return self._include_tableau_built | ||
|
|
||
| @include_tableau_built.setter | ||
| @property_is_boolean | ||
| def include_tableau_built(self, value: bool | None) -> None: | ||
| self._include_tableau_built = value | ||
|
|
||
| @property | ||
| def include_partner_built(self) -> bool | None: | ||
| return self._include_partner_built | ||
|
|
||
| @include_partner_built.setter | ||
| @property_is_boolean | ||
| def include_partner_built(self, value: bool | None) -> None: | ||
| self._include_partner_built = value | ||
|
|
||
| @property | ||
| def include_sandboxed(self) -> bool | None: | ||
| return self._include_sandboxed | ||
|
|
||
| @include_sandboxed.setter | ||
| @property_is_boolean | ||
| def include_sandboxed(self, value: bool | None) -> None: | ||
| self._include_sandboxed = value | ||
|
|
||
| @classmethod | ||
| def from_response(cls: type[Self], response, ns) -> Self: | ||
| xml = fromstring(response) | ||
| element = xml.find(".//t:extensionsSiteSettings", namespaces=ns) | ||
| obj = cls() | ||
| if element is None: | ||
| raise ValueError("Missing extensionsSiteSettings element in response") | ||
|
|
||
| if (enabled_element := element.find("./t:extensionsEnabled", namespaces=ns)) is not None: | ||
| obj.enabled = string_to_bool(enabled_element.text) | ||
| if (default_settings_element := element.find("./t:useDefaultSetting", namespaces=ns)) is not None: | ||
| obj.use_default_setting = string_to_bool(default_settings_element.text) | ||
| if (allow_trusted_element := element.find("./t:allowTrusted", namespaces=ns)) is not None: | ||
| obj.allow_trusted = string_to_bool(allow_trusted_element.text) | ||
| if (include_tableau_built_element := element.find("./t:includeTableauBuilt", namespaces=ns)) is not None: | ||
| obj.include_tableau_built = string_to_bool(include_tableau_built_element.text) | ||
| if (include_partner_built_element := element.find("./t:includePartnerBuilt", namespaces=ns)) is not None: | ||
| obj.include_partner_built = string_to_bool(include_partner_built_element.text) | ||
| if (include_sandboxed_element := element.find("./t:includeSandboxed", namespaces=ns)) is not None: | ||
| obj.include_sandboxed = string_to_bool(include_sandboxed_element.text) | ||
|
|
||
| safe_list = [] | ||
| for safe_extension_element in element.findall("./t:safeList", namespaces=ns): | ||
| url = safe_extension_element.find("./t:url", namespaces=ns) | ||
| full_data_allowed = safe_extension_element.find("./t:fullDataAllowed", namespaces=ns) | ||
| prompt_needed = safe_extension_element.find("./t:promptNeeded", namespaces=ns) | ||
|
|
||
| safe_extension = SafeExtension( | ||
| url=url.text if url is not None else None, | ||
| full_data_allowed=string_to_bool(full_data_allowed.text) if full_data_allowed is not None else None, | ||
| prompt_needed=string_to_bool(prompt_needed.text) if prompt_needed is not None else None, | ||
| ) | ||
| safe_list.append(safe_extension) | ||
|
|
||
| obj.safe_list = safe_list | ||
| return obj | ||
|
|
||
|
|
||
| @overload | ||
| def string_to_bool(s: str) -> bool: ... | ||
jorwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @overload | ||
| def string_to_bool(s: None) -> None: ... | ||
jorwoods marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| def string_to_bool(s): | ||
| return s.lower() == "true" if s is not None else None | ||
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
79 changes: 79 additions & 0 deletions
79
tableauserverclient/server/endpoint/extensions_endpoint.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 |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| from tableauserverclient.models.extensions_item import ExtensionsServer, ExtensionsSiteSettings | ||
| from tableauserverclient.server.endpoint.endpoint import Endpoint | ||
| from tableauserverclient.server.endpoint.endpoint import api | ||
| from tableauserverclient.server.request_factory import RequestFactory | ||
|
|
||
|
|
||
| class Extensions(Endpoint): | ||
| def __init__(self, parent_srv): | ||
| super().__init__(parent_srv) | ||
|
|
||
| @property | ||
| def _server_baseurl(self) -> str: | ||
| return f"{self.parent_srv.baseurl}/settings/extensions" | ||
|
|
||
| @property | ||
| def baseurl(self) -> str: | ||
| return f"{self.parent_srv.baseurl}/sites/{self.parent_srv.site_id}/settings/extensions" | ||
|
|
||
| @api(version="3.21") | ||
| def get_server_settings(self) -> ExtensionsServer: | ||
| """Lists the settings for extensions of a server | ||
|
|
||
| Returns | ||
| ------- | ||
| ExtensionsServer | ||
| The server extensions settings | ||
| """ | ||
| response = self.get_request(self._server_baseurl) | ||
| return ExtensionsServer.from_response(response.content, self.parent_srv.namespace) | ||
|
|
||
| @api(version="3.21") | ||
| def update_server_settings(self, extensions_server: ExtensionsServer) -> ExtensionsServer: | ||
| """Updates the settings for extensions of a server. Overwrites all existing settings. Any | ||
| sites omitted from the block list will be unblocked. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| extensions_server : ExtensionsServer | ||
| The server extensions settings to update | ||
|
|
||
| Returns | ||
| ------- | ||
| ExtensionsServer | ||
| The updated server extensions settings | ||
| """ | ||
| req = RequestFactory.Extensions.update_server_extensions(extensions_server) | ||
| response = self.put_request(self._server_baseurl, req) | ||
| return ExtensionsServer.from_response(response.content, self.parent_srv.namespace) | ||
|
|
||
| @api(version="3.21") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For the site settings, I wonder if we should just use 3.27 here? The methods were added in 3.21, but the new trusted items and such weren't added until 3.27. Thoughts? |
||
| def get(self) -> ExtensionsSiteSettings: | ||
| """Lists the extensions settings for the site | ||
|
|
||
| Returns | ||
| ------- | ||
| ExtensionsSiteSettings | ||
| The site extensions settings | ||
| """ | ||
| response = self.get_request(self.baseurl) | ||
| return ExtensionsSiteSettings.from_response(response.content, self.parent_srv.namespace) | ||
|
|
||
| @api(version="3.21") | ||
| def update(self, extensions_site_settings: ExtensionsSiteSettings) -> ExtensionsSiteSettings: | ||
| """Updates the extensions settings for the site. Any extensions omitted | ||
| from the safe extensions list will be removed. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| extensions_site_settings : ExtensionsSiteSettings | ||
| The site extensions settings to update | ||
|
|
||
| Returns | ||
| ------- | ||
| ExtensionsSiteSettings | ||
| The updated site extensions settings | ||
| """ | ||
| req = RequestFactory.Extensions.update_site_extensions(extensions_site_settings) | ||
| response = self.put_request(self.baseurl, req) | ||
| return ExtensionsSiteSettings.from_response(response.content, self.parent_srv.namespace) | ||
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the
useDefaultSettingsetting is deprecated by the time new new trusted extensions settings come around - we can skip adding it I think! @bcantoni to confirmThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jacksonlauren Sounds like we might need to keep this for as long as anything <3.27 is supported though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I'm remembering correctly, it is fully unhooked from any client code - essentially a noop - and has been for some time now. Even though <3.27 has it in the API, there's not a need for anyone to use it.
I'll check with Brian though, I'm not sure when exactly that happened and if we still support versions of Tableau that would utilize
useDefaultSettingin any way