Remove subnets from API, since we don't use them
This commit is contained in:
1 parent
840c0b9f86
commit
ad44a8816f
4 files changed
+26
-30
No files matched your search
+16
-18
@@ -35,32 +35,30 @@ func ListenHttp(domain string, db Zone, port int) {
|
||||
|
||||
switch r.Method {
|
||||
case "PUT":
|
||||
identifier, weaveIPstr, err := parseUrl(r.URL.Path)
|
||||
ident, weaveIPstr, err := parseUrl(r.URL.Path)
|
||||
name := r.FormValue("fqdn")
|
||||
prefix := r.FormValue("routing_prefix")
|
||||
localIP := r.FormValue("local_ip")
|
||||
localIPstr := r.FormValue("local_ip")
|
||||
|
||||
if identifier == "" || weaveIPstr == "" || name == "" || prefix == "" || localIP == "" {
|
||||
if ident == "" || weaveIPstr == "" || name == "" || localIPstr == "" {
|
||||
reqError("Invalid request", "Invalid request: %s, %s", r.URL, r.Form)
|
||||
return
|
||||
}
|
||||
|
||||
ip := net.ParseIP(localIP)
|
||||
if ip == nil {
|
||||
reqError("Invalid IP in request", "Invalid IP in request: %s", localIP)
|
||||
localIP := net.ParseIP(localIPstr)
|
||||
if localIP == nil {
|
||||
reqError("Invalid IP in request", "Invalid IP in request: %s", localIPstr)
|
||||
return
|
||||
}
|
||||
|
||||
weaveCIDR := weaveIPstr + "/" + prefix
|
||||
weaveIP, subnet, err := net.ParseCIDR(weaveCIDR)
|
||||
if err != nil {
|
||||
reqError("Invalid CIDR", "Invalid CIDR in request: %s", weaveCIDR)
|
||||
weaveIP := net.ParseIP(weaveIPstr)
|
||||
if weaveIP == nil {
|
||||
reqError("Invalid weave IP", "Invalid weave IP in request: %s", weaveIPstr)
|
||||
return
|
||||
}
|
||||
|
||||
if dns.IsSubDomain(domain, name) {
|
||||
Info.Printf("Adding %s (%s) -> %s", name, localIP, weaveCIDR)
|
||||
err = db.AddRecord(identifier, name, ip, weaveIP, subnet)
|
||||
Info.Printf("Adding %s (%s) -> %s", name, localIPstr, weaveIPstr)
|
||||
err = db.AddRecord(ident, name, localIP, weaveIP)
|
||||
if err != nil {
|
||||
dup, ok := err.(DuplicateError)
|
||||
if !ok {
|
||||
@@ -68,7 +66,7 @@ func ListenHttp(domain string, db Zone, port int) {
|
||||
Error, w, "Internal error", http.StatusInternalServerError,
|
||||
"Unexpected error from DB: %s", err)
|
||||
return
|
||||
} else if dup.Ident != identifier {
|
||||
} else if dup.Ident != ident {
|
||||
http.Error(w, err.Error(), http.StatusConflict)
|
||||
return
|
||||
} // else we are golden
|
||||
@@ -78,8 +76,8 @@ func ListenHttp(domain string, db Zone, port int) {
|
||||
}
|
||||
|
||||
case "DELETE":
|
||||
identifier, weaveIPstr, err := parseUrl(r.URL.Path)
|
||||
if identifier == "" || weaveIPstr == "" {
|
||||
ident, weaveIPstr, err := parseUrl(r.URL.Path)
|
||||
if ident == "" || weaveIPstr == "" {
|
||||
reqError("Invalid Request", "Invalid request: %s, %s", r.URL, r.Form)
|
||||
return
|
||||
}
|
||||
@@ -89,8 +87,8 @@ func ListenHttp(domain string, db Zone, port int) {
|
||||
reqError("Invalid IP in request", "Invalid IP in request: %s", weaveIPstr)
|
||||
return
|
||||
}
|
||||
Info.Printf("Deleting %s (%s)", identifier, weaveIPstr)
|
||||
err = db.DeleteRecord(identifier, weaveIP)
|
||||
Info.Printf("Deleting %s (%s)", ident, weaveIPstr)
|
||||
err = db.DeleteRecord(ident, weaveIP)
|
||||
if err != nil {
|
||||
if _, ok := err.(LookupError); !ok {
|
||||
httpErrorAndLog(
|
||||
|
||||
@@ -33,8 +33,8 @@ func TestServerSimpleQuery(t *testing.T) {
|
||||
log.Println("TestServerSimpleQuery starting")
|
||||
var zone = new(ZoneDb)
|
||||
dockerIP := net.ParseIP("9.8.7.6")
|
||||
weaveIP, subnet, _ := net.ParseCIDR(testAddr1)
|
||||
zone.AddRecord(containerID, "test.weave.", dockerIP, weaveIP, subnet)
|
||||
weaveIP, _, _ := net.ParseCIDR(testAddr1)
|
||||
zone.AddRecord(containerID, "test.weave.", dockerIP, weaveIP)
|
||||
|
||||
mdnsServer, err := NewMDNSServer(zone)
|
||||
assertNoErr(t, err)
|
||||
|
||||
+3
-5
@@ -7,8 +7,7 @@ import (
|
||||
)
|
||||
|
||||
type Zone interface {
|
||||
AddRecord(ident string, name string, localIP net.IP,
|
||||
weaveIP net.IP, weaveSubnet *net.IPNet) error
|
||||
AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP) error
|
||||
DeleteRecord(ident string, weaveIp net.IP) error
|
||||
DeleteRecordsFor(ident string) error
|
||||
MatchLocal(name string) (net.IP, error)
|
||||
@@ -19,7 +18,6 @@ type Record struct {
|
||||
Name string
|
||||
LocalIP net.IP
|
||||
WeaveIP net.IP
|
||||
Subnet *net.IPNet
|
||||
}
|
||||
|
||||
// Very simple data structure for now, with linear searching.
|
||||
@@ -65,7 +63,7 @@ func (zone *ZoneDb) MatchLocal(name string) (net.IP, error) {
|
||||
return nil, LookupError(name)
|
||||
}
|
||||
|
||||
func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP, weaveSubnet *net.IPNet) error {
|
||||
func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP net.IP) error {
|
||||
zone.mx.Lock()
|
||||
defer zone.mx.Unlock()
|
||||
fqdn := dns.Fqdn(name)
|
||||
@@ -73,7 +71,7 @@ func (zone *ZoneDb) AddRecord(ident string, name string, localIP net.IP, weaveIP
|
||||
func(r Record) bool { return r.Name == fqdn && r.WeaveIP.Equal(weaveIP) }); index != -1 {
|
||||
return DuplicateError{fqdn, weaveIP, zone.recs[index].Ident}
|
||||
}
|
||||
zone.recs = append(zone.recs, Record{ident, fqdn, localIP, weaveIP, weaveSubnet})
|
||||
zone.recs = append(zone.recs, Record{ident, fqdn, localIP, weaveIP})
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -16,8 +16,8 @@ func TestZone(t *testing.T) {
|
||||
var zone = new(ZoneDb)
|
||||
|
||||
ip := net.ParseIP(dockerIP)
|
||||
weaveIP, subnet, _ := net.ParseCIDR(testAddr1)
|
||||
err := zone.AddRecord(containerID, successTestName, ip, weaveIP, subnet)
|
||||
weaveIP, _, _ := net.ParseCIDR(testAddr1)
|
||||
err := zone.AddRecord(containerID, successTestName, ip, weaveIP)
|
||||
assertNoErr(t, err)
|
||||
|
||||
// Check that the address is now there.
|
||||
@@ -29,7 +29,7 @@ func TestZone(t *testing.T) {
|
||||
}
|
||||
|
||||
// Now try to add the same address again
|
||||
err = zone.AddRecord(containerID, successTestName, ip, weaveIP, subnet)
|
||||
err = zone.AddRecord(containerID, successTestName, ip, weaveIP)
|
||||
assertErrorType(t, err, (*DuplicateError)(nil), "duplicate add")
|
||||
|
||||
// Now delete the record
|
||||
@@ -56,8 +56,8 @@ func TestDeleteFor(t *testing.T) {
|
||||
zone := new(ZoneDb)
|
||||
ip := net.ParseIP(dockerIP)
|
||||
for _, addr := range []string{addr1, addr2} {
|
||||
weaveIP, subnet, _ := net.ParseCIDR(addr)
|
||||
err := zone.AddRecord(id, name, ip, weaveIP, subnet)
|
||||
weaveIP, _, _ := net.ParseCIDR(addr)
|
||||
err := zone.AddRecord(id, name, ip, weaveIP)
|
||||
assertNoErr(t, err)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user