root: put sighelper disco in the main disco document

Change-Id: Ic5ae125f01320fcec6ff23e56b11c75c41c4e94b
This commit is contained in:
Brad Fitzpatrick 2012-12-23 16:58:26 -08:00
parent c46875692a
commit c4dd036203
2 changed files with 25 additions and 10 deletions

View File

@ -132,6 +132,19 @@ func (h *JSONSignHandler) uploadPublicKey(sto blobserver.Storage, key string) er
return err return err
} }
func (h *JSONSignHandler) discoveryMap(base string) map[string]interface{} {
m := map[string]interface{}{
"publicKeyId": h.entity.PrimaryKey.KeyIdString(),
"signHandler": base + "camli/sig/sign",
"verifyHandler": base + "camli/sig/verify",
}
if h.pubKeyBlobRef != nil {
m["publicKeyBlobRef"] = h.pubKeyBlobRef.String()
m["publicKey"] = base + h.pubKeyBlobRefServeSuffix
}
return m
}
func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) { func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
base := req.Header.Get("X-PrefixHandler-PathBase") base := req.Header.Get("X-PrefixHandler-PathBase")
subPath := req.Header.Get("X-PrefixHandler-PathSuffix") subPath := req.Header.Get("X-PrefixHandler-PathSuffix")
@ -150,16 +163,7 @@ func (h *JSONSignHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
http.Error(rw, "POST required", 400) http.Error(rw, "POST required", 400)
return return
case "camli/sig/discovery": case "camli/sig/discovery":
m := map[string]interface{}{ httputil.ReturnJSON(rw, h.discoveryMap(base))
"publicKeyId": h.entity.PrimaryKey.KeyIdString(),
"signHandler": base + "camli/sig/sign",
"verifyHandler": base + "camli/sig/verify",
}
if h.pubKeyBlobRef != nil {
m["publicKeyBlobRef"] = h.pubKeyBlobRef.String()
m["publicKey"] = base + h.pubKeyBlobRefServeSuffix
}
httputil.ReturnJSON(rw, m)
return return
} }
case "POST": case "POST":

View File

@ -77,6 +77,7 @@ type UIHandler struct {
prefix string // of the UI handler itself prefix string // of the UI handler itself
root *RootHandler root *RootHandler
sigh *JSONSignHandler // or nil
Cache blobserver.Storage // or nil Cache blobserver.Storage // or nil
sc ScaledImage // cache for scaled images, optional sc ScaledImage // cache for scaled images, optional
@ -101,6 +102,13 @@ func newUIFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler,
return return
} }
if ui.JSONSignRoot != "" {
h, _ := ld.GetHandler(ui.JSONSignRoot)
if sigh, ok := h.(*JSONSignHandler); ok {
ui.sigh = sigh
}
}
ui.PublishRoots = make(map[string]*PublishHandler) ui.PublishRoots = make(map[string]*PublishHandler)
for _, pubRoot := range pubRoots { for _, pubRoot := range pubRoots {
h, err := ld.GetHandler(pubRoot) h, err := ld.GetHandler(pubRoot)
@ -295,6 +303,9 @@ func (ui *UIHandler) populateDiscoveryMap(m map[string]interface{}) {
"directoryHelper": path.Join(ui.prefix, "tree") + "/", "directoryHelper": path.Join(ui.prefix, "tree") + "/",
"publishRoots": pubRoots, "publishRoots": pubRoots,
} }
if ui.sigh != nil {
uiDisco["signing"] = ui.sigh.discoveryMap(ui.JSONSignRoot)
}
for k, v := range uiDisco { for k, v := range uiDisco {
if _, ok := m[k]; ok { if _, ok := m[k]; ok {
log.Fatalf("Duplicate discovery key %q", k) log.Fatalf("Duplicate discovery key %q", k)