Skip to content

Commit

Permalink
chore: split delete path into separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderleegs committed Jun 27, 2023
1 parent 592ab87 commit f13e3f2
Showing 1 changed file with 48 additions and 39 deletions.
87 changes: 48 additions & 39 deletions src/services/identity/DeploymentsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,26 @@ class DeploymentsService {
return okAsync(deploymentInfo)
}

deletePassword = async (appId: string, deploymentId: number) => {
const updateAppInput = this.deploymentClient.generateDeletePasswordInput(
appId
)
const updateResp = await this.deploymentClient.sendUpdateApp(updateAppInput)

if (updateResp.isErr()) {
return updateResp
}
await this.repository.update(
{
encryptedPassword: null,
encryptionIv: null,
passwordDate: null,
},
{ where: { id: deploymentId } }
)
return updateResp
}

updateAmplifyPassword = async (
repoName: string,
password: string,
Expand All @@ -155,49 +175,38 @@ class DeploymentsService {
if (!deploymentInfo)
return errAsync(`Deployment for ${repoName} does not exist`)
const { id, hostingId: appId } = deploymentInfo
let updateAppInput
if (!enablePassword) {
updateAppInput = this.deploymentClient.generateDeletePasswordInput(appId)
} else {
const {
encryptedPassword: oldEncryptedPassword,
encryptionIv: oldIv,
} = deploymentInfo
if (
!!oldEncryptedPassword &&
decryptPassword(oldEncryptedPassword, oldIv) === oldEncryptedPassword
)
return okAsync("")
updateAppInput = this.deploymentClient.generateUpdatePasswordInput(
appId,
password
)
}
const updateResp = await this.deploymentClient.sendUpdateApp(updateAppInput)

if (!enablePassword) return this.deletePassword(appId, id)

const {
encryptedPassword: oldEncryptedPassword,
encryptionIv: oldIv,
} = deploymentInfo
if (
!!oldEncryptedPassword &&
decryptPassword(oldEncryptedPassword, oldIv) === oldEncryptedPassword
)
return okAsync("")
const updateAppInput = this.deploymentClient.generateUpdatePasswordInput(
appId,
password
)

const updateResp = await this.deploymentClient.sendUpdateApp(updateAppInput)
if (updateResp.isErr()) {
return updateResp
}
if (!enablePassword) {
await this.repository.update(
{
encryptedPassword: null,
encryptionIv: null,
passwordDate: null,
},
{ where: { id } }
)
} else {
const { encryptedPassword, iv } = encryptPassword(password)
await this.repository.update(
{
encryptedPassword,
encryptionIv: iv,
passwordDate: new Date(),
},
{ where: { id } }
)
}

const { encryptedPassword, iv } = encryptPassword(password)
await this.repository.update(
{
encryptedPassword,
encryptionIv: iv,
passwordDate: new Date(),
},
{ where: { id } }
)

return updateResp
}
}
Expand Down

0 comments on commit f13e3f2

Please sign in to comment.