-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(site launch): Allow for ops to remove timed out domain associations #720
Changes from all commits
c91c827
8a4b377
2d578ec
c9a8315
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,7 +11,9 @@ import logger from "@logger/logger" | |
import { Deployment, Launch, Repo, User, Redirection } from "@database/models" | ||
import { RedirectionTypes } from "@root/constants/constants" | ||
import { AmplifyError } from "@root/types/index" | ||
import LaunchClient from "@services/identity/LaunchClient" | ||
import LaunchClient, { | ||
isAmplifyDomainNotFoundException, | ||
} from "@services/identity/LaunchClient" | ||
|
||
export type SiteLaunchCreateParams = { | ||
userId: number | ||
|
@@ -159,6 +161,41 @@ export class LaunchesService { | |
throw siteIdResult.error | ||
} | ||
|
||
try { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrapped in a try catch since AmplifySDK will throw an (expected) not found error, which is still the happy path |
||
// Check if association already exists | ||
const getDomainAssociationCommandInput = this.launchClient.createGetDomainAssociationCommandInput( | ||
appIdResult.value, | ||
domainName | ||
) | ||
|
||
const getDomainAssociationResult = await this.launchClient.sendGetDomainAssociationCommand( | ||
getDomainAssociationCommandInput | ||
) | ||
const hasDomainAssociationFailed = | ||
getDomainAssociationResult?.domainAssociation?.domainStatus === "FAILED" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Refer here for types of domain association result |
||
if (hasDomainAssociationFailed) { | ||
// safe to delete and retry | ||
const deleteDomainAssociationCommandInput = this.launchClient.createDeleteDomainAssociationCommandInput( | ||
appIdResult.value, | ||
domainName | ||
) | ||
await this.launchClient.sendDeleteDomainAssociationCommand( | ||
deleteDomainAssociationCommandInput | ||
) | ||
} | ||
} catch (error: unknown) { | ||
const isExpectedNotFoundError = isAmplifyDomainNotFoundException(error) | ||
if (!isExpectedNotFoundError) { | ||
return err( | ||
new AmplifyError( | ||
`Unable to connect to Amplify for: ${repoName}, ${error}`, | ||
repoName, | ||
appIdResult.value | ||
) | ||
) | ||
} | ||
} | ||
|
||
const launchAppOptions = this.launchClient.createDomainAssociationCommandInput( | ||
appIdResult.value, | ||
domainName, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mocks the behaviour of the real amplify client and throws an exception if domain hasnt been created yet