예제 #1
0
 def new_from_source_descriptor(
         descriptor: cm.ComponentDescriptor,
         context_url: str,
         external_resources: list,
         local_resources: list,
 ):
     return ComponentTool.new_from_descriptor(
         descriptor=cm.ComponentDescriptor(
             meta=descriptor.meta,
             component=cm.Component(
                 name=descriptor.component.name,
                 version=descriptor.component.version,
                 repositoryContexts=[
                     cm.RepositoryContext(
                         baseUrl=context_url,
                         type=cm.AccessType.OCI_REGISTRY,
                     ),
                 ],
                 provider=descriptor.component.provider,
                 sources=descriptor.component.sources,
                 componentReferences=descriptor.component.componentReferences,
                 externalResources=external_resources,
                 localResources=local_resources,
             )
         )
     )
def test_component():
    component = cm.Component(
        name='component-name',
        version='1.2.3',
        repositoryContexts=[
            cm.RepositoryContext(baseUrl='old-ctx-url'),
            cm.RepositoryContext(baseUrl='current-ctx-url'),
        ],
        provider=None,
        sources=(),
        componentReferences=(),
        resources=(),
        labels=(),
    )

    assert component.current_repository_ctx().baseUrl == 'current-ctx-url'
예제 #3
0
def base_component_descriptor_v2(
    component_name_v2: str,
    component_labels: typing.Iterable[cm.Label],
    effective_version: str,
    source_labels: tuple,
    ctx_repository_base_url: str,
    commit: str,
):
    import gci.componentmodel as cm
    import version as version_util
    parsed_version = version_util.parse_to_semver(effective_version)
    if parsed_version.finalize_version() == parsed_version:
        # "final" version --> there will be a tag, later (XXX hardcoded hack)
        src_ref = f'refs/tags/{effective_version}'
    else:
        # let's hope the version contains something committish
        if parsed_version.build:
            src_ref = f'{parsed_version.prerelease}{parsed_version.build}'
        else:
            src_ref = f'{parsed_version.prerelease}'

    # logical names must not contain slashes or dots
    logical_name = component_name_v2.replace('/', '_').replace('.', '_')

    base_descriptor_v2 = cm.ComponentDescriptor(
        meta=cm.Metadata(schemaVersion=cm.SchemaVersion.V2),
        component=cm.Component(
            name=component_name_v2,
            version=effective_version,
            repositoryContexts=[
                cm.RepositoryContext(
                    baseUrl=ctx_repository_base_url,
                    type=cm.AccessType.OCI_REGISTRY,
                )
            ],
            provider=cm.Provider.INTERNAL,
            sources=[
                cm.ComponentSource(
                    name=logical_name,
                    type=cm.SourceType.GIT,
                    access=cm.GithubAccess(
                        type=cm.AccessType.GITHUB,
                        repoUrl=component_name_v2,
                        ref=src_ref,
                        commit=commit,
                    ),
                    version=effective_version,
                    labels=source_labels,
                )
            ],
            componentReferences=[],  # added later
            resources=[],  # added later
            labels=list(component_labels),
        ),
    )

    return base_descriptor_v2
예제 #4
0
 def _comp(name=name, version=version):
     return cm.Component(
                 name=name,
                 version=version,
                 repositoryContexts=[
                     cm.RepositoryContext(
                         baseUrl='example.com/context',
                         type=cm.AccessType.OCI_REGISTRY,
                     ),
                 ],
                 provider=cm.Provider,
                 sources=cm.ComponentSource,
                 componentReferences=cm.ComponentReference,
                 resources=cm.Resource,
             )
예제 #5
0
def test_label_usage():
    component_name = 'c'
    component_version = '1.2.3'
    sources = [
        cm.ComponentSource(
            name='repo_aux_source',
            access=cm.GithubAccess(type=cm.AccessType.GITHUB,
                                   ref='refs/heads/master',
                                   repoUrl='github.com/otherOrg/otherRepo'),
            labels=[
                cm.Label(
                    name='cloud.gardener/cicd/source',
                    value={'repository-classification': 'auxiliary'},
                ),
            ],
        ),
        cm.ComponentSource(
            name='repo_main_source',
            access=cm.GithubAccess(type=cm.AccessType.GITHUB,
                                   ref='refs/heads/master',
                                   repoUrl='github.com/org/repo'),
            labels=[
                cm.Label(
                    name='cloud.gardener/cicd/source',
                    value={'repository-classification': 'main'},
                ),
            ],
        ),
    ]
    component_with_source_label = cm.Component(
        name=component_name,
        version=component_version,
        sources=sources,
        componentReferences=[],
        labels=[],
        repositoryContexts=[
            cm.RepositoryContext(
                baseUrl=
                'eu.gcr.io/sap-se-gcr-k8s-private/cnudie/gardener/landscapes',
                type='ociRegistry',
            ),
        ],
        resources=[],
        provider=[],
    )

    main_source = cnudie.util.determine_main_source_for_component(
        component_with_source_label, )
    assert main_source.labels[0].value == {'repository-classification': 'main'}
    assert main_source.name == 'repo_main_source'

    component_without_source_label = cm.Component(
        name=component_name,
        version=component_version,
        sources=[
            cm.ComponentSource(
                name='repo_main_source',
                access=cm.GithubAccess(type=cm.AccessType.GITHUB,
                                       ref='refs/heads/master',
                                       repoUrl='github.com/org/repo'),
            ),
            cm.ComponentSource(
                name='repo_aux_source',
                access=cm.GithubAccess(
                    type=cm.AccessType.GITHUB,
                    ref='refs/heads/master',
                    repoUrl='github.com/otherOrg/otherRepo'),
            ),
        ],
        componentReferences=[],
        labels=[],
        repositoryContexts=[
            cm.RepositoryContext(
                baseUrl=
                'eu.gcr.io/sap-se-gcr-k8s-private/cnudie/gardener/landscapes',
                type='ociRegistry',
            ),
        ],
        resources=[],
        provider=[],
    )

    main_source = cnudie.util.determine_main_source_for_component(
        component_without_source_label)

    assert main_source.name == 'repo_main_source'