2011-12-07 22:42:16 +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 main
|
|
|
|
|
|
|
|
import (
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"errors"
|
2011-12-07 22:42:16 +00:00
|
|
|
"flag"
|
|
|
|
"strings"
|
|
|
|
|
2013-02-18 23:35:43 +00:00
|
|
|
"camlistore.org/pkg/cmdmain"
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
"camlistore.org/pkg/schema"
|
2011-12-07 22:42:16 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type rawCmd struct {
|
|
|
|
vals string // pipe separated key=value "camliVersion=1|camliType=foo", etc
|
|
|
|
signed bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2013-02-18 23:35:43 +00:00
|
|
|
cmdmain.RegisterCommand("rawobj", func(flags *flag.FlagSet) cmdmain.CommandRunner {
|
2011-12-07 22:42:16 +00:00
|
|
|
cmd := new(rawCmd)
|
|
|
|
flags.StringVar(&cmd.vals, "vals", "", "Pipe-separated key=value properties")
|
|
|
|
flags.BoolVar(&cmd.signed, "signed", true, "whether to sign the JSON object")
|
|
|
|
return cmd
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2013-02-26 14:26:18 +00:00
|
|
|
func (c *rawCmd) Describe() string {
|
|
|
|
return "Upload a custom JSON schema blob."
|
|
|
|
}
|
|
|
|
|
2011-12-07 22:42:16 +00:00
|
|
|
func (c *rawCmd) Usage() {
|
2013-02-18 23:35:43 +00:00
|
|
|
cmdmain.Errf("Usage: camput [globalopts] rawobj [rawopts]\n")
|
2011-12-07 22:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (c *rawCmd) Examples() []string {
|
|
|
|
return []string{"(debug command)"}
|
|
|
|
}
|
|
|
|
|
2013-02-18 23:35:43 +00:00
|
|
|
func (c *rawCmd) RunCommand(args []string) error {
|
2011-12-07 22:42:16 +00:00
|
|
|
if len(args) > 0 {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
return errors.New("Raw Object command doesn't take any additional arguments")
|
2011-12-07 22:42:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if c.vals == "" {
|
Update from r60 to [almost] Go 1.
A lot is still broken, but most stuff at least compiles now.
The directory tree has been rearranged now too. Go libraries are now
under "pkg". Fully qualified, they are e.g. "camlistore.org/pkg/jsonsign".
The go tool cannot yet fetch from arbitrary domains, but discussion is
happening now on which mechanism to use to allow that.
For now, put the camlistore root under $GOPATH/src. Typically $GOPATH
is $HOME, so Camlistore should be at $HOME/src/camlistore.org.
Then you can:
$ go build ./server/camlistored
... etc
The build.pl script is currently disabled. It'll be resurrected at
some point, but with a very different role (helping create a fake
GOPATH and running the go build command, if things are installed at
the wrong place, and/or running fileembed generators).
Many things are certainly broken.
Many things are disabled. (MySQL, all indexing, etc).
Many things need to be moved into
camlistore.org/third_party/{code.google.com,github.com} and updated
from their r60 to Go 1 versions, where applicable.
The GoMySQL stuff should be updated to use database/sql and the ziutek
library implementing database/sql/driver.
Help wanted.
Change-Id: If71217dc5c8f0e70dbe46e9504ca5131c6eeacde
2012-02-19 05:53:06 +00:00
|
|
|
return errors.New("No values")
|
2011-12-07 22:42:16 +00:00
|
|
|
}
|
2013-01-22 04:56:12 +00:00
|
|
|
|
|
|
|
bb := schema.NewBuilder()
|
2011-12-07 22:42:16 +00:00
|
|
|
for _, kv := range strings.Split(c.vals, "|") {
|
|
|
|
kv := strings.SplitN(kv, "=", 2)
|
2013-01-22 04:56:12 +00:00
|
|
|
bb.SetRawStringField(kv[0], kv[1])
|
2011-12-07 22:42:16 +00:00
|
|
|
}
|
|
|
|
|
2013-02-18 23:35:43 +00:00
|
|
|
up := getUploader()
|
2011-12-07 22:42:16 +00:00
|
|
|
if c.signed {
|
2013-01-22 04:56:12 +00:00
|
|
|
put, err := up.UploadAndSignBlob(bb)
|
2011-12-07 22:42:16 +00:00
|
|
|
handleResult("raw-object-signed", put, err)
|
|
|
|
return err
|
|
|
|
}
|
2013-01-22 04:56:12 +00:00
|
|
|
cj, err := bb.JSON()
|
2011-12-07 22:42:16 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
put, err := up.uploadString(cj)
|
|
|
|
handleResult("raw-object-unsigned", put, err)
|
|
|
|
return err
|
|
|
|
}
|