Skip to content

Commit 2a6255b

Browse files
committed
chore: Code cleanup
1 parent 76d482a commit 2a6255b

File tree

7 files changed

+410
-9
lines changed

7 files changed

+410
-9
lines changed

app/handlers/verify.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package handlers
2+
3+
import (
4+
"github.com/gofiber/fiber/v2"
5+
"github.com/limanmys/render-engine/internal/bridge"
6+
"github.com/limanmys/render-engine/pkg/logger"
7+
)
8+
9+
func Verify(c *fiber.Ctx) error {
10+
params := []string{"ip_address", "username", "password", "port", "keyType"}
11+
12+
for _, param := range params {
13+
if len(c.FormValue(param)) < 1 {
14+
return logger.FiberError(fiber.StatusBadRequest, param+" parameter is missing")
15+
}
16+
}
17+
18+
flag := bridge.VerifyAuth(
19+
c.FormValue("username"),
20+
c.FormValue("password"),
21+
c.FormValue("ip_address"),
22+
c.FormValue("port"),
23+
c.FormValue("key_type"),
24+
)
25+
26+
if flag {
27+
return c.JSON("ok")
28+
}
29+
30+
// TODO: change the way request handles on core
31+
c.SendString("nok")
32+
return c.SendStatus(201)
33+
}

app/middleware/app_logger/new.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func New() fiber.Handler {
2121
zap.WithCaller(false),
2222
).Infow(
2323
"render engine request",
24+
"lmn_level", "request",
2425
"latency", time.Since(start).String(),
2526
"log_id", uuid.NewString(),
2627
"user_id", c.Locals("user_id").(string),

app/middleware/auth/new.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,5 @@ func authorization(c *fiber.Ctx) error {
3939
return c.Next()
4040
}
4141

42-
// TODO: Log handlers
43-
4442
return logger.FiberError(fiber.StatusUnauthorized, "authorization token is missing")
4543
}

app/routes/index.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ import (
77

88
func Install(app *fiber.App) {
99
// extension
10-
app.Post("/run", handlers.ExtensionRunner)
10+
app.Post("/extension", handlers.ExtensionRunner)
1111

1212
// command
13-
app.Post("/runCommand", handlers.CommandRunner)
14-
app.Post("/runOutsideCommand", handlers.OutsideCommandRunner)
13+
app.Post("/command", handlers.CommandRunner)
14+
app.Post("/outsideCommand", handlers.OutsideCommandRunner)
1515

1616
// tunnel
1717
app.Post("/openTunnel", handlers.OpenTunnel)
@@ -22,5 +22,11 @@ func Install(app *fiber.App) {
2222
app.Post("/putFile", handlers.PutFile)
2323

2424
// script
25-
app.Post("/runScript", handlers.ScriptRunner)
25+
app.Post("/script", handlers.ScriptRunner)
26+
27+
// verify credentials
28+
app.Post("/verify", handlers.Verify)
29+
30+
// extensionDb
31+
app.Post("/setExtensionDb", handlers.SetExtensionDb)
2632
}

go.mod

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.19
44

55
require (
66
github.com/bytedance/sonic v1.4.0
7-
github.com/gofiber/fiber/v2 v2.37.0
7+
github.com/gofiber/fiber/v2 v2.37.1
88
github.com/gofiber/helmet/v2 v2.2.16
99
github.com/google/uuid v1.3.0
1010
github.com/joho/godotenv v1.4.0
@@ -17,11 +17,19 @@ require (
1717
require (
1818
github.com/Azure/go-ntlmssp v0.0.0-20220621081337-cb9428e4ac1e // indirect
1919
github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect
20+
github.com/atotto/clipboard v0.1.4 // indirect
2021
github.com/benbjohnson/clock v1.3.0 // indirect
22+
github.com/charmbracelet/bubbles v0.14.0 // indirect
23+
github.com/charmbracelet/bubbletea v0.22.1 // indirect
24+
github.com/charmbracelet/lipgloss v0.6.0 // indirect
2125
github.com/chenzhuoyu/base64x v0.0.0-20220526154910-8bf9453eb81a // indirect
26+
github.com/containerd/console v1.0.3 // indirect
27+
github.com/fsnotify/fsnotify v1.5.4 // indirect
2228
github.com/geoffgarside/ber v1.1.0 // indirect
29+
github.com/gofiber/cli v0.0.9 // indirect
2330
github.com/gofrs/uuid v4.2.0+incompatible // indirect
2431
github.com/hashicorp/go-uuid v1.0.3 // indirect
32+
github.com/inconshreveable/mousetrap v1.0.1 // indirect
2533
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
2634
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
2735
github.com/jcmturner/gofork v1.7.6 // indirect
@@ -31,15 +39,27 @@ require (
3139
github.com/klauspost/cpuid/v2 v2.1.1 // indirect
3240
github.com/kr/fs v0.1.0 // indirect
3341
github.com/kr/pretty v0.3.0 // indirect
42+
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
3443
github.com/masterzen/simplexml v0.0.0-20190410153822-31eea3082786 // indirect
44+
github.com/mattn/go-isatty v0.0.16 // indirect
45+
github.com/mattn/go-localereader v0.0.1 // indirect
46+
github.com/mattn/go-runewidth v0.0.13 // indirect
47+
github.com/muesli/ansi v0.0.0-20211031195517-c9f0611b6c70 // indirect
48+
github.com/muesli/cancelreader v0.2.2 // indirect
49+
github.com/muesli/reflow v0.3.0 // indirect
50+
github.com/muesli/termenv v0.12.0 // indirect
3551
github.com/pkg/errors v0.9.1 // indirect
52+
github.com/rivo/uniseg v0.3.4 // indirect
3653
github.com/rogpeppe/go-internal v1.8.1 // indirect
54+
github.com/spf13/cobra v1.5.0 // indirect
55+
github.com/spf13/pflag v1.0.5 // indirect
3756
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
3857
go.uber.org/atomic v1.10.0 // indirect
3958
go.uber.org/goleak v1.1.12 // indirect
4059
go.uber.org/multierr v1.8.0 // indirect
4160
golang.org/x/arch v0.0.0-20220823144127-ada1728cebaa // indirect
42-
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b // indirect
61+
golang.org/x/net v0.0.0-20220907135653-1e95f45603a7 // indirect
62+
golang.org/x/term v0.0.0-20220722155259-a9ba230a4035 // indirect
4363
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
4464
)
4565

@@ -68,6 +88,6 @@ require (
6888
github.com/valyala/fasthttp v1.40.0 // indirect
6989
github.com/valyala/tcplisten v1.0.0 // indirect
7090
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90
71-
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
91+
golang.org/x/sys v0.0.0-20220908164124-27713097b956 // indirect
7292
golang.org/x/text v0.3.7
7393
)

0 commit comments

Comments
 (0)