From 01ff846557f9f0c5b7d6d2a38e4c7eb72ae5c5b9 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Sat, 15 Jan 2011 18:10:58 -0800 Subject: [PATCH] Start of camput --permanode --- build.pl | 1 + clients/go/camput/camput.go | 21 +++++++++++++++++++-- dev-camput | 2 +- lib/go/schema/schema.go | 18 ++++++++++++++++++ 4 files changed, 39 insertions(+), 3 deletions(-) diff --git a/build.pl b/build.pl index ba3f9bf2d..d1df35402 100755 --- a/build.pl +++ b/build.pl @@ -179,6 +179,7 @@ __DATA__ - lib/go/client - lib/go/blobref - lib/go/schema + - lib/go/jsonsign ./clients/go/camget/Makefile - lib/go/client - lib/go/blobref diff --git a/clients/go/camput/camput.go b/clients/go/camput/camput.go index 8abee6cf2..6beeaf27a 100644 --- a/clients/go/camput/camput.go +++ b/clients/go/camput/camput.go @@ -9,6 +9,7 @@ import ( "camli/blobref" "camli/client" "camli/schema" +// "camli/jsonsign" "crypto/sha1" "flag" "fmt" @@ -21,6 +22,8 @@ import ( // Things that can be uploaded. (at most one of these) var flagBlob *bool = flag.Bool("blob", false, "upload a file's bytes as a single blob") var flagFile *bool = flag.Bool("file", false, "upload a file's bytes as a blob, as well as its JSON file record") +var flagPermanode *bool = flag.Bool("permanode", false, "create a new permanode") + var flagVerbose *bool = flag.Bool("verbose", false, "be verbose") var wereErrors = false @@ -142,6 +145,12 @@ func (up *Uploader) UploadMap(m map[string]interface{}) (*client.PutResult, os.E return up.Upload(h) } +func (up *Uploader) UploadNewPermanode() (*client.PutResult, os.Error) { + unsigned := schema.NewUnsignedPermanode() + log.Printf("Got schema: %q", unsigned) + return nil, nil +} + func sumSet(flags ...*bool) (count int) { for _, f := range flags { if *f { @@ -181,12 +190,20 @@ func handleResult(what string, pr *client.PutResult, err os.Error) { func main() { flag.Parse() - if sumSet(flagFile, flagBlob) != 1 { + if sumSet(flagFile, flagBlob, flagPermanode) != 1 { usage("Exactly one of --blob and --file may be set") } uploader := &Uploader{client.NewOrFail()} - if *flagFile || *flagBlob { + + switch { + case *flagPermanode: + if flag.NArg() > 0 { + log.Exitf("--permanode doesn't take any additional arguments") + } + pr, err := uploader.UploadNewPermanode() + handleResult("permanode", pr, err) + case *flagFile || *flagBlob: for n := 0; n < flag.NArg(); n++ { if *flagBlob { pr, err := uploader.UploadFileBlob(flag.Arg(n)) diff --git a/dev-camput b/dev-camput index 3ab027271..75328136b 100755 --- a/dev-camput +++ b/dev-camput @@ -1,4 +1,4 @@ #!/bin/sh ./build.pl camput && \ - clients/go/camput/camput --verbose --blobserver=localhost:3179 --password=foo --file $@ + clients/go/camput/camput --verbose --blobserver=localhost:3179 --password=foo $@ diff --git a/lib/go/schema/schema.go b/lib/go/schema/schema.go index 1290be959..5928334c8 100644 --- a/lib/go/schema/schema.go +++ b/lib/go/schema/schema.go @@ -8,7 +8,9 @@ import ( "fmt" "io" "json" + "log" "os" + "rand" "strconv" "strings" "sync" @@ -63,6 +65,22 @@ func newCamliMap(version int, ctype string) map[string]interface{} { return m } +func NewUnsignedPermanode() string { + m := newCamliMap(1, "permanode") + chars := make([]byte, 20) + // Don't need cryptographically secure random here, as this + // will be GPG signed anyway. + for idx, _ := range chars { + chars[idx] = byte(32 + rand.Intn(126 - 32)) + } + m["random"] = string(chars) + unsigned, err := MapToCamliJson(m) + if err != nil { + log.Panicf("Unexpected error: %v", err) + } + return unsigned +} + // Map returns a Camli map of camliType "static-set" func (ss *StaticSet) Map() map[string]interface{} { m := newCamliMap(1, "static-set")