Skip to content

Commit 6124534

Browse files
committed
wip
1 parent 07a14e3 commit 6124534

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+3438
-27
lines changed

api/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# base stage
2-
FROM golang:1.23-alpine3.19 AS base
2+
FROM golang:1.24-alpine3.22 AS base
33

44
ARG GOPROXY
55

api/go.mod

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
module github.com/shellhub-io/shellhub/api
22

3-
go 1.23.0
3+
go 1.24.0
4+
5+
toolchain go1.24.6
46

57
require (
68
github.com/cnf/structhash v0.0.0-20201127153200-e1b16c1ebc08
79
github.com/getsentry/sentry-go v0.35.3
810
github.com/golang-jwt/jwt/v4 v4.5.2
911
github.com/gorilla/websocket v1.5.3
12+
github.com/jackc/pgx/v5 v5.7.6
1013
github.com/labstack/echo/v4 v4.13.4
1114
github.com/labstack/gommon v0.4.2
15+
github.com/oiime/logrusbun v0.1.2-0.20241011112815-4df3a0fb0e11
1216
github.com/pkg/errors v0.9.1
1317
github.com/shellhub-io/mongotest v0.0.0-20230928124937-e33b07010742
1418
github.com/shellhub-io/shellhub v0.13.4
1519
github.com/sirupsen/logrus v1.9.3
1620
github.com/spf13/cobra v1.10.1
1721
github.com/square/mongo-lock v0.0.0-20230808145049-cfcf499f6bf0
1822
github.com/stretchr/testify v1.11.1
23+
github.com/testcontainers/testcontainers-go v0.38.0
1924
github.com/testcontainers/testcontainers-go/modules/mongodb v0.38.0
25+
github.com/testcontainers/testcontainers-go/modules/postgres v0.38.0
26+
github.com/uptrace/bun v1.2.15
27+
github.com/uptrace/bun/dbfixture v1.2.15
28+
github.com/uptrace/bun/dialect/pgdialect v1.2.15
2029
github.com/xakep666/mongo-migrate v0.3.2
2130
go.mongodb.org/mongo-driver v1.17.4
2231
golang.org/x/crypto v0.41.0
@@ -68,6 +77,10 @@ require (
6877
github.com/hashicorp/go-multierror v1.1.1 // indirect
6978
github.com/hibiken/asynq v0.24.1 // indirect
7079
github.com/inconshreveable/mousetrap v1.1.0 // indirect
80+
github.com/jackc/pgpassfile v1.0.0 // indirect
81+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
82+
github.com/jackc/puddle/v2 v2.2.2 // indirect
83+
github.com/jinzhu/inflection v1.0.0 // indirect
7184
github.com/klauspost/compress v1.18.0 // indirect
7285
github.com/klauspost/pgzip v1.2.5 // indirect
7386
github.com/leodido/go-urn v1.2.2 // indirect
@@ -93,24 +106,25 @@ require (
93106
github.com/pierrec/lz4/v4 v4.1.17 // indirect
94107
github.com/pmezard/go-difflib v1.0.0 // indirect
95108
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
109+
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
96110
github.com/redis/go-redis/v9 v9.0.3 // indirect
97111
github.com/robfig/cron/v3 v3.0.1 // indirect
98112
github.com/sethvargo/go-envconfig v0.9.0 // indirect
99113
github.com/shirou/gopsutil/v4 v4.25.5 // indirect
100114
github.com/spf13/cast v1.3.1 // indirect
101115
github.com/spf13/pflag v1.0.9 // indirect
102116
github.com/stretchr/objx v0.5.2 // indirect
103-
github.com/testcontainers/testcontainers-go v0.38.0 // indirect
104117
github.com/therootcompany/xz v1.0.1 // indirect
105118
github.com/tklauser/go-sysconf v0.3.13 // indirect
106119
github.com/tklauser/numcpus v0.7.0 // indirect
107120
github.com/tkuchiki/go-timezone v0.2.2 // indirect
108121
github.com/tkuchiki/parsetime v0.3.0 // indirect
122+
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
109123
github.com/ulikunitz/xz v0.5.14 // indirect
110124
github.com/valyala/bytebufferpool v1.0.0 // indirect
111125
github.com/valyala/fasttemplate v1.2.2 // indirect
112126
github.com/vmihailenco/go-tinylfu v0.2.2 // indirect
113-
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
127+
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
114128
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
115129
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
116130
github.com/xdg-go/scram v1.1.2 // indirect
@@ -125,7 +139,7 @@ require (
125139
go4.org v0.0.0-20200411211856-f5505b9728dd // indirect
126140
golang.org/x/net v0.42.0 // indirect
127141
golang.org/x/sync v0.16.0 // indirect
128-
golang.org/x/sys v0.35.0 // indirect
142+
golang.org/x/sys v0.36.0 // indirect
129143
golang.org/x/text v0.28.0 // indirect
130144
golang.org/x/time v0.11.0 // indirect
131145
google.golang.org/protobuf v1.35.2 // indirect

api/go.sum

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
200200
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
201201
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
202202
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
203+
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
204+
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
205+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
206+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
207+
github.com/jackc/pgx/v5 v5.7.6 h1:rWQc5FwZSPX58r1OQmkuaNicxdmExaEz5A2DO2hUuTk=
208+
github.com/jackc/pgx/v5 v5.7.6/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
209+
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
210+
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
211+
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
212+
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
203213
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
204214
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
205215
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -225,6 +235,8 @@ github.com/labstack/gommon v0.4.2 h1:F8qTUNXgG1+6WQmqoUWnz8WiEU60mXVVw0P4ht1WRA0
225235
github.com/labstack/gommon v0.4.2/go.mod h1:QlUFxVM+SNXhDL/Z7YhocGIBYOiwB0mXm1+1bAPHPyU=
226236
github.com/leodido/go-urn v1.2.2 h1:7z68G0FCGvDk646jz1AelTYNYWrTNm0bEcFAo147wt4=
227237
github.com/leodido/go-urn v1.2.2/go.mod h1:kUaIbLZWttglzwNuG0pgsh5vuV6u2YcGBYz1hIPjtOQ=
238+
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
239+
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
228240
github.com/lufia/plan9stats v0.0.0-20240408141607-282e7b5d6b74 h1:1KuuSOy4ZNgW0KA2oYIngXVFhQcXxhLqCVK7cBcldkk=
229241
github.com/lufia/plan9stats v0.0.0-20240408141607-282e7b5d6b74/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
230242
github.com/magiconair/properties v1.8.10 h1:s31yESBquKXCV9a/ScB3ESkOjUYYv+X0rg8SYxI99mE=
@@ -235,6 +247,8 @@ github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWE
235247
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
236248
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
237249
github.com/mattn/goveralls v0.0.9/go.mod h1:FRbM1PS8oVsOe9JtdzAAXM+DsvDMMHcM1C7drGJD8HY=
250+
github.com/mdelapenya/tlscert v0.2.0 h1:7H81W6Z/4weDvZBNOfQte5GpIMo0lGYEeWbkGp5LJHI=
251+
github.com/mdelapenya/tlscert v0.2.0/go.mod h1:O4njj3ELLnJjGdkN7M/vIVCpZ+Cf0L6muqOG4tLSl8o=
238252
github.com/mholt/archiver/v4 v4.0.0-alpha.8 h1:tRGQuDVPh66WCOelqe6LIGh0gwmfwxUrSSDunscGsRM=
239253
github.com/mholt/archiver/v4 v4.0.0-alpha.8/go.mod h1:5f7FUYGXdJWUjESffJaYR4R60VhnHxb2X3T1teMyv5A=
240254
github.com/moby/docker-image-spec v1.3.1 h1:jMKff3w6PgbfSa69GfNg+zN/XLhfXJGnEx3Nl2EsFP0=
@@ -263,6 +277,10 @@ github.com/nwaples/rardecode/v2 v2.0.0-beta.2/go.mod h1:yntwv/HfMc/Hbvtq9I19D1n5
263277
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
264278
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
265279
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
280+
github.com/oiime/logrusbun v0.1.1 h1:o3aK0PGErb1G0JC43yAIhoGxSbgtYRHhlyTtq6o1rag=
281+
github.com/oiime/logrusbun v0.1.1/go.mod h1:HH9akx9teKgQPX41TYpLLRNxaL8q9R+ltzABnwUHfBM=
282+
github.com/oiime/logrusbun v0.1.2-0.20241011112815-4df3a0fb0e11 h1:rAqW9sGcM0VsfBwgeBzHk0yebrRwfeSJFy9Egqi0fmM=
283+
github.com/oiime/logrusbun v0.1.2-0.20241011112815-4df3a0fb0e11/go.mod h1:HH9akx9teKgQPX41TYpLLRNxaL8q9R+ltzABnwUHfBM=
266284
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
267285
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
268286
github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
@@ -292,6 +310,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN
292310
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
293311
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
294312
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
313+
github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=
314+
github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
295315
github.com/redis/go-redis/v9 v9.0.3 h1:+7mmR26M0IvyLxGZUHxu4GiBkJkVDid0Un+j4ScYu4k=
296316
github.com/redis/go-redis/v9 v9.0.3/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
297317
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -310,6 +330,7 @@ github.com/shellhub-io/mongotest v0.0.0-20230928124937-e33b07010742 h1:sIFW1zdZv
310330
github.com/shellhub-io/mongotest v0.0.0-20230928124937-e33b07010742/go.mod h1:6J6yfW5oIvAZ6VjxmV9KyFZyPFVM3B4V3Epbb+1c0oo=
311331
github.com/shirou/gopsutil/v4 v4.25.5 h1:rtd9piuSMGeU8g1RMXjZs9y9luK5BwtnG7dZaQUJAsc=
312332
github.com/shirou/gopsutil/v4 v4.25.5/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c=
333+
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
313334
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
314335
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
315336
github.com/spf13/cast v1.3.1 h1:nFm6S0SMdyzrzcmThSipiEubIDy8WEXKNZ0UOgiRpng=
@@ -326,6 +347,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
326347
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
327348
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
328349
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
350+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
329351
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
330352
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
331353
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -339,6 +361,8 @@ github.com/testcontainers/testcontainers-go v0.38.0 h1:d7uEapLcv2P8AvH8ahLqDMMxd
339361
github.com/testcontainers/testcontainers-go v0.38.0/go.mod h1:C52c9MoHpWO+C4aqmgSU+hxlR5jlEayWtgYrb8Pzz1w=
340362
github.com/testcontainers/testcontainers-go/modules/mongodb v0.38.0 h1:A+YGYRoNLjDcYYnupsZBj3O3OfgEnS/o/MbQjiTqQwo=
341363
github.com/testcontainers/testcontainers-go/modules/mongodb v0.38.0/go.mod h1:4PMThrMlJpuUqLG+sCca3pWJKuReeQGioszuESf+uO0=
364+
github.com/testcontainers/testcontainers-go/modules/postgres v0.38.0 h1:KFdx9A0yF94K70T6ibSuvgkQQeX1xKlZVF3hEagXEtY=
365+
github.com/testcontainers/testcontainers-go/modules/postgres v0.38.0/go.mod h1:T/QRECND6N6tAKMxF1Za+G2tpwnGEHcODzHRsgIpw9M=
342366
github.com/testcontainers/testcontainers-go/modules/redis v0.32.0 h1:HW5Qo9qfLi5iwfS7cbXwG6qe8ybXGePcgGPEmVlVDlo=
343367
github.com/testcontainers/testcontainers-go/modules/redis v0.32.0/go.mod h1:5kltdxVKZG0aP1iegeqKz4K8HHyP0wbkW5o84qLyMjY=
344368
github.com/therootcompany/xz v1.0.1 h1:CmOtsn1CbtmyYiusbfmhmkpAAETj0wBIH6kCYaX+xzw=
@@ -352,18 +376,27 @@ github.com/tkuchiki/go-timezone v0.2.2 h1:MdHR65KwgVTwWFQrota4SKzc4L5EfuH5SdZZGt
352376
github.com/tkuchiki/go-timezone v0.2.2/go.mod h1:oFweWxYl35C/s7HMVZXiA19Jr9Y0qJHMaG/J2TES4LY=
353377
github.com/tkuchiki/parsetime v0.3.0 h1:cvblFQlPeAPJL8g6MgIGCHnnmHSZvluuY+hexoZCNqc=
354378
github.com/tkuchiki/parsetime v0.3.0/go.mod h1:OJkQmIrf5Ao7R+WYIdITPOfDVj8LmnHGCfQ8DTs3LCA=
379+
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
380+
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
355381
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
356382
github.com/ulikunitz/xz v0.5.14 h1:uv/0Bq533iFdnMHZdRBTOlaNMdb1+ZxXIlHDZHIHcvg=
357383
github.com/ulikunitz/xz v0.5.14/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
384+
github.com/uptrace/bun v0.3.9/go.mod h1:aL6D9vPw8DXaTQTwGrEPtUderBYXx7ShUmPfnxnqscw=
385+
github.com/uptrace/bun v1.2.15 h1:Ut68XRBLDgp9qG9QBMa9ELWaZOmzHNdczHQdrOZbEFE=
386+
github.com/uptrace/bun v1.2.15/go.mod h1:Eghz7NonZMiTX/Z6oKYytJ0oaMEJ/eq3kEV4vSqG038=
387+
github.com/uptrace/bun/dbfixture v1.2.15 h1:0wncXVJ7L6iYIukWe7WtCpTIxKc3Z3vFX5tAFqV674c=
388+
github.com/uptrace/bun/dbfixture v1.2.15/go.mod h1:vCAi8ESyYHcjFZNTcalwNHI3KYl9TC4CtzL26FsulkQ=
389+
github.com/uptrace/bun/dialect/pgdialect v1.2.15 h1:er+/3giAIqpfrXJw+KP9B7ujyQIi5XkPnFmgjAVL6bA=
390+
github.com/uptrace/bun/dialect/pgdialect v1.2.15/go.mod h1:QSiz6Qpy9wlGFsfpf7UMSL6mXAL1jDJhFwuOVacCnOQ=
358391
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
359392
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
360393
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
361394
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
362395
github.com/vmihailenco/go-tinylfu v0.2.2 h1:H1eiG6HM36iniK6+21n9LLpzx1G9R3DJa2UjUjbynsI=
363396
github.com/vmihailenco/go-tinylfu v0.2.2/go.mod h1:CutYi2Q9puTxfcolkliPq4npPuofg9N9t8JVrjzwa3Q=
364397
github.com/vmihailenco/msgpack/v5 v5.3.4/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
365-
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
366-
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
398+
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
399+
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
367400
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
368401
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
369402
github.com/xakep666/mongo-migrate v0.3.2 h1:qmDtIGiMRIwMvc84fOlsDoP+08S6NWLJDPqa4wPfQ1U=
@@ -533,6 +566,8 @@ golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
533566
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
534567
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
535568
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
569+
golang.org/x/sys v0.36.0 h1:KVRy2GtZBrk1cBYA7MKu5bEZFxQk4NIDV6RLVcC8o0k=
570+
golang.org/x/sys v0.36.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
536571
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
537572
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
538573
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=

api/server.go

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@ package main
22

33
import (
44
"context"
5+
"errors"
56
"os"
67

78
"github.com/getsentry/sentry-go"
89
"github.com/labstack/echo/v4"
910
"github.com/shellhub-io/shellhub/api/routes"
1011
"github.com/shellhub-io/shellhub/api/services"
12+
"github.com/shellhub-io/shellhub/api/store"
1113
"github.com/shellhub-io/shellhub/api/store/mongo"
1214
"github.com/shellhub-io/shellhub/api/store/mongo/options"
15+
"github.com/shellhub-io/shellhub/api/store/pg"
1316
"github.com/shellhub-io/shellhub/pkg/api/internalclient"
1417
"github.com/shellhub-io/shellhub/pkg/cache"
1518
"github.com/shellhub-io/shellhub/pkg/geoip/geolite2"
@@ -19,9 +22,22 @@ import (
1922
)
2023

2124
type env struct {
25+
Database string `env:"DATABASE,default=mongodb"`
26+
2227
// MongoURI specifies the connection string for MongoDB.
2328
MongoURI string `env:"MONGO_URI,default=mongodb://mongo:27017/main"`
2429

30+
// PostgresHost specifies the host for PostgreSQL.
31+
PostgresHost string `env:"POSTGRES_HOST,default=postgres"`
32+
// PostgresPort specifies the port for PostgreSQL.
33+
PostgresPort string `env:"POSTGRES_PORT,default=5432"`
34+
// PostgresUser specifies the username for authenticate PostgreSQL.
35+
PostgresUser string `env:"POSTGRES_USER,default=admin"`
36+
// PostgresUser specifies the password for authenticate PostgreSQL.
37+
PostgresPassword string `env:"POSTGRES_PASSWORD,default=admin"`
38+
// PostgresDB especifica o nome do banco de dados PostgreSQL a ser utilizado.
39+
PostgresDB string `env:"POSTGRES_DB,default=main"`
40+
2541
// RedisURI specifies the connection string for Redis.
2642
RedisURI string `env:"REDIS_URI,default=redis://redis:6379"`
2743
// RedisCachePoolSize defines the maximum number of concurrent connections to Redis cache.
@@ -72,14 +88,22 @@ func (s *Server) Setup(ctx context.Context) error {
7288

7389
log.Debug("Redis cache initialized successfully")
7490

75-
store, err := mongo.NewStore(ctx, s.env.MongoURI, cache, options.RunMigatrions)
76-
if err != nil {
77-
log.
78-
WithError(err).
79-
Fatal("failed to create the store")
91+
var store store.Store
92+
switch s.env.Database {
93+
case "mongodb":
94+
store, err = mongo.NewStore(ctx, s.env.MongoURI, cache, options.RunMigatrions)
95+
case "postgres":
96+
uri := pg.URI(s.env.PostgresHost, s.env.PostgresPort, s.env.PostgresUser, s.env.PostgresPassword, s.env.PostgresDB)
97+
store, err = pg.New(ctx, uri)
98+
default:
99+
log.WithField("database", s.env.Database).Error("invalid database")
100+
return errors.New("invalid database")
80101
}
81102

82-
log.Debug("MongoDB store connected successfully")
103+
if err != nil {
104+
log.WithError(err).Error("failed to create the store")
105+
return err
106+
}
83107

84108
apiClient, err := internalclient.NewClient(internalclient.WithAsynqWorker(s.env.RedisURI))
85109
if err != nil {

0 commit comments

Comments
 (0)