Skip to content

Commit

Permalink
Merge pull request #33 from funbox/develop
Browse files Browse the repository at this point in the history
Version 0.15.1
  • Loading branch information
andyone authored Jun 5, 2017
2 parents 20bbfa9 + 6821067 commit 67b5dfc
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
5 changes: 4 additions & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// App props
const (
APP = "init-exporter"
VER = "0.15.0"
VER = "0.15.1"
DESC = "Utility for exporting services described by Procfile to init system"
)

Expand Down Expand Up @@ -169,6 +169,9 @@ func checkArguments() {
proc := options.GetS(OPT_PROCFILE)

switch {
case proc == "":
printErrorAndExit("You should define path to procfile", proc)

case fsutil.IsExist(proc) == false:
printErrorAndExit("Procfile %s does not exist", proc)

Expand Down
7 changes: 6 additions & 1 deletion common/init-exporter.spec
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

Summary: Utility for exporting services described by Procfile to init system
Name: init-exporter
Version: 0.15.0
Version: 0.15.1
Release: 0%{?dist}
Group: Development/Tools
License: MIT
Expand Down Expand Up @@ -111,6 +111,11 @@ rm -rf %{buildroot}
###############################################################################

%changelog
* Thu Jun 01 2017 Anton Novojilov <[email protected]> - 0.15.1-0
- Added support of asterisk symbol in environment variables
- Improved paths validation
- Improved procfile path validation

* Thu May 18 2017 Anton Novojilov <[email protected]> - 0.15.0-0
- Migrated to ek.v9
- Fixed count property handling
Expand Down
41 changes: 37 additions & 4 deletions procfile/procfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
REGEXP_V1_LINE = `^([A-z\d_]+):\s*(.+)`
REGEXP_V2_VERSION = `(?m)^\s*version:\s*2\s*$`
REGEXP_PATH_CHECK = `\A[A-Za-z0-9_\-./]+\z`
REGEXP_VALUE_CHECK = `\A[A-Za-z0-9_\-.,+/:;${}"' =]+\z`
REGEXP_VALUE_CHECK = `\A[A-Za-z0-9_\-.,+/:;${}"' =\*]+\z`
)

// ////////////////////////////////////////////////////////////////////////////////// //
Expand Down Expand Up @@ -156,8 +156,14 @@ func (so *ServiceOptions) Validate() []error {
errs := errutil.NewErrors()

errs.Add(checkPath(so.WorkingDir))
errs.Add(checkPath(so.LogFile))
errs.Add(checkPath(so.EnvFile))

if so.IsCustomLogEnabled() {
errs.Add(checkPath(so.FullLogPath()))
}

if so.IsEnvFileSet() {
errs.Add(checkPath(so.FullEnvFilePath()))
}

for envName, envVal := range so.Env {
errs.Add(checkEnv(envName, envVal))
Expand Down Expand Up @@ -486,11 +492,17 @@ func checkEnv(name, value string) error {
}

if strings.Contains(value, " ") {
if !strings.Contains(value, "\"") && !strings.Contains(value, "'") {
if isUnquotedValue(value) {
return fmt.Errorf("Environment variable %s has unquoted value with spaces", name)
}
}

if strings.Contains(value, "*") {
if isUnquotedValue(value) {
return fmt.Errorf("Environment variable %s has unquoted asterisk symbol", name)
}
}

if !regexp.MustCompile(REGEXP_VALUE_CHECK).MatchString(name) {
return fmt.Errorf("Environment variable name %s is misformatted and can't be accepted", name)
}
Expand Down Expand Up @@ -535,3 +547,24 @@ func addCrossLink(app *Application) {
service.Application = app
}
}

// isUnquotedValue return true if given value is unquoted
func isUnquotedValue(value string) bool {
if !strings.Contains(value, "\"") && !strings.Contains(value, "'") {
return true
}

if strings.Contains(value, "\"") {
if strings.Count(value, "\"")%2 != 0 {
return true
}
}

if strings.Contains(value, "'") {
if strings.Count(value, "'")%2 != 0 {
return true
}
}

return false
}
3 changes: 2 additions & 1 deletion procfile/procfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ func (s *ProcfileSuite) TestProcV2Parsing(c *C) {
c.Assert(service.Options.Env["JAVA_OPTS"], Equals, "\"${JAVA_OPTS} -Xms512m -Xmx1g -XX:+HeapDumpOnIutOfMemoryError -Djava.net.preferIPv4Stack=true\"")
c.Assert(service.Options.Env["AUX_OPTS"], Equals, "'--debug --native'")
c.Assert(service.Options.Env["QUEUE"], Equals, "log_syncronizer,file_downloader,log_searcher")
c.Assert(service.Options.Env["PATTERN"], Equals, "'*'")
c.Assert(service.Options.Env["LC_ALL"], Equals, "en_US.UTF-8")
c.Assert(service.Options.EnvString(), Equals, "AUX_OPTS='--debug --native' HEX_HOME=/srv/projects/ploy/shared/tmp JAVA_OPTS=\"${JAVA_OPTS} -Xms512m -Xmx1g -XX:+HeapDumpOnIutOfMemoryError -Djava.net.preferIPv4Stack=true\" LC_ALL=en_US.UTF-8 QUEUE=log_syncronizer,file_downloader,log_searcher RAILS_ENV=staging TEST=true")
c.Assert(service.Options.EnvString(), Equals, "AUX_OPTS='--debug --native' HEX_HOME=/srv/projects/ploy/shared/tmp JAVA_OPTS=\"${JAVA_OPTS} -Xms512m -Xmx1g -XX:+HeapDumpOnIutOfMemoryError -Djava.net.preferIPv4Stack=true\" LC_ALL=en_US.UTF-8 PATTERN='*' QUEUE=log_syncronizer,file_downloader,log_searcher RAILS_ENV=staging TEST=true")
c.Assert(service.Options.LimitFile, Equals, 4096)
c.Assert(service.Options.LimitProc, Equals, 4096)
c.Assert(service.Application, NotNil)
Expand Down
1 change: 1 addition & 0 deletions testdata/procfile_v2
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ commands:
JAVA_OPTS: '"${JAVA_OPTS} -Xms512m -Xmx1g -XX:+HeapDumpOnIutOfMemoryError -Djava.net.preferIPv4Stack=true"'
AUX_OPTS: "'--debug --native'"
QUEUE: log_syncronizer,file_downloader,log_searcher
PATTERN: "'*'"
HEX_HOME: /srv/projects/ploy/shared/tmp
LC_ALL: "en_US.UTF-8"
working_directory: '/var/...' # if needs to be redefined
Expand Down

0 comments on commit 67b5dfc

Please sign in to comment.