Skip to content

Commit

Permalink
feat: assert that GAE versionUrl does not exceed 63 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
kirillgroshkov committed Jan 2, 2024
1 parent 75a10da commit a3714c2
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/deploy/deploy.util.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs'
import { _mapValues, _merge, _truncate, localTimeNow } from '@naturalcycles/js-lib'
import { _assert, _mapValues, _merge, _truncate, localTimeNow } from '@naturalcycles/js-lib'
import { dimGrey, white } from '@naturalcycles/nodejs-lib'
import yaml from 'js-yaml'
import { BackendCfg } from './backend.cfg.util'
Expand Down Expand Up @@ -79,6 +79,13 @@ export async function createDeployInfo(backendCfg: BackendCfg): Promise<DeployIn

const versionUrl = `https://${[gaeVersion, gaeService, gaeProject].join('-dot-')}.appspot.com`

// Check the 63-char limit
const versionUrlString = [gaeVersion, gaeService, gaeProject].join('-dot-')
_assert(
versionUrlString.length <= 63,
`versionUrl length should be <= 63 characters, but it's ${versionUrlString.length} instead: ${versionUrlString}`,
)

const serviceUrl = `https://${[gaeService, gaeProject].join('-dot-')}.appspot.com`

const deployInfo: DeployInfo = {
Expand Down Expand Up @@ -198,12 +205,9 @@ function redactedAppYaml(appYaml: AppYaml): AppYaml {

export function validateGAEServiceName(serviceName: string): string {
// May only contain lowercase letters, digits, and hyphens. Must begin and end with a letter or digit. Must not exceed 63 characters.
return replaceAll(serviceName, '_', '-')
return serviceName
.replaceAll('_', '-')
.toLowerCase()
.replaceAll(/[^0-9a-z-]/gi, '')
.slice(0, 40)
}

function replaceAll(str: string, search: string, replacement: string): string {
return str.split(search).join(replacement)
}

0 comments on commit a3714c2

Please sign in to comment.