aboutsummaryrefslogtreecommitdiff
path: root/guix-build-coordinator/datastore
diff options
context:
space:
mode:
authorChristopher Baines <mail@cbaines.net>2021-02-28 18:41:07 +0000
committerChristopher Baines <mail@cbaines.net>2021-02-28 18:41:07 +0000
commit1f79fc38a17ceda30f378efd4e7f80f252c99b4d (patch)
treee5cf6166d69b3f7249d4006846751bf1fb6e5720 /guix-build-coordinator/datastore
parentcaf63dce0ea29a07c5205a69ff6f60b7c6b60084 (diff)
downloadbuild-coordinator-1f79fc38a17ceda30f378efd4e7f80f252c99b4d.tar
build-coordinator-1f79fc38a17ceda30f378efd4e7f80f252c99b4d.tar.gz
Add a new dynamic authentication approach
This avoids the need to create agents upfront, which could be useful when creating many childhurd VMs or using scheduling tools to dynamically run agents.
Diffstat (limited to 'guix-build-coordinator/datastore')
-rw-r--r--guix-build-coordinator/datastore/sqlite.scm115
1 files changed, 111 insertions, 4 deletions
diff --git a/guix-build-coordinator/datastore/sqlite.scm b/guix-build-coordinator/datastore/sqlite.scm
index 3a110e5..898a148 100644
--- a/guix-build-coordinator/datastore/sqlite.scm
+++ b/guix-build-coordinator/datastore/sqlite.scm
@@ -46,6 +46,9 @@
datastore-new-agent
datastore-list-agents
datastore-find-agent
+ datastore-find-agent-by-name
+ datastore-insert-dynamic-auth-token
+ datastore-dynamic-auth-token-exists?
datastore-fetch-agent-tags
datastore-store-build-start
datastore-find-build-starts
@@ -64,6 +67,7 @@
datastore-list-builds-for-output-and-system
datastore-new-agent-password
datastore-agent-password-exists?
+ datastore-agent-list-passwords
datastore-replace-agent-tags
datastore-list-processed-builds
datastore-list-unprocessed-builds
@@ -378,6 +382,82 @@ SELECT description FROM agents WHERE id = :id"
result)))))
+(define-method (datastore-find-agent-by-name
+ (datastore <sqlite-datastore>)
+ name)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT id FROM agents WHERE name = :name"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:name name)
+
+ (let ((result
+ (match (sqlite-map
+ (match-lambda
+ (#(id) id))
+ statement)
+ (() #f)
+ ((agent) agent))))
+ (sqlite-reset statement)
+
+ result)))))
+
+(define-method (datastore-insert-dynamic-auth-token
+ (datastore <sqlite-datastore>)
+ token)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-writer-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+INSERT INTO dynamic_auth_tokens (token) VALUES (:token)"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:token token)
+
+ (sqlite-step statement)
+ (sqlite-reset statement)))))
+
+(define-method (datastore-dynamic-auth-token-exists?
+ (datastore <sqlite-datastore>)
+ token)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT 1 FROM dynamic_auth_tokens WHERE token = :token"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:token token)
+
+ (let ((result
+ (match (sqlite-map
+ (match-lambda
+ (#(1) #t))
+ statement)
+ ((#t) #t)
+ (() #f))))
+ (sqlite-reset statement)
+
+ result)))))
+
(define-method (datastore-fetch-agent-tags
(datastore <sqlite-datastore>)
agent-id)
@@ -416,11 +496,12 @@ WHERE agent_tags.agent_id = :agent_id"
(define-method (datastore-new-agent
(datastore <sqlite-datastore>)
uuid
+ name
description)
(call-with-worker-thread
(slot-ref datastore 'worker-writer-thread-channel)
(lambda (db)
- (insert-agent db uuid description)))
+ (insert-agent db uuid name description)))
#t)
(define-method (datastore-list-agents
@@ -483,6 +564,31 @@ WHERE agent_id = :agent_id AND password = :password"
result)))))
+(define-method (datastore-agent-list-passwords
+ (datastore <sqlite-datastore>)
+ uuid)
+ (call-with-worker-thread
+ (slot-ref datastore 'worker-reader-thread-channel)
+ (lambda (db)
+ (let ((statement
+ (sqlite-prepare
+ db
+ "
+SELECT password FROM agent_passwords WHERE agent_id = :agent_id"
+ #:cache? #t)))
+
+ (sqlite-bind-arguments
+ statement
+ #:agent_id uuid)
+
+ (let ((result (sqlite-map
+ (match-lambda
+ (#(password) password))
+ statement)))
+ (sqlite-reset statement)
+
+ result)))))
+
(define-method (datastore-replace-agent-tags
(datastore <sqlite-datastore>)
agent-id
@@ -3097,18 +3203,19 @@ VALUES (:uuid, :derivation_name, :priority, datetime('now'), :deferred_until)"
(sqlite-reset statement))))
#t)
-(define (insert-agent db uuid description)
+(define (insert-agent db uuid name description)
(let ((statement
(sqlite-prepare
db
"
-INSERT INTO agents (id, description)
-VALUES (:id, :description)"
+INSERT INTO agents (id, name, description)
+VALUES (:id, :name, :description)"
#:cache? #t)))
(sqlite-bind-arguments
statement
#:id uuid
+ #:name name
#:description description)
(sqlite-step statement)