Skip to content
Merged
Next Next commit
feat: add keys to organization provision daemons
  • Loading branch information
f0ssel committed Sep 16, 2024
commit e5b9cc919fd46b7a57da7ed30ddb37039f5607a2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ALTER TABLE provisioner_daemons DROP COLUMN key_id;

DELETE FROM provisioner_keys WHERE name = 'built-in';
DELETE FROM provisioner_keys WHERE name = 'psk';
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
INSERT INTO provisioner_keys (id, created_at, name, public_key, organization_id) VALUES (gen_random_uuid(), NOW(), 'built-in', '', (SELECT id FROM organizations WHERE is_default = true));
INSERT INTO provisioner_keys (id, created_at, name, public_key, organization_id) VALUES (gen_random_uuid(), NOW(), 'psk', '', (SELECT id FROM organizations WHERE is_default = true));

ALTER TABLE provisioner_daemons ADD COLUMN key_id UUID NOT NULL REFERENCES provisioner_keys(id) DEFAULT (SELECT id FROM provisioner_keys WHERE name = 'built-in');
9 changes: 6 additions & 3 deletions coderd/database/queries/provisionerdaemons.sql
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ INSERT INTO
last_seen_at,
"version",
organization_id,
api_version
api_version,
key_id
)
VALUES (
gen_random_uuid(),
Expand All @@ -44,14 +45,16 @@ VALUES (
@last_seen_at,
@version,
@organization_id,
@api_version
@api_version,
@key_id
) ON CONFLICT("organization_id", "name", LOWER(COALESCE(tags ->> 'owner'::text, ''::text))) DO UPDATE SET
provisioners = @provisioners,
tags = @tags,
last_seen_at = @last_seen_at,
"version" = @version,
api_version = @api_version,
organization_id = @organization_id
organization_id = @organization_id,
key_id = @key_id
RETURNING *;

-- name: UpdateProvisionerDaemonLastSeenAt :exec
Expand Down
1 change: 1 addition & 0 deletions codersdk/provisionerdaemons.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ const (
type ProvisionerDaemon struct {
ID uuid.UUID `json:"id" format:"uuid"`
OrganizationID uuid.UUID `json:"organization_id" format:"uuid"`
KeyID uuid.UUID `json:"key_id" format:"uuid"`
CreatedAt time.Time `json:"created_at" format:"date-time"`
LastSeenAt NullTime `json:"last_seen_at,omitempty" format:"date-time"`
Name string `json:"name"`
Expand Down