Skip to content
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

Fix/privatisation quickie interaction #1094

Merged
merged 3 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/services/configServices/SettingsService.js
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,14 @@ class SettingsService {
// only when changing from public to private - not awaited as this is slow and non-blocking
privatiseNetlifySite(siteName, password)
}
const updatePasswordResp = await this.deploymentsService.updateAmplifyPassword(
siteName,
password,
enablePassword
)
if (updatePasswordResp.isErr()) {
return updatePasswordResp
}
if (isPrivate !== enablePassword) {
// For public -> private or private -> public, we also need to update the repo privacy on github
const privatiseRepoRes = await this.gitHubService.changeRepoPrivacy(
Expand All @@ -189,11 +197,7 @@ class SettingsService {
return errAsync(err)
}
}
return this.deploymentsService.updateAmplifyPassword(
siteName,
password,
enablePassword
)
return updatePasswordResp
}

shouldUpdateHomepage(updatedConfigContent, configContent) {
Expand Down
12 changes: 8 additions & 4 deletions src/services/identity/DeploymentClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,23 @@ class DeploymentClient {
},
})

generateDeletePasswordInput = (appId: string): UpdateBranchCommandInput => ({
generateDeletePasswordInput = (
appId: string,
branchName = "staging"
): UpdateBranchCommandInput => ({
appId,
branchName: "staging",
branchName,
enableBasicAuth: false,
basicAuthCredentials: "",
})

generateUpdatePasswordInput = (
appId: string,
password: string
password: string,
branchName = "staging"
): UpdateBranchCommandInput => ({
appId,
branchName: "staging",
branchName,
enableBasicAuth: true,
basicAuthCredentials: Buffer.from(`user:${password}`).toString("base64"),
})
Expand Down
44 changes: 40 additions & 4 deletions src/services/identity/DeploymentsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ class DeploymentsService {
return okAsync(deploymentInfo)
}

deletePassword = async (appId: string, deploymentId: number) => {
deletePassword = async (
appId: string,
deploymentId: number,
isStagingLite: boolean
) => {
const updateAppInput = this.deploymentClient.generateDeletePasswordInput(
appId
appId,
isStagingLite ? "staging-lite" : "staging"
)
const updateResp = await this.deploymentClient.sendUpdateApp(updateAppInput)

Expand Down Expand Up @@ -249,9 +254,22 @@ class DeploymentsService {
return errAsync(
new NotFoundError(`Deployment for site ${repoName} does not exist`)
)
const { id, hostingId: appId } = deploymentInfo
const {
id,
hostingId: appId,
stagingLiteHostingId: stagingLiteId,
} = deploymentInfo

if (!enablePassword) return this.deletePassword(appId, id)
if (!enablePassword) {
const stagingRes = await this.deletePassword(appId, id, false)
if (!stagingLiteId || stagingRes.isErr()) return stagingRes
const stagingLiteRes = await this.deletePassword(stagingLiteId, id, true)
if (stagingLiteRes.isErr())
logger.error(
`Privatisation adjustment failed for ${repoName} - requires manual fixing of inconsistent state`
)
Comment on lines +268 to +270
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have an alarm for this? otherwise, we won't know when this occurs until someone feedsback to us, rendering this log moot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return stagingLiteRes
}

const {
encryptedPassword: oldEncryptedPassword,
Expand All @@ -273,6 +291,24 @@ class DeploymentsService {
return updateResp
}

if (stagingLiteId) {
const updateStagingLiteInput = this.deploymentClient.generateUpdatePasswordInput(
stagingLiteId,
password,
"staging-lite"
)

const updateStagingLiteResp = await this.deploymentClient.sendUpdateApp(
updateStagingLiteInput
)
if (updateStagingLiteResp.isErr()) {
logger.error(
`Privatisation adjustment failed for ${repoName} - requires manual fixing of inconsistent state`
)
return updateStagingLiteResp
}
}

const { encryptedPassword, iv } = encryptPassword(password, SECRET_KEY)
await this.deploymentsRepository.update(
{
Expand Down
23 changes: 17 additions & 6 deletions src/services/identity/SitesService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,19 +327,30 @@ class SitesService {
return okAsync(site.deployment)
}

// Privatisation has priority over growthbook - if private, automatically use staging
const isPrivateSiteSyncedWithDb =
site.isPrivate && site?.deployment?.stagingUrl.includes("staging.")

const featureFlagSyncedWithDb =
(isReduceBuildTimesWhitelistedRepo(sessionData.growthbook) &&
!site.isPrivate &&
((isReduceBuildTimesWhitelistedRepo(sessionData.growthbook) &&
site?.deployment?.stagingUrl.includes("staging-lite.")) ||
// useful for rollbacks
(!isReduceBuildTimesWhitelistedRepo(sessionData.growthbook) &&
site?.deployment?.stagingUrl.includes("staging."))
// useful for rollbacks
(!isReduceBuildTimesWhitelistedRepo(sessionData.growthbook) &&
site?.deployment?.stagingUrl.includes("staging.")))

if (featureFlagSyncedWithDb) {
if (isPrivateSiteSyncedWithDb || featureFlagSyncedWithDb) {
return okAsync(site.deployment)
}

let stagingUrl: StagingPermalink
if (isReduceBuildTimesWhitelistedRepo(sessionData.growthbook)) {
if (site.isPrivate) {
stagingUrl = Brand.fromString(
`https://staging.${site.deployment.hostingId}.amplifyapp.com`
)
} else if (
isReduceBuildTimesWhitelistedRepo(sessionData.growthbook)
) {
stagingUrl = Brand.fromString(
`https://staging-lite.${site.deployment.stagingLiteHostingId}.amplifyapp.com`
)
Expand Down
Loading