diff --git a/.idea/workspace.xml b/.idea/workspace.xml
index 7c68806..9a9a347 100644
--- a/.idea/workspace.xml
+++ b/.idea/workspace.xml
@@ -4,9 +4,17 @@
-
+
-
+
+
+
+
+
+
+
+
+
@@ -36,28 +44,28 @@
- {
- "keyToString": {
- "DefaultGoTemplateProperty": "Go File",
- "Go Build.Backend.executor": "Run",
- "Go 构建.Backend.executor": "Run",
- "RunOnceActivity.ShowReadmeOnStart": "true",
- "RunOnceActivity.go.formatter.settings.were.checked": "true",
- "RunOnceActivity.go.migrated.go.modules.settings": "true",
- "RunOnceActivity.go.modules.automatic.dependencies.download": "true",
- "RunOnceActivity.go.modules.go.list.on.any.changes.was.set": "true",
- "git-widget-placeholder": "master",
- "go.import.settings.migrated": "true",
- "go.sdk.automatically.set": "true",
- "last_opened_file_path": "/Users/littlesheep/Documents/Projects/Hydrogen/Paperclip/pkg/internal/grpc",
- "node.js.detected.package.eslint": "true",
- "node.js.selected.package.eslint": "(autodetect)",
- "nodejs_package_manager_path": "npm",
- "run.code.analysis.last.selected.profile": "pProject Default",
- "settings.editor.selected.configurable": "preferences.lookFeel",
- "vue.rearranger.settings.migration": "true"
+
+}]]>
@@ -116,7 +124,8 @@
-
+
+
true
diff --git a/go.mod b/go.mod
index a326a56..bb5ef9e 100644
--- a/go.mod
+++ b/go.mod
@@ -3,12 +3,10 @@ module git.solsynth.dev/hydrogen/paperclip
go 1.21.6
require (
- git.solsynth.dev/hydrogen/passport v0.0.0-20240623083719-86b2cd81400a
+ git.solsynth.dev/hydrogen/dealer v0.0.0-20240714155615-ad83100677ab
github.com/go-playground/validator/v10 v10.17.0
github.com/gofiber/fiber/v2 v2.52.4
- github.com/golang-jwt/jwt/v5 v5.2.0
github.com/google/uuid v1.6.0
- github.com/hashicorp/consul/api v1.29.1
github.com/json-iterator/go v1.1.12
github.com/minio/minio-go/v7 v7.0.70
github.com/robfig/cron/v3 v3.0.1
@@ -34,6 +32,7 @@ require (
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-sql-driver/mysql v1.7.1 // indirect
github.com/goccy/go-json v0.10.2 // indirect
+ github.com/hashicorp/consul/api v1.29.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
github.com/hashicorp/go-hclog v1.6.3 // indirect
diff --git a/go.sum b/go.sum
index 1b6897d..7785ba8 100644
--- a/go.sum
+++ b/go.sum
@@ -1,7 +1,5 @@
-git.solsynth.dev/hydrogen/passport v0.0.0-20240623081149-7ddbea8bcb86 h1:cxjBOhemnyxf49CJyPmnt1RKFHerK45rXXBPwsIFrhA=
-git.solsynth.dev/hydrogen/passport v0.0.0-20240623081149-7ddbea8bcb86/go.mod h1:tUr7x1v0trG3ALDacdDuhJiPRPgFhJ1Si9OqNlYbgSk=
-git.solsynth.dev/hydrogen/passport v0.0.0-20240623083719-86b2cd81400a h1:oxNbS6Q+sSOfYUQTcx9/awCmlk/lpVP997hgpMmFsyw=
-git.solsynth.dev/hydrogen/passport v0.0.0-20240623083719-86b2cd81400a/go.mod h1:tUr7x1v0trG3ALDacdDuhJiPRPgFhJ1Si9OqNlYbgSk=
+git.solsynth.dev/hydrogen/dealer v0.0.0-20240714155615-ad83100677ab h1:hxqJkL4Ha3Y3SfeSA9TPKBJK6mtY88Q2uialHsDbGf0=
+git.solsynth.dev/hydrogen/dealer v0.0.0-20240714155615-ad83100677ab/go.mod h1:eZwAwP7ahL7TO8GWBlYFYDdjlna+8zHYbDfNabnuUEU=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/template v0.0.0-20190718012654-fb15b899a751/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
@@ -64,8 +62,6 @@ github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5x
github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM=
github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ=
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
-github.com/golang-jwt/jwt/v5 v5.2.0 h1:d/ix8ftRUorsN+5eMIlF4T6J8CAt9rch3My2winC1Jw=
-github.com/golang-jwt/jwt/v5 v5.2.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA=
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
diff --git a/pkg/internal/gap/client.go b/pkg/internal/gap/client.go
deleted file mode 100644
index 6a6a39e..0000000
--- a/pkg/internal/gap/client.go
+++ /dev/null
@@ -1,12 +0,0 @@
-package gap
-
-import (
- "git.solsynth.dev/hydrogen/passport/pkg/hyper"
- "github.com/spf13/viper"
-)
-
-var H *hyper.HyperConn
-
-func NewHyperClient() {
- H = hyper.NewHyperConn(viper.GetString("consul.addr"))
-}
diff --git a/pkg/internal/gap/server.go b/pkg/internal/gap/server.go
index 3edffca..1b9dcc2 100644
--- a/pkg/internal/gap/server.go
+++ b/pkg/internal/gap/server.go
@@ -2,38 +2,41 @@ package gap
import (
"fmt"
- "strconv"
+ "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
+ "git.solsynth.dev/hydrogen/dealer/pkg/proto"
+ "github.com/rs/zerolog/log"
"strings"
- "github.com/hashicorp/consul/api"
"github.com/spf13/viper"
)
-func Register() error {
- cfg := api.DefaultConfig()
- cfg.Address = viper.GetString("consul.addr")
-
- client, err := api.NewClient(cfg)
- if err != nil {
- return err
- }
+var H *hyper.HyperConn
+func RegisterService() error {
grpcBind := strings.SplitN(viper.GetString("grpc_bind"), ":", 2)
+ httpBind := strings.SplitN(viper.GetString("bind"), ":", 2)
outboundIp, _ := GetOutboundIP()
- port, _ := strconv.Atoi(grpcBind[1])
- registration := new(api.AgentServiceRegistration)
- registration.ID = viper.GetString("id")
- registration.Name = "Hydrogen.Paperclip"
- registration.Address = outboundIp.String()
- registration.Port = port
- registration.Check = &api.AgentServiceCheck{
- GRPC: fmt.Sprintf("%s:%s", outboundIp, grpcBind[1]),
- Timeout: "5s",
- Interval: "1m",
- DeregisterCriticalServiceAfter: "3m",
+ grpcOutbound := fmt.Sprintf("%s:%s", outboundIp, grpcBind[1])
+ httpOutbound := fmt.Sprintf("%s:%s", outboundIp, httpBind[1])
+
+ var err error
+ H, err = hyper.NewHyperConn(viper.GetString("dealer.addr"), &proto.ServiceInfo{
+ Id: viper.GetString("id"),
+ Type: hyper.ServiceTypeFileProvider,
+ Label: "Paperclip",
+ GrpcAddr: grpcOutbound,
+ HttpAddr: &httpOutbound,
+ })
+ if err == nil {
+ go func() {
+ err := H.KeepRegisterService()
+ if err != nil {
+ log.Error().Err(err).Msg("An error occurred while registering service...")
+ }
+ }()
}
- return client.Agent().ServiceRegister(registration)
+ return err
}
diff --git a/pkg/internal/server/exts/auth.go b/pkg/internal/server/exts/auth.go
index a018ec3..104cdc6 100644
--- a/pkg/internal/server/exts/auth.go
+++ b/pkg/internal/server/exts/auth.go
@@ -1,13 +1,13 @@
package exts
import (
+ "git.solsynth.dev/hydrogen/dealer/pkg/proto"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/services"
- "git.solsynth.dev/hydrogen/passport/pkg/proto"
"github.com/gofiber/fiber/v2"
)
func LinkAccountMiddleware(c *fiber.Ctx) error {
- if val, ok := c.Locals("p_user").(*proto.Userinfo); ok {
+ if val, ok := c.Locals("p_user").(*proto.UserInfo); ok {
if account, err := services.LinkAccount(val); err != nil {
return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} else {
diff --git a/pkg/internal/services/auth.go b/pkg/internal/services/auth.go
index 9c6645c..a661cf5 100644
--- a/pkg/internal/services/auth.go
+++ b/pkg/internal/services/auth.go
@@ -3,14 +3,14 @@ package services
import (
"errors"
"fmt"
+ "git.solsynth.dev/hydrogen/dealer/pkg/proto"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/database"
"git.solsynth.dev/hydrogen/paperclip/pkg/internal/models"
- "git.solsynth.dev/hydrogen/passport/pkg/proto"
"gorm.io/gorm"
"reflect"
)
-func LinkAccount(userinfo *proto.Userinfo) (models.Account, error) {
+func LinkAccount(userinfo *proto.UserInfo) (models.Account, error) {
var account models.Account
if userinfo == nil {
return account, fmt.Errorf("remote userinfo was not found")
diff --git a/pkg/internal/services/jwt.go b/pkg/internal/services/jwt.go
deleted file mode 100644
index 40cfef0..0000000
--- a/pkg/internal/services/jwt.go
+++ /dev/null
@@ -1,81 +0,0 @@
-package services
-
-import (
- "fmt"
- "github.com/gofiber/fiber/v2"
- "time"
-
- "github.com/golang-jwt/jwt/v5"
- "github.com/spf13/viper"
-)
-
-type PayloadClaims struct {
- jwt.RegisteredClaims
-
- Type string `json:"typ"`
-}
-
-const (
- JwtAccessType = "access"
- JwtRefreshType = "refresh"
-)
-
-const (
- CookieAccessKey = "passport_auth_key"
- CookieRefreshKey = "passport_refresh_key"
-)
-
-func EncodeJwt(id string, typ, sub string, aud []string, exp time.Time) (string, error) {
- tk := jwt.NewWithClaims(jwt.SigningMethodHS512, PayloadClaims{
- jwt.RegisteredClaims{
- Subject: sub,
- Audience: aud,
- Issuer: fmt.Sprintf("https://%s", viper.GetString("domain")),
- ExpiresAt: jwt.NewNumericDate(exp),
- NotBefore: jwt.NewNumericDate(time.Now()),
- IssuedAt: jwt.NewNumericDate(time.Now()),
- ID: id,
- },
- typ,
- })
-
- return tk.SignedString([]byte(viper.GetString("secret")))
-}
-
-func DecodeJwt(str string) (PayloadClaims, error) {
- var claims PayloadClaims
- tk, err := jwt.ParseWithClaims(str, &claims, func(token *jwt.Token) (interface{}, error) {
- if _, ok := token.Method.(*jwt.SigningMethodHMAC); !ok {
- return nil, fmt.Errorf("unexpected signing method: %v", token.Header["alg"])
- }
- return []byte(viper.GetString("secret")), nil
- })
- if err != nil {
- return claims, err
- }
-
- if data, ok := tk.Claims.(*PayloadClaims); ok {
- return *data, nil
- } else {
- return claims, fmt.Errorf("unexpected token payload: not payload claims type")
- }
-}
-
-func SetJwtCookieSet(c *fiber.Ctx, access, refresh string) {
- c.Cookie(&fiber.Cookie{
- Name: CookieAccessKey,
- Value: access,
- Domain: viper.GetString("security.cookie_domain"),
- SameSite: viper.GetString("security.cookie_samesite"),
- Expires: time.Now().Add(60 * time.Minute),
- Path: "/",
- })
- c.Cookie(&fiber.Cookie{
- Name: CookieRefreshKey,
- Value: refresh,
- Domain: viper.GetString("security.cookie_domain"),
- SameSite: viper.GetString("security.cookie_samesite"),
- Expires: time.Now().Add(24 * 30 * time.Hour),
- Path: "/",
- })
-}
diff --git a/pkg/main.go b/pkg/main.go
index 7f2b23d..61e61db 100644
--- a/pkg/main.go
+++ b/pkg/main.go
@@ -44,10 +44,8 @@ func main() {
}
// Connect other services
- if err := gap.Register(); err != nil {
- log.Error().Err(err).Msg("An error occurred when registering service to gateway...")
- } else {
- gap.NewHyperClient()
+ if err := gap.RegisterService(); err != nil {
+ log.Error().Err(err).Msg("An error occurred when registering service to dealer...")
}
// Configure timed tasks
diff --git a/settings.toml b/settings.toml
index 6e5a988..46313dc 100644
--- a/settings.toml
+++ b/settings.toml
@@ -12,8 +12,8 @@ accepts_usage = ["p.avatar", "p.banner", "i.attachment", "m.attachment"]
database = false
print_routes = false
-[consul]
-addr = "127.0.0.1:8500"
+[dealer]
+addr = "127.0.0.1:7442"
[security]
cookie_domain = "localhost"