Exemplo n.º 1
0
func (cli *Client) ThemePull(token string, pkg *Package) error {
	params := url.Values{}
	params.Set("token", token)

	URL := rpc.BuildHttpURL(cli.addr,
		fmt.Sprintf("/themes/pull/%s/%s/%s", pkg.Provider, pkg.Name, pkg.Version),
		params)
	resp, err := cli.conn.GetResponse(nil, URL)
	if err != nil {
		return err
	}

	if resp.StatusCode/100 != 2 {
		if resp.ContentLength != 0 {
			var js JSResponse
			if err := json.NewDecoder(resp.Body).Decode(&js); err != nil {
				return err
			}
			return fmt.Errorf("code: %d, reason: %s", resp.StatusCode, js.Err)
		}
		return fmt.Errorf("code: %d, reason: failed", resp.StatusCode)
	}
	pkg.ArchiveLen = resp.ContentLength
	pkg.ArchiveReader = resp.Body
	return nil
}
Exemplo n.º 2
0
func (h2o *Client) Download(l Logger, auth Auth, dest_uri string) (io.ReadCloser, int64, error)  {
	URL := rpc.BuildHttpURL(h2o.addr, dest_uri, nil)

	h2o.Lock()
	defer h2o.Unlock()

	h2o.conn.Prepare(auth)
	defer h2o.conn.Prepare(nil)

	resp, err := h2o.conn.GetResponse(l, URL)
	if err != nil {
		return nil, 0, err
	}

	if resp.StatusCode/100 != 2 {
		if resp.ContentLength != 0 {
			var ret1 rpc.ErrorRet
			if err := json.NewDecoder(resp.Body).Decode(&ret1); err != nil {
				return nil, 0, err
			}
			return nil, 0, fmt.Errorf("code: %d, reason: %s", resp.StatusCode, ret1.Error)
		}
		return nil, 0, fmt.Errorf("code: %d, reason: failed", resp.StatusCode)
	}
	return resp.Body, resp.ContentLength, nil
}
Exemplo n.º 3
0
func (cli *Client) SignUp(authid, password string, auth interface{}) error {
	URL := rpc.BuildHttpURL(cli.addr, "/auth/email/signup", nil)
	if err := cli.conn.PostForm(nil, URL, map[string][]string{
		"authid":   {authid},
		"password": {password},
	}, auth); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 4
0
func (cli *Client) UnpauseContainer(token string, id string, ret interface{}) error {
	params := url.Values{}
	params.Set("token", token)

	URL := rpc.BuildHttpURL(cli.addr, fmt.Sprintf("/containers/%s/unpause", id), params)
	if err := cli.conn.PostForm(nil, URL, nil, ret); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 5
0
func (cli *Client) Auth(token string, auth interface{}) error {
	params := url.Values{}
	params.Set("token", token)

	URL := rpc.BuildHttpURL(cli.addr, "/auth/info", params)
	if err := cli.conn.Get(nil, URL, auth); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 6
0
func (cli *Client) SignInSecret(authid, secret, remember string, auth interface{}) error {
	URL := rpc.BuildHttpURL(cli.addr, "/auth/email/signinsecret", nil)
	if err := cli.conn.PostForm(nil, URL, map[string][]string{
		"authid":   {authid},
		"secret":   {secret},
		"remember": {remember},
	}, auth); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 7
0
func (h2o *Client) Delete(l Logger, auth Auth, dest_uri string) error {
	URL := rpc.BuildHttpURL(h2o.addr, dest_uri, nil)

	h2o.Lock()
	defer h2o.Unlock()

	h2o.conn.Prepare(auth)
	defer h2o.conn.Prepare(nil)

	return h2o.conn.Delete(l, URL, nil)
}
Exemplo n.º 8
0
func (cli *Client) SignOff(token string) error {

	params := url.Values{}
	params.Set("token", token)

	URL := rpc.BuildHttpURL(cli.addr, "/auth/signoff", params)
	if err := cli.conn.Get(nil, URL, nil); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 9
0
func (cli *Client) DomainContainer(token string, id string, domain string, ret interface{}) error {
	params := url.Values{}
	params.Set("token", token)

	URL := rpc.BuildHttpURL(cli.addr, fmt.Sprintf("/containers/%s/domain", id), params)
	if err := cli.conn.PostForm(nil, URL, map[string][]string{
		"domain": {domain},
	}, ret); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 10
0
func (cli *Client) GetContainers(token string, ids []string, ret interface{}) error {
	params := url.Values{}
	params.Set("token", token)
	for _, id := range ids {
		params.Add("container", id)
	}

	URL := rpc.BuildHttpURL(cli.addr, "/containers/json", params)
	if err := cli.conn.Get(nil, URL, ret); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 11
0
func (cli *Client) CreateContainer(token string, invitation string, version string, ret interface{}) error {
	params := url.Values{}
	params.Set("token", token)
	params.Set("version", version)

	URL := rpc.BuildHttpURL(cli.addr, "/containers/create", params)
	if err := cli.conn.PostForm(nil, URL, map[string][]string{
		"invitation": {invitation},
	}, ret); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 12
0
func (h2o *Client) Upload(l Logger, auth Auth, dest_uri string, contentType string, rd io.Reader, sz int64) error {
	URL := rpc.BuildHttpURL(h2o.addr, dest_uri, nil)

	h2o.Lock()
	defer h2o.Unlock()

	h2o.conn.Prepare(auth)
	defer h2o.conn.Prepare(nil)

	if err := h2o.conn.Put(l, URL, contentType, rd, sz, nil); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 13
0
func (h2o *Client) SetConfig(l Logger, auth Auth, section string, ret interface{}) error {
	URL := rpc.BuildHttpURL(h2o.addr, path.Join(section, ".conf"), nil)

	h2o.Lock()
	defer h2o.Unlock()

	h2o.conn.Prepare(auth)
	defer h2o.conn.Prepare(nil)

	if err := h2o.conn.PutJson(l, URL, ret, nil); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 14
0
func (cli *Client) ThemePush(token string, pkg *Package) error {
	params := url.Values{}
	params.Set("token", token)

	URL := rpc.BuildHttpURL(cli.addr,
		fmt.Sprintf("/themes/push/%s/%s/%s", pkg.Provider, pkg.Name, pkg.Version),
		params)

	var b bytes.Buffer
	wr := multipart.NewWriter(&b)

	if err := wr.WriteField("catagory", fmt.Sprintf("%d", pkg.Catagory)); err != nil {
		return err
	}
	if err := wr.WriteField("description", pkg.Description); err != nil {
		return err
	}
	if err := wr.WriteField("status", fmt.Sprintf("%d", pkg.Status)); err != nil {
		return err
	}
	if err := wr.WriteField("price", fmt.Sprintf("%f", pkg.Price)); err != nil {
		return err
	}
	p, err := wr.CreateFormFile("file", pkg.ArchiveName)
	if err != nil {
		return err
	}
	defer pkg.ArchiveReader.Close()

	if _, err := io.Copy(p, pkg.ArchiveReader); err != nil {
		return err
	}
	if err := wr.Close(); err != nil {
		return err
	}

	bar := pb.New(b.Len()).SetUnits(pb.U_BYTES)
	bar.Prefix(fmt.Sprintf("%s/%s:%s ", pkg.Provider, pkg.Name, pkg.Version))
	bar.Start()

	// create multi writer
	rd := pb.NewPbReader(&b, bar)

	if err := cli.conn.Post(nil, URL, wr.FormDataContentType(), rd, int64(b.Len()), nil); err != nil {
		return err
	}
	bar.FinishPrint(fmt.Sprintf("%s/%s:%s pushed succussfully.", pkg.Provider, pkg.Name, pkg.Version))
	return nil
}
Exemplo n.º 15
0
func (h2o *Client) SetHost(l Logger, auth Auth, hostname string, url string) error {
	URL := rpc.BuildHttpURL(h2o.addr, "/virtualhost.json", nil)

	h2o.Lock()
	defer h2o.Unlock()

	h2o.conn.Prepare(auth)
	defer h2o.conn.Prepare(nil)

	var hurl HostURL
	hurl.Host = hostname
	hurl.URL = url

	if err := h2o.conn.PutJson(l, URL, hurl, nil); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 16
0
func (h2o *Client) DelHost(l Logger, auth Auth, hostname string) error {
	if hostname == "" {
		return errors.New("hostname absent")
	}
	params := url.Values{
		"host": {hostname},
	}
	URL := rpc.BuildHttpURL(h2o.addr, "/virtualhost.json", params)

	h2o.Lock()
	defer h2o.Unlock()

	h2o.conn.Prepare(auth)
	defer h2o.conn.Prepare(nil)

	if err := h2o.conn.Delete(l, URL, nil); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 17
0
func (h2o *Client) GetHost(l Logger, auth Auth, hosts []string, ret interface{}) error {
	var params url.Values = nil
	if len(hosts) > 0 {
		params = url.Values{
			"host": hosts,
		}
	}

	URL := rpc.BuildHttpURL(h2o.addr, "/virtualhost.json", params)

	h2o.Lock()
	defer h2o.Unlock()

	h2o.conn.Prepare(auth)
	defer h2o.conn.Prepare(nil)

	if err := h2o.conn.Get(l, URL, ret); err != nil {
		return err
	}
	return nil
}
Exemplo n.º 18
0
func (cli *Client) ThemeSearch(token string, keyword string, catagory int64, page int64, size int64, themes interface{}) error {
	params := url.Values{}
	params.Set("keyword", keyword)
	if token != "" {
		params.Set("token", token)
	}
	if catagory != 0 {
		params.Set("catagory", fmt.Sprintf("%d", catagory))
	}
	if page != 0 {
		params.Set("page", fmt.Sprintf("%d", page))
	}
	if size != 0 {
		params.Set("size", fmt.Sprintf("%d", size))
	}
	URL := rpc.BuildHttpURL(cli.addr, "/themes/search", params)
	if err := cli.conn.Get(nil, URL, themes); err != nil {
		return err
	}
	return nil
}