From 26c1eb5bf4076f68c82b3542db1c60a2eb53fbf2 Mon Sep 17 00:00:00 2001 From: Correl Roush Date: Mon, 15 Jul 2024 10:56:05 -0400 Subject: [PATCH] Add support for setting string lists --- ssm.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/ssm.py b/ssm.py index d8649bc..ee7d618 100644 --- a/ssm.py +++ b/ssm.py @@ -1,5 +1,6 @@ from __future__ import annotations +import enum import os import pathlib import sys @@ -28,6 +29,12 @@ class SSMPath(pathlib.PurePosixPath): return SSMPath(value) +class SSMParameterType(str, enum.Enum): + String = "String" + SecureString = "SecureString" + StringList = "StringList" + + ProfileArg = typing.Annotated[str, typer.Argument(autocompletion=lambda: aws_profiles)] @@ -103,7 +110,7 @@ def list_parameters( def set( profile: ProfileArg, path: str, - value: str, + values: list[str], secure: bool = False, overwrite: bool = False, description: typing.Annotated[str, typer.Option] = "", @@ -112,12 +119,19 @@ def set( If --secure is used, it will be stored as a SecureString. """ + if secure: + parameter_type = SSMParameterType.SecureString + elif len(values) > 1: + parameter_type = SSMParameterType.StringList + else: + parameter_type = SSMParameterType.String + value: str = ",".join(values) client = get_client(profile) try: client.put_parameter( Name=str(SSMPath(path)), Value=value, - Type="SecureString" if secure else "String", + Type=parameter_type.value, Overwrite=overwrite, Description=description, )