Skip to content

Commit c79919c

Browse files
committed
feat(api): introduce postgres
1 parent 714b9a2 commit c79919c

24 files changed

+700
-615
lines changed

.env

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ SHELLHUB_DOMAIN=localhost
4343
# VALUES: A valid network name
4444
SHELLHUB_NETWORK=shellhub_network
4545

46+
# The host for PostgreSQL connection.
47+
SHELLHUB_POSTGRES_HOST=postgres
48+
# The port for PostgreSQL connection.
49+
SHELLHUB_POSTGRES_PORT=5432
50+
# The username for PostgreSQL authentication.
51+
SHELLHUB_POSTGRES_USER=admin
52+
# The password for PostgreSQL authentication.
53+
SHELLHUB_POSTGRES_PASSWORD=admin
54+
# The name of the default PostgreSQL.
55+
SHELLHUB_POSTGRES_DB=main
56+
4657
# Enable tunnels feature.
4758
SHELLHUB_TUNNELS=false
4859

api/Dockerfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ COPY ./api/entrypoint-dev.sh /entrypoint.sh
5454
WORKDIR $GOPATH/src/github.com/shellhub-io/shellhub/api
5555

5656
RUN mkdir -p /templates
57+
RUN mkdir -p /migrations
5758

5859
COPY ./install.sh /templates/install.sh
5960

@@ -67,6 +68,7 @@ RUN apk add curl
6768
COPY --from=builder /go/src/github.com/shellhub-io/shellhub/api/api /api
6869

6970
RUN mkdir -p /templates
71+
RUN mkdir -p /migrations
7072

7173
COPY ./install.sh /templates/install.sh
7274

api/go.mod

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
github.com/getsentry/sentry-go v0.31.1
1010
github.com/golang-jwt/jwt/v4 v4.5.2
1111
github.com/gorilla/websocket v1.5.3
12+
github.com/jackc/pgx/v5 v5.7.4
1213
github.com/labstack/echo/v4 v4.13.3
1314
github.com/labstack/gommon v0.4.2
1415
github.com/pkg/errors v0.9.1
@@ -19,6 +20,8 @@ require (
1920
github.com/square/mongo-lock v0.0.0-20230808145049-cfcf499f6bf0
2021
github.com/stretchr/testify v1.10.0
2122
github.com/testcontainers/testcontainers-go/modules/mongodb v0.35.0
23+
github.com/uptrace/bun v1.2.11
24+
github.com/uptrace/bun/dialect/pgdialect v1.2.11
2225
github.com/xakep666/mongo-migrate v0.3.2
2326
go.mongodb.org/mongo-driver v1.17.3
2427
golang.org/x/crypto v0.33.0
@@ -67,12 +70,16 @@ require (
6770
github.com/hashicorp/go-multierror v1.1.1 // indirect
6871
github.com/hibiken/asynq v0.24.1 // indirect
6972
github.com/inconshreveable/mousetrap v1.1.0 // indirect
73+
github.com/jackc/pgpassfile v1.0.0 // indirect
74+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
75+
github.com/jackc/puddle/v2 v2.2.2 // indirect
76+
github.com/jinzhu/inflection v1.0.0 // indirect
7077
github.com/klauspost/compress v1.17.8 // indirect
7178
github.com/klauspost/pgzip v1.2.5 // indirect
7279
github.com/leodido/go-urn v1.2.2 // indirect
7380
github.com/lufia/plan9stats v0.0.0-20240408141607-282e7b5d6b74 // indirect
7481
github.com/magiconair/properties v1.8.7 // indirect
75-
github.com/mattn/go-colorable v0.1.13 // indirect
82+
github.com/mattn/go-colorable v0.1.14 // indirect
7683
github.com/mattn/go-isatty v0.0.20 // indirect
7784
github.com/mholt/archiver/v4 v4.0.0-alpha.8 // indirect
7885
github.com/moby/docker-image-spec v1.3.1 // indirect
@@ -91,6 +98,7 @@ require (
9198
github.com/pierrec/lz4/v4 v4.1.17 // indirect
9299
github.com/pmezard/go-difflib v1.0.0 // indirect
93100
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
101+
github.com/puzpuzpuz/xsync/v3 v3.5.1 // indirect
94102
github.com/redis/go-redis/v9 v9.0.3 // indirect
95103
github.com/robfig/cron/v3 v3.0.1 // indirect
96104
github.com/sethvargo/go-envconfig v0.9.0 // indirect
@@ -105,11 +113,12 @@ require (
105113
github.com/tklauser/numcpus v0.7.0 // indirect
106114
github.com/tkuchiki/go-timezone v0.2.2 // indirect
107115
github.com/tkuchiki/parsetime v0.3.0 // indirect
116+
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc // indirect
108117
github.com/ulikunitz/xz v0.5.11 // indirect
109118
github.com/valyala/bytebufferpool v1.0.0 // indirect
110119
github.com/valyala/fasttemplate v1.2.2 // indirect
111120
github.com/vmihailenco/go-tinylfu v0.2.2 // indirect
112-
github.com/vmihailenco/msgpack/v5 v5.3.5 // indirect
121+
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
113122
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
114123
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
115124
github.com/xdg-go/scram v1.1.2 // indirect

api/go.sum

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,16 @@ github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpO
196196
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
197197
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
198198
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
199+
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
200+
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
201+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
202+
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
203+
github.com/jackc/pgx/v5 v5.7.4 h1:9wKznZrhWa2QiHL+NjTSPP6yjl3451BX3imWDnokYlg=
204+
github.com/jackc/pgx/v5 v5.7.4/go.mod h1:ncY89UGWxg82EykZUwSpUKEfccBGGYq1xjrOpsbsfGQ=
205+
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
206+
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
207+
github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E=
208+
github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc=
199209
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
200210
github.com/jstemmer/go-junit-report v0.9.1/go.mod h1:Brl9GWCQeLvo8nXZwPNNblvFj/XSXhF0NWZEnDohbsk=
201211
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
@@ -225,9 +235,8 @@ github.com/lufia/plan9stats v0.0.0-20240408141607-282e7b5d6b74 h1:1KuuSOy4ZNgW0K
225235
github.com/lufia/plan9stats v0.0.0-20240408141607-282e7b5d6b74/go.mod h1:ilwx/Dta8jXAgpFYFvSWEMwxmbWXyiUHkd5FwyKhb5k=
226236
github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY=
227237
github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
228-
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
229-
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
230-
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
238+
github.com/mattn/go-colorable v0.1.14 h1:9A9LHSqF/7dyVVX6g0U9cwm9pG3kP9gSzcuIPHPsaIE=
239+
github.com/mattn/go-colorable v0.1.14/go.mod h1:6LmQG8QLFO4G5z1gPvYEzlUgJ2wF+stgPZH1UqBm1s8=
231240
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
232241
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
233242
github.com/mattn/go-runewidth v0.0.13/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
@@ -286,6 +295,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:Om
286295
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 h1:o4JXh1EVt9k/+g42oCprj/FisM4qX9L3sZB3upGN2ZU=
287296
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
288297
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
298+
github.com/puzpuzpuz/xsync/v3 v3.5.1 h1:GJYJZwO6IdxN/IKbneznS6yPkVC+c3zyY/j19c++5Fg=
299+
github.com/puzpuzpuz/xsync/v3 v3.5.1/go.mod h1:VjzYrABPabuM4KyBh1Ftq6u8nhwY5tBPKP9jpmh0nnA=
289300
github.com/redis/go-redis/v9 v9.0.3 h1:+7mmR26M0IvyLxGZUHxu4GiBkJkVDid0Un+j4ScYu4k=
290301
github.com/redis/go-redis/v9 v9.0.3/go.mod h1:WqMKv5vnQbRuZstUwxQI195wHy+t4PuXDOjzMvcuQHk=
291302
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
@@ -324,6 +335,7 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE
324335
github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
325336
github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
326337
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
338+
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
327339
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
328340
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
329341
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
@@ -354,18 +366,24 @@ github.com/tkuchiki/go-timezone v0.2.2 h1:MdHR65KwgVTwWFQrota4SKzc4L5EfuH5SdZZGt
354366
github.com/tkuchiki/go-timezone v0.2.2/go.mod h1:oFweWxYl35C/s7HMVZXiA19Jr9Y0qJHMaG/J2TES4LY=
355367
github.com/tkuchiki/parsetime v0.3.0 h1:cvblFQlPeAPJL8g6MgIGCHnnmHSZvluuY+hexoZCNqc=
356368
github.com/tkuchiki/parsetime v0.3.0/go.mod h1:OJkQmIrf5Ao7R+WYIdITPOfDVj8LmnHGCfQ8DTs3LCA=
369+
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc h1:9lRDQMhESg+zvGYmW5DyG0UqvY96Bu5QYsTLvCHdrgo=
370+
github.com/tmthrgd/go-hex v0.0.0-20190904060850-447a3041c3bc/go.mod h1:bciPuU6GHm1iF1pBvUfxfsH0Wmnc2VbpgvbI9ZWuIRs=
357371
github.com/ulikunitz/xz v0.5.8/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
358372
github.com/ulikunitz/xz v0.5.11 h1:kpFauv27b6ynzBNT/Xy+1k+fK4WswhN/6PN5WhFAGw8=
359373
github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
374+
github.com/uptrace/bun v1.2.11 h1:l9dTymsdZZAoSZ1+Qo3utms0RffgkDbIv+1UGk8N1wQ=
375+
github.com/uptrace/bun v1.2.11/go.mod h1:ww5G8h59UrOnCHmZ8O1I/4Djc7M/Z3E+EWFS2KLB6dQ=
376+
github.com/uptrace/bun/dialect/pgdialect v1.2.11 h1:n0VKWm1fL1dwJK5TRxYYLaRKRe14BOg2+AQgpvqzG/M=
377+
github.com/uptrace/bun/dialect/pgdialect v1.2.11/go.mod h1:NvV1S/zwtwBnW8yhJ3XEKAQEw76SkeH7yUhfrx3W1Eo=
360378
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
361379
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
362380
github.com/valyala/fasttemplate v1.2.2 h1:lxLXG0uE3Qnshl9QyaK6XJxMXlQZELvChBOCmQD0Loo=
363381
github.com/valyala/fasttemplate v1.2.2/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
364382
github.com/vmihailenco/go-tinylfu v0.2.2 h1:H1eiG6HM36iniK6+21n9LLpzx1G9R3DJa2UjUjbynsI=
365383
github.com/vmihailenco/go-tinylfu v0.2.2/go.mod h1:CutYi2Q9puTxfcolkliPq4npPuofg9N9t8JVrjzwa3Q=
366384
github.com/vmihailenco/msgpack/v5 v5.3.4/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
367-
github.com/vmihailenco/msgpack/v5 v5.3.5 h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
368-
github.com/vmihailenco/msgpack/v5 v5.3.5/go.mod h1:7xyJ9e+0+9SaZT0Wt1RGleJXzli6Q/V5KbhBonMG9jc=
385+
github.com/vmihailenco/msgpack/v5 v5.4.1 h1:cQriyiUvjTwOHg8QZaPihLWeRAAVoCpE00IUPn0Bjt8=
386+
github.com/vmihailenco/msgpack/v5 v5.4.1/go.mod h1:GaZTsDaehaPpQVyxrf5mtQlH+pc21PIudVV/E3rRQok=
369387
github.com/vmihailenco/tagparser/v2 v2.0.0 h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
370388
github.com/vmihailenco/tagparser/v2 v2.0.0/go.mod h1:Wri+At7QHww0WTrCBeu4J6bNtoV6mEfg5OIWRZA9qds=
371389
github.com/xakep666/mongo-migrate v0.3.2 h1:qmDtIGiMRIwMvc84fOlsDoP+08S6NWLJDPqa4wPfQ1U=
@@ -528,7 +546,6 @@ golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBc
528546
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
529547
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
530548
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
531-
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
532549
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
533550
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
534551
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=

api/server.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import (
88
"github.com/labstack/echo/v4"
99
"github.com/shellhub-io/shellhub/api/routes"
1010
"github.com/shellhub-io/shellhub/api/services"
11-
"github.com/shellhub-io/shellhub/api/store/mongo"
12-
"github.com/shellhub-io/shellhub/api/store/mongo/options"
11+
"github.com/shellhub-io/shellhub/api/store/pg"
1312
"github.com/shellhub-io/shellhub/pkg/api/internalclient"
1413
"github.com/shellhub-io/shellhub/pkg/cache"
1514
"github.com/shellhub-io/shellhub/pkg/geoip/geolite2"
@@ -22,6 +21,17 @@ type env struct {
2221
// MongoURI specifies the connection string for MongoDB.
2322
MongoURI string `env:"MONGO_URI,default=mongodb://mongo:27017/main"`
2423

24+
// PostgresHost specifies the host for PostgreSQL.
25+
PostgresHost string `env:"POSTGRES_HOST,default=postgres"`
26+
// PostgresPort specifies the port for PostgreSQL.
27+
PostgresPort string `env:"POSTGRES_PORT,default=5432"`
28+
// PostgresUser specifies the username for authenticate PostgreSQL.
29+
PostgresUser string `env:"POSTGRES_USER,default=admin"`
30+
// PostgresUser specifies the password for authenticate PostgreSQL.
31+
PostgresPassword string `env:"POSTGRES_PASSWORD,default=admin"`
32+
// PostgresDB especifica o nome do banco de dados PostgreSQL a ser utilizado.
33+
PostgresDB string `env:"POSTGRES_DB,default=main"`
34+
2535
// RedisURI specifies the connection string for Redis.
2636
RedisURI string `env:"REDIS_URI,default=redis://redis:6379"`
2737
// RedisCachePoolSize defines the maximum number of concurrent connections to Redis cache.
@@ -72,14 +82,16 @@ func (s *Server) Setup(ctx context.Context) error {
7282

7383
log.Debug("Redis cache initialized successfully")
7484

75-
store, err := mongo.NewStore(ctx, s.env.MongoURI, cache, options.RunMigatrions)
85+
uri := pg.URI(s.env.PostgresHost, s.env.PostgresPort, s.env.PostgresUser, s.env.PostgresPassword, s.env.PostgresDB)
86+
store, err := pg.New(ctx, uri)
7687
if err != nil {
7788
log.
7889
WithError(err).
7990
Fatal("failed to create the store")
91+
return err
8092
}
8193

82-
log.Debug("MongoDB store connected successfully")
94+
log.Debug("Posgres store connected successfully")
8395

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

api/store/pg/api-key.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package pg
2+
3+
import (
4+
"context"
5+
6+
"github.com/shellhub-io/shellhub/pkg/api/query"
7+
"github.com/shellhub-io/shellhub/pkg/models"
8+
)
9+
10+
func (pg *pg) APIKeyCreate(ctx context.Context, APIKey *models.APIKey) (string, error) {
11+
return "", nil
12+
}
13+
14+
func (pg *pg) APIKeyConflicts(ctx context.Context, tenantID string, target *models.APIKeyConflicts) (conflicts []string, has bool, err error) {
15+
return nil, false, nil
16+
}
17+
18+
func (pg *pg) APIKeyList(ctx context.Context, tenantID string, paginator query.Paginator, sorter query.Sorter) (apiKeys []models.APIKey, count int, err error) {
19+
return nil, 0, nil
20+
}
21+
22+
func (pg *pg) APIKeyGet(ctx context.Context, id string) (apiKey *models.APIKey, err error) {
23+
// TODO: unify get methods
24+
return nil, nil
25+
}
26+
27+
func (pg *pg) APIKeyGetByName(ctx context.Context, tenantID string, name string) (apiKey *models.APIKey, err error) {
28+
// TODO: unify get methods
29+
return nil, nil
30+
}
31+
32+
func (pg *pg) APIKeyUpdate(ctx context.Context, tenantID, name string, changes *models.APIKeyChanges) (err error) {
33+
return nil
34+
}
35+
36+
func (pg *pg) APIKeyDelete(ctx context.Context, tenantID, name string) (err error) {
37+
return nil
38+
}

api/store/pg/device.go

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
package pg
2+
3+
import (
4+
"context" //nolint:gosec
5+
6+
"github.com/shellhub-io/shellhub/api/store"
7+
"github.com/shellhub-io/shellhub/pkg/api/query"
8+
"github.com/shellhub-io/shellhub/pkg/models"
9+
)
10+
11+
func (pg *pg) DeviceList(ctx context.Context, status models.DeviceStatus, paginator query.Paginator, filters query.Filters, sorter query.Sorter, acceptable store.DeviceAcceptable) ([]models.Device, int, error) {
12+
return nil, 0, nil
13+
}
14+
15+
func (pg *pg) DeviceGet(ctx context.Context, uid models.UID) (*models.Device, error) {
16+
return nil, nil
17+
}
18+
19+
func (pg *pg) DeviceDelete(ctx context.Context, uid models.UID) error {
20+
return nil
21+
}
22+
23+
func (pg *pg) DeviceCreate(ctx context.Context, d models.Device, hostname string) error {
24+
return nil
25+
}
26+
27+
func (pg *pg) DeviceRename(ctx context.Context, uid models.UID, hostname string) error {
28+
return nil
29+
}
30+
31+
func (pg *pg) DeviceLookup(ctx context.Context, namespace, hostname string) (*models.Device, error) {
32+
return nil, nil
33+
}
34+
35+
// DeviceUpdateStatus updates the status of a specific device in the devices collection
36+
func (pg *pg) DeviceUpdateStatus(ctx context.Context, uid models.UID, status models.DeviceStatus) error {
37+
return nil
38+
}
39+
40+
func (pg *pg) DeviceListByUsage(ctx context.Context, tenant string) ([]models.UID, error) {
41+
return nil, nil
42+
}
43+
44+
func (pg *pg) DeviceGetByMac(ctx context.Context, mac string, tenantID string, status models.DeviceStatus) (*models.Device, error) {
45+
return nil, nil
46+
}
47+
48+
func (pg *pg) DeviceGetByName(ctx context.Context, name string, tenantID string, status models.DeviceStatus) (*models.Device, error) {
49+
return nil, nil
50+
}
51+
52+
func (pg *pg) DeviceGetByUID(ctx context.Context, uid models.UID, tenantID string) (*models.Device, error) {
53+
return nil, nil
54+
}
55+
56+
func (pg *pg) DeviceSetPosition(ctx context.Context, uid models.UID, position models.DevicePosition) error {
57+
return nil
58+
}
59+
60+
func (pg *pg) DeviceChooser(ctx context.Context, tenantID string, chosen []string) error {
61+
return nil
62+
}
63+
64+
func (pg *pg) DeviceConflicts(ctx context.Context, target *models.DeviceConflicts) ([]string, bool, error) {
65+
return nil, false, nil
66+
}
67+
68+
func (pg *pg) DeviceUpdate(ctx context.Context, tenantID, uid string, changepg *models.DeviceChanges) error {
69+
return nil
70+
}
71+
72+
func (pg *pg) DeviceBulkUpdate(ctx context.Context, uids []string, changepg *models.DeviceChanges) (int64, error) {
73+
return int64(0), nil
74+
}
75+
76+
func (pg *pg) DeviceRemovedCount(ctx context.Context, tenant string) (int64, error) {
77+
return int64(0), nil
78+
}
79+
80+
func (pg *pg) DeviceRemovedGet(ctx context.Context, tenant string, uid models.UID) (*models.DeviceRemoved, error) {
81+
return nil, nil
82+
}
83+
84+
func (pg *pg) DeviceRemovedInsert(ctx context.Context, tenant string, device *models.Device) error { //nolint:revive
85+
return nil
86+
}
87+
88+
func (pg *pg) DeviceRemovedDelete(ctx context.Context, tenant string, uid models.UID) error {
89+
return nil
90+
}
91+
92+
func (pg *pg) DeviceRemovedList(ctx context.Context, tenant string, paginator query.Paginator, filters query.Filters, sorter query.Sorter) ([]models.DeviceRemoved, int, error) {
93+
return nil, 0, nil
94+
}
95+
96+
func (pg *pg) DevicePushTag(ctx context.Context, uid models.UID, tag string) error {
97+
return nil
98+
}
99+
100+
func (pg *pg) DevicePullTag(ctx context.Context, uid models.UID, tag string) error {
101+
return nil
102+
}
103+
104+
func (pg *pg) DeviceSetTags(ctx context.Context, uid models.UID, tags []string) (int64, int64, error) {
105+
return int64(0), int64(0), nil
106+
}
107+
108+
func (pg *pg) DeviceBulkRenameTag(ctx context.Context, tenant, currentTag, newTag string) (int64, error) {
109+
return int64(0), nil
110+
}
111+
112+
func (pg *pg) DeviceBulkDeleteTag(ctx context.Context, tenant, tag string) (int64, error) {
113+
return int64(0), nil
114+
}
115+
116+
func (pg *pg) DeviceGetTags(ctx context.Context, tenant string) ([]string, int, error) {
117+
return nil, 0, nil
118+
}

api/store/pg/metrics.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package pg
2+
3+
import (
4+
"context"
5+
6+
"github.com/shellhub-io/shellhub/pkg/models"
7+
)
8+
9+
func (pg *pg) GetStats(ctx context.Context) (*models.Stats, error) {
10+
return nil, nil
11+
}

0 commit comments

Comments
 (0)