Skip to content

Commit

Permalink
Make flexible-scoped resources global-scoped
Browse files Browse the repository at this point in the history
  • Loading branch information
stefannica committed Feb 21, 2025
1 parent 3e5d964 commit d928924
Show file tree
Hide file tree
Showing 45 changed files with 337 additions and 839 deletions.
1 change: 0 additions & 1 deletion src/zenml/cli/service_connectors.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,6 @@ def describe_service_connector(
)

connector = connector_client.to_response_model(
workspace=client.active_workspace,
user=client.active_user,
)
else:
Expand Down
7 changes: 0 additions & 7 deletions src/zenml/cli/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,6 @@ def print_service_connector_configuration(
else "N/A"
),
"OWNER": user_name,
"WORKSPACE": connector.workspace.name,
"CREATED_AT": connector.created,
"UPDATED_AT": connector.updated,
}
Expand Down Expand Up @@ -2161,9 +2160,6 @@ def print_debug_stack() -> None:
console.print(f"ID: {str(stack.id)}")
if stack.user and stack.user.name and stack.user.id: # mypy check
console.print(f"User: {stack.user.name} / {str(stack.user.id)}")
console.print(
f"Workspace: {stack.workspace.name} / {str(stack.workspace.id)}"
)

for component_type, components in stack.components.items():
component = components[0]
Expand All @@ -2190,9 +2186,6 @@ def print_debug_stack() -> None:
console.print(
f"User: {component_response.user.name} / {str(component_response.user.id)}"
)
console.print(
f"Workspace: {component_response.workspace.name} / {str(component_response.workspace.id)}"
)


def _component_display_name(
Expand Down
45 changes: 1 addition & 44 deletions src/zenml/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1236,7 +1236,6 @@ def list_stacks(
updated: Optional[Union[datetime, str]] = None,
name: Optional[str] = None,
description: Optional[str] = None,
workspace_id: Optional[Union[str, UUID]] = None,
component_id: Optional[Union[str, UUID]] = None,
user: Optional[Union[UUID, str]] = None,
component: Optional[Union[UUID, str]] = None,
Expand All @@ -1253,7 +1252,6 @@ def list_stacks(
created: Use to filter by time of creation
updated: Use the last updated date for filtering
description: Use the stack description for filtering
workspace_id: The id of the workspace to filter by.
component_id: The id of the component to filter by.
user: The name/ID of the user to filter by.
component: The name/ID of the component to filter by.
Expand All @@ -1269,7 +1267,6 @@ def list_stacks(
size=size,
sort_by=sort_by,
logical_operator=logical_operator,
workspace_id=workspace_id,
component_id=component_id,
user=user,
component=component,
Expand All @@ -1279,7 +1276,6 @@ def list_stacks(
created=created,
updated=updated,
)
stack_filter_model.set_scope_workspace(self.active_workspace.id)
return self.zen_store.list_stacks(stack_filter_model, hydrate=hydrate)

def update_stack(
Expand Down Expand Up @@ -1884,9 +1880,6 @@ def type_scoped_list_method(
component_filter_model.set_scope_type(
component_type=component_type
)
component_filter_model.set_scope_workspace(
self.active_workspace.id
)
return self.zen_store.list_stack_components(
component_filter_model=component_filter_model,
hydrate=hydrate,
Expand All @@ -1912,7 +1905,6 @@ def list_stack_components(
name: Optional[str] = None,
flavor: Optional[str] = None,
type: Optional[str] = None,
workspace_id: Optional[Union[str, UUID]] = None,
connector_id: Optional[Union[str, UUID]] = None,
stack_id: Optional[Union[str, UUID]] = None,
user: Optional[Union[UUID, str]] = None,
Expand All @@ -1930,7 +1922,6 @@ def list_stack_components(
updated: Use the last updated date for filtering
flavor: Use the component flavor for filtering
type: Use the component type for filtering
workspace_id: The id of the workspace to filter by.
connector_id: The id of the connector to filter by.
stack_id: The id of the stack to filter by.
name: The name of the component to filter by.
Expand All @@ -1946,7 +1937,6 @@ def list_stack_components(
size=size,
sort_by=sort_by,
logical_operator=logical_operator,
workspace_id=workspace_id or self.active_workspace.id,
connector_id=connector_id,
stack_id=stack_id,
name=name,
Expand All @@ -1957,7 +1947,6 @@ def list_stack_components(
updated=updated,
user=user,
)
component_filter_model.set_scope_workspace(self.active_workspace.id)

return self.zen_store.list_stack_components(
component_filter_model=component_filter_model, hydrate=hydrate
Expand Down Expand Up @@ -2263,7 +2252,6 @@ def list_flavors(
created=created,
updated=updated,
)
flavor_filter_model.set_scope_workspace(self.active_workspace.id)
return self.zen_store.list_flavors(
flavor_filter_model=flavor_filter_model, hydrate=hydrate
)
Expand Down Expand Up @@ -4641,7 +4629,6 @@ def list_secrets(
updated: Optional[datetime] = None,
name: Optional[str] = None,
scope: Optional[SecretScope] = None,
workspace_id: Optional[Union[str, UUID]] = None,
user: Optional[Union[UUID, str]] = None,
hydrate: bool = False,
) -> Page[SecretResponse]:
Expand All @@ -4660,7 +4647,6 @@ def list_secrets(
updated: Use the last updated date for filtering
name: The name of the secret to filter by.
scope: The scope of the secret to filter by.
workspace_id: The id of the workspace to filter by.
user: Filter by user name/ID.
hydrate: Flag deciding whether to hydrate the output model(s)
by including metadata fields in the response.
Expand All @@ -4678,14 +4664,12 @@ def list_secrets(
sort_by=sort_by,
logical_operator=logical_operator,
user=user,
workspace_id=workspace_id,
name=name,
scope=scope,
id=id,
created=created,
updated=updated,
)
secret_filter_model.set_scope_workspace(self.active_workspace.id)
try:
return self.zen_store.list_secrets(
secret_filter_model=secret_filter_model,
Expand Down Expand Up @@ -5342,32 +5326,9 @@ def get_service_connector(
Returns:
The registered service connector.
"""

def scoped_list_method(
hydrate: bool = False,
**kwargs: Any,
) -> Page[ServiceConnectorResponse]:
"""Call `zen_store.list_service_connectors` with workspace scoping.
Args:
hydrate: Flag deciding whether to hydrate the output model(s)
by including metadata fields in the response.
**kwargs: Keyword arguments to pass to
`ServiceConnectorFilterModel`.
Returns:
The list of service connectors.
"""
filter_model = ServiceConnectorFilter(**kwargs)
filter_model.set_scope_workspace(self.active_workspace.id)
return self.zen_store.list_service_connectors(
filter_model=filter_model,
hydrate=hydrate,
)

connector = self._get_entity_by_id_or_name_or_prefix(
get_method=self.zen_store.get_service_connector,
list_method=scoped_list_method,
list_method=self.zen_store.list_service_connectors,
name_id_or_prefix=name_id_or_prefix,
allow_name_prefix_match=allow_name_prefix_match,
hydrate=hydrate,
Expand Down Expand Up @@ -5406,7 +5367,6 @@ def list_service_connectors(
auth_method: Optional[str] = None,
resource_type: Optional[str] = None,
resource_id: Optional[str] = None,
workspace_id: Optional[Union[str, UUID]] = None,
user: Optional[Union[UUID, str]] = None,
labels: Optional[Dict[str, Optional[str]]] = None,
secret_id: Optional[Union[str, UUID]] = None,
Expand All @@ -5428,7 +5388,6 @@ def list_service_connectors(
they can give access to.
resource_id: Filter service connectors by the resource id that
they can give access to.
workspace_id: The id of the workspace to filter by.
user: Filter by user name/ID.
name: The name of the service connector to filter by.
labels: The labels of the service connector to filter by.
Expand All @@ -5445,7 +5404,6 @@ def list_service_connectors(
size=size,
sort_by=sort_by,
logical_operator=logical_operator,
workspace_id=workspace_id or self.active_workspace.id,
user=user,
name=name,
connector_type=connector_type,
Expand All @@ -5458,7 +5416,6 @@ def list_service_connectors(
labels=labels,
secret_id=secret_id,
)
connector_filter_model.set_scope_workspace(self.active_workspace.id)
return self.zen_store.list_service_connectors(
filter_model=connector_filter_model,
hydrate=hydrate,
Expand Down
2 changes: 1 addition & 1 deletion src/zenml/integrations/mlflow/steps/mlflow_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def mlflow_register_model_step(
pipeline_name = step_context.pipeline.name
current_run_name = step_context.pipeline_run.name
pipeline_run_uuid = str(step_context.pipeline_run.id)
zenml_workspace = str(model_registry.workspace)
zenml_workspace = str(step_context.pipeline.workspace.name)

# Get MLflow run ID either from params or from experiment tracker using
# pipeline name and run name
Expand Down
8 changes: 0 additions & 8 deletions src/zenml/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
BaseDatedResponseBody,
)
from zenml.models.v2.base.scoped import (
FlexibleScopedFilter,
FlexibleScopedRequest,
FlexibleScopedResponse,
FlexibleScopedUpdate,
TaggableFilter,
UserScopedRequest,
UserScopedFilter,
Expand Down Expand Up @@ -495,10 +491,6 @@
"BaseDatedResponseBody",
"BaseZenModel",
"BasePluginFlavorResponse",
"FlexibleScopedFilter",
"FlexibleScopedRequest",
"FlexibleScopedResponse",
"FlexibleScopedUpdate",
"UserScopedRequest",
"UserScopedFilter",
"UserScopedResponse",
Expand Down
5 changes: 0 additions & 5 deletions src/zenml/models/v2/base/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,6 @@ class BaseUpdate(BaseZenModel):
Used as a base class for all update models.
"""

model_config = ConfigDict(
# Ignore extras on all update models.
extra="ignore",
)


# -------------------- Response Model --------------------

Expand Down
Loading

0 comments on commit d928924

Please sign in to comment.