Skip to content

Commit

Permalink
Connect to Service-connector at component registration (#1858)
Browse files Browse the repository at this point in the history
* add connect attribute to stack component register command to connect service connector

* apply suggested reviews
  • Loading branch information
safoinme authored Oct 10, 2023
1 parent 2f6c9f1 commit 362a0e5
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions src/zenml/cli/stack_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,39 @@ def generate_stack_component_register_command(
help="Use this flag to share this stack component with other users.",
type=click.BOOL,
)
@click.option(
"--connector",
"-c",
"connector",
help="Use this flag to connect this stack component to a service connector.",
type=str,
)
@click.option(
"--connector",
"-c",
"connector",
help="Use this flag to connect this stack component to a service connector.",
type=str,
)
@click.option(
"--resource-id",
"-r",
"resource_id",
help="The resource ID to use with the connector. Only required for "
"multi-instance connectors that are not already configured with a "
"particular resource ID.",
required=False,
type=str,
)
@click.argument("args", nargs=-1, type=click.UNPROCESSED)
def register_stack_component_command(
name: str,
flavor: str,
share: bool,
args: List[str],
labels: Optional[List[str]] = None,
connector: Optional[str] = None,
resource_id: Optional[str] = None,
) -> None:
"""Registers a stack component.
Expand All @@ -253,6 +279,8 @@ def register_stack_component_command(
share: Share the stack with other users.
args: Additional arguments to pass to the component.
labels: Labels to be associated with the component.
connector: Name of the service connector to connect the component to.
resource_id: The resource ID to use with the connector.
"""
if component_type == StackComponentType.SECRETS_MANAGER:
fail_secrets_manager_creation()
Expand All @@ -272,6 +300,14 @@ def register_stack_component_command(
if share is None:
share = False

if connector:
try:
client.get_service_connector(connector)
except KeyError as err:
cli_utils.error(
f"Could not find a connector '{connector}': " f"{str(err)}"
)

with console.status(f"Registering {display_name} '{name}'...\n"):
# Create a new stack component model
component = client.create_stack_component(
Expand All @@ -288,6 +324,16 @@ def register_stack_component_command(
)
print_model_url(get_component_url(component))

if connector:
connect_stack_component_with_service_connector(
component_type=component_type,
name_id_or_prefix=name,
connector=connector,
interactive=False,
no_verify=False,
resource_id=resource_id,
)

return register_stack_component_command


Expand Down

0 comments on commit 362a0e5

Please sign in to comment.