You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/05/05 16:45:43 UTC

[GitHub] [airflow] evgenyshulman edited a comment on pull request #8432: Provide GCP credentials in Bash/Python operators

evgenyshulman edited a comment on pull request #8432:
URL: https://github.com/apache/airflow/pull/8432#issuecomment-624167600


   I think we can have a nice solution together with https://github.com/apache/airflow/pull/8651 
   user can define global context via user_defined_execution_context( probably we should use different name for the variable)
   and if context defined like this:
   ```
   @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
   ```
   
   all operators ( or only selected by function ) will benefit from the change
   @mik-laj 


----------------------------------------------------------------
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:
users@infra.apache.org