Exemplo n.º 1
0
func invokePostRelease(client *http.Client, t flux.Token, router *mux.Router, endpoint string, s jobs.ReleaseJobParams) (jobs.JobID, error) {
	args := []string{"service", string(s.ServiceSpec), "image", string(s.ImageSpec), "kind", string(s.Kind)}
	for _, ex := range s.Excludes {
		args = append(args, "exclude", string(ex))
	}

	u, err := makeURL(endpoint, router, "PostRelease", args...)
	if err != nil {
		return "", errors.Wrap(err, "constructing URL")
	}

	req, err := http.NewRequest("POST", u.String(), nil)
	if err != nil {
		return "", errors.Wrapf(err, "constructing request %s", u)
	}
	t.Set(req)

	resp, err := executeRequest(client, req)
	if err != nil {
		return "", errors.Wrap(err, "executing HTTP request")
	}

	var res postReleaseResponse
	if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
		return "", errors.Wrap(err, "decoding response from server")
	}
	return res.ReleaseID, nil
}
Exemplo n.º 2
0
func invokeUnlock(client *http.Client, t flux.Token, router *mux.Router, endpoint string, id flux.ServiceID) error {
	u, err := makeURL(endpoint, router, "Unlock", "service", string(id))
	if err != nil {
		return errors.Wrap(err, "constructing URL")
	}

	req, err := http.NewRequest("POST", u.String(), nil)
	if err != nil {
		return errors.Wrapf(err, "constructing request %s", u)
	}
	t.Set(req)

	if _, err = executeRequest(client, req); err != nil {
		return errors.Wrap(err, "executing HTTP request")
	}

	return nil
}
Exemplo n.º 3
0
// Dial initiates a new websocket connection.
func Dial(client *http.Client, token flux.Token, u *url.URL) (Websocket, error) {
	// Build the http request
	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		return nil, errors.Wrapf(err, "constructing request %s", u)
	}

	// Add authentication if provided
	token.Set(req)

	// Use http client to do the http request
	conn, _, err := dialer(client).Dial(u.String(), req.Header)
	if err != nil {
		return nil, errors.Wrapf(err, "connecting websocket %s", u)
	}

	// Set up the ping heartbeat
	return Ping(conn), nil
}
Exemplo n.º 4
0
func invokeSetConfig(client *http.Client, t flux.Token, router *mux.Router, endpoint string, updates flux.UnsafeInstanceConfig) error {
	u, err := makeURL(endpoint, router, "SetConfig")
	if err != nil {
		return errors.Wrap(err, "constructing URL")
	}

	var configBytes bytes.Buffer
	if err = json.NewEncoder(&configBytes).Encode(updates); err != nil {
		return errors.Wrap(err, "encoding config updates")
	}

	req, err := http.NewRequest("POST", u.String(), &configBytes)
	if err != nil {
		return errors.Wrapf(err, "constructing request %s", u)
	}
	t.Set(req)

	if _, err = executeRequest(client, req); err != nil {
		return errors.Wrap(err, "executing HTTP request")
	}

	return nil
}
Exemplo n.º 5
0
func invokeGetConfig(client *http.Client, t flux.Token, router *mux.Router, endpoint string) (flux.InstanceConfig, error) {
	u, err := makeURL(endpoint, router, "GetConfig")
	if err != nil {
		return flux.InstanceConfig{}, errors.Wrap(err, "constructing URL")
	}

	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		return flux.InstanceConfig{}, errors.Wrapf(err, "constructing request %s", u)
	}
	t.Set(req)

	resp, err := executeRequest(client, req)
	if err != nil {
		return flux.InstanceConfig{}, errors.Wrap(err, "executing HTTP request")
	}

	var res flux.InstanceConfig
	if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
		return res, errors.Wrap(err, "decoding response body")
	}
	return res, nil
}
Exemplo n.º 6
0
func invokeGetRelease(client *http.Client, t flux.Token, router *mux.Router, endpoint string, id jobs.JobID) (jobs.Job, error) {
	u, err := makeURL(endpoint, router, "GetRelease", "id", string(id))
	if err != nil {
		return jobs.Job{}, errors.Wrap(err, "constructing URL")
	}

	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		return jobs.Job{}, errors.Wrapf(err, "constructing request %s", u)
	}
	t.Set(req)

	resp, err := executeRequest(client, req)
	if err != nil {
		return jobs.Job{}, errors.Wrap(err, "executing HTTP request")
	}

	var res jobs.Job
	if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
		return jobs.Job{}, errors.Wrap(err, "decoding response from server")
	}
	return res, nil
}
Exemplo n.º 7
0
func invokeListImages(client *http.Client, t flux.Token, router *mux.Router, endpoint string, s flux.ServiceSpec) ([]flux.ImageStatus, error) {
	u, err := makeURL(endpoint, router, "ListImages", "service", string(s))
	if err != nil {
		return nil, errors.Wrap(err, "constructing URL")
	}

	req, err := http.NewRequest("GET", u.String(), nil)
	if err != nil {
		return nil, errors.Wrapf(err, "constructing request %s", u)
	}
	t.Set(req)

	resp, err := executeRequest(client, req)
	if err != nil {
		return nil, errors.Wrap(err, "executing HTTP request")
	}

	var res []flux.ImageStatus
	if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
		return nil, errors.Wrap(err, "decoding response from server")
	}
	return res, nil
}