Merge pull request #1023 from william-richard/add-ecr-get-authorization-token
Add ecr get_authorization_token response and tests
This commit is contained in:
commit
4028fe1abd
@ -1,12 +1,14 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import json
|
import json
|
||||||
|
from base64 import b64encode
|
||||||
|
from datetime import datetime
|
||||||
|
import time
|
||||||
|
|
||||||
from moto.core.responses import BaseResponse
|
from moto.core.responses import BaseResponse
|
||||||
from .models import ecr_backends
|
from .models import ecr_backends
|
||||||
|
|
||||||
|
|
||||||
class ECRResponse(BaseResponse):
|
class ECRResponse(BaseResponse):
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def ecr_backend(self):
|
def ecr_backend(self):
|
||||||
return ecr_backends[self.region]
|
return ecr_backends[self.region]
|
||||||
@ -111,9 +113,19 @@ class ECRResponse(BaseResponse):
|
|||||||
'ECR.generate_presigned_url is not yet implemented')
|
'ECR.generate_presigned_url is not yet implemented')
|
||||||
|
|
||||||
def get_authorization_token(self):
|
def get_authorization_token(self):
|
||||||
if self.is_not_dryrun('GetAuthorizationToken'):
|
registry_ids = self._get_param('registryIds')
|
||||||
raise NotImplementedError(
|
if not registry_ids:
|
||||||
'ECR.get_authorization_token is not yet implemented')
|
registry_ids = [self.region]
|
||||||
|
auth_data = []
|
||||||
|
for registry_id in registry_ids:
|
||||||
|
password = '{}-auth-token'.format(registry_id)
|
||||||
|
auth_token = b64encode("AWS:{}".format(password).encode('ascii')).decode()
|
||||||
|
auth_data.append({
|
||||||
|
'authorizationToken': auth_token,
|
||||||
|
'expiresAt': time.mktime(datetime(2015, 1, 1).timetuple()),
|
||||||
|
'proxyEndpoint': 'https://012345678910.dkr.ecr.{}.amazonaws.com'.format(registry_id)
|
||||||
|
})
|
||||||
|
return json.dumps({'authorizationData': auth_data})
|
||||||
|
|
||||||
def get_download_url_for_layer(self):
|
def get_download_url_for_layer(self):
|
||||||
if self.is_not_dryrun('GetDownloadUrlForLayer'):
|
if self.is_not_dryrun('GetDownloadUrlForLayer'):
|
||||||
|
@ -2,11 +2,13 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
import json
|
import json
|
||||||
|
from datetime import datetime
|
||||||
from random import random
|
from random import random
|
||||||
|
|
||||||
import sure # noqa
|
import sure # noqa
|
||||||
|
|
||||||
import boto3
|
import boto3
|
||||||
|
from dateutil.tz import tzlocal
|
||||||
|
|
||||||
from moto import mock_ecr
|
from moto import mock_ecr
|
||||||
|
|
||||||
@ -368,3 +370,39 @@ def test_describe_images_by_digest():
|
|||||||
image_detail['repositoryName'].should.equal("test_repository")
|
image_detail['repositoryName'].should.equal("test_repository")
|
||||||
image_detail['imageTags'].should.equal([put_response['imageId']['imageTag']])
|
image_detail['imageTags'].should.equal([put_response['imageId']['imageTag']])
|
||||||
image_detail['imageDigest'].should.equal(digest)
|
image_detail['imageDigest'].should.equal(digest)
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ecr
|
||||||
|
def test_get_authorization_token_assume_region():
|
||||||
|
client = boto3.client('ecr', region_name='us-east-1')
|
||||||
|
auth_token_response = client.get_authorization_token()
|
||||||
|
|
||||||
|
list(auth_token_response.keys()).should.equal(['authorizationData', 'ResponseMetadata'])
|
||||||
|
auth_token_response['authorizationData'].should.equal([
|
||||||
|
{
|
||||||
|
'authorizationToken': 'QVdTOnVzLWVhc3QtMS1hdXRoLXRva2Vu',
|
||||||
|
'proxyEndpoint': 'https://012345678910.dkr.ecr.us-east-1.amazonaws.com',
|
||||||
|
'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal())
|
||||||
|
},
|
||||||
|
])
|
||||||
|
|
||||||
|
|
||||||
|
@mock_ecr
|
||||||
|
def test_get_authorization_token_explicit_regions():
|
||||||
|
client = boto3.client('ecr', region_name='us-east-1')
|
||||||
|
auth_token_response = client.get_authorization_token(registryIds=['us-east-1', 'us-west-1'])
|
||||||
|
|
||||||
|
list(auth_token_response.keys()).should.equal(['authorizationData', 'ResponseMetadata'])
|
||||||
|
auth_token_response['authorizationData'].should.equal([
|
||||||
|
{
|
||||||
|
'authorizationToken': 'QVdTOnVzLWVhc3QtMS1hdXRoLXRva2Vu',
|
||||||
|
'proxyEndpoint': 'https://012345678910.dkr.ecr.us-east-1.amazonaws.com',
|
||||||
|
'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal()),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'authorizationToken': 'QVdTOnVzLXdlc3QtMS1hdXRoLXRva2Vu',
|
||||||
|
'proxyEndpoint': 'https://012345678910.dkr.ecr.us-west-1.amazonaws.com',
|
||||||
|
'expiresAt': datetime(2015, 1, 1, tzinfo=tzlocal())
|
||||||
|
|
||||||
|
}
|
||||||
|
])
|
||||||
|
Loading…
Reference in New Issue
Block a user