Skip to content
This repository has been archived by the owner on Apr 11, 2022. It is now read-only.

Commit

Permalink
Merge pull request #84 from zalando-stups/sunset-trusted
Browse files Browse the repository at this point in the history
Sunset all support related to `trusted` flag
  • Loading branch information
marcinzaremba authored Apr 15, 2019
2 parents 5538128 + 53e285f commit 53e5da1
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 102 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ virtualenv
*.sw*
.cache/
.tox/
.hypothesis/
1 change: 0 additions & 1 deletion pierone/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,6 @@ def parse_pierone_artifact_dict(original_payload_from_api, team, artifact) -> di
parsed_dict = {
"status": "Not Processed",
"status_reason": "Not Processed",
"trusted": None
}
parsed_dict.update(original_payload_from_api)
parsed_dict['team'] = team
Expand Down
52 changes: 0 additions & 52 deletions pierone/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ def tags(config, team: str, artifact, url, output, limit):
"tag",
"created_time",
"created_by",
"trusted",
"status",
"status_reason",
],
Expand Down Expand Up @@ -365,57 +364,6 @@ def scm_source(config, team, artifact, tag, url, output):
max_column_widths={'revision': 10})


@cli.command('mark-trusted')
@click.argument('team', callback=validate_team)
@click.argument('artifact')
@click.argument('tag')
@url_option
@output_option
@click.pass_obj
def mark_trusted(config, team, artifact, tag, url, output):
'''Mark untrusted image as trusted in Docker Registry'''
set_pierone_url(config, url)
token = get_token()

tags = get_tags(config.get('url'), team, artifact, token)

if not tags:
raise click.UsageError('Artifact or Team does not exist! '
'Please double check for spelling mistakes.')

if tag not in [t['name'] for t in tags]:
raise click.UsageError('Provided Tag does not exist!'
'Please double check for spelling mistakes.')

r = request(config.get('url'), '/teams/{}/artifacts/{}/tags/{}/scm-source'.format(team, artifact, tag),
token, True)
if r is None:
raise click.ClickException('No SCM source available for tag, cannot mark as trusted.')
else:
row = r.json()
tag_info = [d for d in tags if d['name'] == tag][0]
row['tag'] = tag
row['created_by'] = tag_info['created_by']
row['created_time'] = parse_time(tag_info['created'])

with OutputFormat(output):
print_table(['tag', 'author', 'url', 'revision', 'status', 'created_time', 'created_by', 'valid'], [row],
titles={'tag': 'Tag', 'created_by': 'By', 'created_time': 'Created',
'url': 'URL', 'revision': 'Revision', 'status': 'Status', 'valid': 'Valid'},)

valid = row.get('valid')

if not valid:
raise click.ClickException('SCM source information is not valid, cannot mark as trusted.')
else:
if click.confirm('Do you want to mark this image as trusted?'):
request(config.get('url'), '/teams/{}/artifacts/{}/tags/{}/approval'.format(team, artifact, tag),
access_token=token, method='POST', data=None)
click.secho('Marked image as trusted.', fg='green')
else:
click.secho('Canceled.', fg='red')


@cli.command('image')
@click.argument('image')
@url_option
Expand Down
49 changes: 0 additions & 49 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,56 +343,7 @@ def test_tags(monkeypatch, tmpdir, mock_pierone_api):
result = runner.invoke(cli, ['tags', 'myteam', 'myart'], catch_exceptions=False)
assert '1.0' in result.output

def test_mark_trusted(monkeypatch, tmpdir):
tags = [{"clair_details": None,
"clair_id": "",
"created": "2018-06-25T14:14:47.403Z",
"created_by": "mmagoo",
"image": "sha256:519e452a96550dc5d900270d34e453f0395f404c69b26bf87f3347a410a07cfe",
"name": "1",
"severity_fix_available": None,
"severity_no_fix_available": None,
"trusted": False}]

trust_response = MagicMock()
trust_response.raise_for_status = lambda : True
runner = CliRunner()
monkeypatch.setattr('stups_cli.config.load_config', lambda x: {'url': 'foobar'})
monkeypatch.setattr('zign.api.get_token', MagicMock(return_value='tok123'))
monkeypatch.setattr('os.path.expanduser', lambda x: x.replace('~', str(tmpdir)))
monkeypatch.setattr('pierone.cli.get_tags', MagicMock(return_value=[]))
with runner.isolated_filesystem():
result = runner.invoke(cli, ['mark-trusted', 'foo', 'bar', '1'], catch_exceptions=False)
assert 'Artifact or Team does not exist! Please double check for spelling mistakes.' in result.output

scm_response = MagicMock()
scm_response.status_code = 404
monkeypatch.setattr('pierone.cli.get_tags', MagicMock(return_value=tags))
monkeypatch.setattr('click.confirm', lambda x: True)
monkeypatch.setattr('pierone.api.session.request', MagicMock(return_value=scm_response))

with runner.isolated_filesystem():
result = runner.invoke(cli, ['mark-trusted', 'foo', 'bar', '1'], catch_exceptions=False)
assert 'No SCM source available for tag, cannot mark as trusted.' in result.output


scm_response.status_code = 200
scm_response.json.return_value = {"author": "mmagoo",
"created": "2017-11-29T09:56:43.803Z",
"revision": "cs5f25c658a246f836c9fe9fbb01c2c106e066db",
"status": "",
"valid": True,
"url": "git:[email protected]:continuous-delivery/cdp-controller.git"}

monkeypatch.setattr('pierone.api.session.request', MagicMock(return_value=scm_response))
monkeypatch.setattr('pierone.api.session.request', MagicMock(return_value=trust_response))
with runner.isolated_filesystem():
result = runner.invoke(cli, ['mark-trusted', 'foo', 'bar', '1'], catch_exceptions=False)
assert 'Marked image as trusted.' in result.output


def test_tags_versions_limit(monkeypatch, tmpdir, mock_pierone_api):

runner = CliRunner()
monkeypatch.setattr('stups_cli.config.load_config', lambda x: {'url': 'foobar'})
monkeypatch.setattr('zign.api.get_token', MagicMock(return_value='tok123'))
Expand Down

0 comments on commit 53e5da1

Please sign in to comment.