This commit is contained in:
Christian Mantha
2026-03-02 19:10:52 -05:00
commit 2ca0b9ef7c
28907 changed files with 5233713 additions and 0 deletions

View File

@@ -0,0 +1,164 @@
import datetime
import urllib.parse
from typing import Callable, Dict, Generic, List, Optional, Type, TypeVar
from google.protobuf.duration_pb2 import Duration
from google.protobuf.timestamp_pb2 import Timestamp
from databricks.sdk.common.types.fieldmask import FieldMask
def _from_dict(d: Dict[str, any], field: str, cls: Type) -> any:
if field not in d or d[field] is None:
return None
return getattr(cls, "from_dict")(d[field])
def _repeated_dict(d: Dict[str, any], field: str, cls: Type) -> any:
if field not in d or not d[field]:
return []
from_dict = getattr(cls, "from_dict")
return [from_dict(v) for v in d[field]]
def _get_enum_value(cls: Type, value: str) -> Optional[Type]:
return next(
(v for v in getattr(cls, "__members__").values() if v.value == value),
None,
)
def _enum(d: Dict[str, any], field: str, cls: Type) -> any:
"""Unknown enum values are returned as None."""
if field not in d or not d[field]:
return None
return _get_enum_value(cls, d[field])
def _repeated_enum(d: Dict[str, any], field: str, cls: Type) -> any:
"""For now, unknown enum values are not included in the response."""
if field not in d or not d[field]:
return None
res = []
for e in d[field]:
val = _get_enum_value(cls, e)
if val:
res.append(val)
return res
def _escape_multi_segment_path_parameter(param: str) -> str:
return urllib.parse.quote(param)
def _timestamp(d: Dict[str, any], field: str) -> Optional[Timestamp]:
"""
Helper function to convert a timestamp string to a Timestamp object.
It takes a dictionary and a field name, and returns a Timestamp object.
The field name is the key in the dictionary that contains the timestamp string.
"""
if field not in d or not d[field]:
return None
ts = Timestamp()
ts.FromJsonString(d[field])
return ts
def _repeated_timestamp(d: Dict[str, any], field: str) -> Optional[List[Timestamp]]:
"""
Helper function to convert a list of timestamp strings to a list of Timestamp objects.
It takes a dictionary and a field name, and returns a list of Timestamp objects.
The field name is the key in the dictionary that contains the list of timestamp strings.
"""
if field not in d or not d[field]:
return None
result = []
for v in d[field]:
ts = Timestamp()
ts.FromJsonString(v)
result.append(ts)
return result
def _duration(d: Dict[str, any], field: str) -> Optional[Duration]:
"""
Helper function to convert a duration string to a Duration object.
It takes a dictionary and a field name, and returns a Duration object.
The field name is the key in the dictionary that contains the duration string.
"""
if field not in d or not d[field]:
return None
dur = Duration()
dur.FromJsonString(d[field])
return dur
def _repeated_duration(d: Dict[str, any], field: str) -> Optional[List[Duration]]:
"""
Helper function to convert a list of duration strings to a list of Duration objects.
It takes a dictionary and a field name, and returns a list of Duration objects.
The field name is the key in the dictionary that contains the list of duration strings.
"""
if field not in d or not d[field]:
return None
result = []
for v in d[field]:
dur = Duration()
dur.FromJsonString(v)
result.append(dur)
return result
def _fieldmask(d: Dict[str, any], field: str) -> Optional[FieldMask]:
"""
Helper function to convert a fieldmask string to a FieldMask object.
It takes a dictionary and a field name, and returns a FieldMask object.
The field name is the key in the dictionary that contains the fieldmask string.
"""
if field not in d or not d[field]:
return None
fm = FieldMask()
fm.FromJsonString(d[field])
return fm
def _repeated_fieldmask(d: Dict[str, any], field: str) -> Optional[List[FieldMask]]:
"""
Helper function to convert a list of fieldmask strings to a list of FieldMask objects.
It takes a dictionary and a field name, and returns a list of FieldMask objects.
The field name is the key in the dictionary that contains the list of fieldmask strings.
"""
if field not in d or not d[field]:
return None
result = []
for v in d[field]:
fm = FieldMask()
fm.FromJsonString(v)
result.append(fm)
return result
ReturnType = TypeVar("ReturnType")
class Wait(Generic[ReturnType]):
def __init__(self, waiter: Callable, response: any = None, **kwargs) -> None:
self.response = response
self._waiter = waiter
self._bind = kwargs
def __getattr__(self, key) -> any:
return self._bind[key]
def bind(self) -> dict:
return self._bind
def result(
self,
timeout: datetime.timedelta = datetime.timedelta(minutes=20),
callback: Callable[[ReturnType], None] = None,
) -> ReturnType:
kwargs = self._bind.copy()
return self._waiter(callback=callback, timeout=timeout, **kwargs)

View File

@@ -0,0 +1,369 @@
# Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
from __future__ import annotations
import logging
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Optional
from databricks.sdk.client_types import HostType
from databricks.sdk.service._internal import _enum, _from_dict, _repeated_dict
_LOG = logging.getLogger("databricks.sdk")
# all definitions in this file are in alphabetical order
@dataclass
class CustomLlm:
name: str
"""Name of the custom LLM"""
instructions: str
"""Instructions for the custom LLM to follow"""
agent_artifact_path: Optional[str] = None
creation_time: Optional[str] = None
"""Creation timestamp of the custom LLM"""
creator: Optional[str] = None
"""Creator of the custom LLM"""
datasets: Optional[List[Dataset]] = None
"""Datasets used for training and evaluating the model, not for inference"""
endpoint_name: Optional[str] = None
"""Name of the endpoint that will be used to serve the custom LLM"""
guidelines: Optional[List[str]] = None
"""Guidelines for the custom LLM to adhere to"""
id: Optional[str] = None
optimization_state: Optional[State] = None
"""If optimization is kicked off, tracks the state of the custom LLM"""
def as_dict(self) -> dict:
"""Serializes the CustomLlm into a dictionary suitable for use as a JSON request body."""
body = {}
if self.agent_artifact_path is not None:
body["agent_artifact_path"] = self.agent_artifact_path
if self.creation_time is not None:
body["creation_time"] = self.creation_time
if self.creator is not None:
body["creator"] = self.creator
if self.datasets:
body["datasets"] = [v.as_dict() for v in self.datasets]
if self.endpoint_name is not None:
body["endpoint_name"] = self.endpoint_name
if self.guidelines:
body["guidelines"] = [v for v in self.guidelines]
if self.id is not None:
body["id"] = self.id
if self.instructions is not None:
body["instructions"] = self.instructions
if self.name is not None:
body["name"] = self.name
if self.optimization_state is not None:
body["optimization_state"] = self.optimization_state.value
return body
def as_shallow_dict(self) -> dict:
"""Serializes the CustomLlm into a shallow dictionary of its immediate attributes."""
body = {}
if self.agent_artifact_path is not None:
body["agent_artifact_path"] = self.agent_artifact_path
if self.creation_time is not None:
body["creation_time"] = self.creation_time
if self.creator is not None:
body["creator"] = self.creator
if self.datasets:
body["datasets"] = self.datasets
if self.endpoint_name is not None:
body["endpoint_name"] = self.endpoint_name
if self.guidelines:
body["guidelines"] = self.guidelines
if self.id is not None:
body["id"] = self.id
if self.instructions is not None:
body["instructions"] = self.instructions
if self.name is not None:
body["name"] = self.name
if self.optimization_state is not None:
body["optimization_state"] = self.optimization_state
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> CustomLlm:
"""Deserializes the CustomLlm from a dictionary."""
return cls(
agent_artifact_path=d.get("agent_artifact_path", None),
creation_time=d.get("creation_time", None),
creator=d.get("creator", None),
datasets=_repeated_dict(d, "datasets", Dataset),
endpoint_name=d.get("endpoint_name", None),
guidelines=d.get("guidelines", None),
id=d.get("id", None),
instructions=d.get("instructions", None),
name=d.get("name", None),
optimization_state=_enum(d, "optimization_state", State),
)
@dataclass
class Dataset:
table: Table
def as_dict(self) -> dict:
"""Serializes the Dataset into a dictionary suitable for use as a JSON request body."""
body = {}
if self.table:
body["table"] = self.table.as_dict()
return body
def as_shallow_dict(self) -> dict:
"""Serializes the Dataset into a shallow dictionary of its immediate attributes."""
body = {}
if self.table:
body["table"] = self.table
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> Dataset:
"""Deserializes the Dataset from a dictionary."""
return cls(table=_from_dict(d, "table", Table))
class State(Enum):
"""States of Custom LLM optimization lifecycle."""
CANCELLED = "CANCELLED"
COMPLETED = "COMPLETED"
CREATED = "CREATED"
FAILED = "FAILED"
PENDING = "PENDING"
RUNNING = "RUNNING"
@dataclass
class Table:
table_path: str
"""Full UC table path in catalog.schema.table_name format"""
request_col: str
"""Name of the request column"""
response_col: Optional[str] = None
"""Optional: Name of the response column if the data is labeled"""
def as_dict(self) -> dict:
"""Serializes the Table into a dictionary suitable for use as a JSON request body."""
body = {}
if self.request_col is not None:
body["request_col"] = self.request_col
if self.response_col is not None:
body["response_col"] = self.response_col
if self.table_path is not None:
body["table_path"] = self.table_path
return body
def as_shallow_dict(self) -> dict:
"""Serializes the Table into a shallow dictionary of its immediate attributes."""
body = {}
if self.request_col is not None:
body["request_col"] = self.request_col
if self.response_col is not None:
body["response_col"] = self.response_col
if self.table_path is not None:
body["table_path"] = self.table_path
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> Table:
"""Deserializes the Table from a dictionary."""
return cls(
request_col=d.get("request_col", None),
response_col=d.get("response_col", None),
table_path=d.get("table_path", None),
)
class AgentBricksAPI:
"""The Custom LLMs service manages state and powers the UI for the Custom LLM product."""
def __init__(self, api_client):
self._api = api_client
def cancel_optimize(self, id: str):
"""Cancel a Custom LLM Optimization Run.
:param id: str
"""
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
self._api.do("POST", f"/api/2.0/custom-llms/{id}/optimize/cancel", headers=headers)
def create_custom_llm(
self,
name: str,
instructions: str,
*,
agent_artifact_path: Optional[str] = None,
datasets: Optional[List[Dataset]] = None,
guidelines: Optional[List[str]] = None,
) -> CustomLlm:
"""Create a Custom LLM.
:param name: str
Name of the custom LLM. Only alphanumeric characters and dashes allowed.
:param instructions: str
Instructions for the custom LLM to follow
:param agent_artifact_path: str (optional)
This will soon be deprecated!! Optional: UC path for agent artifacts. If you are using a dataset
that you only have read permissions, please provide a destination path where you have write
permissions. Please provide this in catalog.schema format.
:param datasets: List[:class:`Dataset`] (optional)
Datasets used for training and evaluating the model, not for inference. Currently, only 1 dataset is
accepted.
:param guidelines: List[str] (optional)
Guidelines for the custom LLM to adhere to
:returns: :class:`CustomLlm`
"""
body = {}
if agent_artifact_path is not None:
body["agent_artifact_path"] = agent_artifact_path
if datasets is not None:
body["datasets"] = [v.as_dict() for v in datasets]
if guidelines is not None:
body["guidelines"] = [v for v in guidelines]
if instructions is not None:
body["instructions"] = instructions
if name is not None:
body["name"] = name
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("POST", "/api/2.0/custom-llms", body=body, headers=headers)
return CustomLlm.from_dict(res)
def delete_custom_llm(self, id: str):
"""Delete a Custom LLM.
:param id: str
The id of the custom llm
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
self._api.do("DELETE", f"/api/2.0/custom-llms/{id}", headers=headers)
def get_custom_llm(self, id: str) -> CustomLlm:
"""Get a Custom LLM.
:param id: str
The id of the custom llm
:returns: :class:`CustomLlm`
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("GET", f"/api/2.0/custom-llms/{id}", headers=headers)
return CustomLlm.from_dict(res)
def start_optimize(self, id: str) -> CustomLlm:
"""Start a Custom LLM Optimization Run.
:param id: str
The Id of the tile.
:returns: :class:`CustomLlm`
"""
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("POST", f"/api/2.0/custom-llms/{id}/optimize", headers=headers)
return CustomLlm.from_dict(res)
def update_custom_llm(self, id: str, custom_llm: CustomLlm, update_mask: str) -> CustomLlm:
"""Update a Custom LLM.
:param id: str
The id of the custom llm
:param custom_llm: :class:`CustomLlm`
The CustomLlm containing the fields which should be updated.
:param update_mask: str
The list of the CustomLlm fields to update. These should correspond to the values (or lack thereof)
present in `custom_llm`.
The field mask must be a single string, with multiple fields separated by commas (no spaces). The
field path is relative to the resource object, using a dot (`.`) to navigate sub-fields (e.g.,
`author.given_name`). Specification of elements in sequence or map fields is not allowed, as only
the entire collection field can be specified. Field names must exactly match the resource field
names.
A field mask of `*` indicates full replacement. Its recommended to always explicitly list the
fields being updated and avoid using `*` wildcards, as it can lead to unintended results if the API
changes in the future.
:returns: :class:`CustomLlm`
"""
body = {}
if custom_llm is not None:
body["custom_llm"] = custom_llm.as_dict()
if update_mask is not None:
body["update_mask"] = update_mask
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("PATCH", f"/api/2.0/custom-llms/{id}", body=body, headers=headers)
return CustomLlm.from_dict(res)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,666 @@
# Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
from __future__ import annotations
import logging
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, List, Optional
from databricks.sdk.client_types import HostType
from databricks.sdk.service._internal import _enum, _from_dict, _repeated_enum
_LOG = logging.getLogger("databricks.sdk")
# all definitions in this file are in alphabetical order
@dataclass
class Group:
"""The details of a Group resource."""
account_id: Optional[str] = None
"""The parent account ID for group in Databricks."""
external_id: Optional[str] = None
"""ExternalId of the group in the customer's IdP."""
group_name: Optional[str] = None
"""Display name of the group."""
internal_id: Optional[int] = None
"""Internal group ID of the group in Databricks."""
def as_dict(self) -> dict:
"""Serializes the Group into a dictionary suitable for use as a JSON request body."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.external_id is not None:
body["external_id"] = self.external_id
if self.group_name is not None:
body["group_name"] = self.group_name
if self.internal_id is not None:
body["internal_id"] = self.internal_id
return body
def as_shallow_dict(self) -> dict:
"""Serializes the Group into a shallow dictionary of its immediate attributes."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.external_id is not None:
body["external_id"] = self.external_id
if self.group_name is not None:
body["group_name"] = self.group_name
if self.internal_id is not None:
body["internal_id"] = self.internal_id
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> Group:
"""Deserializes the Group from a dictionary."""
return cls(
account_id=d.get("account_id", None),
external_id=d.get("external_id", None),
group_name=d.get("group_name", None),
internal_id=d.get("internal_id", None),
)
class PrincipalType(Enum):
"""The type of the principal (user/sp/group)."""
GROUP = "GROUP"
SERVICE_PRINCIPAL = "SERVICE_PRINCIPAL"
USER = "USER"
@dataclass
class ResolveGroupResponse:
group: Optional[Group] = None
"""The group that was resolved."""
def as_dict(self) -> dict:
"""Serializes the ResolveGroupResponse into a dictionary suitable for use as a JSON request body."""
body = {}
if self.group:
body["group"] = self.group.as_dict()
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ResolveGroupResponse into a shallow dictionary of its immediate attributes."""
body = {}
if self.group:
body["group"] = self.group
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ResolveGroupResponse:
"""Deserializes the ResolveGroupResponse from a dictionary."""
return cls(group=_from_dict(d, "group", Group))
@dataclass
class ResolveServicePrincipalResponse:
service_principal: Optional[ServicePrincipal] = None
"""The service principal that was resolved."""
def as_dict(self) -> dict:
"""Serializes the ResolveServicePrincipalResponse into a dictionary suitable for use as a JSON request body."""
body = {}
if self.service_principal:
body["service_principal"] = self.service_principal.as_dict()
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ResolveServicePrincipalResponse into a shallow dictionary of its immediate attributes."""
body = {}
if self.service_principal:
body["service_principal"] = self.service_principal
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ResolveServicePrincipalResponse:
"""Deserializes the ResolveServicePrincipalResponse from a dictionary."""
return cls(service_principal=_from_dict(d, "service_principal", ServicePrincipal))
@dataclass
class ResolveUserResponse:
user: Optional[User] = None
"""The user that was resolved."""
def as_dict(self) -> dict:
"""Serializes the ResolveUserResponse into a dictionary suitable for use as a JSON request body."""
body = {}
if self.user:
body["user"] = self.user.as_dict()
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ResolveUserResponse into a shallow dictionary of its immediate attributes."""
body = {}
if self.user:
body["user"] = self.user
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ResolveUserResponse:
"""Deserializes the ResolveUserResponse from a dictionary."""
return cls(user=_from_dict(d, "user", User))
@dataclass
class ServicePrincipal:
"""The details of a ServicePrincipal resource."""
account_id: Optional[str] = None
"""The parent account ID for the service principal in Databricks."""
account_sp_status: Optional[State] = None
"""The activity status of a service principal in a Databricks account."""
application_id: Optional[str] = None
"""Application ID of the service principal."""
display_name: Optional[str] = None
"""Display name of the service principal."""
external_id: Optional[str] = None
"""ExternalId of the service principal in the customer's IdP."""
internal_id: Optional[int] = None
"""Internal service principal ID of the service principal in Databricks."""
def as_dict(self) -> dict:
"""Serializes the ServicePrincipal into a dictionary suitable for use as a JSON request body."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.account_sp_status is not None:
body["account_sp_status"] = self.account_sp_status.value
if self.application_id is not None:
body["application_id"] = self.application_id
if self.display_name is not None:
body["display_name"] = self.display_name
if self.external_id is not None:
body["external_id"] = self.external_id
if self.internal_id is not None:
body["internal_id"] = self.internal_id
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ServicePrincipal into a shallow dictionary of its immediate attributes."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.account_sp_status is not None:
body["account_sp_status"] = self.account_sp_status
if self.application_id is not None:
body["application_id"] = self.application_id
if self.display_name is not None:
body["display_name"] = self.display_name
if self.external_id is not None:
body["external_id"] = self.external_id
if self.internal_id is not None:
body["internal_id"] = self.internal_id
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ServicePrincipal:
"""Deserializes the ServicePrincipal from a dictionary."""
return cls(
account_id=d.get("account_id", None),
account_sp_status=_enum(d, "account_sp_status", State),
application_id=d.get("application_id", None),
display_name=d.get("display_name", None),
external_id=d.get("external_id", None),
internal_id=d.get("internal_id", None),
)
class State(Enum):
"""The activity status of a user or service principal in a Databricks account or workspace."""
ACTIVE = "ACTIVE"
INACTIVE = "INACTIVE"
@dataclass
class User:
"""The details of a User resource."""
account_id: Optional[str] = None
"""The accountId parent of the user in Databricks."""
account_user_status: Optional[State] = None
"""The activity status of a user in a Databricks account."""
external_id: Optional[str] = None
"""ExternalId of the user in the customer's IdP."""
internal_id: Optional[int] = None
"""Internal userId of the user in Databricks."""
name: Optional[UserName] = None
username: Optional[str] = None
"""Username/email of the user."""
def as_dict(self) -> dict:
"""Serializes the User into a dictionary suitable for use as a JSON request body."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.account_user_status is not None:
body["account_user_status"] = self.account_user_status.value
if self.external_id is not None:
body["external_id"] = self.external_id
if self.internal_id is not None:
body["internal_id"] = self.internal_id
if self.name:
body["name"] = self.name.as_dict()
if self.username is not None:
body["username"] = self.username
return body
def as_shallow_dict(self) -> dict:
"""Serializes the User into a shallow dictionary of its immediate attributes."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.account_user_status is not None:
body["account_user_status"] = self.account_user_status
if self.external_id is not None:
body["external_id"] = self.external_id
if self.internal_id is not None:
body["internal_id"] = self.internal_id
if self.name:
body["name"] = self.name
if self.username is not None:
body["username"] = self.username
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> User:
"""Deserializes the User from a dictionary."""
return cls(
account_id=d.get("account_id", None),
account_user_status=_enum(d, "account_user_status", State),
external_id=d.get("external_id", None),
internal_id=d.get("internal_id", None),
name=_from_dict(d, "name", UserName),
username=d.get("username", None),
)
@dataclass
class UserName:
family_name: Optional[str] = None
given_name: Optional[str] = None
def as_dict(self) -> dict:
"""Serializes the UserName into a dictionary suitable for use as a JSON request body."""
body = {}
if self.family_name is not None:
body["family_name"] = self.family_name
if self.given_name is not None:
body["given_name"] = self.given_name
return body
def as_shallow_dict(self) -> dict:
"""Serializes the UserName into a shallow dictionary of its immediate attributes."""
body = {}
if self.family_name is not None:
body["family_name"] = self.family_name
if self.given_name is not None:
body["given_name"] = self.given_name
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> UserName:
"""Deserializes the UserName from a dictionary."""
return cls(family_name=d.get("family_name", None), given_name=d.get("given_name", None))
@dataclass
class WorkspaceAccessDetail:
"""The details of a principal's access to a workspace."""
access_type: Optional[WorkspaceAccessDetailAccessType] = None
account_id: Optional[str] = None
"""The account ID parent of the workspace where the principal has access."""
permissions: Optional[List[WorkspacePermission]] = None
"""The permissions granted to the principal in the workspace."""
principal_id: Optional[int] = None
"""The internal ID of the principal (user/sp/group) in Databricks."""
principal_type: Optional[PrincipalType] = None
status: Optional[State] = None
"""The activity status of the principal in the workspace. Not applicable for groups at the moment."""
workspace_id: Optional[int] = None
"""The workspace ID where the principal has access."""
def as_dict(self) -> dict:
"""Serializes the WorkspaceAccessDetail into a dictionary suitable for use as a JSON request body."""
body = {}
if self.access_type is not None:
body["access_type"] = self.access_type.value
if self.account_id is not None:
body["account_id"] = self.account_id
if self.permissions:
body["permissions"] = [v.value for v in self.permissions]
if self.principal_id is not None:
body["principal_id"] = self.principal_id
if self.principal_type is not None:
body["principal_type"] = self.principal_type.value
if self.status is not None:
body["status"] = self.status.value
if self.workspace_id is not None:
body["workspace_id"] = self.workspace_id
return body
def as_shallow_dict(self) -> dict:
"""Serializes the WorkspaceAccessDetail into a shallow dictionary of its immediate attributes."""
body = {}
if self.access_type is not None:
body["access_type"] = self.access_type
if self.account_id is not None:
body["account_id"] = self.account_id
if self.permissions:
body["permissions"] = self.permissions
if self.principal_id is not None:
body["principal_id"] = self.principal_id
if self.principal_type is not None:
body["principal_type"] = self.principal_type
if self.status is not None:
body["status"] = self.status
if self.workspace_id is not None:
body["workspace_id"] = self.workspace_id
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> WorkspaceAccessDetail:
"""Deserializes the WorkspaceAccessDetail from a dictionary."""
return cls(
access_type=_enum(d, "access_type", WorkspaceAccessDetailAccessType),
account_id=d.get("account_id", None),
permissions=_repeated_enum(d, "permissions", WorkspacePermission),
principal_id=d.get("principal_id", None),
principal_type=_enum(d, "principal_type", PrincipalType),
status=_enum(d, "status", State),
workspace_id=d.get("workspace_id", None),
)
class WorkspaceAccessDetailAccessType(Enum):
"""The type of access the principal has to the workspace."""
DIRECT = "DIRECT"
INDIRECT = "INDIRECT"
class WorkspaceAccessDetailView(Enum):
"""Controls what fields are returned in the GetWorkspaceAccessDetail response."""
BASIC = "BASIC"
FULL = "FULL"
class WorkspacePermission(Enum):
"""The type of permission a principal has to a workspace (admin/user)."""
ADMIN_PERMISSION = "ADMIN_PERMISSION"
USER_PERMISSION = "USER_PERMISSION"
class AccountIamV2API:
"""These APIs are used to manage identities and the workspace access of these identities in <Databricks>."""
def __init__(self, api_client):
self._api = api_client
def get_workspace_access_detail(
self, workspace_id: int, principal_id: int, *, view: Optional[WorkspaceAccessDetailView] = None
) -> WorkspaceAccessDetail:
"""Returns the access details for a principal in a workspace. Allows for checking access details for any
provisioned principal (user, service principal, or group) in a workspace. * Provisioned principal here
refers to one that has been synced into Databricks from the customer's IdP or added explicitly to
Databricks via SCIM/UI. Allows for passing in a "view" parameter to control what fields are returned
(BASIC by default or FULL).
:param workspace_id: int
Required. The workspace ID for which the access details are being requested.
:param principal_id: int
Required. The internal ID of the principal (user/sp/group) for which the access details are being
requested.
:param view: :class:`WorkspaceAccessDetailView` (optional)
Controls what fields are returned.
:returns: :class:`WorkspaceAccessDetail`
"""
query = {}
if view is not None:
query["view"] = view.value
headers = {
"Accept": "application/json",
}
res = self._api.do(
"GET",
f"/api/2.0/identity/accounts/{self._api.account_id}/workspaces/{workspace_id}/workspaceAccessDetails/{principal_id}",
query=query,
headers=headers,
)
return WorkspaceAccessDetail.from_dict(res)
def resolve_group(self, external_id: str) -> ResolveGroupResponse:
"""Resolves a group with the given external ID from the customer's IdP. If the group does not exist, it
will be created in the account. If the customer is not onboarded onto Automatic Identity Management
(AIM), this will return an error.
:param external_id: str
Required. The external ID of the group in the customer's IdP.
:returns: :class:`ResolveGroupResponse`
"""
body = {}
if external_id is not None:
body["external_id"] = external_id
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
res = self._api.do(
"POST",
f"/api/2.0/identity/accounts/{self._api.account_id}/groups/resolveByExternalId",
body=body,
headers=headers,
)
return ResolveGroupResponse.from_dict(res)
def resolve_service_principal(self, external_id: str) -> ResolveServicePrincipalResponse:
"""Resolves an SP with the given external ID from the customer's IdP. If the SP does not exist, it will
be created. If the customer is not onboarded onto Automatic Identity Management (AIM), this will
return an error.
:param external_id: str
Required. The external ID of the service principal in the customer's IdP.
:returns: :class:`ResolveServicePrincipalResponse`
"""
body = {}
if external_id is not None:
body["external_id"] = external_id
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
res = self._api.do(
"POST",
f"/api/2.0/identity/accounts/{self._api.account_id}/servicePrincipals/resolveByExternalId",
body=body,
headers=headers,
)
return ResolveServicePrincipalResponse.from_dict(res)
def resolve_user(self, external_id: str) -> ResolveUserResponse:
"""Resolves a user with the given external ID from the customer's IdP. If the user does not exist, it
will be created. If the customer is not onboarded onto Automatic Identity Management (AIM), this will
return an error.
:param external_id: str
Required. The external ID of the user in the customer's IdP.
:returns: :class:`ResolveUserResponse`
"""
body = {}
if external_id is not None:
body["external_id"] = external_id
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
res = self._api.do(
"POST",
f"/api/2.0/identity/accounts/{self._api.account_id}/users/resolveByExternalId",
body=body,
headers=headers,
)
return ResolveUserResponse.from_dict(res)
class WorkspaceIamV2API:
"""These APIs are used to manage identities and the workspace access of these identities in <Databricks>."""
def __init__(self, api_client):
self._api = api_client
def get_workspace_access_detail_local(
self, principal_id: int, *, view: Optional[WorkspaceAccessDetailView] = None
) -> WorkspaceAccessDetail:
"""Returns the access details for a principal in the current workspace. Allows for checking access
details for any provisioned principal (user, service principal, or group) in the current workspace. *
Provisioned principal here refers to one that has been synced into Databricks from the customer's IdP
or added explicitly to Databricks via SCIM/UI. Allows for passing in a "view" parameter to control
what fields are returned (BASIC by default or FULL).
:param principal_id: int
Required. The internal ID of the principal (user/sp/group) for which the access details are being
requested.
:param view: :class:`WorkspaceAccessDetailView` (optional)
Controls what fields are returned.
:returns: :class:`WorkspaceAccessDetail`
"""
query = {}
if view is not None:
query["view"] = view.value
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do(
"GET", f"/api/2.0/identity/workspaceAccessDetails/{principal_id}", query=query, headers=headers
)
return WorkspaceAccessDetail.from_dict(res)
def resolve_group_proxy(self, external_id: str) -> ResolveGroupResponse:
"""Resolves a group with the given external ID from the customer's IdP. If the group does not exist, it
will be created in the account. If the customer is not onboarded onto Automatic Identity Management
(AIM), this will return an error.
:param external_id: str
Required. The external ID of the group in the customer's IdP.
:returns: :class:`ResolveGroupResponse`
"""
body = {}
if external_id is not None:
body["external_id"] = external_id
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("POST", "/api/2.0/identity/groups/resolveByExternalId", body=body, headers=headers)
return ResolveGroupResponse.from_dict(res)
def resolve_service_principal_proxy(self, external_id: str) -> ResolveServicePrincipalResponse:
"""Resolves an SP with the given external ID from the customer's IdP. If the SP does not exist, it will
be created. If the customer is not onboarded onto Automatic Identity Management (AIM), this will
return an error.
:param external_id: str
Required. The external ID of the service principal in the customer's IdP.
:returns: :class:`ResolveServicePrincipalResponse`
"""
body = {}
if external_id is not None:
body["external_id"] = external_id
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do(
"POST", "/api/2.0/identity/servicePrincipals/resolveByExternalId", body=body, headers=headers
)
return ResolveServicePrincipalResponse.from_dict(res)
def resolve_user_proxy(self, external_id: str) -> ResolveUserResponse:
"""Resolves a user with the given external ID from the customer's IdP. If the user does not exist, it
will be created. If the customer is not onboarded onto Automatic Identity Management (AIM), this will
return an error.
:param external_id: str
Required. The external ID of the user in the customer's IdP.
:returns: :class:`ResolveUserResponse`
"""
body = {}
if external_id is not None:
body["external_id"] = external_id
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("POST", "/api/2.0/identity/users/resolveByExternalId", body=body, headers=headers)
return ResolveUserResponse.from_dict(res)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,305 @@
# Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
from __future__ import annotations
import logging
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Iterator, List, Optional
from google.protobuf.timestamp_pb2 import Timestamp
from databricks.sdk.service._internal import (_enum, _from_dict,
_repeated_dict, _timestamp)
_LOG = logging.getLogger("databricks.sdk")
# all definitions in this file are in alphabetical order
@dataclass
class AzurePrivateEndpointInfo:
private_endpoint_name: str
"""The name of the Private Endpoint in the Azure subscription."""
private_endpoint_resource_guid: str
"""The GUID of the Private Endpoint resource in the Azure subscription. This is assigned by Azure
when the user sets up the Private Endpoint."""
private_endpoint_resource_id: Optional[str] = None
"""The full resource ID of the Private Endpoint."""
private_link_service_id: Optional[str] = None
"""The resource ID of the Databricks Private Link Service that this Private Endpoint connects to."""
def as_dict(self) -> dict:
"""Serializes the AzurePrivateEndpointInfo into a dictionary suitable for use as a JSON request body."""
body = {}
if self.private_endpoint_name is not None:
body["private_endpoint_name"] = self.private_endpoint_name
if self.private_endpoint_resource_guid is not None:
body["private_endpoint_resource_guid"] = self.private_endpoint_resource_guid
if self.private_endpoint_resource_id is not None:
body["private_endpoint_resource_id"] = self.private_endpoint_resource_id
if self.private_link_service_id is not None:
body["private_link_service_id"] = self.private_link_service_id
return body
def as_shallow_dict(self) -> dict:
"""Serializes the AzurePrivateEndpointInfo into a shallow dictionary of its immediate attributes."""
body = {}
if self.private_endpoint_name is not None:
body["private_endpoint_name"] = self.private_endpoint_name
if self.private_endpoint_resource_guid is not None:
body["private_endpoint_resource_guid"] = self.private_endpoint_resource_guid
if self.private_endpoint_resource_id is not None:
body["private_endpoint_resource_id"] = self.private_endpoint_resource_id
if self.private_link_service_id is not None:
body["private_link_service_id"] = self.private_link_service_id
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> AzurePrivateEndpointInfo:
"""Deserializes the AzurePrivateEndpointInfo from a dictionary."""
return cls(
private_endpoint_name=d.get("private_endpoint_name", None),
private_endpoint_resource_guid=d.get("private_endpoint_resource_guid", None),
private_endpoint_resource_id=d.get("private_endpoint_resource_id", None),
private_link_service_id=d.get("private_link_service_id", None),
)
@dataclass
class Endpoint:
"""Endpoint represents a cloud networking resource in a user's cloud account and binds it to the
Databricks account."""
display_name: str
"""The human-readable display name of this endpoint. The input should conform to RFC-1034, which
restricts to letters, numbers, and hyphens, with the first character a letter, the last a letter
or a number, and a 63 character maximum."""
region: str
"""The cloud provider region where this endpoint is located."""
account_id: Optional[str] = None
"""The Databricks Account in which the endpoint object exists."""
azure_private_endpoint_info: Optional[AzurePrivateEndpointInfo] = None
"""Info for an Azure private endpoint."""
create_time: Optional[Timestamp] = None
"""The timestamp when the endpoint was created. The timestamp is in RFC 3339 format in UTC
timezone."""
endpoint_id: Optional[str] = None
"""The unique identifier for this endpoint under the account. This field is a UUID generated by
Databricks."""
name: Optional[str] = None
"""The resource name of the endpoint, which uniquely identifies the endpoint."""
state: Optional[EndpointState] = None
"""The state of the endpoint. The endpoint can only be used if the state is `APPROVED`."""
use_case: Optional[EndpointUseCase] = None
"""The use case that determines the type of network connectivity this endpoint provides. This field
is automatically determined based on the endpoint configuration and cloud-specific settings."""
def as_dict(self) -> dict:
"""Serializes the Endpoint into a dictionary suitable for use as a JSON request body."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.azure_private_endpoint_info:
body["azure_private_endpoint_info"] = self.azure_private_endpoint_info.as_dict()
if self.create_time is not None:
body["create_time"] = self.create_time.ToJsonString()
if self.display_name is not None:
body["display_name"] = self.display_name
if self.endpoint_id is not None:
body["endpoint_id"] = self.endpoint_id
if self.name is not None:
body["name"] = self.name
if self.region is not None:
body["region"] = self.region
if self.state is not None:
body["state"] = self.state.value
if self.use_case is not None:
body["use_case"] = self.use_case.value
return body
def as_shallow_dict(self) -> dict:
"""Serializes the Endpoint into a shallow dictionary of its immediate attributes."""
body = {}
if self.account_id is not None:
body["account_id"] = self.account_id
if self.azure_private_endpoint_info:
body["azure_private_endpoint_info"] = self.azure_private_endpoint_info
if self.create_time is not None:
body["create_time"] = self.create_time
if self.display_name is not None:
body["display_name"] = self.display_name
if self.endpoint_id is not None:
body["endpoint_id"] = self.endpoint_id
if self.name is not None:
body["name"] = self.name
if self.region is not None:
body["region"] = self.region
if self.state is not None:
body["state"] = self.state
if self.use_case is not None:
body["use_case"] = self.use_case
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> Endpoint:
"""Deserializes the Endpoint from a dictionary."""
return cls(
account_id=d.get("account_id", None),
azure_private_endpoint_info=_from_dict(d, "azure_private_endpoint_info", AzurePrivateEndpointInfo),
create_time=_timestamp(d, "create_time"),
display_name=d.get("display_name", None),
endpoint_id=d.get("endpoint_id", None),
name=d.get("name", None),
region=d.get("region", None),
state=_enum(d, "state", EndpointState),
use_case=_enum(d, "use_case", EndpointUseCase),
)
class EndpointState(Enum):
APPROVED = "APPROVED"
DISCONNECTED = "DISCONNECTED"
FAILED = "FAILED"
PENDING = "PENDING"
class EndpointUseCase(Enum):
SERVICE_DIRECT = "SERVICE_DIRECT"
@dataclass
class ListEndpointsResponse:
items: Optional[List[Endpoint]] = None
next_page_token: Optional[str] = None
def as_dict(self) -> dict:
"""Serializes the ListEndpointsResponse into a dictionary suitable for use as a JSON request body."""
body = {}
if self.items:
body["items"] = [v.as_dict() for v in self.items]
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ListEndpointsResponse into a shallow dictionary of its immediate attributes."""
body = {}
if self.items:
body["items"] = self.items
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ListEndpointsResponse:
"""Deserializes the ListEndpointsResponse from a dictionary."""
return cls(items=_repeated_dict(d, "items", Endpoint), next_page_token=d.get("next_page_token", None))
class EndpointsAPI:
"""These APIs manage endpoint configurations for this account."""
def __init__(self, api_client):
self._api = api_client
def create_endpoint(self, parent: str, endpoint: Endpoint) -> Endpoint:
"""Creates a new network connectivity endpoint that enables private connectivity between your network
resources and Databricks services.
After creation, the endpoint is initially in the PENDING state. The Databricks endpoint service
automatically reviews and approves the endpoint within a few minutes. Use the GET method to retrieve
the latest endpoint state.
An endpoint can be used only after it reaches the APPROVED state.
:param parent: str
:param endpoint: :class:`Endpoint`
:returns: :class:`Endpoint`
"""
body = endpoint.as_dict()
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
res = self._api.do("POST", f"/api/networking/v1/{parent}/endpoints", body=body, headers=headers)
return Endpoint.from_dict(res)
def delete_endpoint(self, name: str):
"""Deletes a network endpoint. This will remove the endpoint configuration from Databricks. Depending on
the endpoint type and use case, you may also need to delete corresponding network resources in your
cloud provider account.
:param name: str
"""
headers = {
"Accept": "application/json",
}
self._api.do("DELETE", f"/api/networking/v1/{name}", headers=headers)
def get_endpoint(self, name: str) -> Endpoint:
"""Gets details of a specific network endpoint.
:param name: str
:returns: :class:`Endpoint`
"""
headers = {
"Accept": "application/json",
}
res = self._api.do("GET", f"/api/networking/v1/{name}", headers=headers)
return Endpoint.from_dict(res)
def list_endpoints(
self, parent: str, *, page_size: Optional[int] = None, page_token: Optional[str] = None
) -> Iterator[Endpoint]:
"""Lists all network connectivity endpoints for the account.
:param parent: str
:param page_size: int (optional)
:param page_token: str (optional)
:returns: Iterator over :class:`Endpoint`
"""
query = {}
if page_size is not None:
query["page_size"] = page_size
if page_token is not None:
query["page_token"] = page_token
headers = {
"Accept": "application/json",
}
while True:
json = self._api.do("GET", f"/api/networking/v1/{parent}/endpoints", query=query, headers=headers)
if "items" in json:
for v in json["items"]:
yield Endpoint.from_dict(v)
if "next_page_token" not in json or not json["next_page_token"]:
return
query["page_token"] = json["next_page_token"]

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,442 @@
# Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
from __future__ import annotations
import logging
from dataclasses import dataclass
from enum import Enum
from typing import Any, Dict, Iterator, List, Optional
from databricks.sdk.client_types import HostType
from databricks.sdk.service._internal import _enum, _from_dict, _repeated_dict
_LOG = logging.getLogger("databricks.sdk")
# all definitions in this file are in alphabetical order
@dataclass
class AnomalyDetectionConfig:
excluded_table_full_names: Optional[List[str]] = None
"""List of fully qualified table names to exclude from anomaly detection."""
last_run_id: Optional[str] = None
"""Run id of the last run of the workflow"""
latest_run_status: Optional[AnomalyDetectionRunStatus] = None
"""The status of the last run of the workflow."""
def as_dict(self) -> dict:
"""Serializes the AnomalyDetectionConfig into a dictionary suitable for use as a JSON request body."""
body = {}
if self.excluded_table_full_names:
body["excluded_table_full_names"] = [v for v in self.excluded_table_full_names]
if self.last_run_id is not None:
body["last_run_id"] = self.last_run_id
if self.latest_run_status is not None:
body["latest_run_status"] = self.latest_run_status.value
return body
def as_shallow_dict(self) -> dict:
"""Serializes the AnomalyDetectionConfig into a shallow dictionary of its immediate attributes."""
body = {}
if self.excluded_table_full_names:
body["excluded_table_full_names"] = self.excluded_table_full_names
if self.last_run_id is not None:
body["last_run_id"] = self.last_run_id
if self.latest_run_status is not None:
body["latest_run_status"] = self.latest_run_status
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> AnomalyDetectionConfig:
"""Deserializes the AnomalyDetectionConfig from a dictionary."""
return cls(
excluded_table_full_names=d.get("excluded_table_full_names", None),
last_run_id=d.get("last_run_id", None),
latest_run_status=_enum(d, "latest_run_status", AnomalyDetectionRunStatus),
)
class AnomalyDetectionRunStatus(Enum):
"""Status of Anomaly Detection Job Run"""
ANOMALY_DETECTION_RUN_STATUS_CANCELED = "ANOMALY_DETECTION_RUN_STATUS_CANCELED"
ANOMALY_DETECTION_RUN_STATUS_FAILED = "ANOMALY_DETECTION_RUN_STATUS_FAILED"
ANOMALY_DETECTION_RUN_STATUS_JOB_DELETED = "ANOMALY_DETECTION_RUN_STATUS_JOB_DELETED"
ANOMALY_DETECTION_RUN_STATUS_PENDING = "ANOMALY_DETECTION_RUN_STATUS_PENDING"
ANOMALY_DETECTION_RUN_STATUS_RUNNING = "ANOMALY_DETECTION_RUN_STATUS_RUNNING"
ANOMALY_DETECTION_RUN_STATUS_SUCCESS = "ANOMALY_DETECTION_RUN_STATUS_SUCCESS"
ANOMALY_DETECTION_RUN_STATUS_UNKNOWN = "ANOMALY_DETECTION_RUN_STATUS_UNKNOWN"
ANOMALY_DETECTION_RUN_STATUS_WORKSPACE_MISMATCH_ERROR = "ANOMALY_DETECTION_RUN_STATUS_WORKSPACE_MISMATCH_ERROR"
@dataclass
class ListQualityMonitorResponse:
next_page_token: Optional[str] = None
quality_monitors: Optional[List[QualityMonitor]] = None
def as_dict(self) -> dict:
"""Serializes the ListQualityMonitorResponse into a dictionary suitable for use as a JSON request body."""
body = {}
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
if self.quality_monitors:
body["quality_monitors"] = [v.as_dict() for v in self.quality_monitors]
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ListQualityMonitorResponse into a shallow dictionary of its immediate attributes."""
body = {}
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
if self.quality_monitors:
body["quality_monitors"] = self.quality_monitors
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ListQualityMonitorResponse:
"""Deserializes the ListQualityMonitorResponse from a dictionary."""
return cls(
next_page_token=d.get("next_page_token", None),
quality_monitors=_repeated_dict(d, "quality_monitors", QualityMonitor),
)
@dataclass
class PercentNullValidityCheck:
column_names: Optional[List[str]] = None
"""List of column names to check for null percentage"""
upper_bound: Optional[float] = None
"""Optional upper bound; we should use auto determined bounds for now"""
def as_dict(self) -> dict:
"""Serializes the PercentNullValidityCheck into a dictionary suitable for use as a JSON request body."""
body = {}
if self.column_names:
body["column_names"] = [v for v in self.column_names]
if self.upper_bound is not None:
body["upper_bound"] = self.upper_bound
return body
def as_shallow_dict(self) -> dict:
"""Serializes the PercentNullValidityCheck into a shallow dictionary of its immediate attributes."""
body = {}
if self.column_names:
body["column_names"] = self.column_names
if self.upper_bound is not None:
body["upper_bound"] = self.upper_bound
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> PercentNullValidityCheck:
"""Deserializes the PercentNullValidityCheck from a dictionary."""
return cls(column_names=d.get("column_names", None), upper_bound=d.get("upper_bound", None))
@dataclass
class QualityMonitor:
object_type: str
"""The type of the monitored object. Can be one of the following: schema."""
object_id: str
"""The uuid of the request object. For example, schema id."""
anomaly_detection_config: Optional[AnomalyDetectionConfig] = None
validity_check_configurations: Optional[List[ValidityCheckConfiguration]] = None
"""Validity check configurations for anomaly detection."""
def as_dict(self) -> dict:
"""Serializes the QualityMonitor into a dictionary suitable for use as a JSON request body."""
body = {}
if self.anomaly_detection_config:
body["anomaly_detection_config"] = self.anomaly_detection_config.as_dict()
if self.object_id is not None:
body["object_id"] = self.object_id
if self.object_type is not None:
body["object_type"] = self.object_type
if self.validity_check_configurations:
body["validity_check_configurations"] = [v.as_dict() for v in self.validity_check_configurations]
return body
def as_shallow_dict(self) -> dict:
"""Serializes the QualityMonitor into a shallow dictionary of its immediate attributes."""
body = {}
if self.anomaly_detection_config:
body["anomaly_detection_config"] = self.anomaly_detection_config
if self.object_id is not None:
body["object_id"] = self.object_id
if self.object_type is not None:
body["object_type"] = self.object_type
if self.validity_check_configurations:
body["validity_check_configurations"] = self.validity_check_configurations
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> QualityMonitor:
"""Deserializes the QualityMonitor from a dictionary."""
return cls(
anomaly_detection_config=_from_dict(d, "anomaly_detection_config", AnomalyDetectionConfig),
object_id=d.get("object_id", None),
object_type=d.get("object_type", None),
validity_check_configurations=_repeated_dict(
d, "validity_check_configurations", ValidityCheckConfiguration
),
)
@dataclass
class RangeValidityCheck:
column_names: Optional[List[str]] = None
"""List of column names to check for range validity"""
lower_bound: Optional[float] = None
"""Lower bound for the range"""
upper_bound: Optional[float] = None
"""Upper bound for the range"""
def as_dict(self) -> dict:
"""Serializes the RangeValidityCheck into a dictionary suitable for use as a JSON request body."""
body = {}
if self.column_names:
body["column_names"] = [v for v in self.column_names]
if self.lower_bound is not None:
body["lower_bound"] = self.lower_bound
if self.upper_bound is not None:
body["upper_bound"] = self.upper_bound
return body
def as_shallow_dict(self) -> dict:
"""Serializes the RangeValidityCheck into a shallow dictionary of its immediate attributes."""
body = {}
if self.column_names:
body["column_names"] = self.column_names
if self.lower_bound is not None:
body["lower_bound"] = self.lower_bound
if self.upper_bound is not None:
body["upper_bound"] = self.upper_bound
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> RangeValidityCheck:
"""Deserializes the RangeValidityCheck from a dictionary."""
return cls(
column_names=d.get("column_names", None),
lower_bound=d.get("lower_bound", None),
upper_bound=d.get("upper_bound", None),
)
@dataclass
class UniquenessValidityCheck:
column_names: Optional[List[str]] = None
"""List of column names to check for uniqueness"""
def as_dict(self) -> dict:
"""Serializes the UniquenessValidityCheck into a dictionary suitable for use as a JSON request body."""
body = {}
if self.column_names:
body["column_names"] = [v for v in self.column_names]
return body
def as_shallow_dict(self) -> dict:
"""Serializes the UniquenessValidityCheck into a shallow dictionary of its immediate attributes."""
body = {}
if self.column_names:
body["column_names"] = self.column_names
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> UniquenessValidityCheck:
"""Deserializes the UniquenessValidityCheck from a dictionary."""
return cls(column_names=d.get("column_names", None))
@dataclass
class ValidityCheckConfiguration:
name: Optional[str] = None
"""Can be set by system. Does not need to be user facing."""
percent_null_validity_check: Optional[PercentNullValidityCheck] = None
range_validity_check: Optional[RangeValidityCheck] = None
uniqueness_validity_check: Optional[UniquenessValidityCheck] = None
def as_dict(self) -> dict:
"""Serializes the ValidityCheckConfiguration into a dictionary suitable for use as a JSON request body."""
body = {}
if self.name is not None:
body["name"] = self.name
if self.percent_null_validity_check:
body["percent_null_validity_check"] = self.percent_null_validity_check.as_dict()
if self.range_validity_check:
body["range_validity_check"] = self.range_validity_check.as_dict()
if self.uniqueness_validity_check:
body["uniqueness_validity_check"] = self.uniqueness_validity_check.as_dict()
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ValidityCheckConfiguration into a shallow dictionary of its immediate attributes."""
body = {}
if self.name is not None:
body["name"] = self.name
if self.percent_null_validity_check:
body["percent_null_validity_check"] = self.percent_null_validity_check
if self.range_validity_check:
body["range_validity_check"] = self.range_validity_check
if self.uniqueness_validity_check:
body["uniqueness_validity_check"] = self.uniqueness_validity_check
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ValidityCheckConfiguration:
"""Deserializes the ValidityCheckConfiguration from a dictionary."""
return cls(
name=d.get("name", None),
percent_null_validity_check=_from_dict(d, "percent_null_validity_check", PercentNullValidityCheck),
range_validity_check=_from_dict(d, "range_validity_check", RangeValidityCheck),
uniqueness_validity_check=_from_dict(d, "uniqueness_validity_check", UniquenessValidityCheck),
)
class QualityMonitorV2API:
"""Deprecated: Please use the Data Quality Monitoring API instead (REST: /api/data-quality/v1/monitors).
Manage data quality of UC objects (currently support `schema`)."""
def __init__(self, api_client):
self._api = api_client
def create_quality_monitor(self, quality_monitor: QualityMonitor) -> QualityMonitor:
"""Deprecated: Use Data Quality Monitoring API instead (/api/data-quality/v1/monitors). Create a quality
monitor on UC object.
:param quality_monitor: :class:`QualityMonitor`
:returns: :class:`QualityMonitor`
"""
body = quality_monitor.as_dict()
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("POST", "/api/2.0/quality-monitors", body=body, headers=headers)
return QualityMonitor.from_dict(res)
def delete_quality_monitor(self, object_type: str, object_id: str):
"""Deprecated: Use Data Quality Monitoring API instead (/api/data-quality/v1/monitors). Delete a quality
monitor on UC object.
:param object_type: str
The type of the monitored object. Can be one of the following: schema.
:param object_id: str
The uuid of the request object. For example, schema id.
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
self._api.do("DELETE", f"/api/2.0/quality-monitors/{object_type}/{object_id}", headers=headers)
def get_quality_monitor(self, object_type: str, object_id: str) -> QualityMonitor:
"""Deprecated: Use Data Quality Monitoring API instead (/api/data-quality/v1/monitors). Read a quality
monitor on UC object.
:param object_type: str
The type of the monitored object. Can be one of the following: schema.
:param object_id: str
The uuid of the request object. For example, schema id.
:returns: :class:`QualityMonitor`
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("GET", f"/api/2.0/quality-monitors/{object_type}/{object_id}", headers=headers)
return QualityMonitor.from_dict(res)
def list_quality_monitor(
self, *, page_size: Optional[int] = None, page_token: Optional[str] = None
) -> Iterator[QualityMonitor]:
"""Deprecated: Use Data Quality Monitoring API instead (/api/data-quality/v1/monitors). (Unimplemented)
List quality monitors.
:param page_size: int (optional)
:param page_token: str (optional)
:returns: Iterator over :class:`QualityMonitor`
"""
query = {}
if page_size is not None:
query["page_size"] = page_size
if page_token is not None:
query["page_token"] = page_token
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
while True:
json = self._api.do("GET", "/api/2.0/quality-monitors", query=query, headers=headers)
if "quality_monitors" in json:
for v in json["quality_monitors"]:
yield QualityMonitor.from_dict(v)
if "next_page_token" not in json or not json["next_page_token"]:
return
query["page_token"] = json["next_page_token"]
def update_quality_monitor(
self, object_type: str, object_id: str, quality_monitor: QualityMonitor
) -> QualityMonitor:
"""Deprecated: Use Data Quality Monitoring API instead (/api/data-quality/v1/monitors). (Unimplemented)
Update a quality monitor on UC object.
:param object_type: str
The type of the monitored object. Can be one of the following: schema.
:param object_id: str
The uuid of the request object. For example, schema id.
:param quality_monitor: :class:`QualityMonitor`
:returns: :class:`QualityMonitor`
"""
body = quality_monitor.as_dict()
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("PUT", f"/api/2.0/quality-monitors/{object_type}/{object_id}", body=body, headers=headers)
return QualityMonitor.from_dict(res)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,555 @@
# Code generated from OpenAPI specs by Databricks SDK Generator. DO NOT EDIT.
from __future__ import annotations
import logging
from dataclasses import dataclass
from typing import Any, Dict, Iterator, List, Optional
from databricks.sdk.client_types import HostType
from databricks.sdk.service._internal import _repeated_dict
_LOG = logging.getLogger("databricks.sdk")
# all definitions in this file are in alphabetical order
@dataclass
class ListTagAssignmentsResponse:
next_page_token: Optional[str] = None
"""Pagination token to request the next page of tag assignments"""
tag_assignments: Optional[List[TagAssignment]] = None
def as_dict(self) -> dict:
"""Serializes the ListTagAssignmentsResponse into a dictionary suitable for use as a JSON request body."""
body = {}
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
if self.tag_assignments:
body["tag_assignments"] = [v.as_dict() for v in self.tag_assignments]
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ListTagAssignmentsResponse into a shallow dictionary of its immediate attributes."""
body = {}
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
if self.tag_assignments:
body["tag_assignments"] = self.tag_assignments
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ListTagAssignmentsResponse:
"""Deserializes the ListTagAssignmentsResponse from a dictionary."""
return cls(
next_page_token=d.get("next_page_token", None),
tag_assignments=_repeated_dict(d, "tag_assignments", TagAssignment),
)
@dataclass
class ListTagPoliciesResponse:
next_page_token: Optional[str] = None
tag_policies: Optional[List[TagPolicy]] = None
def as_dict(self) -> dict:
"""Serializes the ListTagPoliciesResponse into a dictionary suitable for use as a JSON request body."""
body = {}
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
if self.tag_policies:
body["tag_policies"] = [v.as_dict() for v in self.tag_policies]
return body
def as_shallow_dict(self) -> dict:
"""Serializes the ListTagPoliciesResponse into a shallow dictionary of its immediate attributes."""
body = {}
if self.next_page_token is not None:
body["next_page_token"] = self.next_page_token
if self.tag_policies:
body["tag_policies"] = self.tag_policies
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> ListTagPoliciesResponse:
"""Deserializes the ListTagPoliciesResponse from a dictionary."""
return cls(
next_page_token=d.get("next_page_token", None), tag_policies=_repeated_dict(d, "tag_policies", TagPolicy)
)
@dataclass
class TagAssignment:
entity_type: str
"""The type of entity to which the tag is assigned. Allowed values are apps, dashboards,
geniespaces"""
entity_id: str
"""The identifier of the entity to which the tag is assigned. For apps, the entity_id is the app
name"""
tag_key: str
"""The key of the tag. The characters , . : / - = and leading/trailing spaces are not allowed"""
tag_value: Optional[str] = None
"""The value of the tag"""
def as_dict(self) -> dict:
"""Serializes the TagAssignment into a dictionary suitable for use as a JSON request body."""
body = {}
if self.entity_id is not None:
body["entity_id"] = self.entity_id
if self.entity_type is not None:
body["entity_type"] = self.entity_type
if self.tag_key is not None:
body["tag_key"] = self.tag_key
if self.tag_value is not None:
body["tag_value"] = self.tag_value
return body
def as_shallow_dict(self) -> dict:
"""Serializes the TagAssignment into a shallow dictionary of its immediate attributes."""
body = {}
if self.entity_id is not None:
body["entity_id"] = self.entity_id
if self.entity_type is not None:
body["entity_type"] = self.entity_type
if self.tag_key is not None:
body["tag_key"] = self.tag_key
if self.tag_value is not None:
body["tag_value"] = self.tag_value
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> TagAssignment:
"""Deserializes the TagAssignment from a dictionary."""
return cls(
entity_id=d.get("entity_id", None),
entity_type=d.get("entity_type", None),
tag_key=d.get("tag_key", None),
tag_value=d.get("tag_value", None),
)
@dataclass
class TagPolicy:
tag_key: str
create_time: Optional[str] = None
"""Timestamp when the tag policy was created"""
description: Optional[str] = None
id: Optional[str] = None
update_time: Optional[str] = None
"""Timestamp when the tag policy was last updated"""
values: Optional[List[Value]] = None
def as_dict(self) -> dict:
"""Serializes the TagPolicy into a dictionary suitable for use as a JSON request body."""
body = {}
if self.create_time is not None:
body["create_time"] = self.create_time
if self.description is not None:
body["description"] = self.description
if self.id is not None:
body["id"] = self.id
if self.tag_key is not None:
body["tag_key"] = self.tag_key
if self.update_time is not None:
body["update_time"] = self.update_time
if self.values:
body["values"] = [v.as_dict() for v in self.values]
return body
def as_shallow_dict(self) -> dict:
"""Serializes the TagPolicy into a shallow dictionary of its immediate attributes."""
body = {}
if self.create_time is not None:
body["create_time"] = self.create_time
if self.description is not None:
body["description"] = self.description
if self.id is not None:
body["id"] = self.id
if self.tag_key is not None:
body["tag_key"] = self.tag_key
if self.update_time is not None:
body["update_time"] = self.update_time
if self.values:
body["values"] = self.values
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> TagPolicy:
"""Deserializes the TagPolicy from a dictionary."""
return cls(
create_time=d.get("create_time", None),
description=d.get("description", None),
id=d.get("id", None),
tag_key=d.get("tag_key", None),
update_time=d.get("update_time", None),
values=_repeated_dict(d, "values", Value),
)
@dataclass
class Value:
name: str
def as_dict(self) -> dict:
"""Serializes the Value into a dictionary suitable for use as a JSON request body."""
body = {}
if self.name is not None:
body["name"] = self.name
return body
def as_shallow_dict(self) -> dict:
"""Serializes the Value into a shallow dictionary of its immediate attributes."""
body = {}
if self.name is not None:
body["name"] = self.name
return body
@classmethod
def from_dict(cls, d: Dict[str, Any]) -> Value:
"""Deserializes the Value from a dictionary."""
return cls(name=d.get("name", None))
class TagPoliciesAPI:
"""The Tag Policy API allows you to manage policies for governed tags in Databricks. For Terraform usage, see
the [Tag Policy Terraform documentation]. Permissions for tag policies can be managed using the [Account
Access Control Proxy API].
[Account Access Control Proxy API]: https://docs.databricks.com/api/workspace/accountaccesscontrolproxy
[Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/tag_policy
"""
def __init__(self, api_client):
self._api = api_client
def create_tag_policy(self, tag_policy: TagPolicy) -> TagPolicy:
"""Creates a new tag policy, making the associated tag key governed. For Terraform usage, see the [Tag
Policy Terraform documentation]. To manage permissions for tag policies, use the [Account Access
Control Proxy API].
[Account Access Control Proxy API]: https://docs.databricks.com/api/workspace/accountaccesscontrolproxy
[Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/tag_policy
:param tag_policy: :class:`TagPolicy`
:returns: :class:`TagPolicy`
"""
body = tag_policy.as_dict()
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("POST", "/api/2.1/tag-policies", body=body, headers=headers)
return TagPolicy.from_dict(res)
def delete_tag_policy(self, tag_key: str):
"""Deletes a tag policy by its associated governed tag's key, leaving that tag key ungoverned. For
Terraform usage, see the [Tag Policy Terraform documentation].
[Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/tag_policy
:param tag_key: str
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
self._api.do("DELETE", f"/api/2.1/tag-policies/{tag_key}", headers=headers)
def get_tag_policy(self, tag_key: str) -> TagPolicy:
"""Gets a single tag policy by its associated governed tag's key. For Terraform usage, see the [Tag
Policy Terraform documentation]. To list granted permissions for tag policies, use the [Account Access
Control Proxy API].
[Account Access Control Proxy API]: https://docs.databricks.com/api/workspace/accountaccesscontrolproxy
[Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/data-sources/tag_policy
:param tag_key: str
:returns: :class:`TagPolicy`
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("GET", f"/api/2.1/tag-policies/{tag_key}", headers=headers)
return TagPolicy.from_dict(res)
def list_tag_policies(
self, *, page_size: Optional[int] = None, page_token: Optional[str] = None
) -> Iterator[TagPolicy]:
"""Lists the tag policies for all governed tags in the account. For Terraform usage, see the [Tag Policy
Terraform documentation]. To list granted permissions for tag policies, use the [Account Access
Control Proxy API].
[Account Access Control Proxy API]: https://docs.databricks.com/api/workspace/accountaccesscontrolproxy
[Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/data-sources/tag_policies
:param page_size: int (optional)
The maximum number of results to return in this request. Fewer results may be returned than
requested. If unspecified or set to 0, this defaults to 1000. The maximum value is 1000; values
above 1000 will be coerced down to 1000.
:param page_token: str (optional)
An optional page token received from a previous list tag policies call.
:returns: Iterator over :class:`TagPolicy`
"""
query = {}
if page_size is not None:
query["page_size"] = page_size
if page_token is not None:
query["page_token"] = page_token
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
while True:
json = self._api.do("GET", "/api/2.1/tag-policies", query=query, headers=headers)
if "tag_policies" in json:
for v in json["tag_policies"]:
yield TagPolicy.from_dict(v)
if "next_page_token" not in json or not json["next_page_token"]:
return
query["page_token"] = json["next_page_token"]
def update_tag_policy(self, tag_key: str, tag_policy: TagPolicy, update_mask: str) -> TagPolicy:
"""Updates an existing tag policy for a single governed tag. For Terraform usage, see the [Tag Policy
Terraform documentation]. To manage permissions for tag policies, use the [Account Access Control
Proxy API].
[Account Access Control Proxy API]: https://docs.databricks.com/api/workspace/accountaccesscontrolproxy
[Tag Policy Terraform documentation]: https://registry.terraform.io/providers/databricks/databricks/latest/docs/resources/tag_policy
:param tag_key: str
:param tag_policy: :class:`TagPolicy`
:param update_mask: str
The field mask must be a single string, with multiple fields separated by commas (no spaces). The
field path is relative to the resource object, using a dot (`.`) to navigate sub-fields (e.g.,
`author.given_name`). Specification of elements in sequence or map fields is not allowed, as only
the entire collection field can be specified. Field names must exactly match the resource field
names.
A field mask of `*` indicates full replacement. Its recommended to always explicitly list the
fields being updated and avoid using `*` wildcards, as it can lead to unintended results if the API
changes in the future.
:returns: :class:`TagPolicy`
"""
body = tag_policy.as_dict()
query = {}
if update_mask is not None:
query["update_mask"] = update_mask
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("PATCH", f"/api/2.1/tag-policies/{tag_key}", query=query, body=body, headers=headers)
return TagPolicy.from_dict(res)
class WorkspaceEntityTagAssignmentsAPI:
"""Manage tag assignments on workspace-scoped objects."""
def __init__(self, api_client):
self._api = api_client
def create_tag_assignment(self, tag_assignment: TagAssignment) -> TagAssignment:
"""Create a tag assignment
:param tag_assignment: :class:`TagAssignment`
:returns: :class:`TagAssignment`
"""
body = tag_assignment.as_dict()
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do("POST", "/api/2.0/entity-tag-assignments", body=body, headers=headers)
return TagAssignment.from_dict(res)
def delete_tag_assignment(self, entity_type: str, entity_id: str, tag_key: str):
"""Delete a tag assignment
:param entity_type: str
The type of entity to which the tag is assigned. Allowed values are apps, dashboards, geniespaces
:param entity_id: str
The identifier of the entity to which the tag is assigned. For apps, the entity_id is the app name
:param tag_key: str
The key of the tag. The characters , . : / - = and leading/trailing spaces are not allowed
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
self._api.do(
"DELETE", f"/api/2.0/entity-tag-assignments/{entity_type}/{entity_id}/tags/{tag_key}", headers=headers
)
def get_tag_assignment(self, entity_type: str, entity_id: str, tag_key: str) -> TagAssignment:
"""Get a tag assignment
:param entity_type: str
The type of entity to which the tag is assigned. Allowed values are apps, dashboards, geniespaces
:param entity_id: str
The identifier of the entity to which the tag is assigned. For apps, the entity_id is the app name
:param tag_key: str
The key of the tag. The characters , . : / - = and leading/trailing spaces are not allowed
:returns: :class:`TagAssignment`
"""
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do(
"GET", f"/api/2.0/entity-tag-assignments/{entity_type}/{entity_id}/tags/{tag_key}", headers=headers
)
return TagAssignment.from_dict(res)
def list_tag_assignments(
self, entity_type: str, entity_id: str, *, page_size: Optional[int] = None, page_token: Optional[str] = None
) -> Iterator[TagAssignment]:
"""List the tag assignments for an entity
:param entity_type: str
The type of entity to which the tag is assigned. Allowed values are apps, dashboards, geniespaces
:param entity_id: str
The identifier of the entity to which the tag is assigned. For apps, the entity_id is the app name
:param page_size: int (optional)
Optional. Maximum number of tag assignments to return in a single page
:param page_token: str (optional)
Pagination token to go to the next page of tag assignments. Requests first page if absent.
:returns: Iterator over :class:`TagAssignment`
"""
query = {}
if page_size is not None:
query["page_size"] = page_size
if page_token is not None:
query["page_token"] = page_token
headers = {
"Accept": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
while True:
json = self._api.do(
"GET", f"/api/2.0/entity-tag-assignments/{entity_type}/{entity_id}/tags", query=query, headers=headers
)
if "tag_assignments" in json:
for v in json["tag_assignments"]:
yield TagAssignment.from_dict(v)
if "next_page_token" not in json or not json["next_page_token"]:
return
query["page_token"] = json["next_page_token"]
def update_tag_assignment(
self, entity_type: str, entity_id: str, tag_key: str, tag_assignment: TagAssignment, update_mask: str
) -> TagAssignment:
"""Update a tag assignment
:param entity_type: str
The type of entity to which the tag is assigned. Allowed values are apps, dashboards, geniespaces
:param entity_id: str
The identifier of the entity to which the tag is assigned. For apps, the entity_id is the app name
:param tag_key: str
The key of the tag. The characters , . : / - = and leading/trailing spaces are not allowed
:param tag_assignment: :class:`TagAssignment`
:param update_mask: str
The field mask must be a single string, with multiple fields separated by commas (no spaces). The
field path is relative to the resource object, using a dot (`.`) to navigate sub-fields (e.g.,
`author.given_name`). Specification of elements in sequence or map fields is not allowed, as only
the entire collection field can be specified. Field names must exactly match the resource field
names.
A field mask of `*` indicates full replacement. Its recommended to always explicitly list the
fields being updated and avoid using `*` wildcards, as it can lead to unintended results if the API
changes in the future.
:returns: :class:`TagAssignment`
"""
body = tag_assignment.as_dict()
query = {}
if update_mask is not None:
query["update_mask"] = update_mask
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
}
cfg = self._api._cfg
if cfg.host_type == HostType.UNIFIED and cfg.workspace_id:
headers["X-Databricks-Org-Id"] = cfg.workspace_id
res = self._api.do(
"PATCH",
f"/api/2.0/entity-tag-assignments/{entity_type}/{entity_id}/tags/{tag_key}",
query=query,
body=body,
headers=headers,
)
return TagAssignment.from_dict(res)

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff