Repository: incubator-airflow
Updated Branches:
  refs/heads/master e28f6e224 -> c1d02d91e


[AIRFLOW-2171] Store delegated credentials

add logic to google cloud base hook to make it able to create
delegated credentials

Closes #3090 from morgendave/AIRFLOW-2171-create-
delegated-credentials


Project: http://git-wip-us.apache.org/repos/asf/incubator-airflow/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-airflow/commit/c1d02d91
Tree: http://git-wip-us.apache.org/repos/asf/incubator-airflow/tree/c1d02d91
Diff: http://git-wip-us.apache.org/repos/asf/incubator-airflow/diff/c1d02d91

Branch: refs/heads/master
Commit: c1d02d91ea09797ce83166917b91f29180de51b8
Parents: e28f6e2
Author: Zhiwei Zhao <zhiw...@wepay.com>
Authored: Sun Mar 4 17:56:20 2018 +0100
Committer: Fokko Driesprong <fokkodriespr...@godatadriven.com>
Committed: Sun Mar 4 17:56:24 2018 +0100

----------------------------------------------------------------------
 airflow/contrib/hooks/gcp_api_base_hook.py | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-airflow/blob/c1d02d91/airflow/contrib/hooks/gcp_api_base_hook.py
----------------------------------------------------------------------
diff --git a/airflow/contrib/hooks/gcp_api_base_hook.py 
b/airflow/contrib/hooks/gcp_api_base_hook.py
index 12a7fb5..fea43c8 100644
--- a/airflow/contrib/hooks/gcp_api_base_hook.py
+++ b/airflow/contrib/hooks/gcp_api_base_hook.py
@@ -65,10 +65,6 @@ class GoogleCloudBaseHook(BaseHook, LoggingMixin):
         keyfile_dict = self._get_field('keyfile_dict', False)
         scope = self._get_field('scope', False)
 
-        kwargs = {}
-        if self.delegate_to:
-            kwargs['sub'] = self.delegate_to
-
         if not key_path and not keyfile_dict:
             self.log.info('Getting connection using `gcloud auth` user, '
                           'since no key file is defined for hook.')
@@ -106,7 +102,9 @@ class GoogleCloudBaseHook(BaseHook, LoggingMixin):
                     .from_json_keyfile_dict(keyfile_dict, scopes)
             except json.decoder.JSONDecodeError:
                 raise AirflowException('Invalid key JSON.')
-        return credentials
+
+        return credentials.create_delegated(self.delegate_to) \
+            if self.delegate_to else credentials
 
     def _get_access_token(self):
         """

Reply via email to