예제 #1
0
def log_stack_trace_information(resp, *args, **kwargs):
    '''
    This function stores the current stacktrace in elastic search.
    It must not return anything, otherwise the return value is assumed to replace the response
    '''
    if not util._running_on_ci():
        return  # early exit if not running in ci job

    config_set_name = util.check_env('CONCOURSE_CURRENT_CFG')
    try:
        els_index = 'github_access_stacktrace'
        try:
            config_set = ctx().cfg_factory().cfg_set(config_set_name)
        except KeyError:
            # do nothing: external concourse does not have config set 'internal_active'
            return
        elastic_cfg = config_set.elasticsearch()

        now = datetime.datetime.utcnow()
        json_body = {
            'date': now.isoformat(),
            'url': resp.url,
            'req_method': resp.request.method,
            'stacktrace': traceback.format_stack()
        }

        elastic_client = ccc.elasticsearch.from_cfg(
            elasticsearch_cfg=elastic_cfg)
        elastic_client.store_document(index=els_index, body=json_body)

    except Exception as e:
        info(f'Could not log stack trace information: {e}')
def parse_component_descriptor():
    component_descriptor_file = os.path.join(
        util.check_env('COMPONENT_DESCRIPTOR_DIR'), 'component_descriptor')

    component_descriptor = product.model.ComponentDescriptor.from_dict(
        raw_dict=util.parse_yaml_file(component_descriptor_file))
    return component_descriptor
예제 #3
0
def current_product_descriptor():
    component_descriptor = os.path.join(
        util.check_env('COMPONENT_DESCRIPTOR_DIR'),
        'component_descriptor',
    )
    return product.model.ComponentDescriptor.from_dict(
        util.parse_yaml_file(component_descriptor), )
예제 #4
0
def current_product_descriptor():
    component_descriptor_dir = pathlib.Path(
        util.check_env('COMPONENT_DESCRIPTOR_DIR')).absolute()
    component_descriptor = component_descriptor_dir.joinpath(
        'component_descriptor')
    raw = util.parse_yaml_file(component_descriptor)
    return product.model.Product.from_dict(raw)
예제 #5
0
#!/usr/bin/env python3

# SPDX-FileCopyrightText: 2020 SAP SE or an SAP affiliate company and Gardener contributors
#
# SPDX-License-Identifier: Apache-2.0

import pathlib
import util
import os

from github.util import GitHubRepositoryHelper

VERSION_FILE_NAME = 'VERSION'

repo_owner_and_name = util.check_env('SOURCE_GITHUB_REPO_OWNER_AND_NAME')
repo_dir = util.check_env('MAIN_REPO_DIR')
output_dir = util.check_env('BINARY_PATH')

repo_owner, repo_name = repo_owner_and_name.split('/')

repo_path = pathlib.Path(repo_dir).resolve()
output_path = pathlib.Path(output_dir).resolve()
version_file_path = repo_path / VERSION_FILE_NAME

version_file_contents = version_file_path.read_text()

cfg_factory = util.ctx().cfg_factory()
github_cfg = cfg_factory.github('github_com')

github_repo_helper = GitHubRepositoryHelper(
    owner=repo_owner,
예제 #6
0
#!/usr/bin/env python3

import os
import pathlib
import fileinput

from util import (
    check_env,
    existing_file,
)

repo_dir = check_env('REPO_DIR')
effective_version = check_env('EFFECTIVE_VERSION')

template_file = existing_file(
    pathlib.Path(repo_dir, 'concourse', 'resources', 'defaults.mako'))

lines_replaced = 0
string_to_match = 'tag = '

for line in fileinput.FileInput(str(template_file), inplace=True):
    if string_to_match in line:
        if lines_replaced is not 0:
            raise RuntimeError(
                f'More than one image tag found in template file')
        leading_spaces = line.index(string_to_match)
        print(f'{leading_spaces * " "}{string_to_match}"{effective_version}"')
        lines_replaced = 1
    else:
        print(line, end='')
예제 #7
0
#!/usr/bin/env python3

import pathlib
import util

from github.util import GitHubRepositoryHelper

OUTPUT_FILE_NAME = 'build-result'
VERSION_FILE_NAME = 'VERSION'

repo_owner_and_name = util.check_env('SOURCE_GITHUB_REPO_AND_OWNER')
repo_dir = util.check_env('MAIN_REPO_DIR')
output_dir = util.check_env('OUT_PATH')

repo_owner, repo_name = repo_owner_and_name.split('/')

repo_path = pathlib.Path(repo_dir).resolve()
output_path = pathlib.Path(output_dir).resolve()
output_file_path = output_path / OUTPUT_FILE_NAME
version_file_path = repo_path / VERSION_FILE_NAME

version_file_contents = version_file_path.read_text()

cfg_factory = util.ctx().cfg_factory()
github_cfg = cfg_factory.github()

github_repo_helper = GitHubRepositoryHelper(
    owner=repo_owner,
    name=repo_name,
    github_cfg=github_cfg,
)