Exemple #1
0
def main(argv):
    ota = AWS_IoT_OTA()
    ota_bucket = S3Bucket(args.s3bucket, args.region)
    if (False == ota_bucket.exists()):
        if (True == ota_bucket.create()): print("Created bucket")
        else:
            sys.exit()
    ota_role = Role(args.role)
    if (False == ota_role.exists()):
        ota_role.init_role_policies(account_id=args.account,
                                    bucket_name=args.s3bucket)
    ota.DoUpdate()
def process_role(args):
    """
        args:
            0 -> operation
            create:
                1 -> role_name
            delete, add-schema, remove-schema:
                1 -> role_id
                add-schema, remove-schema:
                    2 -> schema_id
    """
    operation = args[0]

    if operation == 'list':
        return Role.list_current()

    role = args[1]
    if role == '':
        return '>Missing parameters.'

    if operation == 'create':
        role_id = Role.create(role)

        return f'>Role created with ID: {role_id}'

    if not Role.exists(role):
        return '>Role does not exist.'

    if operation == 'delete':
        Role.delete(role)
        return f'>Role {role} deleted.'

    try:
        schema_id = args[2]
    except IndexError:
        return '>No scheme id specified.'

    if operation == 'add-schema':
        Role.add_schema(role, schema_id)

        return f'>Schema {schema_id} added to role {role}'

    elif operation == 'remove-schema':
        Role.remove_schema(role, schema_id)
        return f'>Schema {schema_id} removed from role {role}'

    return False