Пример #1
0
def main(api=None):
    start_time = time.time()
    isLambda = True
    jumpRole = False
    fullUpdate = False
    dir_path = '/tmp'
    config = 'ENVRFIG.yaml'
    svc_in = targetAPI = api
    sendto = '/tmp/%s' % targetAPI

    bucket = os.environ['bucket']
    bucketRoot = os.environ['initKey']
    g_reader = GwyReader(bucket, bucketRoot)

    logging.basicConfig(format='%(asctime)-15s %(message)s')
    logger = logging.getLogger()
    logger.setLevel(logging.INFO)

    logger.info("Started")
    print("  ..... INIT..... 0002")

    fullpath = config
    origin, global_accts = loadConfig(fullpath)
    triggers = origin['triggers']
    if jumpRole:
        accountRole = global_accts[accID]['role']
        region = origin['region']
        accID = origin['account']
        print(
            " ## USING ## %s--> %s, role %s, account originDefinition %s, config %s, copyAnsible to %s"
            % (type_in, svc_in, accountRole, accID, config, sendto))
        print(
            " !!! !! to assume <cross_acct_role> ROLE make sure you set 'assume_role' in 'ENVRFIG.yaml' to True or False as needed"
        )

        awsconnect.stsClient_init()
        sts_client = awsconnect.stsClient
        if 'eID' in origin:
            eID = origin['eID']
        if 'services_map' in origin:
            mapfile = origin['services_map']
            eID = serviceID(origin['account'], mapfile, origin['all'])

        aconnect = awsConnect(accID, eID, origin['role_definer'], sts_client,
                              region)
        aconnect.connect()
    else:
        aconnect = type('obj', (object, ), {'__get_client__': boto3.client})

    lm = ApiGatewayMolder("ansible", isLambda)
    file_tasks, file_defaults = lm.describe_GatewayALL(svc_in, aconnect,
                                                       origin, global_accts,
                                                       triggers, sendto,
                                                       targetAPI, fullUpdate)
    #pushFiles(file_tasks, file_defaults)
    g_reader.s3_send(targetAPI, [file_tasks, file_defaults], aconnect)
    logger.info("Finished")

    print("--- %s seconds ---" % (time.time() - start_time))
Пример #2
0
                fullUpdate = False
            else:
                fullUpdate = True
        else:
            fullUpdate = False

        logging.basicConfig(format='%(asctime)-15s %(message)s')
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)

        logger.info("Started")
        print("  ..... INIT..... 0002. %s ,   %s" % (dir_path, config))

        fullpath = "%s/%s" % (dir_path, config)
        env = 'dev'
        origin, global_accts = loadConfig(fullpath, env)
        triggers = origin['triggers']
        if triggers is None:
            raise ValueError(
                "[E] config file [ %s ] did not load correctly.. PLEASE check / fix and try again" % (fullpath))
        accID = origin['account']
        region = origin['region']
        accountRole = global_accts[accID]['role']
        print(" ## USING ## %s--> %s, role %s, account originDefinition %s, config %s, copyAnsible to %s" %
              (type_in, svc_in, accountRole, accID, config, sendto))
        print(" !!! !! to assume <cross_acct_role> ROLE make sure you set 'assume_role' in 'ENVR.yaml' to True or False as needed")
        awsconnect.stsClient_init()
        sts_client = awsconnect.stsClient
        aconnect = awsConnect(
            accID, origin['eID'], origin['role_definer'], sts_client, region)
        aconnect.connect()
Пример #3
0
        with open(file, 'r') as policyfile:
            jdata = json.load(policyfile)
        response = policy.put(ConfirmRemoveSelfBucketAccess=True, Policy=jdata)
        print(" -- -->  policy updated")
        print(response)


# aws s3api put-bucket-acl --bucket MyBucket --grant-full-control [email protected],[email protected] --grant-read uri=http://acs.amazonaws.com/groups/global/AllUsers
# aws s3api delete-bucket-policy --bucket  cr-portal-dev
#  aws rds add-role-to-db-cluster --db-cluster-identifier some-cluster-id --role-arn arn:aws:iam::1234567890:role/S3_ROLE
if __name__ == "__main__":
    found = None
    length = 0
    config = "ENVR.yaml"
    fullpath = "%s/%s" % (dir_path, config)
    origin, global_accts = loadConfig(fullpath, 'dev')
    eID = 1001000100001
    if 'eID' in origin:
        eID = origin['eID']
    if 'services_map' in origin:
        mapfile = origin['services_map']
        eID = serviceID(origin['account'], mapfile, origin['all'])

    print("  ..... INIT..... 0002")
    accID = origin['account']
    region = 'us-east-1'
    awsconnect.stsClient_init()
    sts_client = awsconnect.stsClient
    aconnect = awsConnect(accID, eID, origin['role_definer'], sts_client,
                          region)
    aconnect.connect()
Пример #4
0
# ansible-playbook -i windows-servers xx_tablename.yaml -vvvv

# python MMAnsibleDeployAll.py "xx-stage,xx-test" xx_tablename ENVR.yaml
#
# python MMAnsibleDeployAll.py "stage,prod" API_Name ENVR.yaml

# OR call it manually in /ansible folder
#  ansible-playbook -i windows-servers xx-LambdaName -vvvv

if __name__ == "__main__":
    found = None
    length = 0
    target_environments = str(sys.argv[1]).strip().split(",")
    role = str(sys.argv[2]).strip()
    config = str(sys.argv[3]).strip()
    start_time = time.time()

    fullpath = "%s/%s" % (dir_path, config)
    origin, global_accts = loadConfig(fullpath, "dev")
    results = testStart(global_accts, target_environments, role)
    for k, v in results.items():
        msg = "%s Account: %s, %s" % (v['name'], k, v['value'])
        print(msg)

    # print(global_accts)

    #print (target_environments)
    # //logger.info("Finished")

    print("--- %s seconds ---" % (time.time() - start_time))
Пример #5
0
        # fullUpdate = str(sys.argv[8]).strip()   ### true
        if tot > 8:
            fullUpdate = str(sys.argv[8]).strip().lower()  # true
            if fullUpdate == "none" or fullUpdate == "null" or fullUpdate == "false":
                fullUpdate = False
            else:
                fullUpdate = True
    else:
        target_environments = type_in.split(",")
        role = str(sys.argv[2]).strip()
        config = str(sys.argv[3]).strip()

    start_time = time.time()

    fullpath = "%s/%s" % (real_dir_path, config)
    origin, global_accts = loadConfig(fullpath, source_environment)
    # if 'eID' in origin:
    #     eID = origin['eID']
    # if 'services_map' in origin:
    #     mapfile = origin['services_map']
    #     eID = serviceID(origin['account'], mapfile, origin['all'])
    triggers = origin['triggers']
    if triggers is None:
        raise ValueError(
            "[E] config file [ %s ] did not load correctly.. PLEASE check / fix and try again" % (fullpath))
    td = TemporalDeployer()
    ready = None

    if not SkipDefinition:
        acctID, target, acctTitle, ready = td.Define(
            type_in, role, origin, global_accts, sendto, config, triggers, targetAPI, fullUpdate)
Пример #6
0
    config = str(sys.argv[4]).strip()  # ENVR.yaml
    if len(target_roles) > 1:
        if tot < 5:  # a general name is required if more than one role is given
            print(
                '[E] please provide a general name "some Alias" for these tests...like:')
            print('           python main_tester.py -L stage "CN-DynamoNormalizer,CN-FileTransform" ENVR.yaml yourAliasHere')
            raise Exception("alias required!!")
        else:
            role_alias = str(sys.argv[5]).strip()

    start_time = time.time()

    # fullpath = "%s/%s" % (real_dir_path, config)
    fullpath = "%s/%s" % (pwd, config)
    for tgt in target_environments:
        orgn, global_accts = loadConfig(fullpath, tgt)
        triggers = orgn['triggers']
        if triggers is None:
            raise ValueError(
                "[E] config file [ %s ] did not load correctly.. PLEASE check / fix and try again" % (fullpath))
    ct = CEDARTests()
    ready = None
    test_time = time.time()
    # print("----START----%s" % tgt)
    # Use first environment defined tests assume its same for all!!
    origin, global_accts = loadConfig(fullpath, target_environments[0])

    errors, results, total = ct.define_tests(
        type_in, target_roles, origin, global_accts, role_alias)
    print(" definition COMPLETE...")
    results = testStart(global_accts, target_environments, target_roles)