Merge pull request #2309 from caguado/fix/2308
Implement update_user_pool_domain
This commit is contained in:
commit
d1e057ecab
4 changed files with 94 additions and 15 deletions
|
|
@ -2,6 +2,7 @@ from __future__ import unicode_literals
|
|||
|
||||
import datetime
|
||||
import functools
|
||||
import hashlib
|
||||
import itertools
|
||||
import json
|
||||
import os
|
||||
|
|
@ -154,20 +155,37 @@ class CognitoIdpUserPool(BaseModel):
|
|||
|
||||
class CognitoIdpUserPoolDomain(BaseModel):
|
||||
|
||||
def __init__(self, user_pool_id, domain):
|
||||
def __init__(self, user_pool_id, domain, custom_domain_config=None):
|
||||
self.user_pool_id = user_pool_id
|
||||
self.domain = domain
|
||||
self.custom_domain_config = custom_domain_config or {}
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
"UserPoolId": self.user_pool_id,
|
||||
"AWSAccountId": str(uuid.uuid4()),
|
||||
"CloudFrontDistribution": None,
|
||||
"Domain": self.domain,
|
||||
"S3Bucket": None,
|
||||
"Status": "ACTIVE",
|
||||
"Version": None,
|
||||
}
|
||||
def _distribution_name(self):
|
||||
if self.custom_domain_config and \
|
||||
'CertificateArn' in self.custom_domain_config:
|
||||
hash = hashlib.md5(
|
||||
self.custom_domain_config['CertificateArn'].encode('utf-8')
|
||||
).hexdigest()
|
||||
return "{hash}.cloudfront.net".format(hash=hash[:16])
|
||||
return None
|
||||
|
||||
def to_json(self, extended=True):
|
||||
distribution = self._distribution_name()
|
||||
if extended:
|
||||
return {
|
||||
"UserPoolId": self.user_pool_id,
|
||||
"AWSAccountId": str(uuid.uuid4()),
|
||||
"CloudFrontDistribution": distribution,
|
||||
"Domain": self.domain,
|
||||
"S3Bucket": None,
|
||||
"Status": "ACTIVE",
|
||||
"Version": None,
|
||||
}
|
||||
elif distribution:
|
||||
return {
|
||||
"CloudFrontDomain": distribution,
|
||||
}
|
||||
return None
|
||||
|
||||
|
||||
class CognitoIdpUserPoolClient(BaseModel):
|
||||
|
|
@ -338,11 +356,13 @@ class CognitoIdpBackend(BaseBackend):
|
|||
del self.user_pools[user_pool_id]
|
||||
|
||||
# User pool domain
|
||||
def create_user_pool_domain(self, user_pool_id, domain):
|
||||
def create_user_pool_domain(self, user_pool_id, domain, custom_domain_config=None):
|
||||
if user_pool_id not in self.user_pools:
|
||||
raise ResourceNotFoundError(user_pool_id)
|
||||
|
||||
user_pool_domain = CognitoIdpUserPoolDomain(user_pool_id, domain)
|
||||
user_pool_domain = CognitoIdpUserPoolDomain(
|
||||
user_pool_id, domain, custom_domain_config=custom_domain_config
|
||||
)
|
||||
self.user_pool_domains[domain] = user_pool_domain
|
||||
return user_pool_domain
|
||||
|
||||
|
|
@ -358,6 +378,14 @@ class CognitoIdpBackend(BaseBackend):
|
|||
|
||||
del self.user_pool_domains[domain]
|
||||
|
||||
def update_user_pool_domain(self, domain, custom_domain_config):
|
||||
if domain not in self.user_pool_domains:
|
||||
raise ResourceNotFoundError(domain)
|
||||
|
||||
user_pool_domain = self.user_pool_domains[domain]
|
||||
user_pool_domain.custom_domain_config = custom_domain_config
|
||||
return user_pool_domain
|
||||
|
||||
# User pool client
|
||||
def create_user_pool_client(self, user_pool_id, extended_config):
|
||||
user_pool = self.user_pools.get(user_pool_id)
|
||||
|
|
|
|||
|
|
@ -50,7 +50,13 @@ class CognitoIdpResponse(BaseResponse):
|
|||
def create_user_pool_domain(self):
|
||||
domain = self._get_param("Domain")
|
||||
user_pool_id = self._get_param("UserPoolId")
|
||||
cognitoidp_backends[self.region].create_user_pool_domain(user_pool_id, domain)
|
||||
custom_domain_config = self._get_param("CustomDomainConfig")
|
||||
user_pool_domain = cognitoidp_backends[self.region].create_user_pool_domain(
|
||||
user_pool_id, domain, custom_domain_config
|
||||
)
|
||||
domain_description = user_pool_domain.to_json(extended=False)
|
||||
if domain_description:
|
||||
return json.dumps(domain_description)
|
||||
return ""
|
||||
|
||||
def describe_user_pool_domain(self):
|
||||
|
|
@ -69,6 +75,17 @@ class CognitoIdpResponse(BaseResponse):
|
|||
cognitoidp_backends[self.region].delete_user_pool_domain(domain)
|
||||
return ""
|
||||
|
||||
def update_user_pool_domain(self):
|
||||
domain = self._get_param("Domain")
|
||||
custom_domain_config = self._get_param("CustomDomainConfig")
|
||||
user_pool_domain = cognitoidp_backends[self.region].update_user_pool_domain(
|
||||
domain, custom_domain_config
|
||||
)
|
||||
domain_description = user_pool_domain.to_json(extended=False)
|
||||
if domain_description:
|
||||
return json.dumps(domain_description)
|
||||
return ""
|
||||
|
||||
# User pool client
|
||||
def create_user_pool_client(self):
|
||||
user_pool_id = self.parameters.pop("UserPoolId")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue