-
Notifications
You must be signed in to change notification settings - Fork 273
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
170 additions
and
37 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. <[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 } | ||
} | ||
} |
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. <[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 } | ||
} | ||
} |
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. <[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 {} } | ||
} |
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 |
---|---|---|
@@ -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" | ||
|
||
|
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 @@ | ||
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 | ||
}) | ||
}) |
4 changes: 2 additions & 2 deletions
4
garden-service/test/src/commands/get.ts → ...rvice/test/src/commands/get/get-secret.ts
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