Only output the AccessKey part

create
Simon Willison 2021-11-02 18:25:26 -07:00
rodzic 411358a5fa
commit 4cb848be9b
2 zmienionych plików z 6 dodań i 4 usunięć

Wyświetl plik

@ -159,7 +159,7 @@ def create(
UserName=username, UserName=username,
) )
log("Created access key for user: {}".format(username)) log("Created access key for user: {}".format(username))
click.echo(json.dumps(response, indent=4, default=str)) click.echo(json.dumps(response["AccessKey"], indent=4, default=str))
@cli.command() @cli.command()

Wyświetl plik

@ -43,8 +43,10 @@ def test_create(mocker):
boto3 = mocker.patch("boto3.client") boto3 = mocker.patch("boto3.client")
boto3.return_value = Mock() boto3.return_value = Mock()
boto3.return_value.create_access_key.return_value = { boto3.return_value.create_access_key.return_value = {
"Key": "key", "AccessKey": {
"Secret": "secret", "AccessKeyId": "access",
"SecretAccessKey": "secret",
}
} }
runner = CliRunner() runner = CliRunner()
with runner.isolated_filesystem(): with runner.isolated_filesystem():
@ -53,7 +55,7 @@ def test_create(mocker):
assert result.output == ( assert result.output == (
"Attached policy s3.read-write.pytest-bucket-simonw-1 to user s3.read-write.pytest-bucket-simonw-1\n" "Attached policy s3.read-write.pytest-bucket-simonw-1 to user s3.read-write.pytest-bucket-simonw-1\n"
"Created access key for user: s3.read-write.pytest-bucket-simonw-1\n" "Created access key for user: s3.read-write.pytest-bucket-simonw-1\n"
'{\n "Key": "key",\n "Secret": "secret"\n}\n' '{\n "AccessKeyId": "access",\n "SecretAccessKey": "secret"\n}\n'
) )
assert [str(c) for c in boto3.mock_calls] == [ assert [str(c) for c in boto3.mock_calls] == [
"call('s3')", "call('s3')",