def write_key_to_file( target_file_path: str, key_config_name: str, ): cfg_factory = ctx.cfg_factory() key_config = cfg_factory._cfg_element(cfg_type_name='gpg_key', cfg_name=key_config_name) with open(target_file_path, 'w') as f: f.write(key_config.raw['private'])
def client( cfg_name: str = None, cfg_factory=None, ) -> delivery.client.DeliveryServiceClient: if not cfg_factory: cfg_factory = ctx.cfg_factory() if not cfg_name: if delivery_client := default_client_if_available(): return delivery_client raise ValueError( 'no (default) delivery-client could be determined - pass cfg_name')
def default_client_if_available(): if not ci.util._running_on_ci(): return None import ctx cfg_factory = ctx.cfg_factory() cfg_set_name = ci.util.current_config_set_name() cfg_set = cfg_factory.cfg_set(cfg_set_name) try: delivery_cfg = cfg_set.delivery() routes = delivery.client.DeliveryServiceRoutes( base_url=delivery_cfg.service().external_host(), ) return delivery.client.DeliveryServiceClient(routes=routes) except: return None
def get_config(name: str): util.check_type(name, str) factory = ctx.cfg_factory() gh_cfg = factory.github(name) technicalUser = gh_cfg.credentials() return { 'httpUrl': gh_cfg.http_url(), 'apiUrl': gh_cfg.api_url(), 'disable_tls_validation': gh_cfg.tls_validation(), 'technicalUser': { 'username': technicalUser.raw.get('username'), 'emailAddress': technicalUser.email_address(), 'password': technicalUser.raw.get('password'), 'authToken': technicalUser.auth_token(), }, }
def get_secret(name: str): util.check_type(name, str) factory = ctx.cfg_factory() registry_cfg = factory.container_registry(name).raw dockerjsonsecret = { 'auths': { registry_cfg.get('host'): { 'username': registry_cfg.get('username'), 'password': registry_cfg.get('password'), 'email': registry_cfg.get('email'), } } } encoded_secret = base64.b64encode(json.dumps(dockerjsonsecret).encode()).decode() return { 'name': name, 'dockerconfigjson': encoded_secret, }
def retrieve_buildlog(uuid: str): concourse_cfg = concourse.util._current_concourse_config() uam_cfg_name = concourse_cfg.concourse_uam_cfg() concourse_uam_cfg = ctx.cfg_factory().concourse_uam(uam_cfg_name) pipeline_metadata = concourse.util.get_pipeline_metadata() client = concourse.client.from_cfg( concourse_cfg=concourse_cfg, concourse_uam_cfg=concourse_uam_cfg, team_name=pipeline_metadata.team_name, ) build = concourse.util.find_own_running_build() build_id = build.id() task_id = client.build_plan(build_id=build_id).task_id( task_name='malware-scan') build_events = client.build_events(build_id=build_id) log = '' for line in build_events.iter_buildlog(task_id=task_id): log += f'{line}' if uuid in line: break return log
# See the License for the specific language governing permissions and # limitations under the License. import os import ctx from gitutil import (GitHelper) from github.util import ( GitHubRepositoryHelper, ) it_label = "test/integration" source_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "../") repo_owner_name = os.getenv("SOURCE_GITHUB_REPO_OWNER_AND_NAME") github_repository_owner, github_repository_name = repo_owner_name.split("/") cfg_set = ctx.cfg_factory().cfg_set(os.getenv("CONCOURSE_CURRENT_CFG")) github_cfg = cfg_set.github() git_helper = GitHelper(repo=os.path.join(source_path, ".git"), github_cfg=github_cfg, github_repo_path=repo_owner_name) pull_request_number = git_helper.repo.git.config("--get", "pullrequest.id") github_helper = GitHubRepositoryHelper( owner=github_repository_owner, name=github_repository_name, github_cfg=github_cfg, ) pull_request = github_helper.repository.pull_request(pull_request_number)
def _current_cfg_set(): cfg_factory = ctx.cfg_factory() cfg_set_name = ci.util.current_config_set_name() cfg_set = cfg_factory.cfg_set(cfg_set_name) return cfg_set
def _resolve_ctx_repository_config(cfg_name): f = ctx.cfg_factory() cfg = f.ctx_repository(cfg_name) return cfg.base_url()