Skip to content
This repository has been archived by the owner on Sep 2, 2022. It is now read-only.

Commit

Permalink
fix custom cluster deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
timsuchanek committed Mar 14, 2019
1 parent 1071f8b commit 337a352
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 15 deletions.
12 changes: 8 additions & 4 deletions cli/packages/prisma-cli-engine/src/Client/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,18 @@ export class Client {
if (!process.env.PRISMA_MANAGEMENT_API_SECRET) {
throw new Error(
`Server at ${chalk.bold(
this.env.activeCluster.name
)
} requires the Management API secret. Please set the the ${chalk.bold('PRISMA_MANAGEMENT_API_SECRET')} environment variable.
this.env.activeCluster.name,
)} requires the Management API secret. Please set the the ${chalk.bold(
'PRISMA_MANAGEMENT_API_SECRET',
)} environment variable.
Learn more about this error in the docs: https://bit.ly/authentication-and-security-docs`,
)
} else {
throw new Error(
`Can not authenticate against Prisma server. It seems that your ${chalk.bold('PRISMA_MANAGEMENT_API_SECRET')} environment variable is set incorrectly. Please make sure that it matches the value that was used when the Prisma server was deployed.
`Can not authenticate against Prisma server. It seems that your ${chalk.bold(
'PRISMA_MANAGEMENT_API_SECRET',
)} environment variable is set incorrectly. Please make sure that it matches the value that was used when the Prisma server was deployed.
For more info visit: https://bit.ly/authentication-and-security-docs`,
)
Expand Down Expand Up @@ -505,6 +508,7 @@ export class Client {
serviceName: string,
stageName: string,
): Promise<string> {
debug('Calling generateClusterToken')
const query = `
mutation ($input: GenerateClusterTokenRequest!) {
generateClusterToken(input: $input) {
Expand Down
4 changes: 2 additions & 2 deletions cli/packages/prisma-yml/src/PrismaDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,9 +229,9 @@ and execute ${chalk.bold.green(
const {
clusterName,
clusterBaseUrl,
shared,
isPrivate,
local,
shared,
workspaceSlug,
} = data

Expand All @@ -253,7 +253,7 @@ and execute ${chalk.bold.green(
local,
shared,
isPrivate,
workspaceSlug,
workspaceSlug!,
)
}

Expand Down
20 changes: 12 additions & 8 deletions cli/packages/prisma-yml/src/utils/parseEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ function getClusterName(origin): string {
return 'default'
}

const getWorkspaceFromPrivateOrigin = (origin: string) =>
origin.split('_')[1].split('.')[0]
const getWorkspaceFromPrivateOrigin = (origin: string) => {
const split = origin.split('_')
if (split.length > 1) {
return split[1].split('.')[0]
}

return null
}

const isLocal = origin =>
origin.includes('localhost') || origin.includes('127.0.0.1')
Expand All @@ -30,28 +36,26 @@ export interface ParseEndpointResult {
isPrivate: boolean
local: boolean
shared: boolean
workspaceSlug: string | undefined
workspaceSlug: string | null
clusterName: string
}

export function parseEndpoint(endpoint: string): ParseEndpointResult {
const url = new URL(endpoint)
const splittedPath = url.pathname.split('/')
const shared = ['eu1.prisma.sh', 'us2.prisma.sh'].includes(url.host)
const isPrivate =
!shared &&
url.host.endsWith('prisma.sh') &&
!url.host.endsWith('db.cloud.prisma.sh')
const isPrivate = !shared && !url.host.endsWith('db.cloud.prisma.sh')
const local = !shared && !isPrivate
// assuming, that the pathname always starts with a leading /, we always can ignore the first element of the split array
const service =
splittedPath.length > 3 ? splittedPath[2] : splittedPath[1] || 'default'
const stage =
splittedPath.length > 3 ? splittedPath[3] : splittedPath[2] || 'default'
let workspaceSlug = splittedPath.length > 3 ? splittedPath[1] : undefined
let workspaceSlug = splittedPath.length > 3 ? splittedPath[1] : null
if (isPrivate && !workspaceSlug) {
workspaceSlug = getWorkspaceFromPrivateOrigin(url.origin)
}

return {
clusterBaseUrl: url.origin,
service,
Expand Down
1 change: 0 additions & 1 deletion cli/packages/prisma-yml/src/yaml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export async function readDefinition(
: validate(populatedJson)
// TODO activate as soon as the backend sends valid yaml
if (!valid) {
debugger
let errorMessage =
`Invalid prisma.yml file` +
'\n' +
Expand Down

0 comments on commit 337a352

Please sign in to comment.