Skip to content

Commit 2fd45f1

Browse files
authored
Merge pull request #38 from clidey/hk/feature/advanced-setup
[Feature] Add advanced section in login
2 parents d9728b4 + dbed830 commit 2fd45f1

File tree

19 files changed

+190
-75
lines changed

19 files changed

+190
-75
lines changed

core/Dockerfile

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,23 @@
1-
FROM node:18.12.1-alpine as build-stage
2-
1+
FROM node:18.12.1-alpine AS build-stage
32
RUN npm i -g pnpm
4-
53
WORKDIR /app
64
COPY ./frontend/package.json ./frontend/pnpm-lock.yaml ./
75
RUN pnpm install
86
COPY ./frontend/ ./
97
RUN pnpm run build
108

11-
12-
FROM golang:1.22.1-alpine3.19 as backend-stage
13-
9+
FROM golang:1.22.1-alpine3.19 AS backend-stage
1410
RUN apk update && apk add --no-cache gcc musl-dev
15-
1611
WORKDIR /app
1712
COPY ./core/go.mod ./core/go.sum ./
1813
RUN go mod download
1914
COPY ./core/ ./
15+
COPY --from=build-stage /app/build/ ./build/
2016
RUN CGO_ENABLED=1 GOOS=linux go build -o /core
2117

2218
FROM alpine:3.19
23-
2419
RUN apk update && apk add --no-cache ca-certificates
25-
2620
WORKDIR /app
2721
COPY --from=backend-stage /core /core
28-
COPY --from=build-stage /app/build/ ./build/
2922

30-
CMD ["/core"]
23+
CMD ["/core"]

core/graph/generated.go

Lines changed: 35 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/graph/model/models_gen.go

Lines changed: 6 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/graph/schema.graphqls

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ input LoginCredentials {
6060
Username: String!
6161
Password: String!
6262
Database: String!
63+
Advanced: [RecordInput!]
6364
}
6465

6566
type StatusResponse {
@@ -77,7 +78,7 @@ type Query {
7778
}
7879

7980
type Mutation {
80-
Login(credentails: LoginCredentials!): StatusResponse!
81+
Login(credentials: LoginCredentials!): StatusResponse!
8182
Logout: StatusResponse!
8283

8384
UpdateStorageUnit(type: DatabaseType!, schema: String!, storageUnit: String!, values: [RecordInput!]!): StatusResponse!

core/graph/schema.resolvers.go

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

core/src/common/utils.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package common
22

3+
import "github.com/clidey/whodb/core/src/engine"
4+
35
func ContainsString(slice []string, element string) bool {
46
for _, item := range slice {
57
if item == element {
@@ -8,3 +10,12 @@ func ContainsString(slice []string, element string) bool {
810
}
911
return false
1012
}
13+
14+
func GetRecordValueOrDefault(records []engine.Record, key string, defaultValue string) string {
15+
for _, record := range records {
16+
if record.Key == key && len(record.Value) > 0 {
17+
return record.Value
18+
}
19+
}
20+
return defaultValue
21+
}

core/src/engine/plugin.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type Credentials struct {
55
Username string
66
Password string
77
Database string
8+
Advanced []Record
89
}
910

1011
type PluginConfig struct {

core/src/plugins/mongodb/db.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,33 @@ import (
44
"context"
55
"fmt"
66

7+
"github.com/clidey/whodb/core/src/common"
78
"github.com/clidey/whodb/core/src/engine"
89
"go.mongodb.org/mongo-driver/mongo"
910
"go.mongodb.org/mongo-driver/mongo/options"
1011
)
1112

1213
func DB(config *engine.PluginConfig) (*mongo.Client, error) {
1314
ctx := context.Background()
15+
port := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Port", "27017")
16+
queryParams := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Query Params", "")
1417
var connectionString string
1518
// TODO: add TLS enabled logic to work instead of hard coded domains
1619
if config.Credentials.Hostname == "localhost" || config.Credentials.Hostname == "host.docker.internal" {
17-
connectionString = fmt.Sprintf("mongodb://%s:%s@%s:%d/%s",
20+
connectionString = fmt.Sprintf("mongodb://%s:%s@%s:%s/%s%s",
1821
config.Credentials.Username,
1922
config.Credentials.Password,
2023
config.Credentials.Hostname,
21-
27017,
22-
config.Credentials.Database)
24+
port,
25+
config.Credentials.Database,
26+
queryParams)
2327
} else {
24-
connectionString = fmt.Sprintf("mongodb+srv://%s:%s@%s/%s",
28+
connectionString = fmt.Sprintf("mongodb+srv://%s:%s@%s/%s%s",
2529
config.Credentials.Username,
2630
config.Credentials.Password,
2731
config.Credentials.Hostname,
28-
config.Credentials.Database)
32+
config.Credentials.Database,
33+
queryParams)
2934
}
3035

3136
clientOptions := options.Client().ApplyURI(connectionString)

core/src/plugins/mysql/db.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,18 @@ package mysql
33
import (
44
"fmt"
55

6+
"github.com/clidey/whodb/core/src/common"
67
"github.com/clidey/whodb/core/src/engine"
78
"gorm.io/driver/mysql"
89
"gorm.io/gorm"
910
)
1011

1112
func DB(config *engine.PluginConfig) (*gorm.DB, error) {
12-
dsn := fmt.Sprintf("%v:%v@tcp(%v:3306)/%v?charset=utf8mb4&parseTime=True&loc=Local", config.Credentials.Username, config.Credentials.Password, config.Credentials.Hostname, config.Credentials.Database)
13+
port := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Port", "3306")
14+
charset := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Charset", "utf8mb4")
15+
parseTime := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Parse Time", "True")
16+
loc := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Loc", "Local")
17+
dsn := fmt.Sprintf("%v:%v@tcp(%v:%v)/%v?charset=%v&parseTime=%v&loc=%v", config.Credentials.Username, config.Credentials.Password, config.Credentials.Hostname, port, config.Credentials.Database, charset, parseTime, loc)
1318
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{})
1419
if err != nil {
1520
return nil, err

core/src/plugins/postgres/db.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@ package postgres
33
import (
44
"fmt"
55

6+
"github.com/clidey/whodb/core/src/common"
67
"github.com/clidey/whodb/core/src/engine"
78
"gorm.io/driver/postgres"
89
"gorm.io/gorm"
910
)
1011

1112
func DB(config *engine.PluginConfig) (*gorm.DB, error) {
12-
dsn := fmt.Sprintf("host=%v user=%v password=%v dbname=%v port=5432", config.Credentials.Hostname, config.Credentials.Username, config.Credentials.Password, config.Credentials.Database)
13+
port := common.GetRecordValueOrDefault(config.Credentials.Advanced, "Port", "5432")
14+
sslMode := common.GetRecordValueOrDefault(config.Credentials.Advanced, "SSL Mode", "disable")
15+
dsn := fmt.Sprintf("host=%v user=%v password=%v dbname=%v port=%v sslmode=%v", config.Credentials.Hostname, config.Credentials.Username, config.Credentials.Password, config.Credentials.Database, port, sslMode)
1316
db, err := gorm.Open(postgres.Open(dsn), &gorm.Config{})
1417
if err != nil {
1518
return nil, err

0 commit comments

Comments
 (0)