Skip to content

Commit

Permalink
v0.0.2-beta (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
yangkenneth authored Aug 25, 2023
1 parent fa77ac0 commit 5aec22d
Show file tree
Hide file tree
Showing 63 changed files with 5,337 additions and 1,096 deletions.
28 changes: 4 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,39 +19,19 @@ info:
clean: info
@ rm -rf target

.PHONY: deps
deps: info clean
.PHONY: dependencies
dependencies: info clean
@ go mod tidy

.PHONY: test
test: info clean deps
test: info clean dependencies
@ go test -v -cover -short $$(go list ./... | grep -v /examples)

.PHONY: build
build: info clean
@ GOOS=darwin GOARCH=amd64 go build $(LDFLAGS) -o $(BIN)/darwin/$(SERVICE) cmd/server/main.go
@ GOOS=linux GOARCH=amd64 go build $(LDFLAGS) -o $(BIN)/linux/$(SERVICE) cmd/server/main.go

.PHONY: postgres
postgres:
@ docker run --name baseca -p 5432:5432 -v /path/to/baseca/db/init:/db/init -e POSTGRES_USER=root -e POSTGRES_PASSWORD=secret -d postgres:latest

.PHONY: createdb
createdb:
@ docker exec -it baseca createdb --username=root --owner=root baseca

.PHONY: dropdb
dropdb:
@ docker exec -it baseca dropdb baseca

.PHONY: migrateup
migrateup:
@ migrate -path db/migration -database "postgresql://root:secret@localhost:5432/baseca?sslmode=disable" -verbose up

.PHONY: migratedown
migratedown:
@ migrate -path db/migration -database "postgresql://root:secret@localhost:5432/baseca?sslmode=disable" -verbose down

.PHONY: sqlc
sqlc:
@ sqlc generate -f db/sqlc.yaml
Expand All @@ -66,7 +46,7 @@ gen: info clean

.PHONY: server
server:
@ password=${DATABASE_CREDENTIALS} \
@ database_credentials=${DATABASE_CREDENTIALS} \
go run cmd/server/main.go

.PHONY: lint
Expand Down
1 change: 1 addition & 0 deletions db/migration/000001_init_schema.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ CREATE TABLE "accounts" (
"extended_key" varchar(100) NOT NULL,
"certificate_validity" smallserial NOT NULL,
"subordinate_ca" varchar(100) NOT NULL,
"provisioned" boolean NOT NULL,
"node_attestation" varchar(100)[],
"created_at" timestamptz NOT NULL DEFAULT (now()),
"created_by" uuid NOT NULL
Expand Down
133 changes: 133 additions & 0 deletions db/mock/store.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 11 additions & 2 deletions db/query/accounts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ INSERT INTO accounts (
extended_key,
certificate_validity,
subordinate_ca,
provisioned,
node_attestation,
created_at,
created_by
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13, $14, $15, $16
) RETURNING *;

-- name: GetServiceUUID :one
Expand Down Expand Up @@ -58,4 +59,12 @@ RETURNING *;

-- name: DeleteServiceAccount :exec
DELETE FROM accounts
WHERE client_id = $1;
WHERE client_id = $1;

-- name: GetServiceAccountBySAN :many
SELECT * FROM accounts
WHERE valid_subject_alternate_name = ANY($1::string[]);

-- name: GetServiceAccountByMetadata :many
SELECT * FROM accounts
WHERE service_account LIKE $1 AND environment LIKE $2 AND extended_key LIKE $3;
6 changes: 5 additions & 1 deletion db/query/certificate.sql
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,8 @@ OFFSET $2;
-- name: RevokeIssuedCertificateSerialNumber :exec
UPDATE certificates
SET revoked = TRUE, revoke_date = $2, revoked_by = $3
WHERE serial_number = $1;
WHERE serial_number = $1;

-- name: GetSignedCertificateByMetadata :many
SELECT * FROM certificates
WHERE serial_number LIKE $1 AND account LIKE $2 AND environment LIKE $3 AND extended_key LIKE $4;
32 changes: 32 additions & 0 deletions db/query/provisioners.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- name: CreateProvisionerAccount :one
INSERT INTO provisioners (
client_id,
api_token,
provisioner_account,
environments,
team,
email,
regular_expression,
node_attestation,
valid_subject_alternate_names,
extended_keys,
max_certificate_validity,
created_at,
created_by
) VALUES (
$1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12, $13
) RETURNING *;

-- name: GetProvisionerUUID :one
SELECT * FROM provisioners
WHERE client_id = $1;

-- name: DeleteProvisionerAccount :exec
DELETE FROM provisioners
WHERE client_id = $1;

-- name: ListProvisionerAccounts :many
SELECT * FROM provisioners
ORDER BY provisioners
LIMIT $1
OFFSET $2;
Loading

0 comments on commit 5aec22d

Please sign in to comment.