Esempio n. 1
0
func InvokeServerCode(entryName string, version string) {
	p := Profile()
	path := fmt.Sprintf("/apps/%s/server-code/versions/%s/%s", p.AppId, version, entryName)
	headers := p.HttpHeadersWithAuthorization("application/json")
	r := goext.OptionalReader(func() io.Reader { return strings.NewReader("{}") })
	b := HttpPost(path, headers, r).Bytes()
	fmt.Printf("%s\n", string(b))
}
Esempio n. 2
0
func QueryObject(bucketname string) {
	p := Profile()
	path := fmt.Sprintf("/apps/%s/buckets/%s/query", p.AppId, bucketname)
	headers := p.HttpHeadersWithAuthorization("application/vnd.kii.QueryRequest+json")
	r := goext.OptionalReader(func() io.Reader { return strings.NewReader(`{"bucketQuery":{"clause":{"type":"all"}}}`) })
	body := HttpPost(path, headers, r).Bytes()

	fmt.Printf("%s\n", string(body))
}
Esempio n. 3
0
func ReplaceObject(bucketname string) {
	p := Profile()
	path := fmt.Sprintf("/apps/%s/buckets/%s/objects", p.AppId, bucketname)
	headers := p.HttpHeadersWithAuthorization("application/json")
	r := goext.OptionalReader(func() io.Reader { return strings.NewReader("{}") })
	body := HttpPut(path, headers, r).Bytes()

	var j map[string]interface{}
	json.Unmarshal(body, &j)
	fmt.Printf("%s\n", j["objectID"])
}
Esempio n. 4
0
func CreateObject(bucketname string) {
	r := goext.OptionalReader(func() io.Reader { return strings.NewReader("{}") })
	j := createObject(bucketname, r)
	fmt.Printf("%s\n", j["objectID"])
}
Esempio n. 5
0
		Name:  "publish",
		Usage: "Publish a body creating a new object into the bucket in application scope",
		Args:  `<bucket-id> <content-type>`,
		Flags: publishFlags,
		Description: `
   Runs object:create, object-body-attach and object:body-publish in order.
   It's expected body is given thru stdin.

   ex)
     dogs image/png < mydog.png`,
		Action: func(c *cli.Context) {
			bid, _ := c.ArgFor("bucket-id")
			ctype, _ := c.ArgFor("content-type")
			expired := relativeTimeToDuration(c.String("expired-in"))
			r := goext.OptionalReader(func() io.Reader {
				log.Fatalf(colorstring.Color("[red]object body must be given thru stdin"))
				return nil
			})
			CreateObjectAndPublishBody(bid, ctype, expired, r)
		},
	},
}

type ExpiredDuration int64

var publishFlags = []cli.Flag{
	cli.StringFlag{Name: "expired-in", Value: "1m", Usage: "Duration in seconds the publication URL has to be available, after that it will expire  ex) 85440h = 10years"},
}

func relativeTimeToDuration(s string) ExpiredDuration {
	d, err := time.ParseDuration(s)
	if err != nil {