Skip to content

Commit

Permalink
Merge pull request #395 from garden-io/dashboard-pt2
Browse files Browse the repository at this point in the history
 feat: add `get config` command
  • Loading branch information
eysi09 committed Nov 29, 2018
2 parents 73ab7f3 + 39ab7b1 commit dd1d17e
Show file tree
Hide file tree
Showing 16 changed files with 251 additions and 63 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. <info@garden.io>
*
* 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. <info@garden.io>
*
* 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. <info@garden.io>
*
* 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 {} }
}
40 changes: 40 additions & 0 deletions garden-service/src/config/dashboard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <info@garden.io>
*
* 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"

export interface DashboardPage {
title: string
description: string
url: string
newWindow: boolean
// TODO: allow nested sections
// children: DashboardPage[]
}

export const dashboardPageSchema = Joi.object()
.keys({
title: Joi.string()
.length(32)
.required()
.description("The link title to show in the menu bar (max length 32)."),
description: Joi.string()
.required()
.description("A description to show when hovering over the link."),
url: Joi.string()
.uri()
.required()
.description("The URL to open in the dashboard pane when clicking the link."),
newWindow: Joi.boolean()
.default(false)
.description("Set to true if the link should open in a new browser tab/window."),
})

export const dashboardPagesSchema = joiArray(dashboardPageSchema)
.description("One or more pages to add to the Garden dashboard.")
13 changes: 10 additions & 3 deletions garden-service/src/config/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
Primitive,
joiRepositoryUrl,
} from "./common"
import { DashboardPage } from "../config/dashboard"

export interface ProviderConfig {
name: string
Expand All @@ -32,6 +33,7 @@ export const providerConfigBaseSchema = Joi.object()

export interface Provider<T extends ProviderConfig = any> {
name: string
dashboardPages: DashboardPage[]
config: T
}

Expand All @@ -52,10 +54,14 @@ export const environmentConfigSchema = Joi.object()
.description("A key/value map of variables that modules can reference when using this environment."),
})

export interface Environment extends CommonEnvironmentConfig {
export interface EnvironmentConfig extends CommonEnvironmentConfig {
name: string
}

export interface Environment extends EnvironmentConfig {
providers: Provider[]
}

export const environmentSchema = environmentConfigSchema
.keys({
name: Joi.string()
Expand Down Expand Up @@ -85,15 +91,15 @@ export interface ProjectConfig {
name: string
defaultEnvironment: string
environmentDefaults: CommonEnvironmentConfig
environments: Environment[]
environments: EnvironmentConfig[]
sources?: SourceConfig[]
}

export const defaultProviders = [
{ name: "container" },
]

export const defaultEnvironments: Environment[] = [
export const defaultEnvironments: EnvironmentConfig[] = [
{
name: "local",
providers: [
Expand Down Expand Up @@ -142,5 +148,6 @@ export const projectSchema = Joi.object()
// this is used for default handlers in the action handler
export const defaultProvider: Provider = {
name: "_default",
dashboardPages: [],
config: {},
}
Loading

0 comments on commit dd1d17e

Please sign in to comment.