Skip to content

Commit

Permalink
chore: snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolk committed Jul 19, 2023
1 parent 0e67080 commit 301000c
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,38 +204,37 @@ async function createUserPoolDomain(domainName, userPoolId) {
await identity.createUserPoolDomain(params).promise();
}
async function createOrUpdateDomain(inputDomainName, userPoolId) {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
if (result.UserPool.Domain === inputDomainName) {
// if existing domain is same as input domain do nothing.
return;
}
if (inputDomainName) {
// create new or replace existing domain.
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
if (result.UserPool.Domain) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
} else if (result.UserPool.Domain) {
// if input domain is undefined delete existing domain if exists.
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
}
async function handleEvent(event, context) {
const userPoolId = event.ResourceProperties.userPoolId;
const inputDomainName = event.ResourceProperties.hostedUIDomainName;
try {
const userPoolId = event.ResourceProperties.userPoolId;
const inputDomainName = event.ResourceProperties.hostedUIDomainName;
if (event.RequestType === 'Delete') {
await deleteUserPoolDomain(inputDomainName, userPoolId);
} else if (event.RequestType === 'Update' || event.RequestType === 'Create') {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
if (inputDomainName) {
if (result.UserPool.Domain !== inputDomainName) {
if (!result.UserPool.Domain) {
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
} else {
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
}
}
} else {
if (result.UserPool.Domain) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
}
await createOrUpdateDomain(inputDomainName, userPoolId);
}
response.send(event, context, response.SUCCESS, {});
} catch (err) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,38 +191,37 @@ async function createUserPoolDomain(domainName, userPoolId) {
await identity.createUserPoolDomain(params).promise();
}
async function createOrUpdateDomain(inputDomainName, userPoolId) {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
if (result.UserPool.Domain === inputDomainName) {
// if existing domain is same as input domain do nothing.
return;
}
if (inputDomainName) {
// create new or replace existing domain.
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
if (result.UserPool.Domain) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
} else if (result.UserPool.Domain) {
// if input domain is undefined delete existing domain if exists.
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
}
async function handleEvent(event, context) {
const userPoolId = event.ResourceProperties.userPoolId;
const inputDomainName = event.ResourceProperties.hostedUIDomainName;
try {
const userPoolId = event.ResourceProperties.userPoolId;
const inputDomainName = event.ResourceProperties.hostedUIDomainName;
if (event.RequestType === 'Delete') {
await deleteUserPoolDomain(inputDomainName, userPoolId);
} else if (event.RequestType === 'Update' || event.RequestType === 'Create') {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
if (inputDomainName) {
if (result.UserPool.Domain !== inputDomainName) {
if (!result.UserPool.Domain) {
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
} else {
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
}
}
} else {
if (result.UserPool.Domain) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
}
await createOrUpdateDomain(inputDomainName, userPoolId);
}
response.send(event, context, response.SUCCESS, {});
} catch (err) {
Expand Down Expand Up @@ -429,38 +428,37 @@ async function createUserPoolDomain(domainName, userPoolId) {
await identity.createUserPoolDomain(params).promise();
}
async function createOrUpdateDomain(inputDomainName, userPoolId) {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
if (result.UserPool.Domain === inputDomainName) {
// if existing domain is same as input domain do nothing.
return;
}
if (inputDomainName) {
// create new or replace existing domain.
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
if (result.UserPool.Domain) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
} else if (result.UserPool.Domain) {
// if input domain is undefined delete existing domain if exists.
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
}
async function handleEvent(event, context) {
const userPoolId = event.ResourceProperties.userPoolId;
const inputDomainName = event.ResourceProperties.hostedUIDomainName;
try {
const userPoolId = event.ResourceProperties.userPoolId;
const inputDomainName = event.ResourceProperties.hostedUIDomainName;
if (event.RequestType === 'Delete') {
await deleteUserPoolDomain(inputDomainName, userPoolId);
} else if (event.RequestType === 'Update' || event.RequestType === 'Create') {
const result = await identity.describeUserPool({ UserPoolId: userPoolId }).promise();
if (inputDomainName) {
if (result.UserPool.Domain !== inputDomainName) {
if (!result.UserPool.Domain) {
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
} else {
const isDomainAvailable = await checkDomainAvailability(inputDomainName);
if (isDomainAvailable) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
await createUserPoolDomain(inputDomainName, userPoolId);
} else {
throw new Error('Domain not available');
}
}
}
} else {
if (result.UserPool.Domain) {
await deleteUserPoolDomain(result.UserPool.Domain, userPoolId);
}
}
await createOrUpdateDomain(inputDomainName, userPoolId);
}
response.send(event, context, response.SUCCESS, {});
} catch (err) {
Expand Down

0 comments on commit 301000c

Please sign in to comment.