Skip to content

Commit

Permalink
Merge pull request #31 from funbox/develop
Browse files Browse the repository at this point in the history
Version 0.14.0.1
  • Loading branch information
andyone authored May 3, 2017
2 parents 48e533c + 4855f69 commit 47b1d86
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
7 changes: 5 additions & 2 deletions common/init-exporter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
Summary: Utility for exporting services described by Procfile to init system
Name: init-exporter
Version: 0.14.0
Release: 0%{?dist}
Release: 1%{?dist}
Group: Development/Tools
License: MIT
URL: https://github.com/funbox/init-exporter
Expand All @@ -69,7 +69,7 @@ Utility for exporting services described by Procfile to init system.
%package converter

Summary: Utility for converting procfiles from v1 to v2 format
Version: 0.6.0
Version: 0.7.0
Release: 0%{?dist}

%description converter
Expand Down Expand Up @@ -132,6 +132,9 @@ rm -rf %{buildroot}
###############################################################################

%changelog
* Wed May 03 2017 Anton Novojilov <[email protected]> - 0.14.0-1
- [init-exporter-converter] Added validation for result YAML data

* Wed Apr 26 2017 Anton Novojilov <[email protected]> - 0.14.0-0
- Environment variables and file with environment variables now can defined
in same time
Expand Down
25 changes: 20 additions & 5 deletions converter/converter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"pkg.re/essentialkaos/ek.v8/knf"
"pkg.re/essentialkaos/ek.v8/usage"

"pkg.re/essentialkaos/go-simpleyaml.v1"

"github.com/funbox/init-exporter/procfile"
)

Expand All @@ -25,7 +27,7 @@ import (
// App props
const (
APP = "init-exporter-converter"
VER = "0.6.0"
VER = "0.7.0"
DESC = "Utility for converting procfiles from v1 to v2 format"
)

Expand Down Expand Up @@ -157,14 +159,20 @@ func convert(file string) error {

validateApplication(app)

data := renderProcfile(&procData{config, app, hasCustomWorkingDirs})
yamlData := renderProcfile(&procData{config, app, hasCustomWorkingDirs})

err = validateYaml(yamlData)

if err != nil {
printErrorAndExit("Can't convert given procfile to YAML: %v", err)
}

if !arg.GetB(ARG_IN_PLACE) {
fmt.Printf(data)
fmt.Printf(yamlData)
return nil
}

return writeData(file, data)
return writeData(file, yamlData)
}

// renderProcfile render procfile
Expand Down Expand Up @@ -197,7 +205,7 @@ func renderProcfile(data *procData) string {
result += "commands:\n"

for _, service := range data.Application.Services {
result += " " + service.Name + "\n"
result += " " + service.Name + ":\n"

if service.HasPreCmd() {
result += " pre: " + service.PreCmd + "\n"
Expand Down Expand Up @@ -269,6 +277,13 @@ func validateApplication(app *procfile.Application) {
os.Exit(1)
}

// validateYaml validate rendered yaml
func validateYaml(data string) error {
_, err := simpleyaml.NewYaml([]byte(data))

return err
}

// writeData write procfile data to file
func writeData(file, data string) error {
return ioutil.WriteFile(file, []byte(data), 0644)
Expand Down

0 comments on commit 47b1d86

Please sign in to comment.