Esempio n. 1
0
    def test_group_object_rules(self):
        h = hris.HrisJSON(boto_session=None)
        h.file_name = 'hris.json'
        h.from_file = True
        hris_mock_json = h.load()

        hris_mock_json_entry = hris_mock_json.get('Report_Entry')[0]

        g = hris.Groups(entry=hris_mock_json_entry)

        group_list = g.all

        cost_center_group_name = g.cost_center_rule()
        cost_center_hierarchy = g.cost_center_hierarchy()
        management_status_rule = g.manager_status_rule()
        manager_name_rule = g.manager_name_rule()
        management_level_rule = g.management_level_rule()

        assert g.hris_entry == hris_mock_json_entry
        assert isinstance(group_list, list)
        assert cost_center_group_name == 'hris_costcenter_9999'
        assert cost_center_hierarchy == 'hris_dept_north'
        assert management_status_rule == 'hris_nonmanagers'
        assert manager_name_rule == 'hris_direct_reports_unknown'
        assert management_level_rule == 'hris_individual_contributor'

        groups_present = [
            'hris_costcenter_9999', 'hris_dept_north',
            'hris_individual_contributor', 'hris_direct_reports_unknown',
            'hris_nonmanagers', 'hris_egencia_ws'
        ]

        for group in groups_present:
            assert group in g.hris_grouplist
    def _load_file_from_s3(self):
        if self._boto_session is None:
            self._connect()

        if self._hris_json is None:
            hris_json_file = hris.HrisJSON(self._boto_session)
            hris_json_file.from_file = self._from_file
            self._hris_json = hris_json_file.load()
        return self._hris_json
Esempio n. 3
0
def handle(event=None, context={}):
    # Load the file of HRIS Data.
    boto_session = boto3.session.Session(region_name='us-west-2')
    hris_json = hris.HrisJSON(boto_session)
    hr_data = hris_json.load()

    v = vault.Search(boto_session)

    valid_records = []
    dead_letters = []
    invalid_records = []

    cis_publisher_session = assume_role_session()

    # For each user validate they have the required fields.
    for record in hr_data.get('Report_Entry'):
        # If user valid go ahead and push them onto a list to use as a stack.
        email = record.get('PrimaryWorkEmail')

        if hris_json.is_valid(record):
            valid_records.append(record)

        else:
            # logger.error('Record invalid for : {user} deadlettering workday record.'.format(user=email))
            dead_letters.append(record)

    # For each user in the valid list
    for record in valid_records:
        email = record.get('PrimaryWorkEmail')
        # Retrieve their current profile from the identity vault.
        vault_record = v.find_by_email(email)

        # Enrich the profile with the new data fields from HRIS extract. (Groups only for now)
        if vault_record is not None:
            logger.info('Processing record :{}'.format(record))
            hris_groups = hris_json.to_groups(record)

            t = task.CISTask(boto_session=cis_publisher_session,
                             vault_record=vault_record,
                             hris_groups=hris_groups)

            data = t.prep()
            res = t.send(data)
            logger.info('Data sent to identity vault: {}'.format(data))
            logger.info(
                'Result of operation in identity vault: {}'.format(res))
        else:
            # logger.error('Could not find record in vault for user: {user}'.format(user=email))
            invalid_records.append('1')
        continue

    logger.info(
        'Processing complete dead_letter_count: {dl}, valid_records: {vr}, unlocated_in_vault: {iv}'
        .format(dl=len(dead_letters),
                vr=len(valid_records),
                iv=len(invalid_records)))
Esempio n. 4
0
    def test_group_object(self):
        h = hris.HrisJSON(boto_session=None)
        h.from_file = True
        hris_mock_json = h.load()

        hris_mock_json_entry = hris_mock_json.get('Report_Entry')[0]

        g = hris.Groups(entry=hris_mock_json_entry)

        assert g is not None
Esempio n. 5
0
    def test_group_object_returns_list(self):
        h = hris.HrisJSON(boto_session=None)
        h.from_file = True
        hris_mock_json = h.load()

        hris_mock_json_entry = hris_mock_json.get('Report_Entry')[0]

        g = hris.Groups(entry=hris_mock_json_entry)

        group_list = g.all

        assert isinstance(group_list, list)
def handle(event=None, context={}):
    boto_session = boto3.session.Session(region_name='us-west-2')
    hris_json = hris.HrisJSON(boto_session)
    hr_data = hris_json.load()

    boto_session = boto3.session.Session(region_name='us-west-2')
    cis_publisher_session = assume_role_session()
    hris_json = hris.HrisJSON(boto_session)

    # Load the file of HRIS Data.
    os.environ["CIS_OAUTH2_CLIENT_ID"] = get_secret(
        'cis_hris_publisher.client_id', dict(app='cis_hris_publisher'))
    os.environ["CIS_OAUTH2_CLIENT_SECRET"] = get_secret(
        'cis_hris_publisher.client_secret', dict(app='cis_hris_publisher'))

    person_api = Person(
        person_api_config={
            'audience': os.getenv('CIS_PERSON_API_AUDIENCE'),
            'client_id': os.getenv('CIS_OAUTH2_CLIENT_ID'),
            'client_secret': os.getenv('CIS_OAUTH2_CLIENT_SECRET'),
            'oauth2_domain': os.getenv('CIS_OAUTH2_DOMAIN'),
            'person_api_url': os.getenv('CIS_PERSON_API_URL'),
            'person_api_version': os.getenv('CIS_PERSON_API_VERSION')
        })

    threads = []

    for record in hr_data.get('Report_Entry'):
        t = threading.Thread(target=publish,
                             args=[
                                 record, boto_session, cis_publisher_session,
                                 hris_json, person_api
                             ])
        threads.append(t)
        t.start()

    for thread in threads:
        thread.join()
Esempio n. 7
0
    def test_groups_validator(self):
        h = hris.HrisJSON(boto_session=None)
        h.from_file = True
        h.file_name = 'hris-bad.json'
        hris_mock_json = h.load()
        hris_mock_json_entry = hris_mock_json.get('Report_Entry')[0]

        bad_status = h.is_valid(hris_mock_json_entry)

        h.file_name = 'hris.json'
        hris_mock_json = h.load()
        hris_mock_json_entry = hris_mock_json.get('Report_Entry')[0]

        good_status = h.is_valid(hris_mock_json_entry)

        assert bad_status is False
        assert good_status is True
Esempio n. 8
0
    def test_groups_returned_from_hris_json(self):
        groups_present = [
            'hris_costcenter_9999', 'hris_dept_north',
            'hris_individual_contributor', 'hris_direct_reports_unknown',
            'hris_nonmanagers', 'hris_egencia_ws', 'hris_is_staff'
        ]

        h = hris.HrisJSON(boto_session=None)
        h.from_file = True
        hris_mock_json = h.load()

        hris_mock_json_entry = hris_mock_json.get('Report_Entry')[0]

        groups = h.to_groups(hris_mock_json_entry)

        for group in groups:
            assert group in groups_present
Esempio n. 9
0
def handle(event=None, context={}):
    # Load the file of HRIS Data.
    os.environ["CIS_OAUTH2_CLIENT_ID"] = get_secret(
        'cis_hris_publisher.client_id', dict(app='cis_hris_publisher'))
    os.environ["CIS_OAUTH2_CLIENT_SECRET"] = get_secret(
        'cis_hris_publisher.client_secret', dict(app='cis_hris_publisher'))

    boto_session = boto3.session.Session(region_name='us-west-2')
    hris_json = hris.HrisJSON(boto_session)
    hr_data = hris_json.load()

    valid_records = []
    dead_letters = []
    invalid_records = []

    cis_publisher_session = assume_role_session()

    person_api = Person(
        person_api_config={
            'audience':
            os.getenv('CIS_PERSON_API_AUDIENCE'),
            'client_id':
            get_secret('cis_hris_publisher.client_id',
                       dict(app='cis_hris_publisher')),
            'client_secret':
            get_secret('cis_hris_publisher.client_secret',
                       dict(app='cis_hris_publisher')),
            'oauth2_domain':
            os.getenv('CIS_OAUTH2_DOMAIN'),
            'person_api_url':
            os.getenv('CIS_PERSON_API_URL'),
            'person_api_version':
            os.getenv('CIS_PERSON_API_VERSION')
        })

    # For each user validate they have the required fields.
    for record in hr_data.get('Report_Entry'):
        # If user valid go ahead and push them onto a list to use as a stack.
        email = record.get('PrimaryWorkEmail')

        if hris_json.is_valid(record):
            valid_records.append(record)

        else:
            # logger.error('Record invalid for : {user} deadlettering workday record.'.format(user=email))
            dead_letters.append(record)

    # For each user in the valid list
    for record in valid_records:
        email = record.get('PrimaryWorkEmail', None)

        # Retrieve their current profile from the identity vault using person-api.
        logger.info('Attempting retrieval of user: {}'.format(email))
        if email is not None:
            vault_record = person_api.get_userinfo('ad|{}|{}'.format(
                os.getenv('LDAP_NAMESPACE'),
                email.split('@')[0]))
        else:
            vault_record = None

        # Enrich the profile with the new data fields from HRIS extract. (Groups only for now)
        if vault_record is not None and vault_record != {}:
            logger.info('Processing record :{}'.format(record))
            hris_groups = hris_json.to_groups(record)

            t = task.CISTask(boto_session=cis_publisher_session,
                             vault_record=vault_record,
                             hris_groups=hris_groups)

            res = t.send()
            logger.info('Data sent to identity vault for: {}'.format(email))
            logger.info(
                'Result of operation in identity vault: {}'.format(res))
            valid_records.append('1')
        else:
            # logger.error('Could not find record in vault for user: {user}'.format(user=email))
            invalid_records.append('1')
        continue

    logger.info(
        'Processing complete dead_letter_count: {dl}, valid_records: {vr}, unlocated_in_vault: {iv}'
        .format(dl=len(dead_letters),
                vr=len(valid_records),
                iv=len(invalid_records)))
Esempio n. 10
0
 def setUp(self):
     h = hris.HrisJSON(boto_session=None)
     h.file_name = 'hris.json'
     assert h is not None
Esempio n. 11
0
 def test_file_loads(self):
     h = hris.HrisJSON(boto_session=None)
     h.file_name = 'hris.json'
     h.from_file = True
     hris_mock_json = h.load()
     assert isinstance(hris_mock_json, dict)
Esempio n. 12
0
 def setUp(self):
     h = hris.HrisJSON(boto_session=None)
     assert h is not None