Skip to content

Commit

Permalink
fix(enterprise): fixes to login & secrets logic
Browse files Browse the repository at this point in the history
  • Loading branch information
thsig authored and edvald committed Jun 24, 2020
1 parent 2602122 commit 2276044
Show file tree
Hide file tree
Showing 14 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion garden-service/src/cli/cli.ts
Expand Up @@ -55,7 +55,7 @@ import { AnalyticsHandler } from "../analytics/analytics"
import { defaultDotIgnoreFiles } from "../util/fs"
import { renderError } from "../logger/renderers"
import { getDefaultProfiler } from "../util/profiling"
import { BufferedEventStream } from "../cloud/buffered-event-stream"
import { BufferedEventStream } from "../enterprise/buffered-event-stream"

const OUTPUT_RENDERERS = {
json: (data: DeepPrimitiveMap) => {
Expand Down
11 changes: 5 additions & 6 deletions garden-service/src/commands/login.ts
Expand Up @@ -9,25 +9,24 @@
import { Command, CommandParams, CommandResult } from "./base"
import { printHeader } from "../logger/util"
import dedent = require("dedent")
import { login } from "../cloud/auth"
import { login } from "../enterprise/auth"
import { ConfigurationError } from "../exceptions"

export class LoginCommand extends Command {
name = "login"
help = "Log in to Garden Cloud."
hidden = true
noProject = true

description = dedent`
Logs you in to Garden Cloud. Subsequent commands will have access to platform features.
`

async action({ garden, log, headerLog }: CommandParams): Promise<CommandResult> {
printHeader(headerLog, "Login", "cloud")

if (garden.cloudDomain) {
await login(garden.cloudDomain, log)
if (!garden.cloudDomain) {
throw new ConfigurationError(`Error: Your project configuration does not specify a domain.`, {})
}

await login(garden.cloudDomain, log)
return {}
}
}
2 changes: 1 addition & 1 deletion garden-service/src/commands/logout.ts
Expand Up @@ -9,7 +9,7 @@
import { Command, CommandParams, CommandResult } from "./base"
import { printHeader } from "../logger/util"
import dedent = require("dedent")
import { clearAuthToken } from "../cloud/auth"
import { clearAuthToken } from "../enterprise/auth"

export class LogOutCommand extends Command {
name = "logout"
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/config/project.ts
Expand Up @@ -317,7 +317,7 @@ export const projectDocsSchema = () =>
domain: joi
.string()
.meta({ internal: true })
.description("The domain to use for cloud features. Should point to the API/backend hostname."),
.description("The domain to use for cloud features. Should point to the API/backend base URL."),
// Note: We provide a different schema below for actual validation, but need to define it this way for docs
// because joi.alternatives() isn't handled well in the doc generation.
environments: joi
Expand Down
Expand Up @@ -17,7 +17,7 @@ import getPort = require("get-port")
import { ClientAuthToken } from "../db/entities/client-auth-token"
import { LogEntry } from "../logger/log-entry"
import { got } from "../util/http"
import { RuntimeError } from "../exceptions"
import { RuntimeError, InternalError } from "../exceptions"

export const makeAuthHeader = (clientAuthToken: string) => ({ "x-access-auth-token": clientAuthToken })

Expand Down Expand Up @@ -53,6 +53,9 @@ export async function login(cloudDomain: string, log: LogEntry): Promise<string>
})
})
await server.close()
if (!newToken) {
throw new InternalError(`Error: Did not receive an auth token after logging in.`, {})
}
await saveAuthToken(newToken, log)
return newToken
}
Expand Down
Expand Up @@ -18,7 +18,7 @@ export async function getSecretsFromGardenCloud({
environmentName,
}: GetSecretsParams): Promise<StringMap> {
try {
const url = `${cloudDomain}/secrets/project/${projectId}/env/${environmentName}`
const url = `${cloudDomain}/secrets/projectUid/${projectId}/env/${environmentName}`
const headers = { "x-access-auth-token": clientAuthToken }
const res = await got(url, { headers }).json<GotResponse<any>>()
if (res && res["status"] === "success") {
Expand Down
Expand Up @@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { getSecretsFromGardenCloud } from "./garden-cloud/get-secret"
import { getSecretsFromGardenCloud } from "./garden/get-secret"
import { LogEntry } from "../../logger/log-entry"
import { StringMap } from "../../config/common"

Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/events.ts
Expand Up @@ -9,7 +9,7 @@
import { EventEmitter2 } from "eventemitter2"
import { ModuleVersion } from "./vcs/vcs"
import { TaskResult } from "./task-graph"
import { LogEntryEvent } from "./cloud/buffered-event-stream"
import { LogEntryEvent } from "./enterprise/buffered-event-stream"

/**
* This simple class serves as the central event bus for a Garden instance. Its function
Expand Down
8 changes: 4 additions & 4 deletions garden-service/src/garden.ts
Expand Up @@ -67,9 +67,9 @@ import { deline, naturalList } from "./util/string"
import { ensureConnected } from "./db/connection"
import { DependencyValidationGraph } from "./util/validate-dependencies"
import { Profile } from "./util/profiling"
import { readAuthToken, checkClientAuthToken } from "./cloud/auth"
import { readAuthToken, checkClientAuthToken } from "./enterprise/auth"
import { ResolveModuleTask, getResolvedModules } from "./tasks/resolve-module"
import { getSecrets } from "./cloud/secrets"
import { getSecrets } from "./enterprise/secrets"
import username from "username"
import { throwOnMissingSecretKeys } from "./template-string"
import { WorkflowConfig, WorkflowResource, WorkflowConfigMap, resolveWorkflowConfig } from "./config/workflow"
Expand Down Expand Up @@ -330,8 +330,8 @@ export class Garden {
if (!cloudDomain) {
errorMessages.push(deline`
${chalk.bold("project.domain")} is not set in your project-level ${chalk.bold("garden.yml")}. Make sure it
is set to the appropriate API backend endpoint (e.g. myusername-cloud-api.cloud.dev.garden.io, without an
http/https prefix).
is set to the appropriate API backend endpoint (e.g. http://myusername-cloud-api.cloud.dev.garden.io,
with an http/https prefix).
`)
}
if (!projectId) {
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/logger/logger.ts
Expand Up @@ -18,7 +18,7 @@ import { JsonTerminalWriter } from "./writers/json-terminal-writer"
import { parseLogLevel } from "../cli/helpers"
import { FullscreenTerminalWriter } from "./writers/fullscreen-terminal-writer"
import { EventBus } from "../events"
import { formatForEventStream } from "../cloud/buffered-event-stream"
import { formatForEventStream } from "../enterprise/buffered-event-stream"

export type LoggerType = "quiet" | "basic" | "fancy" | "fullscreen" | "json"
export const LOGGER_TYPES = new Set<LoggerType>(["quiet", "basic", "fancy", "fullscreen", "json"])
Expand Down
2 changes: 1 addition & 1 deletion garden-service/test/unit/src/cloud/auth.ts
Expand Up @@ -10,7 +10,7 @@ import Bluebird from "bluebird"
import { expect } from "chai"
import { ClientAuthToken } from "../../../../src/db/entities/client-auth-token"
import { makeTestGardenA } from "../../../helpers"
import { saveAuthToken, readAuthToken, clearAuthToken } from "../../../../src/cloud/auth"
import { saveAuthToken, readAuthToken, clearAuthToken } from "../../../../src/enterprise/auth"
import { getLogger } from "../../../../src/logger/logger"

async function cleanupAuthTokens() {
Expand Down
2 changes: 1 addition & 1 deletion garden-service/test/unit/src/logger/logger.ts
Expand Up @@ -11,7 +11,7 @@ import { omit } from "lodash"

import { LogLevel } from "../../../../src/logger/log-node"
import { getLogger } from "../../../../src/logger/logger"
import { LogEntryEvent, formatForEventStream } from "../../../../src/cloud/buffered-event-stream"
import { LogEntryEvent, formatForEventStream } from "../../../../src/enterprise/buffered-event-stream"

const logger: any = getLogger()

Expand Down
Expand Up @@ -7,7 +7,7 @@
*/

import { expect } from "chai"
import { StreamEvent, LogEntryEvent, BufferedEventStream } from "../../../../src/cloud/buffered-event-stream"
import { StreamEvent, LogEntryEvent, BufferedEventStream } from "../../../../src/enterprise/buffered-event-stream"
import { getLogger } from "../../../../src/logger/logger"
import { EventBus } from "../../../../src/events"

Expand Down

0 comments on commit 2276044

Please sign in to comment.