account_setup.py
def create_role_assignment(credentials, subscription_id, scope, principal_id):
    """
        Gives service principal contributor role authorization on scope
        :param credentials: msrestazure.azure_active_directory.AdalAuthentication
        :param subscription_id: str
        :param scope: str
        :param principal_id: str
    """
    authorization_client = AuthorizationManagementClient(credentials, subscription_id)
    role_name = 'Contributor'
    roles = list(authorization_client.role_definitions.list(scope, filter="roleName eq '{}'".format(role_name)))
    contributor_role = roles[0]
    for i in range(10):
        try:
            authorization_client.role_assignments.create(scope, uuid.uuid4(),
                                                         {
                                                             'role_definition_id': contributor_role.id,
                                                             'principal_id': principal_id
                                                         })
            break
        except CloudError as e:
            # ignore error if service principal has not yet been created
            time.sleep(1)
            if i == 10:
                raise e

        Gives service principal contributor role authorization on scope
        :param credentials: msrestazure.azure_active_directory.AdalAuthentication
        :param subscription_id: str
        :param scope: str
        :param principal_id: str
    
Gives service principal contributor role authorization on scope
Gives service principal contributor role authorization on scope
def create_role_assignment(credentials, subscription_id, scope, principal_id):
    authorization_client = AuthorizationManagementClient(credentials, subscription_id)
    role_name = 'Contributor'
    roles = list(authorization_client.role_definitions.list(scope, filter="roleName eq '{}'".format(role_name)))
    contributor_role = roles[0]
    for i in range(10):
        try:
            authorization_client.role_assignments.create(scope, uuid.uuid4(),
                                                         {
                                                             'role_definition_id': contributor_role.id,
                                                             'principal_id': principal_id
                                                         })
            break
        except CloudError as e:
            time.sleep(1)
            if i == 10:
                raise e
def create_role_assignment ( credentials , subscription_id , scope , principal_id ) : authorization_client = AuthorizationManagementClient ( credentials , subscription_id ) role_name = 'Contributor' roles = list ( authorization_client . role_definitions . list ( scope , filter = "roleName eq '{}'" . format ( role_name ) ) ) contributor_role = roles [ 0 ] for i in range ( 10 ) : try : authorization_client . role_assignments . create ( scope , uuid . uuid4 ( ) , { 'role_definition_id' : contributor_role . id , 'principal_id' : principal_id } ) break except CloudError as e : time . sleep ( 1 ) if i == 10 : raise e
Gives service principal contributor role authorization on scope
Gives service principal contributor role authorization on scope
"""
        Gives service principal contributor role authorization on scope
        :param credentials: msrestazure.azure_active_directory.AdalAuthentication
        :param subscription_id: str
        :param scope: str
        :param principal_id: str
    """ # ignore error if service principal has not yet been created
credentials
None
subscription_id
None
scope
None
principal_id
None