Beispiel #1
0
func (h *Server) PostLogs(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	a, err := findApp(ctx, h)
	if err != nil {
		return err
	}

	var form PostLogsForm
	// We ignore the EOF error for backwards compatability with the "emp"
	// command that doesn't support providing a duration.
	ignoreEOF := true
	if err := DecodeRequest(r, &form, ignoreEOF); err != nil {
		return err
	}

	rw := streamhttp.StreamingResponseWriter(w)

	// Prevent the ELB idle connection timeout to close the connection.
	defer close(streamhttp.Heartbeat(rw, 10*time.Second))

	err = h.StreamLogs(a, rw, time.Duration(form.Duration))
	if err != nil {
		return err
	}

	return nil
}
Beispiel #2
0
func newDeployOpts(ctx context.Context, w http.ResponseWriter, req *http.Request) (*empire.DeployOpts, error) {
	var form PostDeployForm

	if err := Decode(req, &form); err != nil {
		return nil, err
	}

	m, err := findMessage(req)
	if err != nil {
		return nil, err
	}

	w.Header().Set("Content-Type", "application/json; boundary=NL")

	if form.Image.Tag == "" && form.Image.Digest == "" {
		form.Image.Tag = "latest"
	}

	opts := empire.DeployOpts{
		User:    auth.UserFromContext(ctx),
		Image:   form.Image,
		Output:  empire.NewDeploymentStream(streamhttp.StreamingResponseWriter(w)),
		Message: m,
		Stream:  form.Stream,
	}
	return &opts, nil
}
Beispiel #3
0
func (h *PostLogs) ServeHTTPContext(ctx context.Context, w http.ResponseWriter, r *http.Request) error {
	a, err := findApp(ctx, h)
	if err != nil {
		return err
	}

	rw := streamhttp.StreamingResponseWriter(w)

	// Prevent the ELB idle connection timeout to close the connection.
	defer close(streamhttp.Heartbeat(rw, 10*time.Second))

	err = h.StreamLogs(a, rw)
	if err != nil {
		return err
	}

	return nil
}
Beispiel #4
0
func newDeploymentsCreateOpts(ctx context.Context, w http.ResponseWriter, req *http.Request) (*empire.DeploymentsCreateOpts, error) {
	var form PostDeployForm

	if err := Decode(req, &form); err != nil {
		return nil, err
	}

	w.Header().Set("Content-Type", "application/json; boundary=NL")

	if form.Image.Tag == "" && form.Image.Digest == "" {
		form.Image.Tag = "latest"
	}

	user, _ := empire.UserFromContext(ctx)

	opts := empire.DeploymentsCreateOpts{
		Image:  form.Image,
		Output: streamhttp.StreamingResponseWriter(w),
		User:   user,
	}
	return &opts, nil
}