-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add get_workspace_id to WorkspaceClient (#537)
## Changes There are times when it is especially useful to get the workspace ID for the current workspace client. Currently, the workspace ID for the current workspace is exposed as a header in the SCIM Me API call. We'll expose this through a get_workspace_id() method, caching the workspace ID for the lifetime of the client. In the future, we may add a meta service for exposing information about the current account/workspace. At that point, we can migrate off of this somewhat hacky approach. Ports databricks/databricks-sdk-go#808 to the Python SDK. ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [ ] `make test` run locally - [ ] `make fmt` applied - [ ] relevant integration tests applied
- Loading branch information
Showing
6 changed files
with
87 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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,38 @@ | ||
class _Name(object): | ||
"""Parses a name in camelCase, PascalCase, snake_case, or kebab-case into its segments.""" | ||
|
||
def __init__(self, raw_name: str): | ||
# | ||
self._segments = [] | ||
segment = [] | ||
for ch in raw_name: | ||
if ch.isupper(): | ||
if segment: | ||
self._segments.append(''.join(segment)) | ||
segment = [ch.lower()] | ||
elif ch.islower(): | ||
segment.append(ch) | ||
else: | ||
if segment: | ||
self._segments.append(''.join(segment)) | ||
segment = [] | ||
if segment: | ||
self._segments.append(''.join(segment)) | ||
|
||
def to_snake_case(self) -> str: | ||
return '_'.join(self._segments) | ||
|
||
def to_header_case(self) -> str: | ||
return '-'.join([s.capitalize() for s in self._segments]) | ||
|
||
|
||
class Casing(object): | ||
|
||
@staticmethod | ||
def to_header_case(name: str) -> str: | ||
""" | ||
Convert a name from camelCase, PascalCase, snake_case, or kebab-case to header-case. | ||
:param name: | ||
:return: | ||
""" | ||
return _Name(name).to_header_case() |
This file contains 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 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 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,10 @@ | ||
import pytest | ||
|
||
from databricks.sdk.casing import Casing | ||
|
||
|
||
@pytest.mark.parametrize('name, expected', [('', ''), ('a', 'A'), ('abc', 'Abc'), ('Abc', 'Abc'), | ||
('abc_def', 'Abc-Def'), ('abc-def', 'Abc-Def'), | ||
('abcDef', 'Abc-Def'), ('AbcDef', 'Abc-Def'), ]) | ||
def test_to_header_case(name, expected): | ||
assert Casing.to_header_case(name) == expected |