def update_build_configuration_set(id, **kwargs): """ Update a BuildConfigurationSet """ invalid_bcs = False if not get_set_id(id, None): return set_to_update = utils.checked_api_call(sets_api, 'get_specific', id=id).content pvi = kwargs.get('product_version_id') if pvi and not productversions.get_product_version(id=pvi): logging.error("There is no ProductVersion with ID {}".format(pvi)) return bc_ids = kwargs.get('build_configuration_ids') if bc_ids: for id in bc_ids: if not buildconfigurations.get_build_configuration(id=id): logging.error("There is no BuildConfiguration with ID {}".format(id)) invalid_bcs = True if invalid_bcs: logging.error("Attempted to add non-existing BuildConfigurations to BuildConfigurationSet.") return for key, value in kwargs.items(): if value is not None: setattr(set_to_update, key, value) response = utils.checked_api_call(sets_api, 'update', id=id, body=set_to_update) if response: return response.content
def build_raw(id=None, name=None, revision=None, temporary_build=False, timestamp_alignment=False, no_build_dependencies=False, keep_pod_on_failure=False, force_rebuild=False, rebuild_mode=common.REBUILD_MODES_DEFAULT): if temporary_build is False and timestamp_alignment is True: print("Error: You can only activate timestamp alignment with the temporary build flag!") sys.exit(1) trigger_id = common.set_id(pnc_api.build_configs, id, name) if revision: response = utils.checked_api_call(pnc_api.build_configs, 'trigger_audited', id=trigger_id, rev=revision, temporary_build=temporary_build, timestamp_alignment=timestamp_alignment, build_dependencies=not no_build_dependencies, keep_pod_on_failure=keep_pod_on_failure, force_rebuild=force_rebuild, rebuild_mode=rebuild_mode) else: response = utils.checked_api_call(pnc_api.build_configs, 'trigger', id=trigger_id, temporary_build=temporary_build, timestamp_alignment=timestamp_alignment, build_dependencies=not no_build_dependencies, keep_pod_on_failure=keep_pod_on_failure, force_rebuild=force_rebuild, rebuild_mode=rebuild_mode) if response: return response.content
def update_build_configuration_set_raw(id, **kwargs): set_to_update = utils.checked_api_call(pnc_api.build_group_configs, 'get_specific', id=id).content for key, value in kwargs.items(): if value is not None: setattr(set_to_update, key, value) response = utils.checked_api_call(pnc_api.build_group_configs, 'update', id=id, body=set_to_update) if response: return response.content
def update_release_raw(id, **kwargs): to_update = utils.checked_api_call(pnc_api.product_releases, 'get_specific', id=id).content for key, value in iteritems(kwargs): if value is not None: setattr(to_update, key, value) response = utils.checked_api_call( pnc_api.product_releases, 'update', id=id, body=to_update) if response: return response.content
def update_project_raw(id, **kwargs): if utils.contains_only_none_values(kwargs): raise argh.exceptions.CommandError("Updating a Project requires at least one modified field.") to_update = utils.checked_api_call(pnc_api.projects, 'get_specific', id=id).content for key, value in iteritems(kwargs): if value is not None: setattr(to_update, key, value) response = utils.checked_api_call(pnc_api.projects, 'update', id=id, body=to_update) if response: return response.content else: return utils.checked_api_call(pnc_api.projects, 'get_specific', id=id).content
def get_user(): global user if user is None: if os.path.exists(SAVED_USER): user = pickle.load(open(SAVED_USER, "rb")) if user.keycloak_config.client_mode in trueValues: logging.info("Command performed using client authorization.\n") else: logging.info("Command performed with user: {}\n".format(user.username)) users_api = swagger_client.UsersApi(user.get_api_client()) utils.checked_api_call(users_api, 'get_logged_user') # inits the user if it doesn't exist in pnc's db already else: user = UserConfig() return user
def add_product_version_to_build_configuration_raw(id=None, name=None, product_version_id=None): found_id = common.set_id(pnc_api.build_configs, id, name) to_add = common.get_entity(pnc_api.product_versions, product_version_id) response = utils.checked_api_call(pnc_api.build_configs, 'add_product_version', id=found_id, body=to_add) if response: return response.content
def list_product_versions_for_build_configuration_raw(id=None, name=None, page_size=200, page_index=0, sort="", q=""): found_id = common.set_id(pnc_api.build_configs, id, name) response = utils.checked_api_call(pnc_api.build_configs, 'get_product_versions', id=found_id, page_size=page_size, page_index=page_index, sort=sort, q=q) if response: return response.content
def remove_dependency_raw(id=None, name=None, dependency_id=None, dependency_name=None): found_id = common.set_id(pnc_api.build_configs, id, name) found_dep_id = common.set_id(pnc_api.build_configs, dependency_id, dependency_name) response = utils.checked_api_call(pnc_api.build_configs, 'remove_dependency', id=found_id, dependency_id=found_dep_id) if response: return response.content
def get_log_for_record(id): """ Get the log for a given BuildRecord """ response = utils.checked_api_call(records_api, 'get_logs', id=id) if response: return response
def list_projects(page_size=200, sort="", q=""): """ List all Projects """ response = utils.checked_api_call(projects_api, 'get_all', page_size=page_size, sort=sort, q=q) if response: return response.content
def match_repository_configuration_raw(url, page_size=10, page_index=0, sort=""): """ Search for Repository Configurations based on internal or external url with exact match """ response = utils.checked_api_call(pnc_api.repositories, 'match', page_size=page_size, page_index=page_index, sort=sort, search=url) if response: return response.content
def create_build_record_set(**kwargs): """ Create a new BuildRecordSet (incomplete). Cannot add ProductMilestone references """ response = utils.checked_api_call(brs_api, 'create_new', body=create_buildrecordset_object(**kwargs)) if response: return response.content
def list_licenses(page_size=200, page_index=0, sort="", q=""): """ List all Licenses """ response = utils.checked_api_call(pnc_api.licenses, 'get_all', page_size=page_size, page_index=page_index, sort=sort, q=q) if response: return utils.format_json_list(response.content)
def list_repository_configurations(page_size=200, page_index=0, sort="", q=""): """ List all RepositoryConfigurations """ response = utils.checked_api_call(pnc_api.repositories, 'get_all', page_size=page_size, page_index=page_index, sort=sort, q=q) if response: return utils.format_json_list(response.content)
def create_build_configuration_set(**kwargs): """ Create a new BuildConfigurationSet. """ name = kwargs.get('name') if get_build_config_set_id_by_name(name): logging.error("A BuildConfigurationSet with name {0} already exists.".format( name)) return version_id = kwargs.get('product_version_id') if version_id and not productversions.version_exists(version_id): logging.error("No ProductVersion with id {0} exists.".format(version_id)) return build_configurations = kwargs.get('build_configuration_ids') failed = False if build_configurations: for config in build_configurations: if not buildconfigurations.config_id_exists(config): logging.error( "No BuildConfiguration with id {0} exists.".format(config)) failed = True if failed: return config_set = _create_build_config_set_object(**kwargs) response = utils.checked_api_call(sets_api, 'create_new', body=config_set) if response: return response.content
def list_environments(page_size=200, sort="", q=""): """ List all Environments """ response = utils.checked_api_call(envs_api, 'get_all', page_size=page_size, sort=sort, q=q) if response: return response.content
def delete_build_configuration_set(id=None, name=None): set_id = get_set_id(id, name) if not set_id: return response = utils.checked_api_call(sets_api, 'delete_specific', id=set_id) if response: return response.content
def get_audited_configuration_for_record(id): """ Get the BuildConfigurationAudited for a given BuildRecord """ response = utils.checked_api_call(records_api, 'get_build_configuration_audited', id=id) if response: return response.content
def list_environments_raw(page_size=200, page_index=0, sort="", q=""): """ List all Environments """ response = utils.checked_api_call(pnc_api.environments, 'get_all', page_size=page_size, page_index=page_index, sort=sort, q=q) if response: return response.content
def list_users(): """ List all Users """ response = utils.checked_api_call(users_api, 'get_all') if response: return response.content
def list_milestones(page_size=200, q="", sort=""): """ List all ProductMilestones """ response = utils.checked_api_call(milestones_api, 'get_all', page_size=page_size, q=q, sort=sort).content if response: return response
def list_build_record_sets(page_size=200, sort="", q=""): """ List all BuildRecordSets """ response = utils.checked_api_call(brs_api, 'get_all', page_size=page_size, sort=sort, q=q) if response: return response.content
def delete_build_configuration(id=None, name=None): """ Delete an existing BuildConfiguration :param id: :param name: :return: """ to_delete_id = get_config_id(id, name) if not to_delete_id: return #ensure that this build configuration is not a dependency of any other build configuration. isDep = False for config in list_build_configurations(): dep_ids = [str(val) for val in config.dependency_ids] if dep_ids is not None and to_delete_id in dep_ids: isDep = True logging.error("BuildConfiguration ID {} is a dependency of BuildConfiguration {}.".format(to_delete_id, config.name)) if not isDep: response = utils.checked_api_call(configs_api, 'delete_specific', id=to_delete_id) if response: return response.content else: logging.warn("No action taken.")
def get_release(id): """ Retrieve a specific ProductRelease """ response = utils.checked_api_call(releases_api, 'get_specific', id=id) if response: return response.content
def list_dependency_artifacts(id, page_size=200, sort="", q=""): """ List dependency artifacts associated with a BuildRecord """ response = utils.checked_api_call(records_api, 'get_dependency_artifacts', id=id, page_size=page_size, sort=sort, q=q) if response: return response.content
def list_build_configurations(page_size=200, sort="", q=""): """ List all BuildConfigurations """ response = utils.checked_api_call(configs_api, 'get_all', page_size=page_size, sort=sort, q=q) if response: return response.content
def list_milestones_for_version_raw(id): response = utils.checked_api_call( pnc_api.product_milestones, 'get_all_by_product_version_id', version_id=id) if response: return response.content
def list_running_builds(page_size=200, sort=""): """ List all RunningBuilds """ response = utils.checked_api_call(running_api, 'get_all', page_size=page_size, sort=sort) if response: return response.content
def list_licenses(page_size=200, sort="", q=""): """ List all Licenses """ response = utils.checked_api_call(licenses_api, 'get_all', page_size=page_size, sort=sort, q=q) if response: return response.content
def get_user(): global user if user is None: if os.path.exists(SAVED_USER): user = pickle.load(open(SAVED_USER, "rb")) if user.keycloak_config.client_mode in trueValues: logging.info("Command performed using client authorization.\n") else: logging.info("Command performed with user: {}\n".format( user.username)) users_api = swagger_client.UsersApi(user.get_api_client()) utils.checked_api_call( users_api, 'get_logged_user' ) # inits the user if it doesn't exist in pnc's db already else: user = UserConfig() return user
def create_build_configuration_set_raw(**kwargs): """ Create a new BuildConfigurationSet. """ config_set = _create_build_config_set_object(**kwargs) response = utils.checked_api_call(pnc_api.build_group_configs, 'create_new', body=config_set) if response: return response.content
def create_environment(**kwargs): """ Create a new Environment """ environment = create_environment_object(**kwargs) response = utils.checked_api_call(envs_api, 'create_new', body=environment) if response: return utils.format_json(response.content)
def get_build_configuration_set_raw(id=None, name=None): """ Get a specific BuildConfigurationSet by name or ID """ found_id = common.set_id(pnc_api.build_group_configs, id, name) response = utils.checked_api_call(pnc_api.build_group_configs, 'get_specific', id=found_id) if response: return response.content
def update_build_configuration_raw(id, **kwargs): to_update_id = id bc_to_update = pnc_api.build_configs.get_specific(id=to_update_id).content project_id = kwargs.get('project') if project_id: project_rest = common.get_entity(pnc_api.projects, project_id) update_project = {'project': project_rest} kwargs.update(update_project) repository_id = kwargs.get('repository_configuration') if repository_id: repository_rest = common.get_entity(pnc_api.repositories, repository_id) update_repository = {'repository_configuration': repository_rest} kwargs.update(update_repository) env_id = kwargs.get('environment') if env_id: env_rest = common.get_entity(pnc_api.environments, env_id) update_env = {'environment': env_rest} kwargs.update(update_env) if isinstance(kwargs.get("generic_parameters"), str): kwargs["generic_parameters"] = ast.literal_eval( kwargs.get("generic_parameters")) for key, value in kwargs.items(): if value is not None: setattr(bc_to_update, key, value) if kwargs.get('get_revision'): response = utils.checked_api_call(pnc_api.build_configs, 'update_and_get_audited', id=to_update_id, body=bc_to_update) else: response = utils.checked_api_call(pnc_api.build_configs, 'update', id=to_update_id, body=bc_to_update) if response: return response.content
def list_releases_for_version(id): """ List all ProductReleases for a ProductVersion """ response = utils.checked_api_call(releases_api, 'get_all_by_product_version_id', version_id=id) if response: return response.content
def get_build_configuration(id=None, name=None): """ Retrieve a specific BuildConfiguration """ found_id = common.set_id(configs_api, id, name) response = utils.checked_api_call(configs_api, 'get_specific', id=found_id) if response: return response.content
def build(id=None, name=None): """ Trigger a BuildConfiguration by name or ID """ trigger_id = common.set_id(configs_api, id, name) response = utils.checked_api_call(configs_api, 'trigger', id=trigger_id) if response: return response.content
def id_exists(api, search_id): """ Test if an ID exists within any arbitrary API :param api: api to search for search_id :param search_id: id to test for :return: True if an entity with ID search_id exists, false otherwise """ response = utils.checked_api_call(api, 'get_specific', id=search_id) return response is not None
def list_build_configurations_for_product_version(product_id, version_id, page_size=200, sort="", q=""): """ List all BuildConfigurations associated with the given ProductVersion """ found_product_id = common.set_id(products_api, product_id, None) response = utils.checked_api_call(configs_api, 'get_all_by_product_version_id', product_id=found_product_id, version_id=version_id, page_size=page_size, sort=sort, q=q) if response: return utils.format_json_list(response.content)
def list_product_releases_raw(page_size=200, page_index=0, sort="", q=""): response = utils.checked_api_call(pnc_api.product_releases, 'get_all', page_size=page_size, page_index=page_index, sort=sort, q=q) if response: return response.content
def list_versions_for_product_raw(id=None, name=None, page_size=200, page_index=0, sort='', q=''): """ List all ProductVersions for a given Product """ prod_id = common.set_id(products_api, id, name) response = utils.checked_api_call( products_api, 'get_product_versions', id=prod_id, page_size=page_size, page_index=page_index, sort=sort, q=q) if response: return response.content
def list_product_versions_for_build_configuration(id=None, name=None, page_size=200, sort="", q=""): """ List all ProductVersions associated with a BuildConfiguration """ found_id = common.set_id(configs_api, id, name) response = utils.checked_api_call(configs_api, 'get_product_versions', id=found_id, page_size=page_size, sort=sort, q=q) if response: return utils.format_json_list(response.content)
def remove_product_version_from_build_configuration(id=None, name=None, product_version_id=None): """ Remove a ProductVersion from association with a BuildConfiguration """ found_id = common.set_id(configs_api, id, name) response = utils.checked_api_call(configs_api, 'remove_product_version', id=found_id, product_version_id=product_version_id) if response: return utils.format_json(response.content)
def list_milestones_for_version(id): """ List ProductMilestones for a specific ProductVersion """ response = utils.checked_api_call(milestones_api, 'get_all_by_product_version_id', version_id=id).content if response: return response
def list_distributed_builds(id, page_size=200, sort='', q=''): response = utils.checked_api_call(milestones_api, 'get_distributed_builds', id=id, page_size=page_size, sort=sort, q=q) if response: return response.content
def list_distributed_artifacts(id, page_size=200, sort="", q=""): response = utils.checked_api_call(milestones_api, 'get_distributed_artifacts', id=id, page_size=page_size, sort=sort, q=q) if response: return utils.format_json_list(response.content)
def list_artifacts(id, page_size=200, sort="", q=""): response = utils.checked_api_call(records_api, 'get_artifacts', id=id, page_size=page_size, sort=sort, q=q) if response: return response.content
def update_project(id, **kwargs): """ Update an existing Project with new information """ if utils.contains_only_none_values(kwargs): raise argh.exceptions.CommandError( "Updating a Project requires at least one modified field.") to_update = utils.checked_api_call(projects_api, 'get_specific', id=id).content for key, value in iteritems(kwargs): if value is not None: setattr(to_update, key, value) response = utils.checked_api_call(projects_api, 'update', id=id, body=to_update) return response
def list_build_configurations_raw(page_size=200, page_index=0, sort="", q=""): response = utils.checked_api_call(pnc_api.build_configs, 'get_all', page_size=page_size, page_index=page_index, sort=sort, q=q) if response: return response.content
def remove_product_version_from_build_configuration_raw( id=None, name=None, product_version_id=None): found_id = common.set_id(pnc_api.build_configs, id, name) response = utils.checked_api_call(pnc_api.build_configs, 'remove_product_version', id=found_id, product_version_id=product_version_id) if response: return response.content
def close_milestone(id, **kwargs): """ Close a milestone. This triggers its release process. The user can optionally specify the release-date, otherwise today's date is used. If the wait parameter is specified and set to True, upon closing the milestone, we'll periodically check that the release being processed is done. Required: - id: int Optional: - wait key: bool """ existing_milestone = utils.checked_api_call(milestones_api, 'get_specific', id=id).content response = utils.checked_api_call(milestones_api, 'close_milestone', id=id, body=existing_milestone) latest_release = utils.checked_api_call(milestones_api, 'get_latest_release', id=id).content if kwargs.get('wait') == True: while latest_release.status == 'IN_PROGRESS': logging.info( "Latest release for milestone is in progress, waiting till it finishes..." ) time.sleep(60) latest_release = utils.checked_api_call(milestones_api, 'get_latest_release', id=id).content logging.error("Status of release for milestone: " + latest_release.status) if response: return utils.format_json(response.content)
def remove_build_configuration_from_set(set_id=None, set_name=None, config_id=None, config_name=None): config_set_id = common.set_id(sets_api, set_id, set_name) bc_id = common.set_id(configs_api, config_id, config_name) response = utils.checked_api_call( sets_api, 'remove_configuration', id=config_set_id, config_id=bc_id) if response: return utils.format_json(response.content)
def config_id_exists(search_id): """ Test if a build configuration matching search_id exists :param search_id: id to test for :return: True if a build configuration with search_id exists, False otherwise """ response = utils.checked_api_call(configs_api, 'get_specific', id=search_id) if not response: return False return True
def list_running_builds(page_size=200, sort=""): """ List all RunningBuilds """ response = utils.checked_api_call(running_api, 'get_all', page_size=page_size, sort=sort) if response: return utils.format_json_list(response.content)
def delete_license(license_id): """ Delete a License by ID """ response = utils.checked_api_call(pnc_api.licenses, 'delete', id=license_id) if response: return utils.format_json(response.content)
def create_license(**kwargs): """ Create a new License """ License = create_license_object(**kwargs) response = utils.checked_api_call(pnc_api.licenses, 'create_new', body=License) if response: return utils.format_json(response.content)
def delete_project(id=None, name=None): """ Delete a Project by ID or name. """ proj_id = common.set_id(projects_api, id, name) response = utils.checked_api_call(projects_api, 'delete_specific', id=proj_id) if response: return utils.format_json(response.content)
def list_dependencies(id=None, name=None, page_size=200, sort="", q=""): found_id = common.set_id(configs_api, id, name) response = utils.checked_api_call(configs_api, 'get_dependencies', id=found_id, page_size=page_size, sort=sort, q=q) if response: return response.content