Пример #1
0
def getpresence(session):
    """Get Presence from logged in user"""
    user_profile = session.get(api_endpoint('me'))
   
    if not user_profile.ok:
        pprint.pprint(user_profile.json()) # display error
        return
    user_data = user_profile.json()
    
    user_presence = session.get(api_endpoint('me/presence'))
   
    if not user_presence.ok:
        pprint.pprint(user_presence.json()) # display error
        return
    user_data = user_presence.json()
    availability = user_data['availability']
    return availability
Пример #2
0
def find_manager(session):

    # print('\nGet user profile ---------> https://graph.microsoft.com/v1.0/me')
    user_profile = session.get(api_endpoint('me'))
    # print(28*' ' + f'<Response [{user_profile.status_code}]>',
    #       f'bytes returned: {len(user_profile.text)}\n')
    # if not user_profile.ok:
    #     pprint.pprint(user_profile.json())  # display error
    #     return
    user_data = user_profile.json()
    email = user_data['mail']
    # display_name = user_data['displayName']

    # print(f'Your name ----------------> {display_name}')
    # print(f'Your email ---------------> {email}')
    user_search = input(f'Search-for (ENTER=self) -->') or email
    search_response = session.get(api_endpoint(f'users/{user_search}/manager'))
    # print(f'\nUser manager ----------> https://graph.microsoft.com/v1.0/users/{user_search}/manager')
    print(f'<Response [{search_response.status_code}]>')
    pprint.pprint(search_response.json())
Пример #3
0
def getpresence(session):
    """Get Presence from logged in user"""
    user_profile = session.get(api_endpoint('me'))
   
    if not user_profile.ok:
        pprint.pprint(user_profile.json()) # display error
        return
    user_data = user_profile.json()
    display_name = user_data['displayName']
    
    print(f'Your name ----------------> {display_name}')
    print('\nGet user presence ---------> https://graph.microsoft.com/beta/me/presence')
    user_presence = session.get(api_endpoint('me/presence'))
   
    if not user_presence.ok:
        pprint.pprint(user_presence.json()) # display error
        return
    user_data = user_presence.json()
    availability = user_data['availability']
    activity = user_data['activity']
    
    print(f'Your availability ----------------> {availability}')
    print(f'Your activity ---------------> {activity}')
Пример #4
0
def search_activedirectory(session, search_string, results_array):
    search_response = session.get(api_endpoint(search_string))
    search_data = search_response.json()
    if not search_response.ok:
        pprint.pprint(search_data)  # display error
        return False

    bMatch = False
    for person in search_data['value']:
        if 'userPrincipalName' in person:
            user_principal_name = person['userPrincipalName'] or ''
            if user_principal_name != '':
                bMatch = True
                # pprint.pprint(person)
                job_title = person['jobTitle'] or 'None'
                office_location = person['officeLocation'] or 'None'
                result = '    ' + person[
                    'userPrincipalName'] + ', ' + job_title + ', ' + office_location
                results_array.append(result)
    return bMatch
Пример #5
0
def sendmail_sample(session):
    """Send email from authenticated user.

    session = requests.Session() instance with a valid access token for
              Microsoft Graph in its default HTTP headers

    This sample retrieves the user's profile photo, uploads it to OneDrive,
    creates a view-only sharing link for the photo, and sends an email
    with the photo attached.

    The code in this function includes many print statements to provide
    information about which endpoints are being called and the status and
    size of Microsoft Graph responses. This information is helpful for
    understanding how the sample works with Graph, but would not be included
    in a typical production application.
    """

    print('\nGet user profile ---------> https://graph.microsoft.com/beta/me')
    user_profile = session.get(api_endpoint('me'))
    print(28*' ' + f'<Response [{user_profile.status_code}]>', f'bytes returned: {len(user_profile.text)}\n')
    if not user_profile.ok:
        pprint.pprint(user_profile.json()) # display error
        return
    user_data = user_profile.json()
    email = user_data['mail']
    display_name = user_data['displayName']

    print(f'Your name ----------------> {display_name}')
    print(f'Your email ---------------> {email}')
    email_to = input(f'Send-to (ENTER=self) -----> ') or email

    print('\nGet profile photo --------> https://graph.microsoft.com/beta/me/photo/$value')
    photo, photo_status_code, _, profile_pic = profile_photo(session, save_as='me')
    print(28*' ' + f'<Response [{photo_status_code}]>',
          f'bytes returned: {len(photo)}, saved as: {profile_pic}')
    if not 200 <= photo_status_code <= 299:
        return

    print(f'Upload to OneDrive ------->',
          f'https://graph.microsoft.com/beta/me/drive/root/children/{profile_pic}/content')
    upload_response = upload_file(session, filename=profile_pic)
    print(28*' ' + f'<Response [{upload_response.status_code}]>')
    if not upload_response.ok:
        pprint.pprint(upload_response.json()) # show error message
        return

    print('Create sharing link ------>',
          'https://graph.microsoft.com/beta/me/drive/items/{id}/createLink')
    response, link_url = sharing_link(session, item_id=upload_response.json()['id'])
    print(28*' ' + f'<Response [{response.status_code}]>',
          f'bytes returned: {len(response.text)}')
    if not response.ok:
        pprint.pprint(response.json()) # show error message
        return

    print('Send mail ---------------->',
          'https://graph.microsoft.com/beta/me/microsoft.graph.sendMail')
    with open('email.html') as template_file:
        template = template_file.read().format(name=display_name, link_url=link_url)

    send_response = send_mail(session=session,
                              subject='email from Microsoft Graph console app',
                              recipients=email_to.split(';'),
                              body=template,
                              attachments=[profile_pic])
    print(28*' ' + f'<Response [{send_response.status_code}]>')
    if not send_response.ok:
        pprint.pprint(send_response.json()) # show error message
Пример #6
0
                results_array.append(result)
    return bMatch


if __name__ == "__main__":
    argparser = build_argparser()
    args = argparser.parse_args()

    if args.profile == None:
        iam = boto3.client('iam')
    else:
        profile = boto3.session.Session(profile_name=args.profile)
        iam = profile.client('iam')

    GRAPH_SESSION = device_flow_session(config.CLIENT_ID, True)
    user_profile = GRAPH_SESSION.get(api_endpoint('me'))
    # print(28*' ' + f'<Response [{user_profile.status_code}]>', f'bytes returned: {len(user_profile.text)}\n')
    if not user_profile.ok:
        pprint.pprint(user_profile.json())  # display error
        exit()

    now = datetime.datetime.now(tzutc())

    paginator = iam.get_paginator('list_users')
    page_iterator = paginator.paginate()
    for users in page_iterator:
        for user in users['Users']:
            # print('{}'.format(user))
            user_name = user['UserName']
            create_date = user['CreateDate']
            print('UserName = ' + user_name)
Пример #7
0
    argparser.add_argument('-c',
                           '--companyemail',
                           help='Filter company email addresses',
                           required=True)
    argparser.add_argument('-v', '--verbose', type=str2bool, help='Verbose')
    return argparser


if __name__ == "__main__":
    argparser = build_argparser()
    args = argparser.parse_args()

    slack_client = slack.WebClient(token=args.token)

    GRAPH_SESSION = device_flow_session(config.CLIENT_ID, True)
    user_profile = GRAPH_SESSION.get(api_endpoint('me'))
    # print(28*' ' + f'<Response [{user_profile.status_code}]>', f'bytes returned: {len(user_profile.text)}\n')
    if not user_profile.ok:
        pprint.pprint(user_profile.json())  # display error
        exit()

    response = slack_client.users_list()
    # print(format(response))
    for member in response['members']:
        # print(format(member))

        if 'email' not in member['profile']:
            if args.verbose:
                print('SKIP: ' + member['name'])
            continue
                           help='Keen organisation',
                           required=True)
    argparser.add_argument('-a',
                           '--authorization',
                           help='Token for Keen',
                           required=True)
    argparser.add_argument('-v', '--verbose', type=str2bool, help='Verbose')
    return argparser


if __name__ == "__main__":
    argparser = build_argparser()
    args = argparser.parse_args()

    GRAPH_SESSION = device_flow_session(config.CLIENT_ID, True)
    user_profile = GRAPH_SESSION.get(api_endpoint('me'))
    # print(28*' ' + f'<Response [{user_profile.status_code}]>', f'bytes returned: {len(user_profile.text)}\n')
    if not user_profile.ok:
        pprint.pprint(user_profile.json())  # display error
        exit()

    headers = {
        'Content-Type': 'application/json',
        'Authorization': args.authorization
    }
    response = requests.get('https://api.keen.io/3.0/organizations/' +
                            args.organisation + '/projects',
                            json={},
                            headers=headers)
    projects = response.json()
    for project in projects: