importer: make the schema.Signer available to the importer

Change-Id: Iad1a2f3bfe381b31a381957edb85d6d4aa21b38c
This commit is contained in:
Brad Fitzpatrick 2013-10-24 22:45:28 -07:00
parent 4fd71c6d16
commit 0324143892
4 changed files with 38 additions and 3 deletions

View File

@ -29,6 +29,8 @@ import (
"camlistore.org/pkg/blob"
"camlistore.org/pkg/blobserver"
"camlistore.org/pkg/jsonconfig"
"camlistore.org/pkg/jsonsign/signhandler"
"camlistore.org/pkg/schema"
"camlistore.org/pkg/search"
"camlistore.org/pkg/server"
)
@ -39,6 +41,7 @@ type Host struct {
target blobserver.StatReceiver
search *search.Handler
signer *schema.Signer
// client optionally specifies how to fetch external network
// resources. If nil, http.DefaultClient is used.
@ -290,8 +293,17 @@ func (h *Host) InitHandler(hl blobserver.FindHandlerByTyper) error {
}
h.target = rh.Storage
_, handler, _ = hl.FindHandlerByType("jsonsign")
if sigh, ok := handler.(*signhandler.Handler); ok {
h.signer = sigh.Signer()
}
if h.signer == nil {
return errors.New("importer requires a 'jsonsign' handler")
}
ro, err := h.RootObject()
log.Printf("Got a %#v, %v", ro, err)
log.Printf("Signer = %s", h.signer)
return nil
}

View File

@ -55,8 +55,11 @@ type Handler struct {
pubKeyWritten bool
entity *openpgp.Entity
signer *schema.Signer
}
func (h *Handler) Signer() *schema.Signer { return h.signer }
func (h *Handler) secretRingPath() string {
if h.secretRing != "" {
return h.secretRing
@ -114,6 +117,11 @@ func newJSONSignFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (http.Hand
Fetcher: ms,
}
h.signer, err = schema.NewSigner(h.pubKeyBlobRef, strings.NewReader(armoredPublicKey), h.entity)
if err != nil {
return nil, err
}
return h, nil
}

View File

@ -42,6 +42,10 @@ type Signer struct {
baseSigReq jsonsign.SignRequest
}
func (s *Signer) String() string {
return fmt.Sprintf("[*schema.Signer for key=%s pubkey=%s]", s.keyId, s.pubref)
}
// NewSigner returns an Signer given an armored public key's blobref,
// its armored content, and its associated private key entity.
// The privateKeySource must be either an *openpgp.Entity or a string filename to a secret key.

View File

@ -168,12 +168,23 @@ func makeCamliHandler(prefix, baseURL string, storage blobserver.Storage, hf blo
}
func (hl *handlerLoader) FindHandlerByType(htype string) (prefix string, handler interface{}, err error) {
for prefix, config := range hl.config {
nFound := 0
for pfx, config := range hl.config {
if config.htype == htype {
return prefix, hl.handler[prefix], nil
nFound++
prefix, handler = pfx, hl.handler[pfx]
}
}
return "", nil, blobserver.ErrHandlerTypeNotFound
if nFound == 0 {
return "", nil, blobserver.ErrHandlerTypeNotFound
}
if htype == "jsonsign" && nFound > 1 {
// TODO: do this for all handler types later? audit
// callers of FindHandlerByType and see if that's
// feasible. For now I'm only paranoid about jsonsign.
return "", nil, fmt.Errorf("%d handlers found of type %q; ambiguous", nFound, htype)
}
return
}
func (hl *handlerLoader) setupAll() {