mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-04-28 00:39:59 -05:00
Embed all key files
This is done in order to make this package more "exportable" for Go. As a benefit, we also got rid of extra "tests" tag.
This commit is contained in:
@@ -101,7 +101,7 @@ jobs:
|
||||
key: unit-coverage-${{ github.run_id }}
|
||||
|
||||
- name: Build tests
|
||||
run: make build-tests
|
||||
run: make build-tests-ee
|
||||
|
||||
- name: Init Postgres
|
||||
run: psql -f pkg/db/migrations/init/postgres.sql "postgres://postgres:postgres@localhost:5432/privatecaptcha?options=--search_path%3Dpublic"
|
||||
|
||||
@@ -20,6 +20,5 @@ linters:
|
||||
run:
|
||||
build-tags:
|
||||
- enterprise
|
||||
- tests
|
||||
timeout: 5m
|
||||
tests: false
|
||||
|
||||
@@ -4,9 +4,10 @@ STAGE ?= dev
|
||||
GIT_COMMIT ?= $(shell git rev-list -1 HEAD)
|
||||
DOCKER_IMAGE ?= private-captcha
|
||||
SQLC_MIGRATION_FIX = pkg/db/migrations/postgres/000000_sqlc_fix.sql
|
||||
EXTRA_BUILD_FLAGS ?=
|
||||
|
||||
test-unit:
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go test -short -coverprofile=coverage_unit.out -tags tests ./...
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go test -short -coverprofile=coverage_unit.out ./...
|
||||
|
||||
bench-unit:
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go test -bench=. -benchtime=20s -short ./...
|
||||
@@ -23,15 +24,17 @@ vendors:
|
||||
|
||||
build: build-server build-loadtest
|
||||
|
||||
build-tests: EXTRA_BUILD_FLAGS ?= -tags enterprise,tests
|
||||
build-tests:
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go test -c -cover -covermode=atomic $(EXTRA_BUILD_FLAGS) -o tests/ $(shell go list $(EXTRA_BUILD_FLAGS) -f '{{if .TestGoFiles}}{{.ImportPath}}{{end}}' ./...)
|
||||
|
||||
build-server:
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go build -ldflags="-s -w -X main.GitCommit=$(GIT_COMMIT)" -o bin/server ./cmd/server
|
||||
build-tests-ee: EXTRA_BUILD_FLAGS = -tags enterprise
|
||||
build-tests-ee: build-tests
|
||||
|
||||
build-server-ee:
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go build -ldflags="-s -w -X main.GitCommit=$(GIT_COMMIT)" -tags enterprise -o bin/server ./cmd/server
|
||||
build-server:
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go build -ldflags="-s -w -X main.GitCommit=$(GIT_COMMIT)" $(EXTRA_BUILD_FLAGS) -o bin/server ./cmd/server
|
||||
|
||||
build-server-ee: EXTRA_BUILD_FLAGS = -tags enterprise
|
||||
build-server-ee: build-server
|
||||
|
||||
build-loadtest:
|
||||
env GOFLAGS="-mod=vendor" CGO_ENABLED=0 go build -ldflags="-s -w" -o bin/loadtest cmd/loadtest/*.go
|
||||
|
||||
+4
-1
@@ -249,7 +249,10 @@ func run(ctx context.Context, cfg common.ConfigStore, stderr io.Writer, listener
|
||||
}
|
||||
}(common.TraceContext(context.Background(), "signal_handler"))
|
||||
|
||||
checkLicenseJob := maintenance.NewCheckLicenseJob(businessDB, cfg, quitFunc)
|
||||
checkLicenseJob, err := maintenance.NewCheckLicenseJob(businessDB, cfg, quitFunc)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
go func() {
|
||||
_ = common.RunPeriodicJobOnce(common.TraceContext(context.Background(), "check_license"), checkLicenseJob)
|
||||
}()
|
||||
|
||||
@@ -5,7 +5,7 @@ services:
|
||||
dockerfile: ./docker/Dockerfile.test
|
||||
args:
|
||||
GIT_COMMIT: '${GIT_COMMIT}'
|
||||
EXTRA_BUILD_FLAGS: '-tags enterprise,tests'
|
||||
EXTRA_BUILD_FLAGS: '-tags enterprise'
|
||||
ports:
|
||||
- 8080:8080
|
||||
environment:
|
||||
@@ -34,7 +34,7 @@ services:
|
||||
dockerfile: ./docker/Dockerfile.test
|
||||
args:
|
||||
GIT_COMMIT: '${GIT_COMMIT}'
|
||||
EXTRA_BUILD_FLAGS: '-tags enterprise,tests'
|
||||
EXTRA_BUILD_FLAGS: '-tags enterprise'
|
||||
command:
|
||||
/app/bin/server -mode migrate -migrate-hash $GIT_COMMIT
|
||||
env_file:
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
//go:build !unittests
|
||||
|
||||
package api
|
||||
|
||||
import (
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
[]
|
||||
+23
-6
@@ -1,16 +1,14 @@
|
||||
//go:build !tests
|
||||
|
||||
package license
|
||||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
_ "embed"
|
||||
"embed"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
//go:embed public.keys
|
||||
var embeddedKeys []byte
|
||||
//go:embed *.keys
|
||||
var embeddedKeys embed.FS
|
||||
|
||||
type hardcodedKey struct {
|
||||
KeyID int `json:"KeyID"`
|
||||
@@ -36,9 +34,28 @@ func activationKeys(hardcodedKeys []*hardcodedKey) ([]*ActivationKey, error) {
|
||||
func ActivationKeys() ([]*ActivationKey, error) {
|
||||
var parsedKeys []*hardcodedKey
|
||||
|
||||
if err := json.Unmarshal(embeddedKeys, &parsedKeys); err != nil {
|
||||
files, err := embeddedKeys.ReadDir(".")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, file := range files {
|
||||
if file.IsDir() {
|
||||
continue
|
||||
}
|
||||
|
||||
content, err := embeddedKeys.ReadFile(file.Name())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var keysFromFile []*hardcodedKey
|
||||
if err := json.Unmarshal(content, &keysFromFile); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
parsedKeys = append(parsedKeys, keysFromFile...)
|
||||
}
|
||||
|
||||
return activationKeys(parsedKeys)
|
||||
}
|
||||
|
||||
@@ -1,7 +0,0 @@
|
||||
//go:build tests
|
||||
|
||||
package license
|
||||
|
||||
func ActivationKeys() ([]*ActivationKey, error) {
|
||||
return []*ActivationKey{}, nil
|
||||
}
|
||||
@@ -32,8 +32,11 @@ var (
|
||||
errEnterpriseConfigError = errors.New("enterprise config error")
|
||||
)
|
||||
|
||||
func NewCheckLicenseJob(store db.Implementor, config common.ConfigStore, quitFunc func(ctx context.Context)) common.PeriodicJob {
|
||||
keys, _ := license.ActivationKeys()
|
||||
func NewCheckLicenseJob(store db.Implementor, config common.ConfigStore, quitFunc func(ctx context.Context)) (common.PeriodicJob, error) {
|
||||
keys, err := license.ActivationKeys()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &checkLicenseJob{
|
||||
store: store,
|
||||
@@ -43,7 +46,7 @@ func NewCheckLicenseJob(store db.Implementor, config common.ConfigStore, quitFun
|
||||
email: config.Get(common.EnterpriseEmailKey),
|
||||
adminEmail: config.Get(common.AdminEmailKey),
|
||||
quitFunc: quitFunc,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
type checkLicenseJob struct {
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
"github.com/PrivateCaptcha/PrivateCaptcha/pkg/db"
|
||||
)
|
||||
|
||||
func NewCheckLicenseJob(db.Implementor, common.ConfigStore, func(ctx context.Context)) common.PeriodicJob {
|
||||
return &checkLicenseNoopJob{}
|
||||
func NewCheckLicenseJob(db.Implementor, common.ConfigStore, func(ctx context.Context)) (common.PeriodicJob, error) {
|
||||
return &checkLicenseNoopJob{}, nil
|
||||
}
|
||||
|
||||
type checkLicenseNoopJob struct {
|
||||
|
||||
Reference in New Issue
Block a user