aboutsummaryrefslogtreecommitdiff
path: root/internal/node/primary/endpoint_internal.go
blob: f7a684fb9dd5db876ea57745cb7f32bf411267a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package primary

// This file implements internal HTTP handler callbacks for primary nodes.

import (
	"context"
	"fmt"
	"net/http"

	"git.sigsum.org/log-go/internal/node/handler"
	"git.sigsum.org/sigsum-go/pkg/log"
	"git.sigsum.org/sigsum-go/pkg/types"
)

func getTreeHeadUnsigned(ctx context.Context, c handler.Config, w http.ResponseWriter, _ *http.Request) (int, error) {
	log.Debug("handling %s request", types.EndpointGetTreeHeadUnsigned)
	p := c.(Primary)
	th, err := p.TrillianClient.GetTreeHead(ctx)
	if err != nil {
		return http.StatusInternalServerError, fmt.Errorf("failed getting tree head: %v", err)
	}
	if err := th.ToASCII(w); err != nil {
		return http.StatusInternalServerError, err
	}
	return http.StatusOK, nil
}

func getLeavesInternal(ctx context.Context, c handler.Config, w http.ResponseWriter, r *http.Request) (int, error) {
	return getLeavesGeneral(ctx, c, w, r, false)
}