Exemplo n.º 1
0
def showModel(ctx, targetRegion, targetEnv, targetRole, targetService, targetPolicy):
    ctxRoles = ctx.model['roles']
    offset = 0
    width = 120
    for region in ctxRoles:
        if targetRegion != None and region != targetRegion:
            continue
        for env in ctxRoles[region]:
            if targetEnv != None and env != targetEnv:
                continue
            for roleName in ctxRoles[region][env]:
                if (targetPolicy == None and targetService == None) and targetRole == None:
                    ctx.log(click.style('Role: %s: ' % (roleName), fg='cyan'))
                    offset = 10
                else:
                    offset = 0
                for policyName in ctxRoles[region][env][roleName]:
                    if targetPolicy != None and policyName != targetPolicy:
                        continue
                    modelPolicy = ctx.dumps(ctx.modelPolicies[policyName])
                    if modelPolicy != None:
                        if targetPolicy == None:
                            # Don't display the policy name if only 1 policy is
                            # being shown.
                            ctx.log(click.style('%*sPolicy: %s: ' % (offset,'',policyName), fg='cyan'))
                        utils.showPolicyJson(ctx, modelPolicy, offset, width)
Exemplo n.º 2
0
def showRoles(ctx, targetRegion, targetEnv, targetRole):
    for role in ctx.currentRoles:
        roleName = role['RoleName']
        if targetRole != None and roleName != targetRole:
            continue
        region, env, _ = utils.regionEnvAndRole(roleName)
        if targetRegion != None and region != targetRegion:
            continue
        if targetEnv != None and env != targetEnv:
            continue
        attached = aws_roles.getAttachedPolicies(ctx, roleName)
        ctx.log('Role: %s: %d attached policies:' % (roleName, len(attached)))
        for policyName in attached:
            policyDoc = csm_policies.getAWSPolicyDocument(ctx,policyName)
            utils.showPolicyJson(ctx, policyName, ctx.dumps(policyDoc), 15, 120)
        ctx.log('')