diff --git a/go/membership/membership.go b/go/membership/membership.go index 4f957cb..38e225c 100644 --- a/go/membership/membership.go +++ b/go/membership/membership.go @@ -6,7 +6,6 @@ package membership import ( "encoding/json" - "strings" "git.novox.be/novox/mesh-sdk/go/catalogue" ) @@ -172,32 +171,3 @@ type WaitIssued struct { Event string `json:"event"` Subject string `json:"subject"` } - -// CredentialIn reads the credential out of a bus address, `[scheme://]user:password@host:port`, splitting on -// the last at-sign so a password containing one stays whole, and returns the address without it. -func CredentialIn(address string) (user, password, bare string) { - at := strings.LastIndex(address, "@") - if at < 0 { - return "", "", address - } - scheme := "" - rest := address[:at] - if i := strings.Index(rest, "://"); i >= 0 { - scheme, rest = rest[:i+3], rest[i+3:] - } - user, password, _ = strings.Cut(rest, ":") - return user, password, scheme + address[at+1:] -} - -// BareAddress is a bus address with any credential stripped, for something that only needs to know -// whether a server is answering there. -func BareAddress(address string) string { - _, _, bare := CredentialIn(address) - if bare == "" { - return address - } - if strings.Contains(bare, "://") { - return bare - } - return "nats://" + bare -} diff --git a/go/membership/membership_test.go b/go/membership/membership_test.go index e80d346..555f19c 100644 --- a/go/membership/membership_test.go +++ b/go/membership/membership_test.go @@ -8,26 +8,6 @@ import ( "git.novox.be/novox/mesh-sdk/go/catalogue" ) -// A credential is read out of a bus address, and the bare address carries no credential and a scheme. -func TestACredentialIsReadOutOfABusAddress(t *testing.T) { - for _, c := range []struct{ in, user, password, bare, schemed string }{ - {"nats://controller:secret@127.0.0.1:4222", "controller", "secret", "nats://127.0.0.1:4222", "nats://127.0.0.1:4222"}, - {"controller:secret@127.0.0.1:4222", "controller", "secret", "127.0.0.1:4222", "nats://127.0.0.1:4222"}, - {"nats://127.0.0.1:4222", "", "", "nats://127.0.0.1:4222", "nats://127.0.0.1:4222"}, - {"127.0.0.1:4222", "", "", "127.0.0.1:4222", "nats://127.0.0.1:4222"}, - // A password containing an at-sign: split on the last one. - {"nats://controller:a@b@127.0.0.1:4222", "controller", "a@b", "nats://127.0.0.1:4222", "nats://127.0.0.1:4222"}, - } { - user, password, bare := CredentialIn(c.in) - if user != c.user || password != c.password || bare != c.bare { - t.Errorf("%q read as %q/%q at %q; wanted %q/%q at %q", c.in, user, password, bare, c.user, c.password, c.bare) - } - if got := BareAddress(c.in); got != c.schemed { - t.Errorf("BareAddress(%q) = %q, want %q", c.in, got, c.schemed) - } - } -} - func TestAMembershipIsPublishedAndReadAtTheSubjectDerivedFromTheTwoNames(t *testing.T) { if got := Subject("ace", "route-proxy"); got != "mesh.assignment.ace.route-proxy" { t.Errorf("subject: %q", got)