1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: Apache-2.0
15 "git.arvados.org/arvados.git/sdk/go/arvados"
18 // keepViaHTTP implements arvados.KeepGateway by using a KeepClient to
19 // do upstream requests to keepstore and keepproxy.
21 // This enables KeepClient to use KeepGateway wrappers (like
22 // arvados.DiskCache) to wrap its own HTTP client back-end methods
23 // (getOrHead, httpBlockWrite).
25 // See (*KeepClient)upstreamGateway() for the relevant glue.
26 type keepViaHTTP struct {
30 func (kvh *keepViaHTTP) ReadAt(locator string, dst []byte, offset int) (int, error) {
31 rdr, _, _, _, err := kvh.getOrHead("GET", locator, nil)
36 _, err = io.CopyN(io.Discard, rdr, int64(offset))
40 n, err := rdr.Read(dst)
44 func (kvh *keepViaHTTP) BlockRead(ctx context.Context, opts arvados.BlockReadOptions) (int, error) {
45 rdr, _, _, _, err := kvh.getOrHead("GET", opts.Locator, nil)
49 n, err := io.Copy(opts.WriteTo, rdr)
50 errClose := rdr.Close()
57 func (kvh *keepViaHTTP) BlockWrite(ctx context.Context, req arvados.BlockWriteOptions) (arvados.BlockWriteResponse, error) {
58 return kvh.httpBlockWrite(ctx, req)
61 func (kvh *keepViaHTTP) LocalLocator(locator string) (string, error) {
62 if !strings.Contains(locator, "+R") {
63 // Either it has +A, or it's unsigned and we assume
64 // it's a local locator on a site with signatures
68 sighdr := fmt.Sprintf("local, time=%s", time.Now().UTC().Format(time.RFC3339))
69 _, _, url, hdr, err := kvh.KeepClient.getOrHead("HEAD", locator, http.Header{"X-Keep-Signature": []string{sighdr}})
73 loc := hdr.Get("X-Keep-Locator")
75 return "", fmt.Errorf("missing X-Keep-Locator header in HEAD response from %s", url)