Skip to content
This repository has been archived by the owner on Jan 14, 2020. It is now read-only.

Commit

Permalink
Merge d77287f into a5058e6
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaggerman committed Sep 7, 2018
2 parents a5058e6 + d77287f commit 1488cfa
Show file tree
Hide file tree
Showing 11 changed files with 66 additions and 50 deletions.
30 changes: 15 additions & 15 deletions internal/cloudformation/parameters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ func TestResolveEnvironmentParameters(t *testing.T) {
name: "Returns map of env vars",
environment: "development",
manifest: manifest.Manifest{
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
GenerateDefaultOutputs: false,
Environments: map[string]manifest.Environment{
"development": {
Expand All @@ -55,9 +55,9 @@ func TestResolveEnvironmentParameters(t *testing.T) {
name: "Returns emtpy map",
environment: "production",
manifest: manifest.Manifest{
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
GenerateDefaultOutputs: false,
Environments: map[string]manifest.Environment{
"development": {
Expand Down Expand Up @@ -93,8 +93,8 @@ func TestResolveEnvironmentParameters(t *testing.T) {

func TestResolveParameters(t *testing.T) {
type input struct {
envName string
cliParams map[string]string
envName string
cliParams map[string]string
cfYaml YamlCloudformation
cfClient *awsCF.CloudFormation
manifestFile *manifest.Manifest
Expand All @@ -109,7 +109,7 @@ func TestResolveParameters(t *testing.T) {
name: "Dev",
input: input{
envName: "development",
cliParams: map[string]string {
cliParams: map[string]string{
"parameterOneName": "parameterOneValue",
"parameterTwoName": "8654238642489624862",
},
Expand All @@ -129,9 +129,9 @@ func TestResolveParameters(t *testing.T) {
Outputs: types.TemplateObject{},
},
manifestFile: &manifest.Manifest{
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
GenerateDefaultOutputs: false,
Environments: map[string]manifest.Environment{
"development": {
Expand Down Expand Up @@ -226,9 +226,9 @@ func TestResolveParametersS3(t *testing.T) {
return context
}(),
manifestFile: &manifest.Manifest{
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
Name: "TestManifestWithEnvironment",
Plugins: nil,
Architectures: []string(nil),
GenerateDefaultOutputs: false,
Environments: map[string]manifest.Environment{
"development": {
Expand Down
4 changes: 2 additions & 2 deletions internal/cloudformation/template_parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func TestGenerateYamlTemplate(t *testing.T) {
{
input: GenerateParams{
ObjectStore: objectStore,
Filename: "test.yaml",
Filename: "test.yaml",
},
output: YamlCloudformation{
AWSTemplateFormatVersion: "2010-09-09",
Expand Down Expand Up @@ -124,7 +124,7 @@ func TestGenerateYamlTemplate(t *testing.T) {
},
{
input: GenerateParams{
ObjectStore: objectStore,
ObjectStore: objectStore,
Filename: "test.yaml",
GenerateDefaultOutputs: true,
},
Expand Down
2 changes: 1 addition & 1 deletion internal/manifest/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import (
"fmt"
"strings"

"github.com/KablamoOSS/kombustion/internal/core"
printer "github.com/KablamoOSS/go-cli-printer"
"github.com/KablamoOSS/kombustion/internal/core"
"gopkg.in/AlecAivazis/survey.v1"
)

Expand Down
2 changes: 0 additions & 2 deletions internal/manifest/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
yaml "github.com/KablamoOSS/yaml"
)


func CheckManifestExists(objectStore core.ObjectStore) bool {
data, err := GetManifestObject(objectStore)
if err != nil {
Expand All @@ -16,7 +15,6 @@ func CheckManifestExists(objectStore core.ObjectStore) bool {
return data != nil
}


func GetManifestObject(objectStore core.ObjectStore, path ...string) (*Manifest, error) {
var manifest Manifest
var err error
Expand Down
2 changes: 1 addition & 1 deletion internal/plugins/lock/write.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package lock

import (
printer "github.com/KablamoOSS/go-cli-printer"
"github.com/KablamoOSS/kombustion/internal/core"
"github.com/KablamoOSS/kombustion/config"
"github.com/KablamoOSS/kombustion/internal/core"
"github.com/KablamoOSS/yaml"
)

Expand Down
2 changes: 1 addition & 1 deletion internal/tasks/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

printer "github.com/KablamoOSS/go-cli-printer"
"github.com/KablamoOSS/kombustion/config"
"github.com/KablamoOSS/kombustion/internal/core"
"github.com/KablamoOSS/kombustion/internal/cloudformation"
"github.com/KablamoOSS/kombustion/internal/cloudformation/tasks"
"github.com/KablamoOSS/kombustion/internal/core"
"github.com/KablamoOSS/kombustion/internal/manifest"
"github.com/urfave/cli"
)
Expand Down
2 changes: 1 addition & 1 deletion internal/tasks/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import (

printer "github.com/KablamoOSS/go-cli-printer"
"github.com/KablamoOSS/kombustion/config"
"github.com/KablamoOSS/kombustion/internal/core"
"github.com/KablamoOSS/kombustion/internal/cloudformation"
"github.com/KablamoOSS/kombustion/internal/cloudformation/tasks"
"github.com/KablamoOSS/kombustion/internal/core"
"github.com/KablamoOSS/kombustion/internal/manifest"
"github.com/urfave/cli"
)
Expand Down
33 changes: 21 additions & 12 deletions internal/tasks/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func Generate(c *cli.Context) {
outputDirectory := c.String("output-directory")
inputParameters := c.String("read-parameters")
outputParameters := c.Bool("write-parameters")
env := c.String("env")
env := c.String("environment")
generateDefaultOutputs := c.Bool("generate-default-outputs")

generate(
Expand All @@ -88,21 +88,12 @@ func generate(
devPluginPath string,
outputDirectory string,
outputParameters bool,
env string,
envName string,
generateDefaultOutputs bool,
) {
printer.Step("Generate template")
printer.Progress("Kombusting")

paramMap := make(map[string]string)
if paramsPath != "" {
paramMap = readParamsObject(objectStore, paramsPath)
}

for key, value := range cliParams {
paramMap[key] = value
}

lockFile, err := lock.GetLockObject(objectStore, "kombustion.lock")
if err != nil {
printer.Fatal(
Expand All @@ -122,6 +113,24 @@ func generate(
)
}

paramMap := make(map[string]string)

if env, ok := manifestFile.Environments[envName]; ok {
for key, value := range env.Parameters {
paramMap[key] = value
}
}

if paramsPath != "" {
for key, value := range readParamsObject(objectStore, paramsPath) {
paramMap[key] = value
}
}

for key, value := range cliParams {
paramMap[key] = value
}

// load all plugins
loadedPlugins := plugins.LoadPlugins(manifestFile, lockFile)

Expand All @@ -136,7 +145,7 @@ func generate(
Filename: templatePath,
Directory: outputDirectory,
WriteParams: outputParameters,
Env: env,
Env: envName,
ParamMap: paramMap,
Plugins: loadedPlugins,
GenerateDefaultOutputs: generateDefaultOutputs || manifestFile.GenerateDefaultOutputs,
Expand Down
32 changes: 21 additions & 11 deletions internal/tasks/generate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ var sampleKombYaml = `---
Name: Kombustion
Region: ""
Environments:
development:
ci:
Parameters:
Environment: development
BucketName: fooBucket
GenerateDefaultOutputs: false
Tags: {}
`
Expand Down Expand Up @@ -61,6 +61,13 @@ Resources:
Value: 123
`

var expectedParameterOutput = `[
{
"ParameterKey": "BucketName",
"ParameterValue": "fooBucket"
}
]`

func TestSimpleGenerate(t *testing.T) {
objectStore := coretest.NewMockObjectStore()
objectStore.Put([]byte(sampleKombYaml), "kombustion.yaml")
Expand All @@ -71,19 +78,22 @@ func TestSimpleGenerate(t *testing.T) {
t,
func() {
generate(
objectStore,
"test.yaml",
map[string]string{},
"",
"",
"compiled",
true,
"ci",
false,
objectStore, // objectStore
"test.yaml", // templatePath
map[string]string{}, // cliParams
"", // paramsPath
"", // devPluginPath
"compiled", // outputDirectory
true, // ouputParameters
"ci", // envName
false, // generateDefaultOutputs
)
},
)

output, _ := objectStore.Get("compiled", "test.yaml")
assert.Equal(t, expectedOutput, string(output))

output, _ = objectStore.Get("compiled", "test-params.json")
assert.Equal(t, expectedParameterOutput, string(output))
}
1 change: 0 additions & 1 deletion internal/tasks/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ func installPlugins(objectStore core.ObjectStore) {
printer.Step("Install plugins")
printer.Progress("Kombusting")


lockFile, err := lock.GetLockObject(objectStore, "kombustion.lock")
if err != nil {
printer.Fatal(err, config.ErrorHelpInfo, "")
Expand Down
6 changes: 3 additions & 3 deletions internal/tasks/upsert.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func Upsert(c *cli.Context) {
region := c.String("region")
devPluginPath := c.GlobalString("load-plugin")
inputParameters := c.String("read-parameters")
env := c.String("env")
env := c.String("environment")
generateDefaultOutputs := c.Bool("generate-default-outputs")
capabilities := getCapabilities(c)
confirm := c.Bool("confirm")
Expand Down Expand Up @@ -186,8 +186,8 @@ func upsert(
// Template generation parameters
generateParams := cloudformation.GenerateParams{
ObjectStore: objectStore,
Filename: templatePath,
Env: env,
Filename: templatePath,
Env: env,
GenerateDefaultOutputs: generateDefaultOutputs || manifestFile.GenerateDefaultOutputs,
ParamMap: paramMap,
Plugins: loadedPlugins,
Expand Down

0 comments on commit 1488cfa

Please sign in to comment.