Merge branch '8784-dir-listings'
[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 main
6
7 import (
8         "git.curoverse.com/arvados.git/sdk/go/keepclient"
9         "time"
10 )
11
12 // SignLocator takes a blobLocator, an apiToken and an expiry time, and
13 // returns a signed locator string.
14 func SignLocator(blobLocator, apiToken string, expiry time.Time) string {
15         return keepclient.SignLocator(blobLocator, apiToken, expiry, theConfig.BlobSignatureTTL.Duration(), theConfig.blobSigningKey)
16 }
17
18 // VerifySignature returns nil if the signature on the signedLocator
19 // can be verified using the given apiToken. Otherwise it returns
20 // either ExpiredError (if the timestamp has expired, which is
21 // something the client could have figured out independently) or
22 // PermissionError.
23 func VerifySignature(signedLocator, apiToken string) error {
24         err := keepclient.VerifySignature(signedLocator, apiToken, theConfig.BlobSignatureTTL.Duration(), theConfig.blobSigningKey)
25         if err == keepclient.ErrSignatureExpired {
26                 return ExpiredError
27         } else if err != nil {
28                 return PermissionError
29         }
30         return nil
31 }