def getUserByEmail(userEmail): rawoutput = executeProcess( f'az ad user list --filter startswith(mail,\'{userEmail}\') --query [0].{{Name:displayName,Email:mail,ObjectId:objectId}} --output tsv' .split(' ')) output = rawoutput.split('\t') if len(output) != 3: raise Exception(f'Not found - User with email - {userEmail}.') else: user = User(output[0], output[1], output[2]) return user
def getServicePrincipalById(objectId): rawoutput = executeProcess( f'az ad sp show --id {objectId} --query [displayName,objectId] --output tsv' .split(' ')) output = rawoutput.split('\n') if len(output) != 2: raise Exception( f'Unable to get AAD ServicePrincipal with Id - {objectId}. Error - {rawoutput}' ) else: sp = ServicePrincipal(output[0], output[1]) return sp
def getGroupById(groupId): rawoutput = executeProcess( f'az ad group show --group {groupId} --query [displayName,mail,objectId] --output tsv' .split(' ')) output = rawoutput.split('\n') if len(output) != 3: raise Exception( f'Unable to get AAD Group with Id - {groupId}. Error - {rawoutput}' ) else: group = Group(output[0], output[1], output[2]) return group
def getUserById(userId): rawoutput = executeProcess( f'az ad user show --id {userId} --query [displayName,mail,objectId] --output tsv' .split(' ')) output = rawoutput.split('\n') if len(output) != 3: raise Exception( f'Unable to get AAD User with Id - {userId}. Error - {rawoutput}' ) else: user = User(output[0], output[1], output[2]) return user