Skip to content

Commit 98ededb

Browse files
Marius Postajatinyadav-cc
Marius Posta
authored andcommitted
airbyte-ci: remove connector secrets hack for --is-local (airbytehq#33972)
1 parent a59d8f3 commit 98ededb

File tree

5 files changed

+19
-48
lines changed

5 files changed

+19
-48
lines changed

airbyte-ci/connectors/pipelines/README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,8 @@ E.G.: running `pytest` on a specific test folder:
521521

522522
| Version | PR | Description |
523523
| ------- | ---------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
524-
| 3.1.1 | [#33979](https://github.com/airbytehq/airbyte/pull/33979) | Fix AssertionError on report existence again |
524+
| 3.1.2 | [#33972](https://github.com/airbytehq/airbyte/pull/33972) | Remove secrets scrubbing hack for --is-local and other small tweaks. |
525+
| 3.1.1 | [#33979](https://github.com/airbytehq/airbyte/pull/33979) | Fix AssertionError on report existence again |
525526
| 3.1.0 | [#33994](https://github.com/airbytehq/airbyte/pull/33994) | Log more context information in CI. |
526527
| 3.0.2 | [#33987](https://github.com/airbytehq/airbyte/pull/33987) | Fix type checking issue when running --help |
527528
| 3.0.1 | [#33981](https://github.com/airbytehq/airbyte/pull/33981) | Fix issues with deploying dagster, pin pendulum version in dagster-cli install |

airbyte-ci/connectors/pipelines/pipelines/airbyte_ci/metadata/commands.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#
44

55
import asyncclick as click
6-
from pipelines.airbyte_ci.metadata.pipeline import run_metadata_orchestrator_deploy_pipeline
76
from pipelines.cli.dagger_pipeline_command import DaggerPipelineCommand
87

98
# MAIN GROUP
@@ -24,6 +23,9 @@ def deploy(ctx: click.Context) -> None:
2423
@deploy.command(cls=DaggerPipelineCommand, name="orchestrator", help="Deploy the metadata service orchestrator to production")
2524
@click.pass_context
2625
async def deploy_orchestrator(ctx: click.Context) -> None:
26+
# Import locally to speed up CLI.
27+
from pipelines.airbyte_ci.metadata.pipeline import run_metadata_orchestrator_deploy_pipeline
28+
2729
await run_metadata_orchestrator_deploy_pipeline(
2830
ctx.obj["is_local"],
2931
ctx.obj["git_branch"],

airbyte-ci/connectors/pipelines/pipelines/dagger/actions/secrets.py

+8-37
Original file line numberDiff line numberDiff line change
@@ -137,45 +137,16 @@ async def get_connector_secrets(context: ConnectorContext) -> dict[str, Secret]:
137137

138138

139139
async def mounted_connector_secrets(context: ConnectorContext, secret_directory_path: str) -> Callable[[Container], Container]:
140-
# By default, mount the secrets properly as dagger secret files.
141-
#
142-
# This will cause the contents of these files to be scrubbed from the logs. This scrubbing comes at the cost of
143-
# unavoidable latency in the log output, see next paragraph for details as to why. This is fine in a CI environment
144-
# however this becomes a nuisance locally: the developer wants the logs to be displayed to them in an as timely
145-
# manner as possible. Since the secrets aren't really secret in that case anyway, we mount them in the container as
146-
# regular files instead.
147-
#
148-
# The buffering behavior that comes into play when logs are scrubbed is both unavoidable and not configurable.
149-
# It's fundamentally unavoidable because dagger needs to match a bunch of regexes (one per secret) and therefore
150-
# needs to buffer at least as many bytes as the longest of all possible matches. Still, this isn't that long in
151-
# practice in our case. The real problem is that the buffering is not configurable: dagger relies on a golang
152-
# library called transform [1] to perform the regexp matching on a stream and this library hard-codes a buffer
153-
# size of 4096 bytes for each regex [2].
154-
#
155-
# Remove the special local case whenever dagger implements scrubbing differently [3,4].
156-
#
157-
# [1] https://golang.org/x/text/transform
158-
# [2] https://cs.opensource.google/go/x/text/+/refs/tags/v0.13.0:transform/transform.go;l=130
159-
# [3] https://github.com/dagger/dagger/blob/v0.6.4/cmd/shim/main.go#L294
160-
# [4] https://github.com/airbytehq/airbyte/issues/30394
161-
#
162-
connector_secrets = await context.get_connector_secrets()
163-
if context.is_local:
164-
# Special case for local development.
165-
# Query dagger for the contents of the secrets and mount these strings as files in the container.
166-
contents = {}
167-
for secret_file_name, secret in connector_secrets.items():
168-
contents[secret_file_name] = await secret.plaintext()
140+
"""Returns an argument for a dagger container's with_ method which mounts all connector secrets in it.
169141
170-
def with_secrets_mounted_as_regular_files(container: Container) -> Container:
171-
container = container.with_exec(["mkdir", "-p", secret_directory_path], skip_entrypoint=True)
172-
for secret_file_name, secret_content_str in contents.items():
173-
container = container.with_new_file(
174-
f"{secret_directory_path}/{secret_file_name}", contents=secret_content_str, permissions=0o600
175-
)
176-
return container
142+
Args:
143+
context (ConnectorContext): The context providing a connector object and its secrets.
144+
secret_directory_path (str): Container directory where the secrets will be mounted, as files.
177145
178-
return with_secrets_mounted_as_regular_files
146+
Returns:
147+
fn (Callable[[Container], Container]): A function to pass as argument to the connector container's with_ method.
148+
"""
149+
connector_secrets = await context.get_connector_secrets()
179150

180151
def with_secrets_mounted_as_dagger_secrets(container: Container) -> Container:
181152
container = container.with_exec(["mkdir", "-p", secret_directory_path], skip_entrypoint=True)

airbyte-ci/connectors/pipelines/pipelines/helpers/utils.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import anyio
1919
import asyncclick as click
2020
import asyncer
21-
from dagger import Client, Config, Container, ExecError, File, ImageLayerCompression, Platform, QueryError, Secret
21+
from dagger import Client, Config, Container, ExecError, File, ImageLayerCompression, Platform, Secret
2222
from more_itertools import chunked
2323

2424
if TYPE_CHECKING:
@@ -101,13 +101,10 @@ async def get_file_contents(container: Container, path: str) -> Optional[str]:
101101
Returns:
102102
Optional[str]: The file content if the file exists in the container, None otherwise.
103103
"""
104-
try:
105-
return await container.file(path).contents()
106-
except QueryError as e:
107-
if "no such file or directory" not in str(e):
108-
# this error could come from a network issue
109-
raise
110-
return None
104+
dir_name, file_name = os.path.split(path)
105+
if file_name not in set(await container.directory(dir_name).entries()):
106+
return None
107+
return await container.file(path).contents()
111108

112109

113110
@contextlib.contextmanager

airbyte-ci/connectors/pipelines/pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
44

55
[tool.poetry]
66
name = "pipelines"
7-
version = "3.1.1"
7+
version = "3.1.2"
88
description = "Packaged maintained by the connector operations team to perform CI for connectors' pipelines"
99
authors = ["Airbyte <[email protected]>"]
1010

0 commit comments

Comments
 (0)