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 2022/02/05 21:12:26 UTC

[GitHub] [airflow] subkanthi commented on a change in pull request #21073: Feature : Implement a AWS Session manager Parameter Store Operators and hooks

subkanthi commented on a change in pull request #21073:
URL: https://github.com/apache/airflow/pull/21073#discussion_r800100429



##########
File path: airflow/providers/amazon/aws/hooks/ssm_parameter_store.py
##########
@@ -0,0 +1,107 @@
+#
+# 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 airflow.providers.amazon.aws.hooks.base_aws import AwsBaseHook
+
+
+class SSMParameterStoreHook(AwsBaseHook):
+    """
+    Interact with Amazon SSM Service.
+
+    Additional arguments (such as ``aws_conn_id``) may be specified and
+    are passed down to the underlying AwsBaseHook.
+
+    .. see also::
+        :class:`~airflow.providers.amazon.aws.hooks.base_aws.AwsBaseHook`
+    """
+
+    def __init__(self, *args, **kwargs):
+        super().__init__(client_type='ssm', *args, **kwargs)
+
+    def get_parameter(self, parameter_name: str, with_decryption: bool):
+        """
+        Retrieve parameter value from AWS Systems Manager Parameter Store.
+        Reflecting format it stored in the AWS Systems Manager Parameter Store
+        :param parameter_name: name of the parameter
+        :param with_decryption: Return decrypted values for secure string parameters
+        :return: str with the value of the Systems Manager Parameter
+        :rtype: str
+        """
+        ssm_client = self.get_conn()
+        try:
+            get_parameter_response = ssm_client.get_parameter(
+                Name=parameter_name, WithDecryption=with_decryption
+            )
+            if 'Parameter' in get_parameter_response:
+                self.log.info("Returning value of the parameter")
+                return get_parameter_response['Parameter']['Value']
+        except ssm_client.exceptions.ParameterNotFound:
+            self.log.error('Parameter Does Not Exist')
+            raise
+        except Exception as general_error:
+            self.log.error("Failed to list SSM Parameter, error: %s", general_error)
+            raise
+
+    def get_parameters_by_path(self, path: str, **parameter_kwargs):
+        """
+        Retrieve parameter value from AWS Systems Manager Parameter Store.

Review comment:
       This looks like a copy/paste error, should this be retrieve parameter value by path maybe?




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

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org