def company_instance(): """ Mock Company instance """ with patch(PATCH_METHOD) as req: req.return_value = COMPANY_TABLE_DATA instance = get_company_instance() instance.set_company_id("uuid") instance.set_company_name("co") instance.set_company_external_id("external id") instance.save() yield instance
def test_create_event(): """ Test endpoint that creates event instance """ url = "/v1/events" event_project_id = str(uuid.uuid4()) event_company_id = str(uuid.uuid4()) user_id = str(uuid.uuid4()) payload = { "event_type": "cla", "event_company_id": event_company_id, "event_project_id": event_project_id, "user_id": user_id, "event_data": json.dumps({"foo": "bar"}), } response = hug.test.post(routes, url, payload) assert response.status == HTTP_400 user = get_user_instance() user.set_user_id(user_id) user.save() company = get_company_instance() company.set_company_id(event_company_id) company.set_company_name("foobar") company.save() project = get_project_instance() project.set_project_name("project") project.set_project_external_id(str(uuid.uuid4())) project.set_project_id(event_project_id) project.save() response = hug.test.post(routes, url, payload) assert response.status == HTTP_200 assert response.data["data"]["event_type"] == "cla" assert response.data["data"]["event_company_id"] == event_company_id assert response.data["data"]["event_project_id"] == event_project_id assert response.data["data"]["user_id"] == user_id assert response.data["data"]["event_data"] == json.dumps({"foo": "bar"})
# Copyright The Linux Foundation and each contributor to CommunityBridge. # SPDX-License-Identifier: MIT """ Convenience script to create companies. Based on the database storage configuration found in config.py and config_instance.py. """ import sys sys.path.append('../') if len(sys.argv) != 2: print('Usage: python3 add_company_whitelist.py <*****@*****.**>') exit() whitelist = sys.argv[1] import cla from cla.utils import get_company_instance cla.log.info('Adding whitelist item to all companies: %s', whitelist) # User companies = get_company_instance().all() for company in companies: company.add_company_whitelist(whitelist) company.save()
import sys sys.path.append('../') import cla from cla.utils import get_signature_instance, get_user_instance, get_project_instance, \ get_company_instance PROJECT_EXTERNAL_ID1 = 'a090t0000008DEiAAM' PROJECT_EXTERNAL_ID2 = 'a090t0000008E7iAAE' COMPANY_EXTERNAL_ID = 'company-external-id' USER_GITHUB_ID = 123 user = get_user_instance().get_user_by_github_id(USER_GITHUB_ID) project1 = get_project_instance().get_projects_by_external_id(PROJECT_EXTERNAL_ID1)[0] project2 = get_project_instance().get_projects_by_external_id(PROJECT_EXTERNAL_ID2)[0] company = get_company_instance().get_company_by_external_id(COMPANY_EXTERNAL_ID) # Test ICLA Agreement. sig_id = str(uuid.uuid4()) cla.log.info('Creating ICLA signature for user %s and project %s: %s' \ %(user.get_user_name(), project1.get_project_external_id(), sig_id)) signature = get_signature_instance() signature.set_signature_id(sig_id) signature.set_signature_project_id(project1.get_project_id()) signature.set_signature_signed(True) signature.set_signature_approved(True) signature.set_signature_type('cla') signature.set_signature_reference_id(user.get_user_id()) signature.set_signature_reference_type('user') signature.set_signature_document_major_version(1) signature.set_signature_document_minor_version(0)
github_org.set_organization_installation_id(GITHUB_INSTALLATION_ID) github_org.save() ## User (For Company Management) cla.log.info('Creating company manager user') manager = get_user_instance() manager.set_user_id(str(uuid.uuid4())) manager.set_user_name('First User') manager.set_user_email('*****@*****.**') manager.set_user_email('*****@*****.**') manager.set_user_github_id(123) manager.save() ## Company cla.log.info('Creating new company with manager ID: %s', manager.get_user_id()) company = get_company_instance() company.set_company_id(str(uuid.uuid4())) company.set_company_external_id('company-external-id') company.set_company_manager_id(manager.get_user_id()) company.set_company_name('Test Company') company.set_company_whitelist([]) company.set_company_whitelist_patterns(['*@listed.org']) company.save() ## Add another company with same manager ID cla.log.info('Creating new company with manager ID: %s', manager.get_user_id()) company = get_company_instance() company.set_company_id(str(uuid.uuid4())) company.set_company_external_id('company-external-id') company.set_company_manager_id(manager.get_user_id()) company.set_company_name('Test Company 2')
def return_url(signature_id, event=None): # pylint: disable=unused-argument """ Handle the GET request from the user once they have successfully signed. :param signature_id: The ID of the signature they have just signed. :type signature_id: string :param event: The event GET flag sent back from the signing service provider. :type event: string | None """ fn = 'return_url' try: # Load the signature based on ID. signature = get_signature_instance() signature.load(str(signature_id)) except DoesNotExist as err: cla.log.error('%s - Invalid signature_id provided when trying to send user back to their ' + \ 'return_url after signing: %s', fn, signature_id) return {'errors': {'signature_id': str(err)}} # Ensure everything went well on the signing service provider's side. if event is not None: # Expired signing URL - the user was redirected back immediately but still needs to sign. if event == 'ttl_expired' and not signature.get_signature_signed(): # Need to re-generate a sign_url and try again. cla.log.info( 'DocuSign URL used was expired, re-generating sign_url') callback_url = signature.get_signature_callback_url() get_signing_service().populate_sign_url(signature, callback_url) signature.save() raise falcon.HTTPFound(signature.get_signature_sign_url()) if event == 'cancel': return canceled_signature_html(signature=signature) ret_url = signature.get_signature_return_url() if ret_url is not None: cla.log.info('%s- Signature success - sending user to return_url: %s', fn, ret_url) try: project = get_project_instance() project.load(str(signature.get_signature_project_id())) except DoesNotExist as err: cla.log.error('%s - Invalid project_id provided when trying to send user back to'\ 'their return_url : %s', fn, signature.get_signature_project_id()) if project.get_version() == 'v2': if signature.get_signature_reference_type() == 'company': cla.log.info('%s - Getting company instance : %s ', fn, signature.get_signature_reference_id()) try: company = get_company_instance() company.load(str(signature.get_signature_reference_id())) except DoesNotExist as err: cla.log.error('%s - Invalid company_id provided : err: %s', fn, signature.get_signature_reference_id) user_service = UserService cla.log.info( '%s - Checking if cla managers have cla-manager role permission', fn) num_tries = 10 i = 1 cla.log.info( f'{fn} - checking if managers:{signature.get_signature_acl()} have roles with {num_tries} tries' ) while i <= num_tries: cla.log.info(f'{fn} - check try #: {i}') assigned = {} for manager in signature.get_signature_acl(): cla.log.info( f'{fn}- Checking {manager} for {CLA_MANAGER_ROLE} for company: {company.get_company_external_id()}, cla_group_id: {signature.get_signature_project_id()}' ) assigned[manager] = user_service.has_role( manager, CLA_MANAGER_ROLE, company.get_company_external_id(), signature.get_signature_project_id()) cla.log.info(f'{fn} - Assigned status : {assigned}') #Ensure that assigned list doesnt have any False values -> All Managers have role assigned if all(list(assigned.values())): cla.log.info( f'All managers have cla-manager role for company: {company.get_company_external_id()} and cla_group_id: {signature.get_signature_project_id()}' ) break time.sleep(0.5) i += 1 raise falcon.HTTPFound(ret_url) cla.log.info('No return_url set for signature - returning success message') return {'success': 'Thank you for signing'}
def main( aws_region, rds_database, rds_host, rds_username, rds_password, rds_port, dry_run, ): """ This script runs data migration from dynamodb to postgresql """ if os.environ.get("STAGE") is None: logger.warning( "Please set the 'STAGE' environment varaible - typically one of: {dev, staging, prod}" ) return stage = os.environ.get("STAGE") if dry_run: exit_cmd = input( "This is a dry run. " "You are running the script for the '{}' environment. " 'Press <ENTER> to continue ("exit" to exit): '.format(stage)) else: exit_cmd = input( "This is NOT a dry run. " "You are running the script for the '{}' environment. " 'Press <ENTER> to continue ("exit" to exit): '.format(stage)) if exit_cmd == "exit": return start_time = datetime.now() lock = threading.Lock() threads = [] count = 0 for _ in range(IMPORT_THREADS): connection = psycopg2.connect( database=rds_database, host=rds_host, user=rds_username, password=rds_password, port=rds_port, ) cursor = connection.cursor() worker = Thread(target=import_to_pg, args=(connection, cursor, tables_queues, dry_run)) worker.start() threads.append(worker) # TODO: cla models for signature,company-invitations and user-permissions try: user = utils.get_user_instance() company = utils.get_company_instance() project = utils.get_project_instance() repository = utils.get_repository_instance() github_orgs = utils.get_github_organization_instance() gerrit = utils.get_gerrit_instance() #signature = utils.get_signature_instance() update_queue(user.all()) update_queue(company.all()) update_queue(project.all()) #update_queue(signature.all()) update_queue(repository.all()) update_queue(gerrit.all()) update_queue(github_orgs.all()) # block until all tasks are done tables_queues.join() except Exception as err: logger.error(err) # End workers for _ in range(IMPORT_THREADS): tables_queues.put(None) for thread in threads: thread.join() duration = datetime.now() - start_time logger.info( "Data migration to the pg database run for a duration of {} ".format( duration))