1+ CloudFormation do
2+
3+
4+ Cognito_UserPool :UserPool do
5+ UserPoolName pool_name
6+ AliasAttributes alias_attributes
7+ schema = user_schema . collect do |key , val |
8+ { Name : key ,
9+ AttributeDataType : val [ 'type' ] ,
10+ Mutable : val [ 'mutable' ] ,
11+ Required : val [ 'required' ] }
12+ end
13+
14+ Schema schema
15+
16+ end
17+
18+ if defined? domain_name and ( not domain_name . nil? )
19+ CloudFormation_CustomResource ( 'PoolDomainName' ) do
20+ ServiceToken FnGetAtt ( 'ccrCognitoDN' , 'Arn' )
21+ Property 'UserPoolId' , Ref ( :UserPool )
22+ Property 'Domain' , domain_name
23+ Property 'GenerateRandomIfNotAvailable' , 'true'
24+ end
25+
26+ Output ( 'PoolDomainUrl' ) do
27+ Value ( FnGetAtt ( 'PoolDomainName' , 'DomainFull' ) )
28+ end
29+ Output ( 'PoolDomainName' ) do
30+ Value ( FnGetAtt ( 'PoolDomainName' , 'Domain' ) )
31+ end
32+ end
33+
34+
35+ def user_pool_client ( name , config )
36+
37+ CloudFormation_CustomResource ( "PoolClient#{ name } " ) do
38+
39+ ServiceToken FnGetAtt ( 'ccrCognitoUPC' , 'Arn' )
40+
41+ Property 'UserPoolId' , Ref ( :UserPool )
42+ Property 'ClientName' , config [ 'name' ]
43+
44+ if config . key? 'generate_secret'
45+ Property 'GenerateSecret' , config [ 'generate_secret' ]
46+ end
47+
48+ if config . key? 'explicit_auth_flows'
49+ Property 'ExplicitAuthFlows' , config [ 'explicit_auth_flows' ]
50+ end
51+
52+ if config . key? 'callback_urls'
53+ Property 'CallbackURLs' , config [ 'callback_urls' ]
54+ end
55+
56+ if config . key? 'logout_urls'
57+ Property 'LogoutURLs' , config [ 'logout_urls' ]
58+ end
59+
60+ if config . key? 'default_redirect_uri'
61+ Property 'DefaultRedirectURI' , config [ 'default_redirect_uri' ]
62+ end
63+
64+ if config . key? 'read_attributes'
65+ Property 'ReadAttributes' , config [ 'read_attributes' ]
66+ end
67+
68+ if config . key? 'write_attributes'
69+ Property 'WriteAttributes' , config [ 'write_attributes' ]
70+ end
71+
72+ if config . key? 'refresh_token_validity'
73+ Property 'RefreshTokenValidity' , config [ 'refresh_token_validity' ]
74+ end
75+
76+ if config . key? 'allowed_oauth_flows_userpool_client'
77+ Property 'AllowedOAuthFlowsUserPoolClient' , config [ 'allowed_oauth_flows_userpool_client' ]
78+ end
79+
80+ if config . key? 'allowed_oauth_flows'
81+ Property 'AllowedOAuthFlows' , config [ 'allowed_oauth_flows' ]
82+ end
83+
84+ if config . key? 'allowed_oauth_scopes'
85+ Property 'AllowedOAuthScopes' , config [ 'allowed_oauth_scopes' ]
86+ end
87+
88+ if config . key? 'supported_identity_providers'
89+ Property 'SupportedIdentityProviders' , config [ 'supported_identity_providers' ]
90+ elsif config . key? 'allow_cognito_idp' and config [ 'allow_cognito_idp' ]
91+ Property 'SupportedIdentityProviders' , [ 'COGNITO' ]
92+ end
93+
94+ if config . key? 'skip_update'
95+ Property 'SkipUpdate' , config [ 'skip_update' ]
96+ end
97+
98+ end
99+
100+ Output ( "PoolClient#{ name } Id" ) do
101+ Value ( FnGetAtt ( "PoolClient#{ name } " , 'UserPoolClient.ClientId' ) )
102+ end
103+
104+ if ( config . key? 'generate_secret' ) and ( config [ 'generate_secret' ] )
105+ if config . key? 'output_secret' and config [ 'output_secret' ]
106+ Output ( "PoolClient#{ name } Secret" ) do
107+ Value ( FnGetAtt ( "PoolClient#{ name } " , 'UserPoolClient.ClientSecret' ) )
108+ end
109+ end
110+ end
111+
112+ end
113+
114+ def user_pool_group ( name , config )
115+ Cognito_UserPoolGroup ( "UserGroup#{ name } " ) do
116+
117+ GroupName config [ 'name' ]
118+ Description config [ 'description' ]
119+ Precedence config [ 'precedence' ] if config . key? 'precedence'
120+ UserPoolId Ref ( :UserPool )
121+ end
122+ end
123+
124+
125+ if defined? clients and ( not clients . nil? )
126+ clients . each do |key , config |
127+ user_pool_client ( key , config )
128+ end
129+ else
130+ user_pool_client ( :defaultPoolClient , default_client )
131+ end
132+
133+
134+ if defined? groups and ( not groups . nil? )
135+ groups . each do |key , config |
136+ user_pool_group ( key , config )
137+ end
138+ else
139+ user_pool_group ( :defaultUserGroup , default_user_group )
140+ end
141+
142+
143+ Output ( :UserPoolId ) do
144+ Value ( Ref ( :UserPool ) )
145+ end
146+
147+ Output ( :UserPoolArn ) do
148+ Value ( FnGetAtt ( :UserPool , 'Arn' ) )
149+ end
150+
151+ Output ( :UserPoolProviderURL ) do
152+ Value ( FnGetAtt ( :UserPool , 'ProviderURL' ) )
153+ end
154+
155+ Output ( :UserPoolProviderName ) do
156+ Value ( FnGetAtt ( :UserPool , 'ProviderName' ) )
157+ end
158+
159+ end
0 commit comments