Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Glorious SQL #54

Merged
merged 13 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
- name: Run Gosec Security Scanner
uses: securego/gosec@master
with:
args: ./...
args: ./api ./vault ./logger

- name: Check code formatting
run: |
Expand Down Expand Up @@ -66,7 +66,7 @@ jobs:
up-flags: "--remove-orphans --abort-on-container-exit"
down-flags: "--volumes --remove-orphans"
services: |
keydb
postgres
tests

- name: Run simulations
Expand All @@ -76,6 +76,6 @@ jobs:
up-flags: "--remove-orphans --abort-on-container-exit"
down-flags: "--volumes --remove-orphans"
services: |
keydb
postgres
api
simulations
4 changes: 2 additions & 2 deletions api/collections_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestCollections(t *testing.T) {
t.Run("can delete a collection", func(t *testing.T) {
// Create a dummy collection
collectionToDelete := CollectionModel{
Name: "delete-me",
Name: "delete_me",
Fields: map[string]CollectionFieldModel{
"name": {Type: "name", IsIndexed: true},
},
Expand All @@ -74,7 +74,7 @@ func TestCollections(t *testing.T) {
response := performRequest(t, app, request)
checkResponse(t, response, http.StatusCreated, nil)
// Delete it
request = newRequest(t, http.MethodDelete, "/collections/delete-me", map[string]string{
request = newRequest(t, http.MethodDelete, "/collections/delete_me", map[string]string{
"Authorization": createBasicAuthHeader(core.conf.VAULT_ADMIN_USERNAME, core.conf.VAULT_ADMIN_PASSWORD),
}, nil)

Expand Down
28 changes: 11 additions & 17 deletions api/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,7 @@ import (

// CoreConfig is used to parameterize a core
type CoreConfig struct {
DB_HOST string
DB_PORT int
DB_USER string
DB_PASSWORD string
DB_DB int
DB_NAME string
DATABASE_URL string
VAULT_ENCRYPTION_KEY string
VAULT_ENCRYPTION_SECRET string
VAULT_SIGNING_KEY string
Expand Down Expand Up @@ -65,12 +60,7 @@ func ReadConfigs(configPath string) (*CoreConfig, error) {
}

// Inject
conf.DB_HOST = Config.String("db_host")
conf.DB_PORT = Config.Int("db_port")
conf.DB_USER = Config.String("db_user")
conf.DB_PASSWORD = Config.String("db_password")
conf.DB_DB = Config.Int("db_db")
conf.DB_NAME = Config.String("db_name")
conf.DATABASE_URL = Config.String("database_url")
conf.VAULT_ENCRYPTION_KEY = Config.String("encryption_key")
conf.VAULT_ENCRYPTION_SECRET = Config.String("encryption_secret")
conf.VAULT_ADMIN_USERNAME = Config.String("admin_access_key")
Expand Down Expand Up @@ -113,8 +103,7 @@ func CreateCore(conf *CoreConfig) (*Core, error) {
// conf.DB_PASSWORD,
// conf.DB_DB,
// )
db, err := _vault.NewSqlStore(_vault.FormatDsn(conf.DB_HOST, conf.DB_USER, conf.DB_PASSWORD, conf.DB_NAME, conf.DB_PORT))

db, err := _vault.NewSqlStore(conf.DATABASE_URL)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -143,18 +132,23 @@ func (core *Core) Init() error {
if core.conf.DEV_MODE {
_ = core.vault.Db.Flush(ctx)
}
_, _ = core.vault.Db.CreatePolicy(ctx, _vault.Policy{
_, err := core.vault.Db.CreatePolicy(ctx, _vault.Policy{
PolicyId: "root",
Effect: _vault.EffectAllow,
Actions: []_vault.PolicyAction{_vault.PolicyActionWrite, _vault.PolicyActionRead},
Resources: []string{"*"},
})
if err != nil {
panic(err)
}
adminPrincipal := _vault.Principal{
Username: core.conf.VAULT_ADMIN_USERNAME,
Password: core.conf.VAULT_ADMIN_PASSWORD,
Description: "admin",
Policies: []string{"root"}}
err := core.vault.CreatePrincipal(ctx, adminPrincipal, adminPrincipal.Username, adminPrincipal.Password, adminPrincipal.Description, adminPrincipal.Policies)

err = core.vault.CreatePrincipal(ctx, adminPrincipal, adminPrincipal.Username, adminPrincipal.Password, adminPrincipal.Description, adminPrincipal.Policies)
if err != nil {
panic(err)
}
return err
}
7 changes: 3 additions & 4 deletions api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,11 @@ type ErrorResponse struct {
}

func ValidateResourceName(fl validator.FieldLevel) bool {
// Validation for vault internal resource names
reg := "^[a-zA-Z0-9._-]{1,249}$"
reg := "^[a-zA-Z0-9._]{1,249}$"
match, _ := regexp.MatchString(reg, fl.Field().String())

// Check for prohibited values: single period and double underscore
if fl.Field().String() == "." || fl.Field().String() == "__" {
// Check for prohibited values: single period, double underscore, and hyphen
if fl.Field().String() == "." || fl.Field().String() == "__" || fl.Field().String() == "-" {
return false
}

Expand Down
9 changes: 2 additions & 7 deletions api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,25 @@ require (
)

require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/jackc/pgpassfile v1.0.0 // indirect
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgx/v5 v5.4.3 // indirect
github.com/jinzhu/inflection v1.0.0 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/jmoiron/sqlx v1.3.5 // indirect
github.com/leodido/go-urn v1.2.1 // indirect
github.com/lib/pq v1.10.9 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/nyaruka/phonenumbers v1.1.6 // indirect
github.com/redis/go-redis/v9 v9.0.2 // indirect
github.com/segmentio/ksuid v1.0.4 // indirect
github.com/valyala/bytebufferpool v1.0.0 // indirect
golang.org/x/crypto v0.14.0 // indirect
golang.org/x/exp v0.0.0-20230817173708-d852ddb80c63 // indirect
golang.org/x/sys v0.13.0 // indirect
golang.org/x/text v0.13.0 // indirect
google.golang.org/protobuf v1.28.0 // indirect
gorm.io/driver/postgres v1.5.4 // indirect
gorm.io/gorm v1.25.5 // indirect
)

replace github.com/subrose/vault v0.0.0 => ../vault
Expand Down
29 changes: 11 additions & 18 deletions api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bsm/ginkgo/v2 v2.5.0 h1:aOAnND1T40wEdAtkGSkvSICWeQ8L3UASX7YVCqQx+eQ=
github.com/bsm/ginkgo/v2 v2.5.0/go.mod h1:AiKlXPm7ItEHNc/2+OkrNG4E0ITzojb9/xWzvQ9XZ9w=
github.com/bsm/gomega v1.20.0 h1:JhAwLmtRzXFTx2AkALSLa8ijZafntmhSoU63Ok18Uq8=
github.com/bsm/gomega v1.20.0/go.mod h1:JifAceMQ4crZIWYUKrlGcmbN3bqHogVTADMD2ATsbwk=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44=
github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/cncf/udpa/go v0.0.0-20201120205902-5459f2c99403/go.mod h1:WmhPx2Nbnhtbo57+VJT5O0JRkEi1Wbu0z5j0R8u5Hbk=
Expand All @@ -46,8 +40,6 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
github.com/dustin/go-humanize v1.0.0/go.mod h1:HtrtbFcZ19U5GC7JDqmcUSB87Iq5E25KnS6fMYU6eOk=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -76,6 +68,9 @@ github.com/go-playground/universal-translator v0.18.0 h1:82dyy6p4OuJq4/CByFNOn/j
github.com/go-playground/universal-translator v0.18.0/go.mod h1:UvRDBj+xPUEGrFYl+lu/H90nyDXpg0fqeB/AQUGNTVA=
github.com/go-playground/validator/v10 v10.11.1 h1:prmOlTVv+YjZjmRmNSF3VmspqJIxJWXmqUsHwfTRRkQ=
github.com/go-playground/validator/v10 v10.11.1/go.mod h1:i+3WkQ1FvaUjjxh1kSvIA4dMGDBiPU55YFDl0WbKdWU=
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ7YPc=
github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.2-0.20181118220953-042da051cf31/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
Expand Down Expand Up @@ -161,12 +156,10 @@ github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
github.com/jackc/pgx/v5 v5.4.3 h1:cxFyXhxlvAifxnkKKdlxv8XqUf59tDlYjnV5YYfsJJY=
github.com/jackc/pgx/v5 v5.4.3/go.mod h1:Ig06C2Vu0t5qXC60W8sqIthScaEnFvojjj9dSljmHRA=
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.4.0/go.mod h1:T8mJZnbsbmF+m6zOOFylbeCJqk5+pHWvzYPziyZiYoo=
github.com/jmespath/go-jmespath/internal/testify v1.5.1/go.mod h1:L3OGu8Wl2/fWfCI6z80xFu9LTZmf1ZRjMHUOPmWr69U=
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g=
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ=
github.com/joho/godotenv v1.3.0 h1:Zjp+RcGpHhGlrMbJzXTrZZPrWj+1vfm90La1wgB6Bhc=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4=
Expand Down Expand Up @@ -194,6 +187,9 @@ github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/leodido/go-urn v1.2.1 h1:BqpAaACuzVSgi/VLzGZIobT2z4v53pjosyNd9Yv6n/w=
github.com/leodido/go-urn v1.2.1/go.mod h1:zt4jvISO2HfUBqxjfIshjdMTYS56ZS/qv49ictyFfxY=
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
Expand All @@ -209,6 +205,9 @@ github.com/mattn/go-isatty v0.0.17 h1:BTarxUcIeDqL27Mc+vyvdWYSL28zpIhv3RoTdsLMPn
github.com/mattn/go-isatty v0.0.17/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-runewidth v0.0.14 h1:+xnbZSEeDbOIg5/mE6JF0w6n9duR1l3/WmbinWVwUuU=
github.com/mattn/go-runewidth v0.0.14/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU=
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM=
github.com/mattn/go-sqlite3 v1.14.17/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
github.com/miekg/dns v1.1.41/go.mod h1:p6aan82bvRIyn+zDIv9xYNUpwa73JcSh9BKwknJysuI=
Expand Down Expand Up @@ -269,8 +268,6 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
github.com/prometheus/procfs v0.6.0/go.mod h1:cz+aTbrPOrUb4q7XlbU9ygM+/jj0fzG6c1xBZuNvfVA=
github.com/redis/go-redis/v9 v9.0.2 h1:BA426Zqe/7r56kCcvxYLWe1mkaz71LKF77GwgFzSxfE=
github.com/redis/go-redis/v9 v9.0.2/go.mod h1:/xDTe9EF1LM61hek62Poq2nzQSGj0xSrEtEHbBQevps=
github.com/rhnvrm/simples3 v0.6.1/go.mod h1:Y+3vYm2V7Y4VijFoJHHTrja6OgPrJ2cBti8dPGkC3sA=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.4 h1:8TfxU8dW6PdqD27gjM8MVNuicgxIjxpm4K7x4jp8sis=
Expand Down Expand Up @@ -503,10 +500,6 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gorm.io/driver/postgres v1.5.4 h1:Iyrp9Meh3GmbSuyIAGyjkN+n9K+GHX9b9MqsTL4EJCo=
gorm.io/driver/postgres v1.5.4/go.mod h1:Bgo89+h0CRcdA33Y6frlaHHVuTdOf87pmyzwW9C/BH0=
gorm.io/gorm v1.25.5 h1:zR9lOiiYf09VNh5Q1gphfyia1JpiClIWG9hQaxB/mls=
gorm.io/gorm v1.25.5/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
4 changes: 3 additions & 1 deletion api/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

func (core *Core) GetPolicies(c *fiber.Ctx) error {
sessionPrincipal := GetSessionPrincipal(c)
policies, err := core.vault.GetPolicies(c.Context(), sessionPrincipal)
policies, err := core.vault.GetPrincipalPolicies(c.Context(), sessionPrincipal)
if err != nil {
return err
}
Expand Down Expand Up @@ -56,3 +56,5 @@ func (core *Core) DeletePolicy(c *fiber.Ctx) error {
}
return c.SendStatus(http.StatusNoContent)
}

// Note: You cannot update a policy
2 changes: 1 addition & 1 deletion api/principals.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,5 @@ func (core *Core) DeletePrincipal(c *fiber.Ctx) error {
if err != nil {
return err
}
return c.SendStatus(http.StatusOK)
return c.SendStatus(http.StatusNoContent)
}
2 changes: 1 addition & 1 deletion api/principals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestPrincipals(t *testing.T) {

response := performRequest(t, app, request)

checkResponse(t, response, http.StatusOK, nil)
checkResponse(t, response, http.StatusNoContent, nil)

// Check that the principal has been deleted
request = newRequest(t, http.MethodGet, fmt.Sprintf("/principals/%s", newPrincipal.Username), map[string]string{
Expand Down
7 changes: 1 addition & 6 deletions api/testing_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ func InitTestingVault(t *testing.T) (*fiber.App, *Core) {
// coreConfig.DB_PASSWORD,
// coreConfig.DB_DB,
// )
db, err := _vault.NewSqlStore(_vault.FormatDsn(
coreConfig.DB_HOST,
coreConfig.DB_USER,
coreConfig.DB_PASSWORD,
coreConfig.DB_NAME,
coreConfig.DB_PORT))
db, err := _vault.NewSqlStore(coreConfig.DATABASE_URL)

if err != nil {
t.Fatal("Failed to create db", err)
Expand Down
File renamed without changes.
File renamed without changes.
7 changes: 1 addition & 6 deletions conf/dev.conf.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
[db]
host = "localhost"
port = 5432
name = "postgres"
user = "postgres"
password = "postgres"
db = 0
url = "postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable"

[system]
env_prefix = "VAULT_"
Expand Down
7 changes: 1 addition & 6 deletions conf/test.conf.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
[db]
host = "localhost"
port = 5432
name = "postgres"
user = "postgres"
password = "postgres"
db = 0
url = "postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable"

[system]
env_prefix = "VAULT_"
Expand Down
41 changes: 21 additions & 20 deletions docker-compose.ci.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
version: "3.8"
services:
keydb:
image: eqalpha/keydb:x86_64_v6.3.3
container_name: keydb
command: keydb-server --server-threads 1 --protected-mode no --appendonly yes
# keydb:
# image: eqalpha/keydb:x86_64_v6.3.3
# container_name: keydb
# command: keydb-server --server-threads 1 --protected-mode no --appendonly yes
# ports:
# - 6379:6379
# restart: unless-stopped
# volumes:
# - ./keydb/redis.conf:/etc/keydb/redis.conf
postgres:
image: postgres:16.1-alpine
ports:
- 6379:6379
restart: unless-stopped
volumes:
- ./keydb/redis.conf:/etc/keydb/redis.conf
- 5432:5432
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_USER=postgres
- POSTGRES_DB=postgres
api:
profiles: ["simulations"]
environment:
- VAULT_DB_HOST=keydb
- VAULT_DB_PORT=6379
- VAULT_DB_USER=default
- VAULT_DB_PASSWORD=
- VAULT_DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable
- VAULT_API_HOST=0.0.0.0
- VAULT_API_PORT=3001
- VAULT_ADMIN_USERNAME=admin
Expand All @@ -29,7 +34,7 @@ services:
ports:
- 3001:3001
depends_on:
- keydb
- postgres
volumes:
- "./:/app"
simulations:
Expand All @@ -43,7 +48,7 @@ services:
working_dir: /code
depends_on:
- api
- keydb
- postgres
command: sh -c "cd simulator && ./simulate.sh"
volumes:
- "./:/code"
Expand All @@ -54,14 +59,10 @@ services:
dockerfile: Dockerfile
target: build
environment:
- KEYDB_CONN_STRING=keydb:6379
- VAULT_DB_HOST=keydb
- VAULT_DB_PORT=6379
- VAULT_DB_USER=default
- VAULT_DB_PASSWORD=
- VAULT_DATABASE_URL=postgres://postgres:postgres@postgres:5432/postgres?sslmode=disable
working_dir: /code
depends_on:
- keydb
- postgres
command: sh -c "go test ./vault && go test ./api"
volumes:
- "./:/code"
Loading
Loading