diff --git a/pkg/converter/linker.go b/pkg/converter/linker.go index 06fad24..d0a8164 100644 --- a/pkg/converter/linker.go +++ b/pkg/converter/linker.go @@ -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+)(:\/\/)+` ) @@ -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 } diff --git a/pkg/converter/linker_test.go b/pkg/converter/linker_test.go index 0086e5a..898ffa3 100644 --- a/pkg/converter/linker_test.go +++ b/pkg/converter/linker_test.go @@ -79,6 +79,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:pass@b.apps.%s:443", name), + "API_URL": fmt.Sprintf("b.apps.%s:443", name), + }, + Image: ToStrPtr("hugo"), + }, + Env: converter.SloppyEnvSlice{ + {"API_AUTH": fmt.Sprintf("https://admin:pass@b.apps.%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 } diff --git a/pkg/converter/testdata/fixture_linker1.yml b/pkg/converter/testdata/fixture_linker1.yml new file mode 100644 index 0000000..8b32a9a --- /dev/null +++ b/pkg/converter/testdata/fixture_linker1.yml @@ -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