-
Notifications
You must be signed in to change notification settings - Fork 267
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #395 from garden-io/dashboard-pt2
feat: add `get config` command
- Loading branch information
Showing
16 changed files
with
251 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 {} } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.