Skip to content

Commit

Permalink
Merge pull request #2 from bloock/feature/EIT-3312
Browse files Browse the repository at this point in the history
  • Loading branch information
edutomesco committed Sep 21, 2023
2 parents 3ed239a + 1a0fc5d commit 5b06dbc
Show file tree
Hide file tree
Showing 11 changed files with 279 additions and 98 deletions.
314 changes: 260 additions & 54 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ BLOOCK_AUTHENTICITY_PUBLIC_KEY: ""
BLOOCK_API_HOST: "0.0.0.0"
BLOOCK_API_PORT: "8080"
BLOOCK_API_DEBUG_MODE: false
BLOOCK_FILE_DIR: ""
BLOOCK_FILE_DIR: "./tmp"
8 changes: 0 additions & 8 deletions docker-compose-mysql.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,3 @@ services:
environment:
BLOOCK_DB_CONNECTION_STRING: "mysql://root:admin@tcp(mysql:3306)/managed"
BLOOCK_API_KEY: ""
BLOOCK_CLIENT_ENDPOINT_URL: ""
BLOOCK_WEBHOOK_SECRET_KEY: ""
BLOOCK_AUTHENTICITY_PRIVATE_KEY: ""
BLOOCK_AUTHENTICITY_PUBLIC_KEY: ""
BLOOCK_API_HOST: "0.0.0.0"
BLOOCK_API_PORT: "8080"
BLOOCK_API_DEBUG_MODE: false
BLOOCK_FILE_DIR: ""
15 changes: 5 additions & 10 deletions docker-compose-postgres.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ services:
image: postgres
restart: always
environment:
POSTGRES_DB: managed
POSTGRES_PASSWORD: admin
ports:
- "5432:5432"
healthcheck:
test: ["CMD-SHELL", "pg_isready -U postgres"]
timeout: 5s
Expand All @@ -21,13 +24,5 @@ services:
postgres:
condition: service_healthy
environment:
BLOOCK_DB_CONNECTION_STRING: "postgres://postgres:admin@tcp(postgres:5432)/managed"
BLOOCK_API_KEY: ""
BLOOCK_CLIENT_ENDPOINT_URL: ""
BLOOCK_WEBHOOK_SECRET_KEY: ""
BLOOCK_AUTHENTICITY_PRIVATE_KEY: ""
BLOOCK_AUTHENTICITY_PUBLIC_KEY: ""
BLOOCK_API_HOST: "0.0.0.0"
BLOOCK_API_PORT: "8080"
BLOOCK_API_DEBUG_MODE: false
BLOOCK_FILE_DIR: ""
BLOOCK_DB_CONNECTION_STRING: "postgresql://postgres:admin@postgres/managed?sslmode=disable"
BLOOCK_API_KEY: "test_u4NFCv4ht7ho3fWPWem-UYC3qLHU2HXT5MEQkAV66BSOrKMprZRdIS1bshVZ8QvP"
7 changes: 3 additions & 4 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
services:
bloock-managed-api:
platform: linux/x86_64
build:
context: .
dockerfile: Dockerfile
image: bloock/managed-api:latest
container_name: bloock-managed-api
volumes:
- ./config.yml:/go/bin/config.yml:ro
ports:
- 8080:8080
environment:
BLOOCK_API_KEY: ""
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ module bloock-managed-api
go 1.18

require (
entgo.io/ent v0.12.3
entgo.io/ent v0.12.4
github.com/bloock/bloock-sdk-go/v2 v2.5.7
github.com/gin-gonic/gin v1.7.7
github.com/go-playground/validator/v10 v10.14.0
github.com/go-sql-driver/mysql v1.7.1
github.com/golang/mock v1.6.0
github.com/google/uuid v1.3.0
Expand All @@ -18,7 +19,7 @@ require (
)

require (
ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf // indirect
ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935 // indirect
github.com/agext/levenshtein v1.2.1 // indirect
github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
Expand All @@ -28,7 +29,6 @@ require (
github.com/go-openapi/inflect v0.19.0 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.14.0 // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect
Expand Down
12 changes: 4 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf h1:Tq2DRB39ZHScIwWACjPKLv5oEErv7zv6PBb5RTz5CKA=
ariga.io/atlas v0.10.2-0.20230427182402-87a07dfb83bf/go.mod h1:+TR129FJZ5Lvzms6dvCeGWh1yR6hMvmXBhug4hrNIGk=
ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935 h1:JnYs/y8RJ3+MiIUp+3RgyyeO48VHLAZimqiaZYnMKk8=
ariga.io/atlas v0.14.1-0.20230918065911-83ad451a4935/go.mod h1:isZrlzJ5cpoCoKFoY9knZug7Lq4pP1cm8g3XciLZ0Pw=
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
Expand Down Expand Up @@ -38,8 +38,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
entgo.io/ent v0.12.3 h1:N5lO2EOrHpCH5HYfiMOCHYbo+oh5M8GjT0/cx5x6xkk=
entgo.io/ent v0.12.3/go.mod h1:AigGGx+tbrBBYHAzGOg8ND661E5cxx1Uiu5o/otJ6Yg=
entgo.io/ent v0.12.4 h1:LddPnAyxls/O7DTXZvUGDj0NZIdGSu317+aoNLJWbD8=
entgo.io/ent v0.12.4/go.mod h1:Y3JVAjtlIk8xVZYSn3t3mf8xlZIn5SAOXZQxD6kKI+Q=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/DATA-DOG/go-sqlmock v1.5.0 h1:Shsta01QNfFxHCfpW6YH2STWB0MudeXXEWMr20OEh60=
Expand Down Expand Up @@ -197,7 +197,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA=
github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-sqlite3 v1.14.16 h1:yOQRA0RpS5PFz/oikGwBEqvAWhWg5ufRz4ETLjwpU1Y=
github.com/mattn/go-sqlite3 v1.14.16/go.mod h1:2eHXhiwb8IkHr+BDWZGa96P6+rkvnG63S2DGjv9HUNg=
github.com/mitchellh/go-wordwrap v0.0.0-20150314170334-ad45545899c7 h1:DpOJ2HYzCv8LZP15IdmG+YdwD2luVPHITV96TkirNBM=
Expand All @@ -210,7 +209,6 @@ github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJ
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
github.com/olekukonko/tablewriter v0.0.5 h1:P2Ga83D34wi1o9J6Wh1mRuqd4mF/x/lgBS7N7AbDhec=
github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ=
github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
Expand All @@ -228,7 +226,6 @@ github.com/spf13/afero v1.9.5 h1:stMpOSZFs//0Lv29HduCmli3GUfpFoF3Y1Q/aXj/wVM=
github.com/spf13/afero v1.9.5/go.mod h1:UBogFpq8E9Hx+xc5CNTTEpTnuHVmXDwZcZcE1eb/UhQ=
github.com/spf13/cast v1.5.1 h1:R+kOtfhWQE6TVQzY+4D7wJLBgkdVasCEFxSUBYBYIlA=
github.com/spf13/cast v1.5.1/go.mod h1:b9PdjNptOpzXr7Rq1q9gJML/2cdGQAo69NKzQ10KN48=
github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I=
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo=
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
Expand Down Expand Up @@ -477,7 +474,6 @@ golang.org/x/tools v0.0.0-20210105154028-b0ab187a4818/go.mod h1:emZCQorbCU4vsT4f
golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.8.1-0.20230428195545-5283a0178901 h1:0wxTF6pSjIIhNt7mo9GvjDfzyCOiWhmICgtO/Ah948s=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
2 changes: 0 additions & 2 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Config struct {
DebugMode bool `mapstructure:"BLOOCK_API_DEBUG_MODE"`
PrivateKey string `mapstructure:"BLOOCK_AUTHENTICITY_PRIVATE_KEY"`
PublicKey string `mapstructure:"BLOOCK_AUTHENTICITY_PUBLIC_KEY"`
MaxMemory int64 `mapstructure:"BLOOCK_MAX_MEMORY"`
FileDir string `mapstructure:"BLOOCK_FILE_DIR"`
}

Expand Down Expand Up @@ -53,7 +52,6 @@ func setDefaultConfigValues() {
viper.SetDefault("bloock_api_host", "0.0.0.0")
viper.SetDefault("bloock_api_port", "8080")
viper.SetDefault("bloock_api_debug_mode", false)
viper.SetDefault("bloock_max_memory", 10<<20) //10MB
viper.SetDefault("bloock_file_dir", "./tmp")
viper.SetDefault("bloock_authenticity_private_key", "")
viper.SetDefault("bloock_authenticity_public_key", "")
Expand Down
5 changes: 0 additions & 5 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package config

import (
"os"
"strconv"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -12,7 +11,6 @@ func TestInitConfig(t *testing.T) {

t.Run("given env vars it should populate config", func(t *testing.T) {
value := "1234abcd"
intVal := "1234"
_ = os.Setenv("BLOOCK_API_PORT", value)
_ = os.Setenv("BLOOCK_API_HOST", value)
_ = os.Setenv("BLOOCK_API_KEY", value)
Expand All @@ -22,7 +20,6 @@ func TestInitConfig(t *testing.T) {
_ = os.Setenv("BLOOCK_API_DEBUG_MODE", "true")
_ = os.Setenv("BLOOCK_AUTHENTICITY_PRIVATE_KEY", value)
_ = os.Setenv("BLOOCK_AUTHENTICITY_PUBLIC_KEY", value)
_ = os.Setenv("BLOOCK_MAX_MEMORY", intVal)
_ = os.Setenv("BLOOCK_FILE_DIR", value)
config, err := InitConfig()

Expand All @@ -36,8 +33,6 @@ func TestInitConfig(t *testing.T) {
assert.Equal(t, value, config.WebhookSecretKey)
assert.Equal(t, value, config.PublicKey)
assert.Equal(t, value, config.PrivateKey)
atoi, _ := strconv.Atoi(intVal)
assert.Equal(t, int64(atoi), config.MaxMemory)
assert.Equal(t, value, config.FileDir)
assert.Equal(t, true, config.DebugMode)

Expand Down
4 changes: 2 additions & 2 deletions internal/platform/repository/sql/connection/ent_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ func NewEntConnection(connectionURL string, connector SQLConnector, logger zerol
db: client,
}, nil
}
if strings.Contains(connectionURL, "postgres") {
client, err := open(connector, Postgres, strings.Replace(connectionURL, "postgres://", "", 1))
if strings.Contains(connectionURL, "postgresql") {
client, err := open(connector, Postgres, strings.Replace(connectionURL, "postgresql://", "", 1))
if err != nil {
return nil, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func TestConnection_NewConnection(t *testing.T) {
expected string
}{
{name: "given mysql url it should be detected", url: "mysql://username:password@localhost:3306/mydatabase", driver: Mysql, expected: "username:password@localhost:3306/mydatabase"},
{name: "given postgres url it should be detected", url: "postgres://username:password@localhost:5432/mydatabase", driver: Postgres, expected: "username:password@localhost:5432/mydatabase"},
{name: "given postgres url it should be detected", url: "postgresql://username:password@localhost/mydatabase?sslmode=disable", driver: Postgres, expected: "username:password@localhost/mydatabase?sslmode=disable"},
{name: "given sqlite memory url it should be detected", url: "file:ent?mode=memory&cache=shared&_fk=1", driver: Sqlite, expected: "file:ent?mode=memory&cache=shared&_fk=1"},
}
for _, test := range tests {
Expand Down

0 comments on commit 5b06dbc

Please sign in to comment.