AlejandroMorgante commented on code in PR #69886: URL: https://github.com/apache/airflow/pull/69886#discussion_r3598826881
########## providers/amazon/tests/system/amazon/aws/example_ecr.py: ########## @@ -0,0 +1,99 @@ +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +from __future__ import annotations + +from datetime import datetime + +from airflow.providers.amazon.aws.operators.ecr import ( + EcrCreateRepositoryOperator, + EcrDeleteRepositoryOperator, + EcrSetRepositoryPolicyOperator, +) +from airflow.providers.common.compat.sdk import DAG, chain + +from system.amazon.aws.utils import ENV_ID_KEY, SystemTestContextBuilder +from tests_common.test_utils.version_compat import AIRFLOW_V_3_0_PLUS + +if AIRFLOW_V_3_0_PLUS: + from airflow.sdk import TriggerRule +else: + from airflow.utils.trigger_rule import TriggerRule # type: ignore[no-redef,attr-defined] + +DAG_ID = "example_ecr" + +sys_test_context_task = SystemTestContextBuilder().build() + + +with DAG( + dag_id=DAG_ID, + schedule=None, + start_date=datetime(2024, 1, 1), + catchup=False, +) as dag: + test_context = sys_test_context_task() + repository_name = f"{test_context[ENV_ID_KEY]}-test-repository" + + # [START howto_operator_ecr_create_repository] + create_repository = EcrCreateRepositoryOperator( + task_id="create_repository", + repository_name=repository_name, + ) + # [END howto_operator_ecr_create_repository] + + # [START howto_operator_ecr_set_repository_policy] + set_repository_policy = EcrSetRepositoryPolicyOperator( + task_id="set_repository_policy", + repository_name=repository_name, + policy_text=""" + { + "Version": "2012-10-17", + "Statement": [ + { + "Sid": "AllowAccountPull", + "Effect": "Allow", + "Principal": { + "AWS": "arn:aws:iam::{{ task_instance.xcom_pull(task_ids='create_repository')['repository']['registryId'] }}:root" Review Comment: The repository is created in the default registry, but the registryId is used here to build the policy principal ARN (arn:aws:iam::<account-id>:root). IAM requires the account ID explicitly in that ARN, so it cannot simply be omitted or replaced with a “default account” value We could provide the account ID through an environment variable forwarded by Breeze, but that would require additional configuration. Since create_repository already returns the account ID as registryId, using its XCom output keeps the system test simpler and self-contained -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
