Skip to content
This repository has been archived by the owner on May 24, 2023. It is now read-only.

Commit

Permalink
Add repository_suffix organization config
Browse files Browse the repository at this point in the history
* OSBS-8412

Signed-off-by: Luiz Carvalho <[email protected]>
  • Loading branch information
lcarva authored and MartinBasti committed Dec 20, 2019
1 parent a1e9132 commit b2f730a
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 3 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ Here's an example:
```
Replacements occur when pushing manifests into the application registry.

#### Altering repository names

Organizations can be configured so a suffix is appended to the repository name.
The suffix is only applied if the repository name does not already end with the suffix.
Example configuration:
```
"repository_suffix": "-suffix"
```

### Greenwave integration

This is optional. When `GREENWAVE` settings are missing in config file checks
Expand Down
2 changes: 2 additions & 0 deletions omps/api/v1/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def _zip_flow(*, organization, repo, version, extract_manifest_func,
if repo is None:
repo = _get_reponame_from_manifests(tmpdir)

repo = quay_org.adjust_repository_name(repo)

version = get_package_version(quay_org, repo, version)
logger.info("Using release version: %s", version)

Expand Down
28 changes: 26 additions & 2 deletions omps/quay.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,10 @@ class OrgManager:
},
"required": ["old", "new"],
}
},
"repository_suffix": {
"description": "suffix to append to repository name",
"type": "string"
}
},
},
Expand Down Expand Up @@ -199,7 +203,8 @@ def get_org(self, organization, cnr_token):
oauth_token=org_config.get('oauth_token'),
public=org_config.get('public', False),
timeout=self._timeout,
replace_registry_conf=org_config.get('replace_registry')
replace_registry_conf=org_config.get('replace_registry'),
repository_suffix=org_config.get('repository_suffix'),
)


Expand All @@ -208,7 +213,7 @@ class QuayOrganization:

def __init__(
self, organization, cnr_token, oauth_token=None, public=False,
timeout=None, replace_registry_conf=None
timeout=None, replace_registry_conf=None, repository_suffix=None
):
"""
:param organization: organization name
Expand All @@ -226,6 +231,7 @@ def __init__(
self._public = public
self._timeout = timeout
self._replace_registry_conf = replace_registry_conf
self._repository_suffix = repository_suffix

@property
def public(self):
Expand Down Expand Up @@ -271,6 +277,24 @@ def replace_registries(self, text):

return text

def adjust_repository_name(self, repo):
"""Returns the modified repository name
The repository name is modified if there's a repository_suffix
configured for the Quay organization *and* the repository name
does not already end in the repository_suffix
:param repo: name of repository
:rtype: str
:return: text with replaced registries
"""
if self._repository_suffix:
if not repo.endswith(self._repository_suffix):
self.logger.info("Applying repository suffix, %s, to %s",
self._repository_suffix, repo)
repo = repo + self._repository_suffix
return repo

def push_operator_manifest(self, repo, version, source_dir):
"""Build, verify and push operators artifact to quay.io registry
Expand Down
19 changes: 18 additions & 1 deletion tests/test_quay.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ def test_regexp_replace_registries(self, text, expected):
qo = QuayOrganization(org, TOKEN, replace_registry_conf=replace_conf)
assert qo.replace_registries(text) == expected

@pytest.mark.parametrize(('repo', 'suffix', 'expected'), (
('repo', '-suffix', 'repo-suffix'),
('repo-suffix', '-suffix', 'repo-suffix'),
('repo', '', 'repo'),
('repo', None, 'repo'),
))
def test_repository_suffix(self, repo, suffix, expected, organization):
"""Test if repository_suffix property returns correct value"""
qo = QuayOrganization(organization, TOKEN, repository_suffix=suffix)
assert qo.adjust_repository_name(repo) == expected


class TestOrgManager:
"""Tets for OrgManager class"""
Expand All @@ -537,7 +548,10 @@ class ConfClass:
'replace_registry': [
{'new': 'reg1', 'old': 'reg2'},
]
}
},
'org_with_repository_suffix': {
'repository_suffix': '-suffix',
},
}

conf = Config(ConfClass)
Expand Down Expand Up @@ -569,6 +583,9 @@ class ConfClass:
assert not priv_org_replacing_registries.oauth_access
assert priv_org_replacing_registries.registry_replacing_enabled

org_with_repository_suffix = om.get_org('org_with_repository_suffix', 'cnr_token')
assert org_with_repository_suffix.adjust_repository_name('repo') == 'repo-suffix'

def test_getting_unconfigured_org(self):
"""Test of getting organization instance whne org is not configured in
settings"""
Expand Down

0 comments on commit b2f730a

Please sign in to comment.