def set_secret(service_client, arn, token, context):
    """Set the secret

    This method should set the AWSPENDING secret in the service that the secret belongs to. For example, if the secret is a database
    credential, this method should take the value of the AWSPENDING secret and set the user's password to this value in the database.

    Args:
        service_client (client): The secrets manager service client

        arn (string): The secret ARN or other identifier

        token (string): The ClientRequestToken associated with the secret version

    """
    # This is where the secret should be set in the service
    pending = service_client.get_secret_value(SecretId=arn,
                                              VersionId=token,
                                              VersionStage="AWSPENDING")

    pending_version = pending['VersionId']

    pending_dict = get_secret_dict(service_client, arn, "AWSPENDING")

    ssm = SSM(context, TARGETS, USERNAME)

    print(
        "setSecret: Invoking Systems Manager to add the new public key with token %s."
        % pending_version)
    command_id = ssm.add_public_key(pending_dict[PUBLIC_KEY], pending_version)
    print("setSecret: Waiting for Systems Manager command %s to complete." %
          (command_id))
    ssm.wait_completion(command_id)
    print("setSecret: Systems Manager command %s completed successfully." %
          (command_id))
コード例 #2
0
def test_secret(service_client, arn, token, context):
    """Test the secret

    This method should validate that the AWSPENDING secret works in the service that the secret belongs to. For example, if the secret
    is a database credential, this method should validate that the user can login with the password in AWSPENDING and that the user has
    all of the expected permissions against the database.

    Args:
        service_client (client): The secrets manager service client

        arn (string): The secret ARN or other identifier

        token (string): The ClientRequestToken associated with the secret version

    """
    command = 'hostname'
    pending_dict = get_secret_dict(service_client, arn, "AWSPENDING")
    print("testSecret: getting instance IDs for version %s" % (token))
    ssm = SSM(context, TARGETS)
    for username in USERNAMES:
        ssm.set_username(username)
        ip_addresses = ssm.get_addrs_for_add_key(token)

        print("testSecret: Performing SSH test by invoking command '%s'." % (command))
        ssh.run_command(ip_addresses, username, pending_dict[PRIVATE_KEY], command)
def finish_secret(service_client, arn, token, context):
    """Finish the secret

    This method finalizes the rotation process by marking the secret version passed in as the AWSCURRENT secret.

    Args:
        service_client (client): The secrets manager service client

        arn (string): The secret ARN or other identifier

        token (string): The ClientRequestToken associated with the secret version

    Raises:
        ResourceNotFoundException: If the secret with the specified arn does not exist

    """
    # First describe the secret to get the current version
    metadata = service_client.describe_secret(SecretId=arn)

    new_version = token
    current_version = None
    for version in metadata["VersionIdsToStages"]:
        if "AWSCURRENT" in metadata["VersionIdsToStages"][version]:
            if version == token:
                # The correct version is already marked as current, return
                print(
                    "finishSecret: Version %s already marked as AWSCURRENT for %s"
                    % (version, arn))
                return
            current_version = version
            break

    # Finalize by staging the secret version current
    service_client.update_secret_version_stage(
        SecretId=arn,
        VersionStage="AWSCURRENT",
        MoveToVersionId=new_version,
        RemoveFromVersionId=current_version)
    print(
        "finishSecret: Successfully set AWSCURRENT stage to version %s for secret %s."
        % (new_version, arn))

    # after change above:
    prior_version = current_version

    new_dict = get_secret_dict(service_client, arn, "AWSCURRENT")

    ssm = SSM(context, TARGETS, USERNAME)

    print(
        "finishSecret: Invoking Systems Manager to delete the old public key with token %s."
        % (prior_version))
    command_id = ssm.del_public_key(prior_version)
    print("finishSecret: Waiting for Systems Manager command %s to complete." %
          (command_id))
    ssm.wait_completion(command_id)
    print("finishSecret: Systems Manager command %s completed successfully." %
          (command_id))
コード例 #4
0
def get_values(event):
    region = None
    if 'region' in event:
        region = event['region']

    modules_process = []
    
    if 'custom' not in event:
        beanstalk = Beanstalk()
        modules_process.append(beanstalk.run(region))

        ec2 = EC2()
        modules_process.append(ec2.run(region))

        rds = RDS()
        modules_process.append(rds.run(region))

        ssm = SSM()
        modules_process.append(ssm.run(region))

        ses = SES()
        modules_process.append(ses.run(region))

        elasticache = Elasticache()
        modules_process.append(elasticache.run(region))
    else:
        data = str(event['custom'])

        if 'BEANSTALK' in data:
            beanstalk = Beanstalk()
            modules_process.append(beanstalk.run(region))

        if 'INSTANCES' in data:
            ec2 = EC2()
            modules_process.append(ec2.run(region))

        if 'SSM' in data:
            ssm = SSM()
            modules_process.append(ssm.run(region))

        if 'ELASTICACHE' in data:
            elasticache = Elasticache()
            modules_process.append(elasticache.run(region))

        if 'RDS' in data:
            rds = RDS()
            modules_process.append(rds.run(region))

        if 'SES' in data:
            ses = SES()
            modules_process.append(ses.run(region))


    start_all(modules_process)
    wait_all(modules_process)
    ret_dict = read_all(modules_process)

    return ret_dict
コード例 #5
0
 def get_parameter(self):
     parameter = SSM().get_parameter(self.param_name,
                                     None)['Parameter']['Value']
     if parameter == 'None': parameter = None
     return parameter
コード例 #6
0
import math
import time
from typing import Dict, AnyStr
from settings import *

from ftp import FTP
from s3 import S3
from ssm import SSM

sentry_sdk.init(DEFAULT_SENTRY, traces_sample_rate=1.0)

LOG = loguru.logger

LOG.debug("cold start")

ssm = SSM()


async def handler(event, context):
    parameters = ssm.list_namespace(DEFAULT_NAMESPACE)

    LOG.debug(f"Handling data sources: {parameters}")

    for parameter in parameters:
        LOG.debug(f"Starting {parameter}")
        if 'connection_parameters' not in parameter or 'bucket' not in parameter[
                'connection_parameters']:
            continue
        target = parameter.get("s3_path")[1:]  # remove leading slash
        source = parameter.get("connection_parameters")
        s3 = S3(source.get("bucket"))
コード例 #7
0
        ]
    to_dir = "./figures/ssm_imgs/"
    for s in subjs:
        for g in gests:
            os.makedirs(to_dir+s+"/"+g, exist_ok=True)

    ### load data ###
    dc = DataCube(
        subjects="all",
        gestures=["1", "2", "3", "4", "5", "6"],
        data_grp="parsed"
    )
    dc.load_data()

    ### smooth modalities ###
    dc.rms_smooth(300, 50)

    ### generate SSM and images ###
    ed = lambda i, j: (i-j)**2 # use euclidian distance

    for s, gdict in dc.data_set_smooth.items():
        print(f"Subject number {s}")
        for g, a in gdict.items():
            print(f"    Gesture ID {g}")
            smtrx = SSM(a[:, :-1], metric=ed) # -1 for removing label column
            smtrx.calc_SSM()
            for m in range(smtrx.n_mods):
                fig_pth = to_dir+"/"+s+"/"+g+"/"+"channel_"+str(m+1)+".png"
                smtrx.plot_SSM(m, save=True, path=fig_pth)
                plt.close("all")
コード例 #8
0
def set_parameter(value):
    return SSM().put_parameter(CHECKPOINT_PARAMETER_NAME, value)