Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Commit

Permalink
Merge pull request #14 from sloppyio/fix/usrpwd-urls
Browse files Browse the repository at this point in the history
Fix/usrpwd urls
  • Loading branch information
jzaefferer authored Feb 13, 2018
2 parents 178707a + 7a4fdb5 commit c2ad652
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/converter/linker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
)

const (
fqdnTemplate = "%s.%s.%s" // app.service.project
hostPortPattern = `([a-z]+[a-z0-9._-]*)(:[0-9]+)?` // sloppy appName conform
fqdnTemplate = "%s.%s.%s" // app.service.project
hostPortPattern = `([a-z][a-z0-9._-]*)(:[0-9]{2,5})?` // sloppy appName conform
schemePattern = `^(\w+)(:\/\/)+`
)

Expand Down Expand Up @@ -50,13 +50,19 @@ func (l *Linker) GetByApp(name string) *link {
}

func (l *Linker) Resolve(cf *ComposeFile, sf *SloppyFile) error {
const at = "@"
l.buildLinks(sf)

// resolve possible connections
for _, link := range l.links {
for key, val := range link.app.App.EnvVars {
app := link.app.App
match := l.FindServiceString(key, val)
var match string
if strings.Contains(val, at) { // handling admin:pass@urls
match = l.FindServiceString(key, strings.Split(val, at)[1])
} else {
match = l.FindServiceString(key, val)
}
if match == "" {
continue
}
Expand Down
45 changes: 45 additions & 0 deletions pkg/converter/linker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,51 @@ func TestLinker_Resolve(t *testing.T) {

}

func TestLinker_ResolveUsrPwd(t *testing.T) {
linker := &converter.Linker{}
name := "sloppy-test"

expected := &converter.SloppyFile{
Version: "v1",
Project: name,
Services: map[string]converter.SloppyApps{
"apps": {
"a": &converter.SloppyApp{
App: &sloppy.App{
Dependencies: []string{"../apps/b"},
EnvVars: map[string]string{
"API_AUTH": fmt.Sprintf("https://admin:[email protected].%s:443", name),
"API_URL": fmt.Sprintf("b.apps.%s:443", name),
},
Image: ToStrPtr("hugo"),
},
Env: converter.SloppyEnvSlice{
{"API_AUTH": fmt.Sprintf("https://admin:[email protected].%s:443", name)},
{"API_URL": fmt.Sprintf("b.apps.%s:443", name)},
},
},
"b": &converter.SloppyApp{
App: &sloppy.App{
Image: ToStrPtr("go:rulez"),
},
Port: ToIntPtr(4443),
},
},
},
}

cf, sf := loadSloppyFile("/testdata/fixture_linker1.yml")
err := linker.Resolve(cf, sf)
if err != nil {
t.Fatal(err)
}

if diff := cmp.Diff(sf, expected); diff != "" {
t.Errorf("Result differs: (-got +want)\n%s", diff)
}

}

func ToIntPtr(i int) *int {
return &i
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/converter/testdata/fixture_linker1.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
version: "2"

services:
a:
image: hugo
environment:
- API_URL=b:443
# even if this is not a html standard and are not supported by any major browser
- API_AUTH=https://admin:pass@b:443
b:
image: go:rulez
ports:
- 443:4443

0 comments on commit c2ad652

Please sign in to comment.