Refactor the multi-host salt install page.
[arvados.git] / services / keepstore / perms.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package keepstore
6
7 import (
8         "time"
9
10         "git.arvados.org/arvados.git/sdk/go/arvados"
11         "git.arvados.org/arvados.git/sdk/go/keepclient"
12 )
13
14 // SignLocator takes a blobLocator, an apiToken and an expiry time, and
15 // returns a signed locator string.
16 func SignLocator(cluster *arvados.Cluster, blobLocator, apiToken string, expiry time.Time) string {
17         return keepclient.SignLocator(blobLocator, apiToken, expiry, cluster.Collections.BlobSigningTTL.Duration(), []byte(cluster.Collections.BlobSigningKey))
18 }
19
20 // VerifySignature returns nil if the signature on the signedLocator
21 // can be verified using the given apiToken. Otherwise it returns
22 // either ExpiredError (if the timestamp has expired, which is
23 // something the client could have figured out independently) or
24 // PermissionError.
25 func VerifySignature(cluster *arvados.Cluster, signedLocator, apiToken string) error {
26         err := keepclient.VerifySignature(signedLocator, apiToken, cluster.Collections.BlobSigningTTL.Duration(), []byte(cluster.Collections.BlobSigningKey))
27         if err == keepclient.ErrSignatureExpired {
28                 return ExpiredError
29         } else if err != nil {
30                 return PermissionError
31         }
32         return nil
33 }