adds basic implementation for describe-identity-pool
This commit is contained in:
parent
3a5d857a60
commit
1ae641fab8
15
moto/cognitoidentity/exceptions.py
Normal file
15
moto/cognitoidentity/exceptions.py
Normal file
@ -0,0 +1,15 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
import json
|
||||
|
||||
from werkzeug.exceptions import BadRequest
|
||||
|
||||
|
||||
class ResourceNotFoundError(BadRequest):
|
||||
|
||||
def __init__(self, message):
|
||||
super(ResourceNotFoundError, self).__init__()
|
||||
self.description = json.dumps({
|
||||
"message": message,
|
||||
'__type': 'ResourceNotFoundException',
|
||||
})
|
@ -8,7 +8,7 @@ import boto.cognito.identity
|
||||
from moto.compat import OrderedDict
|
||||
from moto.core import BaseBackend, BaseModel
|
||||
from moto.core.utils import iso_8601_datetime_with_milliseconds
|
||||
|
||||
from .exceptions import ResourceNotFoundError
|
||||
from .utils import get_random_identity_id
|
||||
|
||||
|
||||
@ -39,17 +39,36 @@ class CognitoIdentityBackend(BaseBackend):
|
||||
self.__dict__ = {}
|
||||
self.__init__(region)
|
||||
|
||||
def create_identity_pool(self, identity_pool_name, allow_unauthenticated_identities,
|
||||
supported_login_providers, developer_provider_name, open_id_connect_provider_arns,
|
||||
cognito_identity_providers, saml_provider_arns):
|
||||
def describe_identity_pool(self, identity_pool_id):
|
||||
identity_pool = self.identity_pools.get(identity_pool_id, None)
|
||||
|
||||
if not identity_pool:
|
||||
raise ResourceNotFoundError(identity_pool)
|
||||
|
||||
response = json.dumps({
|
||||
'AllowUnauthenticatedIdentities': identity_pool.allow_unauthenticated_identities,
|
||||
'CognitoIdentityProviders': identity_pool.cognito_identity_providers,
|
||||
'DeveloperProviderName': identity_pool.developer_provider_name,
|
||||
'IdentityPoolId': identity_pool.identity_pool_id,
|
||||
'IdentityPoolName': identity_pool.identity_pool_name,
|
||||
'IdentityPoolTags': {},
|
||||
'OpenIdConnectProviderARNs': identity_pool.open_id_connect_provider_arns,
|
||||
'SamlProviderARNs': identity_pool.saml_provider_arns,
|
||||
'SupportedLoginProviders': identity_pool.supported_login_providers
|
||||
})
|
||||
|
||||
return response
|
||||
|
||||
def create_identity_pool(self, identity_pool_name, allow_unauthenticated_identities,
|
||||
supported_login_providers, developer_provider_name, open_id_connect_provider_arns,
|
||||
cognito_identity_providers, saml_provider_arns):
|
||||
new_identity = CognitoIdentity(self.region, identity_pool_name,
|
||||
allow_unauthenticated_identities=allow_unauthenticated_identities,
|
||||
supported_login_providers=supported_login_providers,
|
||||
developer_provider_name=developer_provider_name,
|
||||
open_id_connect_provider_arns=open_id_connect_provider_arns,
|
||||
cognito_identity_providers=cognito_identity_providers,
|
||||
saml_provider_arns=saml_provider_arns)
|
||||
allow_unauthenticated_identities=allow_unauthenticated_identities,
|
||||
supported_login_providers=supported_login_providers,
|
||||
developer_provider_name=developer_provider_name,
|
||||
open_id_connect_provider_arns=open_id_connect_provider_arns,
|
||||
cognito_identity_providers=cognito_identity_providers,
|
||||
saml_provider_arns=saml_provider_arns)
|
||||
self.identity_pools[new_identity.identity_pool_id] = new_identity
|
||||
|
||||
response = json.dumps({
|
||||
@ -77,12 +96,12 @@ class CognitoIdentityBackend(BaseBackend):
|
||||
response = json.dumps(
|
||||
{
|
||||
"Credentials":
|
||||
{
|
||||
"AccessKeyId": "TESTACCESSKEY12345",
|
||||
"Expiration": expiration_str,
|
||||
"SecretKey": "ABCSECRETKEY",
|
||||
"SessionToken": "ABC12345"
|
||||
},
|
||||
{
|
||||
"AccessKeyId": "TESTACCESSKEY12345",
|
||||
"Expiration": expiration_str,
|
||||
"SecretKey": "ABCSECRETKEY",
|
||||
"SessionToken": "ABC12345"
|
||||
},
|
||||
"IdentityId": identity_id
|
||||
})
|
||||
return response
|
||||
|
@ -1,7 +1,6 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from moto.core.responses import BaseResponse
|
||||
|
||||
from .models import cognitoidentity_backends
|
||||
from .utils import get_random_identity_id
|
||||
|
||||
@ -16,6 +15,7 @@ class CognitoIdentityResponse(BaseResponse):
|
||||
open_id_connect_provider_arns = self._get_param('OpenIdConnectProviderARNs')
|
||||
cognito_identity_providers = self._get_param('CognitoIdentityProviders')
|
||||
saml_provider_arns = self._get_param('SamlProviderARNs')
|
||||
|
||||
return cognitoidentity_backends[self.region].create_identity_pool(
|
||||
identity_pool_name=identity_pool_name,
|
||||
allow_unauthenticated_identities=allow_unauthenticated_identities,
|
||||
@ -28,6 +28,9 @@ class CognitoIdentityResponse(BaseResponse):
|
||||
def get_id(self):
|
||||
return cognitoidentity_backends[self.region].get_id()
|
||||
|
||||
def describe_identity_pool(self):
|
||||
return cognitoidentity_backends[self.region].describe_identity_pool(self._get_param('IdentityPoolId'))
|
||||
|
||||
def get_credentials_for_identity(self):
|
||||
return cognitoidentity_backends[self.region].get_credentials_for_identity(self._get_param('IdentityId'))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user