Skip to content

Commit

Permalink
feat: add get config command
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and eysi09 committed Nov 29, 2018
1 parent c67b7be commit 39ab7b1
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 37 deletions.
9 changes: 9 additions & 0 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,15 @@ Examples:
| -------- | ----- | ---- | ----------- |
| `--interactive` | | boolean | Set to false to skip interactive mode and just output the command result

### garden get config

Outputs the fully resolved configuration for this project and environment.


##### Usage

garden get config

### garden get secret

Get a secret from the environment.
Expand Down
4 changes: 2 additions & 2 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type TypeGuard = {
readonly [P in keyof (PluginActionParams | ModuleActionParams<any>)]: (...args: any[]) => Promise<any>
}

export interface ContextStatus {
export interface EnvironmentStatus {
providers: EnvironmentStatusMap
services: { [name: string]: ServiceStatus }
}
Expand Down Expand Up @@ -338,7 +338,7 @@ export class ActionHelper implements TypeGuard {
return keyBy(dependencies, "name")
}

async getStatus({ log }: { log: LogEntry }): Promise<ContextStatus> {
async getStatus({ log }: { log: LogEntry }): Promise<EnvironmentStatus> {
const envStatus: EnvironmentStatusMap = await this.getEnvironmentStatus({ log })
const services = keyBy(await this.garden.getServices(), "name")

Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { InitCommand } from "./init"
import { DeleteCommand } from "./delete"
import { DeployCommand } from "./deploy"
import { DevCommand } from "./dev"
import { GetCommand } from "./get"
import { GetCommand } from "./get/get"
import { LinkCommand } from "./link/link"
import { LogsCommand } from "./logs"
import { PublishCommand } from "./publish"
Expand Down
56 changes: 56 additions & 0 deletions garden-service/src/commands/get/get-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import * as yaml from "js-yaml"
import { highlightYaml } from "../../util/util"
import { Provider } from "../../config/project"
import { PrimitiveMap } from "../../config/common"
import { Module } from "../../types/module"
import { Command, CommandResult, CommandParams } from "../base"

interface ConfigOutput {
environmentName: string
providers: Provider[]
variables: PrimitiveMap
modules: Module[]
}

export class GetConfigCommand extends Command {
name = "config"
help = "Outputs the fully resolved configuration for this project and environment."

async action({ garden, log }: CommandParams): Promise<CommandResult<ConfigOutput>> {
const modules = await garden.getModules()

// Remove circular references and superfluous keys.
for (const module of modules) {
delete module._ConfigType

for (const service of module.services) {
delete service.module
}
for (const task of module.tasks) {
delete task.module
}
}

const config: ConfigOutput = {
environmentName: garden.environment.name,
providers: garden.environment.providers,
variables: garden.environment.variables,
modules,
}

const yamlConfig = yaml.safeDump(config, { noRefs: true, skipInvalid: true })

// TODO: do a nicer print of this by default and use --yaml/--json options for exporting
log.info(highlightYaml(yamlConfig))

return { result: config }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,14 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import * as yaml from "js-yaml"
import { NotFoundError } from "../exceptions"
import { highlightYaml } from "../util/util"
import { NotFoundError } from "../../exceptions"
import {
Command,
CommandResult,
CommandParams,
StringParameter,
} from "./base"
} from "../base"
import dedent = require("dedent")
import { ContextStatus } from "../actions"

export class GetCommand extends Command {
name = "get"
help = "Retrieve and output data and objects, e.g. secrets, status info etc."

subCommands = [
GetSecretCommand,
GetStatusCommand,
]

async action() { return {} }
}

const getSecretArgs = {
provider: new StringParameter({
Expand Down Expand Up @@ -77,18 +62,3 @@ export class GetSecretCommand extends Command<typeof getSecretArgs> {
return { [key]: value }
}
}

export class GetStatusCommand extends Command {
name = "status"
help = "Outputs the status of your environment."

async action({ garden, log }: CommandParams): Promise<CommandResult<ContextStatus>> {
const status = await garden.actions.getStatus({ log })
const yamlStatus = yaml.safeDump(status, { noRefs: true, skipInvalid: true })

// TODO: do a nicer print of this by default and add --yaml/--json options (maybe globally) for exporting
log.info(highlightYaml(yamlStatus))

return { result: status }
}
}
31 changes: 31 additions & 0 deletions garden-service/src/commands/get/get-status.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import * as yaml from "js-yaml"
import { highlightYaml } from "../../util/util"
import {
Command,
CommandResult,
CommandParams,
} from "../base"
import { EnvironmentStatus } from "../../actions"

export class GetStatusCommand extends Command {
name = "status"
help = "Outputs the status of your environment."

async action({ garden, log }: CommandParams): Promise<CommandResult<EnvironmentStatus>> {
const status = await garden.actions.getStatus({ log })
const yamlStatus = yaml.safeDump(status, { noRefs: true, skipInvalid: true })

// TODO: do a nicer print of this by default and use --yaml/--json options for exporting
log.info(highlightYaml(yamlStatus))

return { result: status }
}
}
25 changes: 25 additions & 0 deletions garden-service/src/commands/get/get.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { Command } from "../base"
import { GetConfigCommand } from "./get-config"
import { GetSecretCommand } from "./get-secret"
import { GetStatusCommand } from "./get-status"

export class GetCommand extends Command {
name = "get"
help = "Retrieve and output data and objects, e.g. secrets, status info etc."

subCommands = [
GetConfigCommand,
GetSecretCommand,
GetStatusCommand,
]

async action() { return {} }
}
8 changes: 8 additions & 0 deletions garden-service/src/config/dashboard.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import Joi = require("joi")
import { joiArray } from "./common"

Expand Down
31 changes: 31 additions & 0 deletions garden-service/test/src/commands/get/get-config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { expect } from "chai"
import { makeTestGardenA } from "../../../helpers"
import { GetConfigCommand } from "../../../../src/commands/get/get-config"
import { isSubset } from "../../../../src/util/is-subset"

describe("GetConfigCommand", () => {
const pluginName = "test-plugin"
const provider = pluginName

it("should get the project configuration", async () => {
const garden = await makeTestGardenA()
const log = garden.log
const command = new GetConfigCommand()

const res = await command.action({
garden,
log,
args: { provider },
opts: {},
})

const config = {
environmentName: garden.environment.name,
providers: garden.environment.providers,
variables: garden.environment.variables,
modules: await garden.getModules(),
}

expect(isSubset(config, res.result)).to.be.true
})
})
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai"
import { expectError, makeTestGardenA } from "../../helpers"
import { GetSecretCommand } from "../../../src/commands/get"
import { expectError, makeTestGardenA } from "../../../helpers"
import { GetSecretCommand } from "../../../../src/commands/get/get-secret"

describe("GetSecretCommand", () => {
const pluginName = "test-plugin"
Expand Down
3 changes: 3 additions & 0 deletions garden-service/test/src/plugins/kubernetes/ingress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const basicConfig: KubernetesConfig = {
const basicProvider: KubernetesProvider = {
name: "kubernetes",
config: basicConfig,
dashboardPages: [],
}

const singleTlsConfig: KubernetesConfig = {
Expand All @@ -60,6 +61,7 @@ const singleTlsConfig: KubernetesConfig = {
const singleTlsProvider: KubernetesProvider = {
name: "kubernetes",
config: singleTlsConfig,
dashboardPages: [],
}

const multiTlsConfig: KubernetesConfig = {
Expand Down Expand Up @@ -93,6 +95,7 @@ const multiTlsConfig: KubernetesConfig = {
const multiTlsProvider: KubernetesProvider = {
name: "kubernetes",
config: multiTlsConfig,
dashboardPages: [],
}

// generated with `openssl req -newkey rsa:2048 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem`
Expand Down

0 comments on commit 39ab7b1

Please sign in to comment.