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

adding extra credentials argument to s3source #356

Merged
merged 1 commit into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,8 @@ keys used to populate the parameters of the S3 table function:
| structure | The column structure of the data in bucket, as a list of name/datatype pairs, such as `['id UInt32', 'date DateTime', 'value String']` If not provided ClickHouse will infer the structure. |
| aws_access_key_id | The S3 access key id. |
| aws_secret_access_key | The S3 secret key. |
| role_arn | The ARN of a ClickhouseAccess IAM role to use to securely access the S3 objects. See this [documentation](https://clickhouse.com/docs/en/cloud/security/secure-s3) for more information. |
| compression | The compression method used with the S3 objects. If not provided ClickHouse will attempt to determine compression based on the file name. |

See the [S3 test file](https://github.com/ClickHouse/dbt-clickhouse/blob/main/tests/integration/adapter/clickhouse/test_clickhouse_s3.py) for examples of how to use this macro.

# Contracts and Constraints
Expand Down
6 changes: 5 additions & 1 deletion dbt/adapters/clickhouse/impl.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,7 @@ def s3source_clause(
structure: Union[str, list, dict],
aws_access_key_id: str,
aws_secret_access_key: str,
role_arn: str,
compression: str = '',
) -> str:
s3config = self.config.vars.vars.get(config_name, {})
Expand Down Expand Up @@ -273,7 +274,10 @@ def s3source_clause(
comp = compression or s3config.get('compression', '')
if comp:
comp = f"', {comp}'"
return f"s3('{url}'{access}, '{fmt}'{struct}{comp})"
extra_credentials = ''
if role_arn:
extra_credentials = f", extra_credentials(role_arn='{role_arn}')"
return f"s3('{url}'{access}, '{fmt}'{struct}{comp}{extra_credentials})"

def check_schema_exists(self, database, schema):
results = self.execute_macro(LIST_SCHEMAS_MACRO_NAME, kwargs={'database': database})
Expand Down
3 changes: 2 additions & 1 deletion dbt/include/clickhouse/macros/materializations/s3.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{% macro clickhouse_s3source(config_name='', bucket='', path='', fmt='', structure='',
aws_access_key_id='', aws_secret_access_key='', compression='') %}
aws_access_key_id='', aws_secret_access_key='', role_arn='', compression='') %}
{% if config_name and not config_name.lower().endswith('s3') %}
{{ exceptions.raise_compiler_error("S3 configuration should end with 's3'") }}
{% endif %}
Expand All @@ -13,5 +13,6 @@
structure=structure,
aws_access_key_id=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
role_arn=role_arn,
compression=compression) }}
{% endmacro %}