You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by po...@apache.org on 2020/10/09 22:47:13 UTC
[airflow] branch v1-10-test updated: Add GCP Service Account rule
(#11230)
This is an automated email from the ASF dual-hosted git repository.
potiuk pushed a commit to branch v1-10-test
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/v1-10-test by this push:
new 8372ed3 Add GCP Service Account rule (#11230)
8372ed3 is described below
commit 8372ed344782ed9c98017a56bfbd8c20ff0c8ad8
Author: Patrick Cando <32...@users.noreply.github.com>
AuthorDate: Fri Oct 9 23:46:20 2020 +0100
Add GCP Service Account rule (#11230)
---
.../upgrade/rules/gcp_service_account_keys_rule.py | 39 ++++++++++++++++++
.../rules/test_gcp_service_account_key_rule.py | 48 ++++++++++++++++++++++
2 files changed, 87 insertions(+)
diff --git a/airflow/upgrade/rules/gcp_service_account_keys_rule.py b/airflow/upgrade/rules/gcp_service_account_keys_rule.py
new file mode 100644
index 0000000..be462f1
--- /dev/null
+++ b/airflow/upgrade/rules/gcp_service_account_keys_rule.py
@@ -0,0 +1,39 @@
+# 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 absolute_import
+
+from airflow.configuration import conf
+from airflow.upgrade.rules.base_rule import BaseRule
+
+
+class GCPServiceAccountKeyRule(BaseRule):
+ title = "GCP service account key deprecation"
+
+ description = """Option has been removed because it is no longer \
+supported by the Google Kubernetes Engine."""
+
+ def check(self):
+ gcp_option = conf.get(section="kubernetes", key="gcp_service_account_keys")
+ if gcp_option:
+ msg = """This option has been removed because it is no longer \
+supported by the Google Kubernetes Engine. The new recommended \
+service account keys for the Google Cloud management method is \
+Workload Identity."""
+ return [msg]
+ else:
+ return None
diff --git a/tests/upgrade/rules/test_gcp_service_account_key_rule.py b/tests/upgrade/rules/test_gcp_service_account_key_rule.py
new file mode 100644
index 0000000..e9d5209
--- /dev/null
+++ b/tests/upgrade/rules/test_gcp_service_account_key_rule.py
@@ -0,0 +1,48 @@
+# 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 unittest import TestCase
+
+from airflow.upgrade.rules.gcp_service_account_keys_rule import GCPServiceAccountKeyRule
+from tests.test_utils.config import conf_vars
+
+
+class TestGCPServiceAccountKeyRule(TestCase):
+
+ @conf_vars({("kubernetes", "gcp_service_account_keys"): "key_name:key_path"})
+ def test_invalid_check(self):
+ rule = GCPServiceAccountKeyRule()
+
+ assert isinstance(rule.description, str)
+ assert isinstance(rule.title, str)
+
+ msg = """This option has been removed because it is no longer \
+supported by the Google Kubernetes Engine. The new recommended \
+service account keys for the Google Cloud management method is \
+Workload Identity."""
+ response = rule.check()
+ assert response == [msg]
+
+ @conf_vars({("kubernetes", "gcp_service_account_keys"): ""})
+ def test_valid_check(self):
+ rule = GCPServiceAccountKeyRule()
+
+ assert isinstance(rule.description, str)
+ assert isinstance(rule.title, str)
+
+ msg = None
+ response = rule.check()
+ assert response == msg