-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #79 from keboola/KAB-46-prepare-structure-for-meta…
…store-metadata-to-be-stored-with-storage-objects KAB-46 prepare structure for metastore metadata to be stored with storage objects
- Loading branch information
Showing
7 changed files
with
337 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,6 @@ services: | |
<<: *ci | ||
tty: true | ||
stdin_open: true | ||
command: bash | ||
entrypoint: bash | ||
volumes: | ||
- .:/code |
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,104 @@ | ||
""" | ||
Manages calls to the Storage API relating to configurations metadata | ||
Full documentation https://keboola.docs.apiary.io/#reference/metadata/components-configurations-metadata/ | ||
""" | ||
import json | ||
from kbcstorage.base import Endpoint | ||
|
||
|
||
class ConfigurationsMetadata(Endpoint): | ||
""" | ||
Configurations metadata Endpoint | ||
""" | ||
|
||
def __init__(self, root_url, token, branch_id): | ||
""" | ||
Create a Component metadata endpoint. | ||
Args: | ||
root_url (:obj:`str`): The base url for the API. | ||
token (:obj:`str`): A storage API key. | ||
branch_id (str): The ID of branch to use, use 'default' to work without branch (in main). | ||
""" | ||
super().__init__(root_url, f"branch/{branch_id}/components", token) | ||
|
||
def delete(self, component_id, configuration_id, metadata_id): | ||
""" | ||
Deletes the configuration metadata identified by ``metadata_id``. | ||
Args: | ||
component_id (str): The id of the component. | ||
configuration_id (str): The id of the configuration. | ||
metadata_id (str): The id of the metadata (not key!). | ||
Raises: | ||
requests.HTTPError: If the API request fails. | ||
ValueError: If the component_id/configuration_id/metadata_id is not a string or is empty. | ||
""" | ||
if not isinstance(component_id, str) or component_id == '': | ||
raise ValueError("Invalid component_id '{}'.".format(component_id)) | ||
if not isinstance(configuration_id, str) or configuration_id == '': | ||
raise ValueError("Invalid configuration_id '{}'.".format(configuration_id)) | ||
if not isinstance(metadata_id, str) or metadata_id == '': | ||
raise ValueError("Invalid metadata_id '{}'.".format(metadata_id)) | ||
url = '{}/{}/configs/{}/metadata/{}'.format(self.base_url, component_id, configuration_id, metadata_id) | ||
self._delete(url) | ||
|
||
def list(self, component_id, configuration_id): | ||
""" | ||
Lists metadata for a given component configuration. | ||
Args: | ||
component_id (str): The id of the component. | ||
configuration_id (str): The id of the configuration. | ||
Raises: | ||
requests.HTTPError: If the API request fails. | ||
ValueError: If the component_id/configuration_id is not a string or is empty. | ||
""" | ||
if not isinstance(component_id, str) or component_id == '': | ||
raise ValueError("Invalid component_id '{}'.".format(component_id)) | ||
if not isinstance(configuration_id, str) or configuration_id == '': | ||
raise ValueError("Invalid configuration_id '{}'.".format(configuration_id)) | ||
url = '{}/{}/configs/{}/metadata'.format(self.base_url, component_id, configuration_id) | ||
return self._get(url) | ||
|
||
def create(self, component_id, configuration_id, provider, metadata): | ||
""" | ||
Writes metadata for a given component configuration. | ||
Args: | ||
component_id (str): The id of the component. | ||
configuration (str): The id of the configuration. | ||
provider (str): The provider of the configuration (currently ignored and "user" is sent). | ||
metadata (list): A list of metadata items. Item is a dictionary with 'key' and 'value' keys. | ||
Returns: | ||
response_body: The parsed json from the HTTP response. | ||
Raises: | ||
requests.HTTPError: If the API request fails. | ||
ValueError: If the component_id/configuration_id is not a string or is empty. | ||
ValueError: If the metadata is not a list. | ||
ValueError: If the metadata item is not a dictionary. | ||
""" | ||
if not isinstance(component_id, str) or component_id == '': | ||
raise ValueError("Invalid component_id '{}'.".format(component_id)) | ||
if not isinstance(configuration_id, str) or configuration_id == '': | ||
raise ValueError("Invalid component_id '{}'.".format(configuration_id)) | ||
url = '{}/{}/configs/{}/metadata'.format(self.base_url, component_id, configuration_id) | ||
if not isinstance(metadata, list): | ||
raise ValueError("Metadata must be a list '{}'.".format(metadata)) | ||
for metadataItem in metadata: | ||
if not isinstance(metadataItem, dict): | ||
raise ValueError("Metadata item must be a dictionary '{}'.".format(metadataItem)) | ||
|
||
headers = { | ||
'Content-Type': 'application/json', | ||
} | ||
data = { | ||
# 'provider': provider, # not yet implemented | ||
'metadata': metadata | ||
} | ||
return self._post(url, data=json.dumps(data), headers=headers) |
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,107 @@ | ||
""" | ||
Manages calls to the Storage API relating to table metadatas | ||
Full documentation `here`. | ||
.. _here: | ||
http://docs.keboola.apiary.io/#reference/metadata/table-metadata | ||
""" | ||
import json | ||
from kbcstorage.base import Endpoint | ||
|
||
|
||
class TablesMetadata(Endpoint): | ||
""" | ||
Tables Metadata Endpoint | ||
""" | ||
def __init__(self, root_url, token): | ||
""" | ||
Create a Tables metadata endpoint. | ||
Args: | ||
root_url (:obj:`str`): The base url for the API. | ||
token (:obj:`str`): A storage API key. | ||
""" | ||
super().__init__(root_url, 'tables', token) | ||
|
||
def list(self, table_id): | ||
""" | ||
List all metadata for table | ||
Args: | ||
table_id (str): Table id | ||
Returns: | ||
response_body: The parsed json from the HTTP response. | ||
Raises: | ||
requests.HTTPError: If the API request fails. | ||
ValueError: If the table_id is not a string or is empty. | ||
""" | ||
if not isinstance(table_id, str) or table_id == '': | ||
raise ValueError("Invalid table_id '{}'.".format(table_id)) | ||
|
||
url = '{}/{}/metadata'.format(self.base_url, table_id) | ||
|
||
return self._get(url) | ||
|
||
def delete(self, table_id, metadata_id): | ||
""" | ||
Delete a table metadata referenced by ``metadata_id``. | ||
Args: | ||
table_id (str): The id of the table. | ||
metadata_id (str): The id of the table metdata entry to be deleted. | ||
Raises: | ||
requests.HTTPError: If the API request fails. | ||
ValueError: If the table_id/metadata_id is not a string or is empty. | ||
""" | ||
if not isinstance(table_id, str) or table_id == '': | ||
raise ValueError("Invalid table_id '{}'.".format(table_id)) | ||
if not isinstance(metadata_id, str) or metadata_id == '': | ||
raise ValueError("Invalid metadata_id '{}'.".format(metadata_id)) | ||
|
||
url = '{}/{}/metadata/{}'.format(self.base_url, table_id, metadata_id) | ||
|
||
self._delete(url) | ||
|
||
def create(self, table_id, provider, metadata, columns_metadata): | ||
""" | ||
Post metadata to a table. | ||
Args: | ||
table_id (str): Table id | ||
provider (str): Provider of the metadata | ||
metadata (list): List of metadata dictionaries with 'key' and 'value' | ||
columns_metadata (dict): Dictionary with lists of metadata dictionaries with 'key', 'value', 'columnName'. | ||
Returns: | ||
response_body: The parsed json from the HTTP response. | ||
Raises: | ||
requests.HTTPError: If the API request fails. | ||
ValueError: If the table_id is not a string or is empty. | ||
ValueError: If the provider is not a string or is empty. | ||
ValueError: If the metadata is not a list. | ||
ValueError: If the columns_metadata is not a list | ||
""" | ||
if not isinstance(table_id, str) or table_id == '': | ||
raise ValueError("Invalid table_id '{}'.".format(table_id)) | ||
if not isinstance(provider, str) or provider == '': | ||
raise ValueError("Invalid provider '{}'.".format(provider)) | ||
if not isinstance(metadata, list): | ||
raise ValueError("Invalid metadata '{}'.".format(metadata)) | ||
if not isinstance(columns_metadata, list): | ||
raise ValueError("Invalid columns_metadata '{}'.".format(columns_metadata)) | ||
|
||
url = '{}/{}/metadata'.format(self.base_url, table_id) | ||
headers = { | ||
'Content-Type': 'application/json', | ||
} | ||
data = { | ||
"provider": provider, | ||
"metadata": metadata, | ||
"columnsMetadata": columns_metadata | ||
} | ||
return self._post(url, data=json.dumps(data), headers=headers) |
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