This commit is contained in:
Stephan Huber 2018-05-09 09:20:48 +02:00
parent cb364eedc6
commit ecbaf76413
2 changed files with 9 additions and 9 deletions

View File

@ -5,7 +5,7 @@ from datetime import datetime
import time import time
from moto.core.responses import BaseResponse from moto.core.responses import BaseResponse
from .models import ecr_backends from .models import ecr_backends, DEFAULT_REGISTRY_ID
class ECRResponse(BaseResponse): class ECRResponse(BaseResponse):
@ -120,7 +120,7 @@ class ECRResponse(BaseResponse):
def get_authorization_token(self): def get_authorization_token(self):
registry_ids = self._get_param('registryIds') registry_ids = self._get_param('registryIds')
if not registry_ids: if not registry_ids:
registry_ids = [self.region] registry_ids = [DEFAULT_REGISTRY_ID]
auth_data = [] auth_data = []
for registry_id in registry_ids: for registry_id in registry_ids:
password = '{}-auth-token'.format(registry_id) password = '{}-auth-token'.format(registry_id)
@ -128,7 +128,7 @@ class ECRResponse(BaseResponse):
auth_data.append({ auth_data.append({
'authorizationToken': auth_token, 'authorizationToken': auth_token,
'expiresAt': time.mktime(datetime(2015, 1, 1).timetuple()), 'expiresAt': time.mktime(datetime(2015, 1, 1).timetuple()),
'proxyEndpoint': 'https://012345678910.dkr.ecr.{}.amazonaws.com'.format(registry_id) 'proxyEndpoint': 'https://{}.dkr.ecr.{}.amazonaws.com'.format(registry_id, self.region)
}) })
return json.dumps({'authorizationData': auth_data}) return json.dumps({'authorizationData': auth_data})

View File

@ -418,7 +418,7 @@ def test_get_authorization_token_assume_region():
auth_token_response.should.contain('ResponseMetadata') auth_token_response.should.contain('ResponseMetadata')
auth_token_response['authorizationData'].should.equal([ auth_token_response['authorizationData'].should.equal([
{ {
'authorizationToken': 'QVdTOnVzLWVhc3QtMS1hdXRoLXRva2Vu', 'authorizationToken': 'QVdTOjAxMjM0NTY3ODkxMC1hdXRoLXRva2Vu',
'proxyEndpoint': 'https://012345678910.dkr.ecr.us-east-1.amazonaws.com', 'proxyEndpoint': 'https://012345678910.dkr.ecr.us-east-1.amazonaws.com',
'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal()) 'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal())
}, },
@ -428,19 +428,19 @@ def test_get_authorization_token_assume_region():
@mock_ecr @mock_ecr
def test_get_authorization_token_explicit_regions(): def test_get_authorization_token_explicit_regions():
client = boto3.client('ecr', region_name='us-east-1') client = boto3.client('ecr', region_name='us-east-1')
auth_token_response = client.get_authorization_token(registryIds=['us-east-1', 'us-west-1']) auth_token_response = client.get_authorization_token(registryIds=['10987654321', '878787878787'])
auth_token_response.should.contain('authorizationData') auth_token_response.should.contain('authorizationData')
auth_token_response.should.contain('ResponseMetadata') auth_token_response.should.contain('ResponseMetadata')
auth_token_response['authorizationData'].should.equal([ auth_token_response['authorizationData'].should.equal([
{ {
'authorizationToken': 'QVdTOnVzLWVhc3QtMS1hdXRoLXRva2Vu', 'authorizationToken': 'QVdTOjEwOTg3NjU0MzIxLWF1dGgtdG9rZW4=',
'proxyEndpoint': 'https://012345678910.dkr.ecr.us-east-1.amazonaws.com', 'proxyEndpoint': 'https://10987654321.dkr.ecr.us-east-1.amazonaws.com',
'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal()), 'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal()),
}, },
{ {
'authorizationToken': 'QVdTOnVzLXdlc3QtMS1hdXRoLXRva2Vu', 'authorizationToken': 'QVdTOjg3ODc4Nzg3ODc4Ny1hdXRoLXRva2Vu',
'proxyEndpoint': 'https://012345678910.dkr.ecr.us-west-1.amazonaws.com', 'proxyEndpoint': 'https://878787878787.dkr.ecr.us-east-1.amazonaws.com',
'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal()) 'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal())
} }