From 6cd12911f4d3aa4c6a75c922f9de231e2cf309dd Mon Sep 17 00:00:00 2001 From: Rasmus Dahlberg Date: Tue, 1 Dec 2020 15:34:55 +0100 Subject: attached url method on endpoint type --- client/client.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'client') diff --git a/client/client.go b/client/client.go index 21be669..6ab654a 100644 --- a/client/client.go +++ b/client/client.go @@ -4,7 +4,6 @@ import ( "bytes" "context" "fmt" - "strings" "crypto/ed25519" "crypto/tls" @@ -99,7 +98,7 @@ func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StI } glog.V(3).Infof("created post data: %s", string(data)) - url := c.protocol() + strings.Join([]string{c.Log.BaseUrl, string(stfe.EndpointAddEntry)}, "/") + url := stfe.EndpointAddEntry.Url(c.protocol() + c.Log.BaseUrl) req, err := http.NewRequest("POST", url, bytes.NewBuffer(data)) if err != nil { return nil, fmt.Errorf("failed creating http request: %v", err) @@ -126,7 +125,7 @@ func (c *Client) AddEntry(ctx context.Context, name, checksum []byte) (*stfe.StI // GetSth fetches and verifies the most recent STH. Safe to use without a // client chain and corresponding private key. func (c *Client) GetSth(ctx context.Context) (*stfe.StItem, error) { - url := c.protocol() + strings.Join([]string{c.Log.BaseUrl, string(stfe.EndpointGetSth)}, "/") + url := stfe.EndpointGetSth.Url(c.protocol() + c.Log.BaseUrl) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed creating http request: %v", err) @@ -152,7 +151,7 @@ func (c *Client) GetSth(ctx context.Context) (*stfe.StItem, error) { // GetConsistencyProof fetches and verifies a consistency proof between two // STHs. Safe to use without a client chain and corresponding private key. func (c *Client) GetConsistencyProof(ctx context.Context, first, second *stfe.StItem) (*stfe.StItem, error) { - url := c.protocol() + strings.Join([]string{c.Log.BaseUrl, string(stfe.EndpointGetConsistencyProof)}, "/") + url := stfe.EndpointGetConsistencyProof.Url(c.protocol() + c.Log.BaseUrl) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed creating http request: %v", err) @@ -181,7 +180,7 @@ func (c *Client) GetConsistencyProof(ctx context.Context, first, second *stfe.St // STH. Safe to use without a client chain and corresponding private key. func (c *Client) GetProofByHash(ctx context.Context, treeSize uint64, rootHash, leaf []byte) (*stfe.StItem, error) { leafHash := rfc6962.DefaultHasher.HashLeaf(leaf) - url := c.protocol() + strings.Join([]string{c.Log.BaseUrl, string(stfe.EndpointGetProofByHash)}, "/") + url := stfe.EndpointGetProofByHash.Url(c.protocol() + c.Log.BaseUrl) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed creating http request: %v", err) @@ -214,7 +213,7 @@ func (c *Client) GetProofByHash(ctx context.Context, treeSize uint64, rootHash, // Note that a certificate chain is considered valid if it is chained correctly. // In other words, the caller may want to check whether the anchor is trusted. func (c *Client) GetEntries(ctx context.Context, start, end uint64) ([]*stfe.GetEntryResponse, error) { - url := c.protocol() + strings.Join([]string{c.Log.BaseUrl, string(stfe.EndpointGetEntries)}, "/") + url := stfe.EndpointGetEntries.Url(c.protocol() + c.Log.BaseUrl) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed creating http request: %v", err) @@ -252,7 +251,7 @@ func (c *Client) GetEntries(ctx context.Context, start, end uint64) ([]*stfe.Get // GetAnchors fetches the log's trust anchors. Safe to use without a client // chain and corresponding private key. func (c *Client) GetAnchors(ctx context.Context) ([]*x509.Certificate, error) { - url := c.protocol() + strings.Join([]string{c.Log.BaseUrl, string(stfe.EndpointGetAnchors)}, "/") + url := stfe.EndpointGetAnchors.Url(c.protocol() + c.Log.BaseUrl) req, err := http.NewRequest("GET", url, nil) if err != nil { return nil, fmt.Errorf("failed creating http request: %v", err) -- cgit v1.2.3