Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Octavia CLI uses Basic Auth #17982

Merged
merged 11 commits into from
Oct 18, 2022
4 changes: 3 additions & 1 deletion octavia-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ docker-compose run octavia-cli <command>`
| **Flag** | **Description** | **Env Variable** | **Default** |
| ---------------------------------------- | --------------------------------------------------------------------------------- | -------------------------- | ------------------------------------------------------ |
| `--airbyte-url` | Airbyte instance URL. | `AIRBYTE_URL` | `http://localhost:8000` |
| `--airbyte-username` | Airbyte instance username (basic auth). | `AIRBYTE_URL` | `airbyte` |
| `--airbyte-password` | Airbyte instance password (basic auth). | `AIRBYTE_URL` | password` |
| `--workspace-id` | Airbyte workspace id. | `AIRBYTE_WORKSPACE_ID` | The first workspace id found on your Airbyte instance. |
| `--enable-telemetry/--disable-telemetry` | Enable or disable the sending of telemetry data. | `OCTAVIA_ENABLE_TELEMETRY` | True |
| `--api-http-header` | HTTP Header value pairs passed while calling Airbyte's API | None | None |
Expand Down Expand Up @@ -709,7 +711,7 @@ You can disable telemetry by setting the `OCTAVIA_ENABLE_TELEMETRY` environment

| Version | Date | Description | PR |
| ------- | ---------- | ------------------------------------------------------------------------------------- | ----------------------------------------------------------- |
| 0.40.14 | 2022-08-10 | Enable cron and basic scheduling | [#15253](https://github.com/airbytehq/airbyte/pull/15253) |
| 0.40.14 | 2022-08-10 | Enable cron and basic scheduling | [#15253](https://github.com/airbytehq/airbyte/pull/15253) |
| 0.39.33 | 2022-07-05 | Add `octavia import all` command | [#14374](https://github.com/airbytehq/airbyte/pull/14374) |
| 0.39.32 | 2022-06-30 | Create import command to import and manage existing Airbyte resource from octavia-cli | [#14137](https://github.com/airbytehq/airbyte/pull/14137) |
| 0.39.27 | 2022-06-24 | Create get command to retrieve resources JSON representation | [#13254](https://github.com/airbytehq/airbyte/pull/13254) |
Expand Down
2 changes: 1 addition & 1 deletion octavia-cli/integration_tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def octavia_test_project_directory():

@pytest.fixture(scope="session")
def api_client():
return get_api_client("http://localhost:8000", "octavia-cli/integration-tests", None)
return get_api_client("http://localhost:8000", "airbyte", "password", "octavia-cli/integration-tests", None)


@pytest.fixture(scope="session")
Expand Down
14 changes: 13 additions & 1 deletion octavia-cli/integration_tests/test_api_http_headers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
vcr_log.setLevel(logging.WARN)

AIRBYTE_URL = "http://localhost:8000"
AIRBYTE_USERNAME = "airbyte"
AIRBYTE_PASSWORD = "password"


@pytest.fixture(scope="module")
Expand Down Expand Up @@ -47,7 +49,17 @@ def test_api_http_headers(vcr, file_based_headers, option_based_headers):
expected_headers = expected_option_based_headers + expected_file_based_headers
runner = CliRunner()
command_options = (
["--airbyte-url", AIRBYTE_URL, "--api-http-headers-file-path", custom_api_http_headers_yaml_file_path, "--api-http-header"]
[
"--airbyte-url",
AIRBYTE_URL,
"--airbyte-username",
AIRBYTE_USERNAME,
"--airbyte-password",
AIRBYTE_PASSWORD,
"--api-http-headers-file-path",
custom_api_http_headers_yaml_file_path,
"--api-http-header",
]
+ raw_option_based_headers
+ ["list", "connectors", "sources"]
)
Expand Down
35 changes: 31 additions & 4 deletions octavia-cli/octavia_cli/entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
def set_context_object(
ctx: click.Context,
airbyte_url: str,
airbyte_username: str,
airbyte_password: str,
workspace_id: str,
enable_telemetry: bool,
option_based_api_http_headers: Optional[List[Tuple[str, str]]],
Expand All @@ -44,6 +46,8 @@ def set_context_object(
Args:
ctx (click.Context): Current command context.
airbyte_url (str): The airbyte instance url.
airbyte_username (str): The OSS airbyte instance username.
airbyte_password (str): The OSS airbyte instance password.
workspace_id (str): The user_defined workspace id.
enable_telemetry (bool): Whether the telemetry should send data.
option_based_api_http_headers (Optional[List[Tuple[str, str]]]): Option based headers.
Expand All @@ -63,7 +67,7 @@ def set_context_object(
ctx.obj["TELEMETRY_CLIENT"] = telemetry_client
user_agent = build_user_agent(ctx.obj["OCTAVIA_VERSION"])
api_http_headers = merge_api_headers(option_based_api_http_headers, api_http_headers_file_path)
api_client = get_api_client(airbyte_url, user_agent, api_http_headers)
api_client = get_api_client(airbyte_url, airbyte_username, airbyte_password, user_agent, api_http_headers)
ctx.obj["WORKSPACE_ID"] = get_workspace_id(api_client, workspace_id)
ctx.obj["ANONYMOUS_DATA_COLLECTION"] = get_anonymous_data_collection(api_client, ctx.obj["WORKSPACE_ID"])
ctx.obj["API_CLIENT"] = api_client
Expand All @@ -76,6 +80,8 @@ def set_context_object(

@click.group()
@click.option("--airbyte-url", envvar="AIRBYTE_URL", default="http://localhost:8000", help="The URL of your Airbyte instance.")
@click.option("--airbyte-username", envvar="AIRBYTE_USERNAME", default="airbyte", help="The username for your Airbyte OSS instance.")
@click.option("--airbyte-password", envvar="AIRBYTE_PASSWORD", default="password", help="The password for your Airbyte OSS instance.")
@click.option(
"--workspace-id",
envvar="AIRBYTE_WORKSPACE_ID",
Expand Down Expand Up @@ -107,13 +113,24 @@ def set_context_object(
def octavia(
ctx: click.Context,
airbyte_url: str,
airbyte_username: str,
airbyte_password: str,
workspace_id: str,
enable_telemetry: bool,
option_based_api_http_headers: Optional[List[Tuple[str, str]]] = None,
api_http_headers_file_path: Optional[str] = None,
) -> None:

ctx = set_context_object(ctx, airbyte_url, workspace_id, enable_telemetry, option_based_api_http_headers, api_http_headers_file_path)
ctx = set_context_object(
ctx,
airbyte_url,
airbyte_username,
airbyte_password,
workspace_id,
enable_telemetry,
option_based_api_http_headers,
api_http_headers_file_path,
)

click.echo(
click.style(
Expand All @@ -124,8 +141,18 @@ def octavia(
click.echo(click.style("🐙 - Project is not yet initialized.", fg="red", bold=True))


def get_api_client(airbyte_url: str, user_agent: str, api_http_headers: Optional[List[ApiHttpHeader]]):
client_configuration = airbyte_api_client.Configuration(host=f"{airbyte_url}/api")
def get_api_client(
airbyte_url: str, airbyte_username: str, airbyte_password: str, user_agent: str, api_http_headers: Optional[List[ApiHttpHeader]]
):
# basic_auth = ""
# if len(airbyte_username) > 0:
# basic_auth += airbyte_username
# if len(airbyte_password) > 0:
# if len(airbyte_username) > 0:
# basic_auth += ":"
# basic_auth += airbyte_password

client_configuration = airbyte_api_client.Configuration(host=f"{airbyte_url}/api", username=airbyte_username, password=airbyte_password)
api_client = airbyte_api_client.ApiClient(client_configuration)
api_client.user_agent = user_agent
if api_http_headers:
Expand Down
28 changes: 23 additions & 5 deletions octavia-cli/unit_tests/test_entrypoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,14 @@ def test_set_context_object(mocker, option_based_api_http_headers, api_http_head
mocker.patch.object(entrypoint, "get_anonymous_data_collection")
mock_ctx = mocker.Mock(obj={})
built_context = entrypoint.set_context_object(
mock_ctx, "my_airbyte_url", "my_workspace_id", "enable_telemetry", option_based_api_http_headers, api_http_headers_file_path
mock_ctx,
"my_airbyte_url",
"my_airbyte_username",
"my_airbyte_password",
"my_workspace_id",
"enable_telemetry",
option_based_api_http_headers,
api_http_headers_file_path,
)
entrypoint.TelemetryClient.assert_called_with("enable_telemetry")
mock_ctx.ensure_object.assert_called_with(dict)
Expand All @@ -52,7 +59,11 @@ def test_set_context_object(mocker, option_based_api_http_headers, api_http_head
entrypoint.build_user_agent.assert_called_with(built_context.obj["OCTAVIA_VERSION"])
entrypoint.merge_api_headers.assert_called_with(option_based_api_http_headers, api_http_headers_file_path)
entrypoint.get_api_client.assert_called_with(
"my_airbyte_url", entrypoint.build_user_agent.return_value, entrypoint.merge_api_headers.return_value
"my_airbyte_url",
"my_airbyte_username",
"my_airbyte_password",
entrypoint.build_user_agent.return_value,
entrypoint.merge_api_headers.return_value,
)


Expand All @@ -62,7 +73,14 @@ def test_set_context_object_error(mocker):
mock_ctx.ensure_object.side_effect = NotImplementedError()
with pytest.raises(NotImplementedError):
entrypoint.set_context_object(
mock_ctx, "my_airbyte_url", "my_workspace_id", "enable_telemetry", [("foo", "bar")], "api_http_headers_file_path"
mock_ctx,
"my_airbyte_url",
"my_airbyte_username",
"my_airbyte_password",
"my_workspace_id",
"enable_telemetry",
[("foo", "bar")],
"api_http_headers_file_path",
)
entrypoint.TelemetryClient.return_value.send_command_telemetry.assert_called_with(
mock_ctx, error=mock_ctx.ensure_object.side_effect
Expand Down Expand Up @@ -156,8 +174,8 @@ def test_get_api_client(mocker, api_http_headers: Optional[List[str]]):
mocker.patch.object(entrypoint, "airbyte_api_client")
mocker.patch.object(entrypoint, "check_api_health")
mocker.patch.object(entrypoint, "set_api_headers_on_api_client")
api_client = entrypoint.get_api_client("test-url", "test-user-agent", api_http_headers)
entrypoint.airbyte_api_client.Configuration.assert_called_with(host="test-url/api")
api_client = entrypoint.get_api_client("test-url", "test-username", "test-password", "test-user-agent", api_http_headers)
entrypoint.airbyte_api_client.Configuration.assert_called_with(host="test-url/api", username="test-username", password="test-password")
entrypoint.airbyte_api_client.ApiClient.assert_called_with(entrypoint.airbyte_api_client.Configuration.return_value)
assert entrypoint.airbyte_api_client.ApiClient.return_value.user_agent == "test-user-agent"
if api_http_headers:
Expand Down