aboutsummaryrefslogtreecommitdiff
path: root/guix-data-service/model
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2023-11-24 16:11:57 +0000
committerChristopher Baines <mail@cbaines.net>2023-11-24 16:11:57 +0000
commitb9026488ed53e76c5b8ff741a76e6b8c57256d4a (patch)
tree41c403547df8ae774209573c388d0f6ba3927157 /guix-data-service/model
parent241a704db15d36153b21d43742290bf308d05869 (diff)
downloaddata-service-b9026488ed53e76c5b8ff741a76e6b8c57256d4a.tar
data-service-b9026488ed53e76c5b8ff741a76e6b8c57256d4a.tar.gz
Memoize computing tokens
As I'm not sure how expensive this is, but it doesn't need doing for every request.
Diffstat (limited to 'guix-data-service/model')
-rw-r--r--guix-data-service/model/build-server-token-seed.scm29
1 files changed, 16 insertions, 13 deletions
diff --git a/guix-data-service/model/build-server-token-seed.scm b/guix-data-service/model/build-server-token-seed.scm
index c26f796..59cce2c 100644
--- a/guix-data-service/model/build-server-token-seed.scm
+++ b/guix-data-service/model/build-server-token-seed.scm
@@ -21,21 +21,24 @@
#:use-module (squee)
#:use-module (gcrypt hash)
#:use-module (gcrypt base64)
+ #:use-module (guix memoization)
#:export (compute-tokens-for-build-server))
-(define (compute-token secret-key-base build-server-id token-seed)
- (let ((source-string
- (simple-format #f "~A:~A:~A"
- secret-key-base
- build-server-id
- token-seed)))
- (string-filter
- ;; Remove the + / and = to make handling the value easier
- char-set:letter+digit
- (base64-encode
- (bytevector-hash
- (string->utf8 source-string)
- (hash-algorithm sha1))))))
+(define compute-token
+ (memoize
+ (lambda (secret-key-base build-server-id token-seed)
+ (let ((source-string
+ (simple-format #f "~A:~A:~A"
+ secret-key-base
+ build-server-id
+ token-seed)))
+ (string-filter
+ ;; Remove the + / and = to make handling the value easier
+ char-set:letter+digit
+ (base64-encode
+ (bytevector-hash
+ (string->utf8 source-string)
+ (hash-algorithm sha1))))))))
(define (compute-tokens-for-build-server conn secret-key-base build-server-id)
(define query