2011-03-13 23:38:32 +00:00
|
|
|
/*
|
|
|
|
Copyright 2011 Google Inc.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package search
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"http"
|
2011-03-14 03:51:58 +00:00
|
|
|
"log"
|
2011-03-14 00:14:48 +00:00
|
|
|
"os"
|
2011-03-14 03:51:58 +00:00
|
|
|
"sort"
|
2011-05-30 22:44:25 +00:00
|
|
|
"strings"
|
2011-03-14 02:27:59 +00:00
|
|
|
"sync"
|
2011-03-14 00:14:48 +00:00
|
|
|
"time"
|
2011-05-30 05:52:31 +00:00
|
|
|
|
|
|
|
"camli/blobref"
|
|
|
|
"camli/blobserver"
|
|
|
|
"camli/jsonconfig"
|
|
|
|
"camli/httputil"
|
2011-03-13 23:38:32 +00:00
|
|
|
)
|
|
|
|
|
2011-05-30 05:52:31 +00:00
|
|
|
func init() {
|
|
|
|
blobserver.RegisterHandlerConstructor("search", newHandlerFromConfig)
|
|
|
|
}
|
|
|
|
|
2011-06-17 03:45:47 +00:00
|
|
|
type Handler struct {
|
2011-05-30 05:52:31 +00:00
|
|
|
index Index
|
|
|
|
owner *blobref.BlobRef
|
|
|
|
}
|
|
|
|
|
|
|
|
func newHandlerFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Handler, os.Error) {
|
|
|
|
indexPrefix := conf.RequiredString("index") // TODO: add optional help tips here?
|
|
|
|
ownerBlobStr := conf.RequiredString("owner")
|
|
|
|
if err := conf.Validate(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
indexHandler, err := ld.GetHandler(indexPrefix)
|
|
|
|
if err != nil {
|
|
|
|
return nil, fmt.Errorf("search config references unknown handler %q", indexPrefix)
|
2011-03-13 23:38:32 +00:00
|
|
|
}
|
2011-05-30 05:52:31 +00:00
|
|
|
indexer, ok := indexHandler.(Index)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("search config references invalid indexer %q (actually a %T)", indexPrefix, indexHandler)
|
|
|
|
}
|
|
|
|
ownerBlobRef := blobref.Parse(ownerBlobStr)
|
|
|
|
if ownerBlobRef == nil {
|
|
|
|
return nil, fmt.Errorf("search 'owner' has malformed blobref %q; expecting e.g. sha1-xxxxxxxxxxxx",
|
|
|
|
ownerBlobStr)
|
|
|
|
}
|
2011-06-17 03:45:47 +00:00
|
|
|
return &Handler{
|
2011-05-30 05:52:31 +00:00
|
|
|
index: indexer,
|
|
|
|
owner: ownerBlobRef,
|
|
|
|
}, nil
|
2011-03-13 23:38:32 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 19:11:01 +00:00
|
|
|
// TODO: figure out a plan for an owner having multiple active public keys, or public
|
|
|
|
// key rotation
|
|
|
|
func (h *Handler) Owner() *blobref.BlobRef {
|
|
|
|
return h.owner
|
|
|
|
}
|
|
|
|
|
|
|
|
func (h *Handler) Index() Index {
|
|
|
|
return h.index
|
|
|
|
}
|
2011-03-14 00:14:48 +00:00
|
|
|
|
2011-06-09 19:55:38 +00:00
|
|
|
func jsonMap() map[string]interface{} {
|
|
|
|
return make(map[string]interface{})
|
|
|
|
}
|
|
|
|
|
|
|
|
func jsonMapList() []map[string]interface{} {
|
|
|
|
return make([]map[string]interface{}, 0)
|
|
|
|
}
|
2011-03-14 02:27:59 +00:00
|
|
|
|
2011-06-17 03:45:47 +00:00
|
|
|
func (sh *Handler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
|
2011-05-30 22:44:25 +00:00
|
|
|
_ = req.Header.Get("X-PrefixHandler-PathBase")
|
|
|
|
suffix := req.Header.Get("X-PrefixHandler-PathSuffix")
|
|
|
|
|
2011-06-09 19:55:38 +00:00
|
|
|
if req.Method == "GET" {
|
|
|
|
switch suffix {
|
2011-06-23 04:59:17 +00:00
|
|
|
case "camli/search/recent":
|
2011-06-09 19:55:38 +00:00
|
|
|
sh.serveRecentPermanodes(rw, req)
|
|
|
|
return
|
|
|
|
case "camli/search/describe":
|
|
|
|
sh.serveDescribe(rw, req)
|
|
|
|
return
|
|
|
|
case "camli/search/claims":
|
|
|
|
sh.serveClaims(rw, req)
|
|
|
|
return
|
|
|
|
case "camli/search/files":
|
|
|
|
sh.serveFiles(rw, req)
|
|
|
|
return
|
2011-06-23 05:21:18 +00:00
|
|
|
case "camli/search/signerattrvalue":
|
|
|
|
sh.serveSignerAttrValue(rw, req)
|
|
|
|
return
|
2011-06-26 00:50:38 +00:00
|
|
|
case "camli/search/signerpaths":
|
|
|
|
sh.serveSignerPaths(rw, req)
|
|
|
|
return
|
2011-06-09 19:55:38 +00:00
|
|
|
}
|
2011-05-30 22:44:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-09 19:55:38 +00:00
|
|
|
// TODO: discovery for the endpoints & better error message with link to discovery info
|
|
|
|
ret := jsonMap()
|
|
|
|
ret["error"] = "Unsupported search path or method"
|
|
|
|
ret["errorType"] = "input"
|
|
|
|
httputil.ReturnJson(rw, ret)
|
2011-05-30 22:44:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 03:45:47 +00:00
|
|
|
func (sh *Handler) serveRecentPermanodes(rw http.ResponseWriter, req *http.Request) {
|
2011-06-12 07:20:57 +00:00
|
|
|
ret := jsonMap()
|
|
|
|
defer httputil.ReturnJson(rw, ret)
|
|
|
|
|
2011-03-14 00:14:48 +00:00
|
|
|
ch := make(chan *Result)
|
|
|
|
errch := make(chan os.Error)
|
|
|
|
go func() {
|
2011-05-30 05:52:31 +00:00
|
|
|
errch <- sh.index.GetRecentPermanodes(ch, []*blobref.BlobRef{sh.owner}, 50)
|
2011-03-14 00:14:48 +00:00
|
|
|
}()
|
2011-03-14 02:27:59 +00:00
|
|
|
|
2011-06-12 07:20:57 +00:00
|
|
|
dr := &describeRequest{sh: sh, m: ret, wg: new(sync.WaitGroup)}
|
|
|
|
|
|
|
|
recent := jsonMapList()
|
2011-03-14 00:14:48 +00:00
|
|
|
for res := range ch {
|
2011-06-09 19:55:38 +00:00
|
|
|
jm := jsonMap()
|
2011-06-12 07:20:57 +00:00
|
|
|
dr.describe(res.BlobRef, 2)
|
2011-03-14 00:14:48 +00:00
|
|
|
jm["blobref"] = res.BlobRef.String()
|
2011-03-14 02:27:59 +00:00
|
|
|
jm["owner"] = res.Signer.String()
|
2011-03-14 00:14:48 +00:00
|
|
|
t := time.SecondsToUTC(res.LastModTime)
|
|
|
|
jm["modtime"] = t.Format(time.RFC3339)
|
2011-06-12 07:20:57 +00:00
|
|
|
recent = append(recent, jm)
|
2011-03-14 00:14:48 +00:00
|
|
|
}
|
2011-03-14 02:27:59 +00:00
|
|
|
|
2011-03-14 00:14:48 +00:00
|
|
|
err := <-errch
|
2011-03-14 02:27:59 +00:00
|
|
|
if err != nil {
|
|
|
|
// TODO: return error status code
|
|
|
|
ret["error"] = fmt.Sprintf("%v", err)
|
2011-06-12 07:20:57 +00:00
|
|
|
return
|
2011-03-14 02:27:59 +00:00
|
|
|
}
|
2011-06-12 07:20:57 +00:00
|
|
|
|
|
|
|
dr.wg.Wait()
|
|
|
|
ret["recent"] = recent
|
2011-05-30 22:44:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-17 03:45:47 +00:00
|
|
|
func (sh *Handler) serveClaims(rw http.ResponseWriter, req *http.Request) {
|
2011-06-09 19:55:38 +00:00
|
|
|
ret := jsonMap()
|
2011-06-03 22:23:23 +00:00
|
|
|
|
|
|
|
pn := blobref.Parse(req.FormValue("permanode"))
|
|
|
|
if pn == nil {
|
|
|
|
http.Error(rw, "Missing or invalid 'permanode' param", 400)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO: rename GetOwnerClaims to GetClaims?
|
|
|
|
claims, err := sh.index.GetOwnerClaims(pn, sh.owner)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error getting claims of %s: %v", pn.String(), err)
|
|
|
|
} else {
|
|
|
|
sort.Sort(claims)
|
2011-06-09 19:55:38 +00:00
|
|
|
jclaims := jsonMapList()
|
2011-06-03 22:23:23 +00:00
|
|
|
|
|
|
|
for _, claim := range claims {
|
2011-06-09 19:55:38 +00:00
|
|
|
jclaim := jsonMap()
|
2011-06-03 22:23:23 +00:00
|
|
|
jclaim["blobref"] = claim.BlobRef.String()
|
|
|
|
jclaim["signer"] = claim.Signer.String()
|
|
|
|
jclaim["permanode"] = claim.Permanode.String()
|
|
|
|
jclaim["date"] = claim.Date.Format(time.RFC3339)
|
|
|
|
jclaim["type"] = claim.Type
|
|
|
|
if claim.Attr != "" {
|
|
|
|
jclaim["attr"] = claim.Attr
|
|
|
|
}
|
|
|
|
if claim.Value != "" {
|
|
|
|
jclaim["value"] = claim.Value
|
|
|
|
}
|
|
|
|
|
|
|
|
jclaims = append(jclaims, jclaim)
|
|
|
|
}
|
|
|
|
ret["claims"] = jclaims
|
|
|
|
}
|
|
|
|
|
|
|
|
httputil.ReturnJson(rw, ret)
|
|
|
|
}
|
|
|
|
|
2011-06-12 07:20:57 +00:00
|
|
|
type describeRequest struct {
|
2011-06-17 03:45:47 +00:00
|
|
|
sh *Handler
|
2011-06-12 07:20:57 +00:00
|
|
|
|
|
|
|
lk sync.Mutex // protects m
|
|
|
|
m map[string]interface{} // top-level response JSON
|
|
|
|
done map[string]bool // blobref -> described
|
|
|
|
|
|
|
|
wg *sync.WaitGroup // for load requests
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dr *describeRequest) blobRefMap(b *blobref.BlobRef) map[string]interface{} {
|
|
|
|
dr.lk.Lock()
|
|
|
|
defer dr.lk.Unlock()
|
|
|
|
bs := b.String()
|
|
|
|
if m, ok := dr.m[bs]; ok {
|
|
|
|
return m.(map[string]interface{})
|
|
|
|
}
|
|
|
|
m := jsonMap()
|
|
|
|
dr.m[bs] = m
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dr *describeRequest) describe(br *blobref.BlobRef, depth int) {
|
|
|
|
if depth <= 0 {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dr.lk.Lock()
|
|
|
|
defer dr.lk.Unlock()
|
|
|
|
if dr.done == nil {
|
|
|
|
dr.done = make(map[string]bool)
|
|
|
|
}
|
|
|
|
if dr.done[br.String()] {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
dr.done[br.String()] = true
|
|
|
|
dr.wg.Add(1)
|
|
|
|
go func() {
|
|
|
|
defer dr.wg.Done()
|
|
|
|
dr.describeReally(br, depth)
|
|
|
|
}()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dr *describeRequest) describeReally(br *blobref.BlobRef, depth int) {
|
|
|
|
mime, size, err := dr.sh.index.GetBlobMimeType(br)
|
|
|
|
if err == os.ENOENT {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if err != nil {
|
|
|
|
dr.lk.Lock()
|
|
|
|
defer dr.lk.Unlock()
|
|
|
|
dr.m["error"] = err.String()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
m := dr.blobRefMap(br)
|
|
|
|
setMimeType(m, mime)
|
|
|
|
m["size"] = size
|
|
|
|
|
|
|
|
switch mime {
|
|
|
|
case "application/json; camliType=permanode":
|
|
|
|
pm := jsonMap()
|
|
|
|
m["permanode"] = pm
|
|
|
|
dr.populatePermanodeFields(pm, br, dr.sh.owner, depth)
|
|
|
|
case "application/json; camliType=file":
|
|
|
|
fm := jsonMap()
|
|
|
|
m["file"] = fm
|
|
|
|
dr.populateFileFields(fm, br)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-17 03:45:47 +00:00
|
|
|
func (sh *Handler) serveDescribe(rw http.ResponseWriter, req *http.Request) {
|
2011-06-09 19:55:38 +00:00
|
|
|
ret := jsonMap()
|
2011-06-11 16:29:41 +00:00
|
|
|
defer httputil.ReturnJson(rw, ret)
|
|
|
|
|
2011-05-30 22:44:25 +00:00
|
|
|
br := blobref.Parse(req.FormValue("blobref"))
|
|
|
|
if br == nil {
|
2011-06-11 16:29:41 +00:00
|
|
|
ret["error"] = "Missing or invalid 'blobref' param"
|
|
|
|
ret["errorType"] = "input"
|
2011-05-30 22:44:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-06-12 07:20:57 +00:00
|
|
|
dr := &describeRequest{sh: sh, m: ret, wg: new(sync.WaitGroup)}
|
|
|
|
dr.describe(br, 4)
|
|
|
|
dr.wg.Wait()
|
2011-03-13 23:38:32 +00:00
|
|
|
}
|
2011-03-14 02:27:59 +00:00
|
|
|
|
2011-06-17 03:45:47 +00:00
|
|
|
func (sh *Handler) serveFiles(rw http.ResponseWriter, req *http.Request) {
|
2011-06-09 19:55:38 +00:00
|
|
|
ret := jsonMap()
|
|
|
|
defer httputil.ReturnJson(rw, ret)
|
|
|
|
|
|
|
|
br := blobref.Parse(req.FormValue("bytesref"))
|
|
|
|
if br == nil {
|
|
|
|
// TODO: formalize how errors are returned And make
|
|
|
|
// ReturnJson set the HTTP status to 400 automatically
|
|
|
|
// in some cases, if errorType is "input"? Document
|
|
|
|
// this somewhere. Are there existing JSON
|
|
|
|
// conventions to use?
|
|
|
|
ret["error"] = "Missing or invalid 'bytesref' param"
|
|
|
|
ret["errorType"] = "input"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
files, err := sh.index.ExistingFileSchemas(br)
|
|
|
|
if err != nil {
|
|
|
|
ret["error"] = err.String()
|
|
|
|
ret["errorType"] = "server"
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
strList := []string{}
|
|
|
|
for _, br := range files {
|
|
|
|
strList = append(strList, br.String())
|
|
|
|
}
|
|
|
|
ret["files"] = strList
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2011-06-12 07:20:57 +00:00
|
|
|
func (dr *describeRequest) populateFileFields(fm map[string]interface{}, fbr *blobref.BlobRef) {
|
|
|
|
fi, err := dr.sh.index.GetFileInfo(fbr)
|
|
|
|
if err != nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fm["size"] = fi.Size
|
|
|
|
fm["fileName"] = fi.FileName
|
|
|
|
fm["mimeType"] = fi.MimeType
|
|
|
|
}
|
|
|
|
|
2011-05-30 22:44:25 +00:00
|
|
|
// dmap may be nil, returns the jsonMap to populate into
|
2011-06-12 07:20:57 +00:00
|
|
|
func (dr *describeRequest) populatePermanodeFields(jm map[string]interface{}, pn, signer *blobref.BlobRef, depth int) {
|
|
|
|
//log.Printf("populate permanode %s depth %d", pn, depth)
|
2011-06-09 19:55:38 +00:00
|
|
|
attr := jsonMap()
|
2011-03-14 02:27:59 +00:00
|
|
|
jm["attr"] = attr
|
2011-03-14 03:51:58 +00:00
|
|
|
|
2011-06-12 07:20:57 +00:00
|
|
|
claims, err := dr.sh.index.GetOwnerClaims(pn, signer)
|
2011-03-14 03:51:58 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error getting claims of %s: %v", pn.String(), err)
|
2011-06-11 16:51:08 +00:00
|
|
|
jm["error"] = fmt.Sprintf("Error getting claims of %s: %v", pn.String(), err)
|
|
|
|
return
|
|
|
|
}
|
2011-06-12 07:20:57 +00:00
|
|
|
|
2011-06-11 16:51:08 +00:00
|
|
|
sort.Sort(claims)
|
|
|
|
claimLoop:
|
|
|
|
for _, cl := range claims {
|
|
|
|
switch cl.Type {
|
|
|
|
case "del-attribute":
|
|
|
|
if cl.Value == "" {
|
2011-03-14 03:51:58 +00:00
|
|
|
attr[cl.Attr] = nil, false
|
2011-06-11 16:51:08 +00:00
|
|
|
} else {
|
2011-03-14 03:51:58 +00:00
|
|
|
sl, ok := attr[cl.Attr].([]string)
|
2011-06-04 17:18:38 +00:00
|
|
|
if ok {
|
2011-06-11 16:51:08 +00:00
|
|
|
filtered := make([]string, 0, len(sl))
|
|
|
|
for _, val := range sl {
|
|
|
|
if val != cl.Value {
|
|
|
|
filtered = append(filtered, val)
|
2011-06-04 17:18:38 +00:00
|
|
|
}
|
|
|
|
}
|
2011-06-11 16:51:08 +00:00
|
|
|
attr[cl.Attr] = filtered
|
|
|
|
}
|
|
|
|
}
|
|
|
|
case "set-attribute":
|
|
|
|
attr[cl.Attr] = nil, false
|
|
|
|
fallthrough
|
|
|
|
case "add-attribute":
|
|
|
|
if cl.Value == "" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
sl, ok := attr[cl.Attr].([]string)
|
|
|
|
if ok {
|
|
|
|
for _, exist := range sl {
|
|
|
|
if exist == cl.Value {
|
|
|
|
continue claimLoop
|
|
|
|
}
|
2011-03-14 03:51:58 +00:00
|
|
|
}
|
2011-06-11 16:51:08 +00:00
|
|
|
} else {
|
|
|
|
sl = make([]string, 0, 1)
|
|
|
|
attr[cl.Attr] = sl
|
2011-03-14 03:51:58 +00:00
|
|
|
}
|
2011-06-11 16:51:08 +00:00
|
|
|
attr[cl.Attr] = append(sl, cl.Value)
|
2011-03-14 03:51:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the content permanode is now known, look up its type
|
2011-06-11 16:51:08 +00:00
|
|
|
if content, ok := attr["camliContent"].([]string); ok && len(content) > 0 {
|
|
|
|
cbr := blobref.Parse(content[len(content)-1])
|
2011-06-12 07:20:57 +00:00
|
|
|
dr.describe(cbr, depth-1)
|
2011-05-30 22:44:25 +00:00
|
|
|
}
|
2011-06-11 17:12:39 +00:00
|
|
|
|
|
|
|
// Resolve children
|
2011-06-12 07:20:57 +00:00
|
|
|
if member, ok := attr["camliMember"].([]string); ok && len(member) > 0 {
|
|
|
|
for _, member := range member {
|
|
|
|
membr := blobref.Parse(member)
|
|
|
|
if membr != nil {
|
|
|
|
dr.describe(membr, depth-1)
|
2011-06-11 17:12:39 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-05-30 22:44:25 +00:00
|
|
|
}
|
|
|
|
|
2011-06-23 05:21:18 +00:00
|
|
|
func mustGet(req *http.Request, param string) string {
|
|
|
|
v := req.FormValue(param)
|
|
|
|
if v == "" {
|
|
|
|
panic(fmt.Sprintf("missing required parameter %q", param))
|
|
|
|
}
|
|
|
|
return v
|
|
|
|
}
|
|
|
|
|
|
|
|
func setPanicError(m map[string]interface{}) {
|
|
|
|
p := recover()
|
|
|
|
if p == nil {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
m["error"] = p.(string)
|
|
|
|
m["errorType"] = "input"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (sh *Handler) serveSignerAttrValue(rw http.ResponseWriter, req *http.Request) {
|
|
|
|
ret := jsonMap()
|
|
|
|
defer httputil.ReturnJson(rw, ret)
|
|
|
|
defer setPanicError(ret)
|
|
|
|
|
|
|
|
signer := blobref.MustParse(mustGet(req, "signer"))
|
|
|
|
attr := mustGet(req, "attr")
|
|
|
|
value := mustGet(req, "value")
|
|
|
|
pn, err := sh.index.PermanodeOfSignerAttrValue(signer, attr, value)
|
|
|
|
if err != nil {
|
|
|
|
ret["error"] = err.String()
|
|
|
|
} else {
|
|
|
|
ret["permanode"] = pn.String()
|
|
|
|
|
|
|
|
dr := &describeRequest{sh: sh, m: ret, wg: new(sync.WaitGroup)}
|
|
|
|
dr.describe(pn, 2)
|
|
|
|
dr.wg.Wait()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-26 00:50:38 +00:00
|
|
|
func (sh *Handler) serveSignerPaths(rw http.ResponseWriter, req *http.Request) {
|
|
|
|
ret := jsonMap()
|
|
|
|
defer httputil.ReturnJson(rw, ret)
|
|
|
|
defer setPanicError(ret)
|
|
|
|
|
|
|
|
signer := blobref.MustParse(mustGet(req, "signer"))
|
|
|
|
target := blobref.MustParse(mustGet(req, "target"))
|
|
|
|
paths, err := sh.index.PathsOfSignerTarget(signer, target)
|
|
|
|
if err != nil {
|
|
|
|
ret["error"] = err.String()
|
|
|
|
} else {
|
|
|
|
jpaths := []map[string]interface{}{}
|
|
|
|
for _, path := range paths {
|
|
|
|
jpaths = append(jpaths, map[string]interface{}{
|
|
|
|
"claimRef": path.Claim.String(),
|
|
|
|
"baseRef": path.Base.String(),
|
|
|
|
"suffix": path.Suffix,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
ret["paths"] = jpaths
|
|
|
|
dr := &describeRequest{sh: sh, m: ret, wg: new(sync.WaitGroup)}
|
|
|
|
for _, path := range paths {
|
|
|
|
dr.describe(path.Base, 2)
|
|
|
|
}
|
|
|
|
dr.wg.Wait()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-30 22:44:25 +00:00
|
|
|
const camliTypePrefix = "application/json; camliType="
|
|
|
|
|
2011-06-09 19:55:38 +00:00
|
|
|
func setMimeType(m map[string]interface{}, mime string) {
|
2011-05-30 22:44:25 +00:00
|
|
|
m["type"] = mime
|
|
|
|
if strings.HasPrefix(mime, camliTypePrefix) {
|
|
|
|
m["camliType"] = mime[len(camliTypePrefix):]
|
2011-03-14 03:51:58 +00:00
|
|
|
}
|
2011-03-14 02:27:59 +00:00
|
|
|
}
|