Skip to content

Commit

Permalink
postman: Make HostToEnv variable name configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
saifulwebid committed Nov 8, 2017
1 parent 2275473 commit 7b261ae
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
4 changes: 3 additions & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ type Config struct {
Name string `yaml:"Name,omitempty"`
} `yaml:"SchemeToEnv,omitempty"`
HostToEnv struct {
Segments int `yaml:"segments,omitempty"`
Enabled bool `yaml:"Enabled,omitempty"`
Segments int `yaml:"Segments,omitempty"`
Name string `yaml:"Name,omitempty"`
} `yaml:"HostToEnv,omitempty"`
AuthTokenToEnv struct {
Enabled bool `yaml:"Enabled,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ func main() {
if cfg.SchemeToEnv.Enabled {
postman.SchemeToEnv(&collection, cfg.SchemeToEnv.Name)
}
if cfg.HostToEnv.Segments > 0 {
postman.HostToEnv(&collection, cfg.HostToEnv.Segments)
if cfg.HostToEnv.Enabled && cfg.HostToEnv.Segments > 0 {
postman.HostToEnv(&collection, cfg.HostToEnv.Segments, cfg.HostToEnv.Name)
}
if cfg.AuthTokenToEnv.Enabled {
postman.AuthTokenToEnv(&collection, cfg.AuthTokenToEnv.Name)
Expand Down
4 changes: 2 additions & 2 deletions postman/transformer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func SchemeToEnv(c *Collection, placeholder string) {
}
}

func HostToEnv(c *Collection, n int) {
func HostToEnv(c *Collection, n int, placeholder string) {
items := getItemsFromCollection(c)

for i := range items {
Expand All @@ -30,7 +30,7 @@ func HostToEnv(c *Collection, n int) {
hostSegments[0:len(hostSegments)-2]...,
)
}
newHostSegments = append(newHostSegments, "{{host}}")
newHostSegments = append(newHostSegments, fmt.Sprintf("{{%s}}", placeholder))
items[i].Request.Url.Host = strings.Join(newHostSegments, ".")
}
}
Expand Down
4 changes: 3 additions & 1 deletion vanadia.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ SchemeToEnv:
Name: scheme

HostToEnv:
segments: 2
Enabled: true
Segments: 2
Name: host

AuthTokenToEnv:
Enabled: true
Expand Down

0 comments on commit 7b261ae

Please sign in to comment.