dstandish commented on a change in pull request #6376: [WIP] [AIRFLOW-5705] Add 
creds backend classes including AWS SSM
URL: https://github.com/apache/airflow/pull/6376#discussion_r359167966
 
 

 ##########
 File path: airflow/creds/aws_ssm.py
 ##########
 @@ -0,0 +1,127 @@
+# -*- coding: utf-8 -*-
+#
+# 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.
+"""
+Objects relating to sourcing connections from AWS SSM Parameter Store
+"""
+
+from typing import List
+
+import boto3
+
+from airflow import conf
+from airflow.creds import CONN_ENV_PREFIX, BaseCredsBackend
+from airflow.models import Connection
+
+
+class AwsSsmCredsBackend(BaseCredsBackend):
+    """
+    Retrieves Connection object from AWS SSM Parameter Store
+
+    Configurable via airflow config like so:
+
+    .. code-block:: ini
+
+        [aws_ssm_creds]
+        ssm_prefix = /airflow
+        profile_name = default
+
+    For example, if ssm path is ``/airflow/AIRFLOW_CONN_SMTP_DEFAULT``, this 
would be accessible if you
+    provide ``ssm_prefix = /airflow`` and conn_id ``smtp_default``.
+
+    """
+
+    conf_section = "aws_ssm_creds"
+    conf_key_ssm_prefix = "ssm_prefix"
+    default_prefix = "/airflow"
+    conf_key_profile_name = "profile_name"
+    default_profile = "default"
+
+    def __init__(self, *args, **kwargs):
+        pass
+
+    @property
+    def ssm_prefix(self) -> str:
+        """
+        Gets ssm prefix from conf.
+
+        Ensures that there is no trailing slash.
+
+        :return:
+        """
+        ssm_prefix = conf.get(
+            section=self.conf_section,
+            key=self.conf_key_ssm_prefix,
+            fallback=self.default_prefix,
+        )
+        if ssm_prefix[-1] == "/":
+            ssm_prefix = ssm_prefix[:-1]
 
 Review comment:
   good point; updated

----------------------------------------------------------------
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]


With regards,
Apache Git Services

Reply via email to