evgenyshulman edited a comment on pull request #8651: URL: https://github.com/apache/airflow/pull/8651#issuecomment-624172030
continuing on this discussion: actually you have a really great usecase for this feature - https://github.com/apache/airflow/pull/8432 this feature will enable to provide GCP context in the runtime without change every and every operator ( right now you have change Bash and Python, but what about all others? ) so useful example for contextmanager can be something like this ( it can be part of airflow library, or just defined by the user in place accordingly to his requirements) ``` @contextlib.contextmanager def gcp_context(context): if not ( "some condition on config that provide what gcp project to use ( maybe conf.get('gcp', 'project_id', None)..)"): yield None return gcp_gcp_delegate_to = ... gcp_conn_id = ... with TemporaryDirectory(prefix='airflowtmp') as tmp_dir: try: from airflow.providers.google.common.hooks.base_google import GoogleBaseHook except ImportError: raise AirflowException( 'Additional packages gcp are not installed. Please install it to use gcp_conn_id ' 'parameter.' 'For more information, please look at: ' f'{DOC_BASE_URL}/installation' ) with GoogleBaseHook(gcp_conn_id=gcp_conn_id, delegate_to=gcp_gcp_delegate_to).provide_authorized_gcloud() as gcp_context : yield gcp_context # will not be in use ``` ( based on https://github.com/apache/airflow/pull/8432 implementation) ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: [email protected]
