def ls(prefix="", profile="", region="", values=False, decryption=True): """ List Paramters, optional matching a specific prefix """ aws_params = AWSParams(profile, region) if not values: decryption = False for parm in aws_params.get_all_parameters(prefix=prefix, values=values, decryption=decryption, trim_name=False): if values: click.echo(f"{parm.Name}: {parm.Value}") else: click.echo(parm.Name)
def set(src=None, value=None, profile="", region=""): """ Edit an existing parameter """ result = AWSParams(profile, region).set_param(src, value) if result: click.echo(f"updated param '{src}' with value") else: click.echo(f"not updated, param '{src}' already contains that value")
def cp( src, dst, src_profile, src_region, dst_profile, dst_region, prefix=False, overwrite=False, key="", ): """ Copy a parameter, optionally across accounts """ aws_params = AWSParams(src_profile, src_region) # cross account copy without needing dst if dst_profile and src_profile != dst_profile and not dst: dst = src elif not dst: click.echo( "dst (Destination) is required when not copying to another profile" ) return if prefix: params = aws_params.get_all_parameters(prefix=src, trim_name=False) for i in params: i = i._asdict() orignal_name = i["Name"] i["Name"] = i["Name"].replace(src, dst) if key: i["KeyId"] = key aws_params.put_parameter(i, overwrite=overwrite, profile=dst_profile, region=dst_region) click.echo(f'Copied {orignal_name} to {i["Name"]}') return True else: if isinstance(src, str): src_param = aws_params.get_parameter(src) if not src_param: click.echo(f"Parameter: {src} not found") return src_param = src_param._asdict() src_param["Name"] = dst if key: src_param["KeyId"] = key aws_params.put_parameter(src_param, overwrite=overwrite, profile=dst_profile, region=dst_region) click.echo(f"Copied {src} to {dst}") return True
def rm(src, force=False, prefix=False, profile="", region=""): """ Remove/Delete a parameter """ aws_params = AWSParams(profile, region) if prefix: params = aws_params.get_all_parameters(prefix=src, trim_name=False) if len(params) == 0: click.echo(f"No parameters with the {src} prefix found") else: for param in params: if sanity_check(param.Name, force): aws_params.remove_parameter(param.Name) click.echo(f"The {param.Name} parameter has been removed") else: param = aws_params.get_parameter(name=src) if param and param.Name == src: if sanity_check(src, force): aws_params.remove_parameter(src) click.echo(f"The {src} parameter has been removed") else: click.echo(f"Parameter {src} not found")
def new( name=None, value=None, param_type="String", key="", description="", profile="", region="", overwrite=False, ): """ Create a new parameter """ AWSParams(profile, region).new_param( name, value, param_type=param_type, key=key, description=description, overwrite=overwrite, )
def test_awsparam(): assert AWSParams() try: assert AWSParams('default') except ProfileNotFound: pass
def awsparams(): return AWSParams()