Skip to content

Commit cfc935a

Browse files
refactor: use _util.resolve_connector_name_and_directory and set help=__doc__
Co-Authored-By: Aaron <AJ> Steers <[email protected]>
1 parent 881beda commit cfc935a

File tree

1 file changed

+17
-45
lines changed

1 file changed

+17
-45
lines changed

airbyte_cdk/cli/airbyte_cdk/_secrets.py

Lines changed: 17 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,15 @@
2323

2424
import rich_click as click
2525

26-
from airbyte_cdk.test.standard_tests.test_resources import find_connector_root_from_name
26+
from airbyte_cdk.cli.airbyte_cdk._util import resolve_connector_name_and_directory
2727

2828
AIRBYTE_INTERNAL_GCP_PROJECT = "dataline-integration-testing"
2929
CONNECTOR_LABEL = "connector"
3030

3131

32-
@click.group(name="secrets")
32+
@click.group(name="secrets", help=__doc__.replace("\n", "\n\n"))
3333
def secrets_cli_group() -> None:
34-
"""Secret management commands.
35-
36-
This module provides commands for managing secrets for Airbyte connectors.
37-
38-
Usage:
39-
airbyte-cdk secrets fetch --connector-name source-github
40-
airbyte-cdk secrets fetch --connector-directory /path/to/connector
41-
airbyte-cdk secrets fetch # Run from within a connector directory
42-
43-
Usage without pre-installing (stateless):
44-
pipx run airbyte-cdk[dev] secrets fetch ...
45-
uvx airbyte-cdk[dev] secrets fetch ...
46-
47-
The 'fetch' command retrieves secrets from Google Secret Manager based on connector
48-
labels and writes them to the connector's `secrets` directory.
49-
"""
34+
"""Secret management commands."""
5035
pass
5136

5237

@@ -92,33 +77,20 @@ def fetch(
9277
click.echo("Fetching secrets...")
9378

9479
# Resolve connector name/directory
95-
if not connector_name and not connector_directory:
96-
cwd = Path().resolve().absolute()
97-
if cwd.name.startswith("source-") or cwd.name.startswith("destination-"):
98-
connector_name = cwd.name
99-
connector_directory = cwd
100-
else:
101-
raise ValueError(
102-
"Either connector_name or connector_directory must be provided if not "
103-
"running from a connector directory."
104-
)
105-
106-
if connector_directory:
107-
connector_directory = connector_directory.resolve().absolute()
108-
if not connector_name:
109-
connector_name = connector_directory.name
110-
elif connector_name:
111-
try:
112-
connector_directory = find_connector_root_from_name(connector_name)
113-
except FileNotFoundError as e:
114-
raise FileNotFoundError(
115-
f"Could not find connector directory for '{connector_name}'. "
116-
"Please provide the --connector-directory option with the path to the connector. "
117-
"Note: This command requires either running from within a connector directory, "
118-
"being in the airbyte monorepo, or explicitly providing the connector directory path."
119-
) from e
120-
else:
121-
raise ValueError("Either connector_name or connector_directory must be provided.")
80+
try:
81+
connector_name, connector_directory = resolve_connector_name_and_directory(
82+
connector_name=connector_name,
83+
connector_directory=connector_directory,
84+
)
85+
except FileNotFoundError as e:
86+
raise FileNotFoundError(
87+
f"Could not find connector directory for '{connector_name}'. "
88+
"Please provide the --connector-directory option with the path to the connector. "
89+
"Note: This command requires either running from within a connector directory, "
90+
"being in the airbyte monorepo, or explicitly providing the connector directory path."
91+
) from e
92+
except ValueError as e:
93+
raise ValueError(str(e))
12294

12395
# Create secrets directory if it doesn't exist
12496
secrets_dir = connector_directory / "secrets"

0 commit comments

Comments
 (0)