Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 0 additions & 18 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package api
import (
"net/http"

libcommon "github.com/String-xyz/go-lib/common"
"github.com/String-xyz/go-lib/database"
libmiddleware "github.com/String-xyz/go-lib/middleware"
"github.com/String-xyz/go-lib/validator"
Expand Down Expand Up @@ -43,7 +42,6 @@ func Start(config APIConfig) {
services := NewServices(config, repos)

// initialize routes - A route group only needs access to the services layer. It should'n access the repos layer directly
AuthAPIKey(services, e, libcommon.IsLocalEnv())
transactRoute(services, e)
quoteRoute(services, e)
userRoute(services, e)
Expand All @@ -59,13 +57,7 @@ func StartInternal(config APIConfig) {
baseMiddleware(config.Logger, e)
e.GET("/heartbeat", heartbeat)

// initialize route dependencies
repos := NewRepos(config)
services := NewServices(config, repos)

// initialize routes - A route group only needs access to the services layer. It doesn't need access to the repos layer
platformRoute(services, e)
AuthAPIKey(services, e, true)
e.Logger.Fatal(e.Start(":" + config.Port))
}

Expand All @@ -78,16 +70,6 @@ func baseMiddleware(logger *zerolog.Logger, e *echo.Echo) {
e.Use(libmiddleware.LogRequest())
}

func platformRoute(services service.Services, e *echo.Echo) {
handler := handler.NewPlatform(services.Platform)
handler.RegisterRoutes(e.Group("/platforms"), middleware.BearerAuth())
}

func AuthAPIKey(services service.Services, e *echo.Echo, internal bool) {
handler := handler.NewAuthAPIKey(services.ApiKey, internal)
handler.RegisterRoutes(e.Group("/apikeys"))
}

func transactRoute(services service.Services, e *echo.Echo) {
handler := handler.NewTransaction(e, services.Transaction)
handler.RegisterRoutes(e.Group("/transactions"), middleware.APIKeyAuth(services.Auth), middleware.BearerAuth())
Expand Down
9 changes: 1 addition & 8 deletions api/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ func NewRepos(config APIConfig) repository.Repositories {
// TODO: Make sure all of the repos are initialized here
return repository.Repositories{
Auth: repository.NewAuth(config.Redis, config.DB),
Apikey: repository.NewApikey(config.DB),
User: repository.NewUser(config.DB),
Contact: repository.NewContact(config.DB),
Instrument: repository.NewInstrument(config.DB),
Device: repository.NewDevice(config.DB),
UserToPlatform: repository.NewUserToPlatform(config.DB),
Asset: repository.NewAsset(config.DB),
Network: repository.NewNetwork(config.DB),
Platform: repository.NewPlatform(config.DB),
Transaction: repository.NewTransaction(config.DB),
TxLeg: repository.NewTxLeg(config.DB),
Location: repository.NewLocation(config.DB),
Expand All @@ -44,25 +44,18 @@ func NewServices(config APIConfig, repos repository.Repositories) service.Servic
device := service.NewDevice(deviceRepos, fingerprint)

auth := service.NewAuth(repos, verification, device)
apiKey := service.NewAPIKeyStrategy(repos.Auth)
cost := service.NewCost(config.Redis)
executor := service.NewExecutor()
geofencing := service.NewGeofencing(config.Redis)

// we don't need to pass in the entire repos struct, just the ones we need
platformRepos := repository.Repositories{Auth: repos.Auth, Platform: repos.Platform}
platform := service.NewPlatform(platformRepos)

transaction := service.NewTransaction(repos, config.Redis, unit21)
user := service.NewUser(repos, auth, fingerprint, device, unit21)

return service.Services{
Auth: auth,
ApiKey: apiKey,
Cost: cost,
Executor: executor,
Geofencing: geofencing,
Platform: platform,
Transaction: transaction,
User: user,
Verification: verification,
Expand Down
90 changes: 0 additions & 90 deletions api/handler/auth_key.go

This file was deleted.

46 changes: 0 additions & 46 deletions api/handler/platform.go

This file was deleted.

6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ go 1.19

require (
github.com/DATA-DOG/go-sqlmock v1.5.0
github.com/String-xyz/go-lib v1.2.1
github.com/String-xyz/go-lib v1.3.0
github.com/aws/aws-sdk-go v1.44.168
github.com/aws/aws-sdk-go-v2/config v1.18.7
github.com/aws/aws-sdk-go-v2/service/ssm v1.33.4
github.com/checkout/checkout-sdk-go v0.0.22
github.com/ethereum/go-ethereum v1.10.25
github.com/go-playground/validator/v10 v10.11.1
github.com/go-redis/redis/v8 v8.11.5
github.com/golang-jwt/jwt v3.2.2+incompatible
github.com/golang-jwt/jwt/v4 v4.4.2
github.com/google/uuid v1.3.0
Expand Down Expand Up @@ -61,6 +59,8 @@ require (
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-playground/locales v0.14.0 // indirect
github.com/go-playground/universal-translator v0.18.0 // indirect
github.com/go-playground/validator/v10 v10.11.1 // indirect
github.com/go-redis/redis/v8 v8.11.5 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/mock v1.6.0 // indirect
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ github.com/Microsoft/go-winio v0.5.1/go.mod h1:JPGBdM1cNvN/6ISo+n8V5iA4v8pBzdOpz
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 h1:fLjPD/aNc3UIOA6tDi6QXUemppXK3P9BI7mr2hd6gx8=
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6/go.mod h1:3eOhrUMpNV+6aFIbp5/iudMxNCF27Vw2OZgy4xEx0Fg=
github.com/String-xyz/go-lib v1.2.0 h1:bjaWfoOtwbrbZ84XBtPLe4uG7wyXeLDmK+7WHyvANRQ=
github.com/String-xyz/go-lib v1.2.0/go.mod h1:TFAJPYo6YXvk3A1p1WkFuoN5k1wGHbRTxuOg9KLjpUI=
github.com/String-xyz/go-lib v1.2.1 h1:8pWAux7yUkmb99M98XUtcwk/I89XiKhpEm+3LvryrVE=
github.com/String-xyz/go-lib v1.2.1/go.mod h1:TFAJPYo6YXvk3A1p1WkFuoN5k1wGHbRTxuOg9KLjpUI=
github.com/String-xyz/go-lib v1.3.0 h1:aqakDSl38S6oV0XIUZF+9BIot9dVMtJDYmpr9dA4RwA=
github.com/String-xyz/go-lib v1.3.0/go.mod h1:TFAJPYo6YXvk3A1p1WkFuoN5k1wGHbRTxuOg9KLjpUI=
github.com/VictoriaMetrics/fastcache v1.6.0 h1:C/3Oi3EiBCqufydp1neRZkqcwmEiuRT9c3fqvvgKm5o=
github.com/VictoriaMetrics/fastcache v1.6.0/go.mod h1:0qHz5QP0GMX4pfmMA/zt5RgfNuXJrTP0zS7DqpHGGTw=
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
Expand Down
7 changes: 0 additions & 7 deletions pkg/internal/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package common

import (
"bytes"
"crypto/sha256"
"encoding/hex"
"encoding/json"
"fmt"
"io"
Expand All @@ -19,11 +17,6 @@ import (
"github.com/rs/zerolog/log"
)

func ToSha256(v string) string {
bs := sha256.Sum256([]byte(v))
return hex.EncodeToString(bs[:])
}

func RecoverAddress(message string, signature string) (ethcommon.Address, error) {
sig := hexutil.MustDecode(signature)
if sig[crypto.RecoveryIDOffset] == 27 || sig[crypto.RecoveryIDOffset] == 28 {
Expand Down
12 changes: 12 additions & 0 deletions pkg/model/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ type AuthStrategy struct {
DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"`
}

type Apikey struct {
ID string `json:"id,omitempty" db:"id"`
CreatedAt time.Time `json:"createdAt,omitempty" db:"created_at"`
UpdatedAt time.Time `json:"updatedAt,omitempty" db:"updated_at"`
DeactivatedAt *time.Time `json:"deactivatedAt,omitempty" db:"deactivated_at"`
Type string `json:"type" db:"type"`
Data string `json:"data" db:"data"`
Description *string `json:"description" db:"description"`
CreatedBy string `json:"createdBy" db:"created_by"`
PlatformID string `json:"platformId" db:"platform_id"`
}

func (a AuthStrategy) MarshalBinary() ([]byte, error) {
return json.Marshal(a)
}
47 changes: 47 additions & 0 deletions pkg/repository/apikey.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package repository

import (
"context"
"database/sql"
"fmt"
"time"

"github.com/String-xyz/go-lib/common"
"github.com/String-xyz/go-lib/database"
strrepo "github.com/String-xyz/go-lib/repository"
serror "github.com/String-xyz/go-lib/stringerror"
"github.com/String-xyz/string-api/pkg/model"
)

type ApikeyUpdates struct {
DeactivatedAt *time.Time `json:"deactivatedAt" db:"deactivated_at"`
Type *string `json:"type" db:"type"`
Data *string `json:"data" db:"data"`
Description *string `json:"description" db:"description"`
CreatedBy *string `json:"createdBy" db:"created_by"`
PlatformID *string `json:"platformId" db:"platform_id"`
}

type Apikey interface {
database.Transactable
GetByData(ctx context.Context, data string) (model.Apikey, error)
}

type apikey[T any] struct {
strrepo.Base[T]
}

func NewApikey(db database.Queryable) Apikey {
return &apikey[model.Apikey]{strrepo.Base[model.Apikey]{Store: db, Table: "apikey"}}
}

func (p apikey[T]) GetByData(ctx context.Context, data string) (model.Apikey, error) {
m := model.Apikey{}
err := p.Store.GetContext(ctx, &m, fmt.Sprintf("SELECT * FROM %s WHERE data = $1", p.Table), data)
if err == sql.ErrNoRows {
return m, common.StringError(serror.NOT_FOUND)
} else if err != nil {
return m, common.StringError(err)
}
return m, nil
}
Loading