diff --git a/api/api.go b/api/api.go index 751b2725..600a4be1 100644 --- a/api/api.go +++ b/api/api.go @@ -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" @@ -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) @@ -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)) } @@ -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()) diff --git a/api/config.go b/api/config.go index 57947d26..692959ba 100644 --- a/api/config.go +++ b/api/config.go @@ -11,6 +11,7 @@ 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), @@ -18,7 +19,6 @@ func NewRepos(config APIConfig) repository.Repositories { 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), @@ -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, diff --git a/api/handler/auth_key.go b/api/handler/auth_key.go deleted file mode 100644 index 5bc265fb..00000000 --- a/api/handler/auth_key.go +++ /dev/null @@ -1,90 +0,0 @@ -package handler - -import ( - "net/http" - - libcommon "github.com/String-xyz/go-lib/common" - "github.com/String-xyz/go-lib/httperror" - "github.com/String-xyz/string-api/pkg/service" - "github.com/labstack/echo/v4" - "github.com/rs/zerolog" -) - -type AuthAPIKey interface { - Create(c echo.Context) error - Approve(c echo.Context) error - List(c echo.Context) error - RegisterRoutes(g *echo.Group, ms ...echo.MiddlewareFunc) -} - -type authAPIKey struct { - isInternal bool - service service.APIKeyStrategy - logger *zerolog.Logger -} - -func NewAuthAPIKey(service service.APIKeyStrategy, internal bool) AuthAPIKey { - return &authAPIKey{service: service, isInternal: internal} -} - -func (o authAPIKey) Create(c echo.Context) error { - key, err := o.service.Create() - if err != nil { - libcommon.LogStringError(c, err, "authKey approve: create") - return echo.NewHTTPError(http.StatusInternalServerError, "Unable to process request") - } - return c.JSON(http.StatusOK, key) -} - -func (o authAPIKey) List(c echo.Context) error { - if !o.isInternal { - return httperror.NotAllowedError(c) - } - body := struct { - Status string `query:"status"` - Limit int `query:"limit"` - Offset int `query:"offset"` - }{} - err := c.Bind(&body) - if err != nil { - libcommon.LogStringError(c, err, "authKey list: bind") - return echo.NewHTTPError(http.StatusBadRequest) - } - list, err := o.service.List(body.Limit, body.Offset, body.Status) - if err != nil { - libcommon.LogStringError(c, err, "authKey list") - return echo.NewHTTPError(http.StatusInternalServerError, "ApiKey Service Failed") - } - return c.JSON(http.StatusCreated, list) -} - -func (o authAPIKey) Approve(c echo.Context) error { - if !o.isInternal { - return httperror.NotAllowedError(c) - } - params := struct { - Id string `param:"id"` - }{} - err := c.Bind(¶ms) - - if err != nil { - libcommon.LogStringError(c, err, "authKey approve: bind") - return echo.NewHTTPError(http.StatusInternalServerError, "Unable to process request") - } - err = o.service.Approve(params.Id) - if err != nil { - libcommon.LogStringError(c, err, "authKey approve: approve") - return echo.NewHTTPError(http.StatusInternalServerError, "Unable to process request") - } - return c.JSON(http.StatusOK, ResultMessage{Status: "Success"}) -} - -func (o authAPIKey) RegisterRoutes(g *echo.Group, ms ...echo.MiddlewareFunc) { - if g == nil { - panic("no group attached to the authKey handler") - } - g.Use(ms...) - g.POST("", o.Create) - g.GET("", o.List) - g.POST("/:id/approve", o.Approve) -} diff --git a/api/handler/platform.go b/api/handler/platform.go deleted file mode 100644 index 0b02591e..00000000 --- a/api/handler/platform.go +++ /dev/null @@ -1,46 +0,0 @@ -package handler - -import ( - "net/http" - - libcommon "github.com/String-xyz/go-lib/common" - "github.com/String-xyz/string-api/pkg/service" - "github.com/labstack/echo/v4" -) - -type Platform interface { - Create(e echo.Context) error - RegisterRoutes(g *echo.Group, ms ...echo.MiddlewareFunc) -} - -type platform struct { - service service.Platform -} - -func NewPlatform(service service.Platform) Platform { - return &platform{service: service} -} - -func (p platform) Create(c echo.Context) error { - body := service.CreatePlatform{} - err := c.Bind(&body) - if err != nil { - libcommon.LogStringError(c, err, "platform: create bind") - return echo.NewHTTPError(http.StatusBadRequest) - } - - m, err := p.service.Create(body) - if err != nil { - libcommon.LogStringError(c, err, "platform: create") - return echo.NewHTTPError(http.StatusInternalServerError) - } - return c.JSON(http.StatusCreated, m) -} - -func (p platform) RegisterRoutes(g *echo.Group, ms ...echo.MiddlewareFunc) { - if g == nil { - panic("no group attached to the platform handler") - } - g.Use(ms...) - g.POST("", p.Create) -} diff --git a/go.mod b/go.mod index ca37936c..698f32a1 100644 --- a/go.mod +++ b/go.mod @@ -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 @@ -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 diff --git a/go.sum b/go.sum index 8dcb662f..b993fa06 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/internal/common/util.go b/pkg/internal/common/util.go index 34cc061d..09959419 100644 --- a/pkg/internal/common/util.go +++ b/pkg/internal/common/util.go @@ -2,8 +2,6 @@ package common import ( "bytes" - "crypto/sha256" - "encoding/hex" "encoding/json" "fmt" "io" @@ -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 { diff --git a/pkg/model/entity.go b/pkg/model/entity.go index ec69dfb9..122d7dd9 100644 --- a/pkg/model/entity.go +++ b/pkg/model/entity.go @@ -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) } diff --git a/pkg/repository/apikey.go b/pkg/repository/apikey.go new file mode 100644 index 00000000..681b5420 --- /dev/null +++ b/pkg/repository/apikey.go @@ -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 +} diff --git a/pkg/repository/auth.go b/pkg/repository/auth.go index f6f1cdb8..a706a7be 100644 --- a/pkg/repository/auth.go +++ b/pkg/repository/auth.go @@ -1,7 +1,6 @@ package repository import ( - "database/sql" "encoding/json" "fmt" "time" @@ -27,16 +26,11 @@ const ( ) type AuthStrategy interface { - Create(authType AuthType, m model.AuthStrategy) error CreateAny(key string, val any, expire time.Duration) error - CreateAPIKey(entityId string, authType AuthType, apiKey string, persistOnly bool) (model.AuthStrategy, error) CreateJWTRefresh(key string, val string) (model.AuthStrategy, error) GetUserIdFromRefreshToken(key string) (string, error) Get(string) (model.AuthStrategy, error) GetKeyString(key string) (string, error) - List(limit, offset int) ([]model.AuthStrategy, error) - ListByStatus(limit, offset int, status string) ([]model.AuthStrategy, error) - UpdateStatus(Id, status string) (model.AuthStrategy, error) Delete(key string) error } @@ -65,33 +59,6 @@ func (a auth[T]) CreateAny(key string, val any, expire time.Duration) error { return a.redis.Set(key, val, expire) } -// CreateAPIKey creates and persists an API Key for a platform -func (a auth[T]) CreateAPIKey(entityId string, authType AuthType, key string, persistOnly bool) (model.AuthStrategy, error) { - // only insert to postgres and skip redis cache - if persistOnly { - rows, err := a.Store.Queryx("INSERT INTO auth_strategy(type,data) VALUES($1, $2) RETURNING *", authType, key) - if err == nil { - m := model.AuthStrategy{} - var scanErr error - for rows.Next() { - scanErr = rows.StructScan(&m) - } - return m, scanErr - } - return model.AuthStrategy{}, err - } - - m := model.AuthStrategy{ - EntityId: entityId, - CreatedAt: time.Now(), - Type: string(authType), - EntityType: string(EntityTypePlatform), - Data: key, - } - - return m, a.redis.Set(key, m, 0) -} - // CreateJWTRefresh creates and persists a refresh jwt token func (a auth[T]) CreateJWTRefresh(key string, userId string) (model.AuthStrategy, error) { expireAt := time.Hour * 24 * 7 // 7 days expiration @@ -148,34 +115,6 @@ func (a auth[T]) GetKeyString(key string) (string, error) { return string(m), nil } -// List all the available auth_keys on the postgres db -func (a auth[T]) List(limit, offset int) ([]model.AuthStrategy, error) { - list := []model.AuthStrategy{} - err := a.Store.Select(&list, "SELECT * FROM auth_strategy LIMIT $1 OFFSET $2", limit, offset) - if err != nil && err == sql.ErrNoRows { - return list, nil - } - return list, err -} - -// ListByStatus lists all auth_keys with a given status on the postgres db -func (a auth[T]) ListByStatus(limit, offset int, status string) ([]model.AuthStrategy, error) { - list := []model.AuthStrategy{} - err := a.Store.Select(&list, "SELECT * FROM auth_strategy WHERE status = $1 LIMIT $2 OFFSET $3", status, limit, offset) - if err != nil && err == sql.ErrNoRows { - return list, nil - } - return list, err -} - -// UpdateStatus updates the status on postgres db and returns the updated row -func (a auth[T]) UpdateStatus(Id, status string) (model.AuthStrategy, error) { - row := a.Store.QueryRowx("UPDATE auth_strategy SET status = $2 WHERE id = $1 RETURNING *", Id, status) - m := model.AuthStrategy{} - err := row.StructScan(&m) - return m, err -} - func (a auth[T]) Delete(key string) error { return a.redis.Delete(key) } diff --git a/pkg/repository/repository.go b/pkg/repository/repository.go index 6f6866c7..92fc65fa 100644 --- a/pkg/repository/repository.go +++ b/pkg/repository/repository.go @@ -2,6 +2,7 @@ package repository type Repositories struct { Auth AuthStrategy + Apikey Apikey User User Contact Contact Instrument Instrument diff --git a/pkg/service/auth.go b/pkg/service/auth.go index 8a81205b..3c105afb 100644 --- a/pkg/service/auth.go +++ b/pkg/service/auth.go @@ -47,10 +47,10 @@ type JWTClaims struct { type Auth interface { // PayloadToSign returns a payload to be sign by a wallet // to authenticate an user, the payload expires in 15 minutes - PayloadToSign(walletAdress string) (SignablePayload, error) + PayloadToSign(walletAddress string) (SignablePayload, error) // VerifySignedPayload receives a signed payload from the user and verifies the signature - // if signaure is valid it returns a JWT to authenticate the user + // if signature is valid it returns a JWT to authenticate the user VerifySignedPayload(ctx context.Context, signature model.WalletSignaturePayloadSigned) (UserCreateResponse, error) GenerateJWT(string, ...model.Device) (JWT, error) @@ -163,7 +163,7 @@ func (a auth) GenerateJWT(userId string, m ...model.Device) (JWT, error) { t.Token = signed // create and save - refreshObj, err := a.repos.Auth.CreateJWTRefresh(common.ToSha256(refreshToken), userId) + refreshObj, err := a.repos.Auth.CreateJWTRefresh(libcommon.ToSha256(refreshToken), userId) if err != nil { return *t, err } @@ -184,23 +184,23 @@ func (a auth) ValidateJWT(token string) (bool, error) { } func (a auth) ValidateAPIKey(key string) bool { - hashed := common.ToSha256(key) - authKey, err := a.repos.Auth.Get(hashed) + ctx := context.Background() + authKey, err := a.repos.Apikey.GetByData(ctx, key) if err != nil { return false } - return authKey.Data == hashed + return authKey.Data == key } func (a auth) InvalidateRefreshToken(refreshToken string) error { - return a.repos.Auth.Delete(common.ToSha256(refreshToken)) + return a.repos.Auth.Delete(libcommon.ToSha256(refreshToken)) } func (a auth) RefreshToken(ctx context.Context, refreshToken string, walletAddress string) (UserCreateResponse, error) { resp := UserCreateResponse{} // get user id from refresh token - userId, err := a.repos.Auth.GetUserIdFromRefreshToken(common.ToSha256(refreshToken)) + userId, err := a.repos.Auth.GetUserIdFromRefreshToken(libcommon.ToSha256(refreshToken)) if err != nil { return resp, libcommon.StringError(err) } diff --git a/pkg/service/auth_key.go b/pkg/service/auth_key.go deleted file mode 100644 index ec24ef18..00000000 --- a/pkg/service/auth_key.go +++ /dev/null @@ -1,55 +0,0 @@ -package service - -import ( - "github.com/String-xyz/string-api/pkg/internal/common" - "github.com/String-xyz/string-api/pkg/model" - "github.com/String-xyz/string-api/pkg/repository" -) - -type APIKeyStrategy interface { - Create() (model.AuthStrategy, error) - List(limit, offset int, status string) ([]model.AuthStrategy, error) - Approve(id string) error -} - -type aPIKeyStrategy struct { - repo repository.AuthStrategy -} - -func NewAPIKeyStrategy(repo repository.AuthStrategy) APIKeyStrategy { - return aPIKeyStrategy{repo} -} - -func (g aPIKeyStrategy) Create() (model.AuthStrategy, error) { - uuiKey := "str." + uuidWithoutHyphens() - hashed := common.ToSha256(uuiKey) - m, err := g.repo.CreateAPIKey("", repository.AuthTypeAPIKey, hashed, true) - m.Data = uuiKey - m.ContactData = "" - return m, err -} - -func (g aPIKeyStrategy) List(limit, offset int, status string) ([]model.AuthStrategy, error) { - if status != "" { - return g.ListByStatus(limit, offset, status) - } - return g.repo.List(limit, offset) -} - -func (g aPIKeyStrategy) ListByStatus(limit, offset int, status string) ([]model.AuthStrategy, error) { - if limit == 0 { - limit = 100 - } - return g.repo.ListByStatus(limit, offset, status) -} - -// Approve updates the APIKey status and creates an entry on redis -func (g aPIKeyStrategy) Approve(id string) error { - m, err := g.repo.UpdateStatus(id, "active") - if err != nil { - return err - } - - _, err = g.repo.CreateAPIKey(m.Id, repository.AuthTypeAPIKey, m.Data, false) - return err -} diff --git a/pkg/service/base.go b/pkg/service/base.go index 8c3a04cf..4c51f35b 100644 --- a/pkg/service/base.go +++ b/pkg/service/base.go @@ -1,14 +1,12 @@ package service type Services struct { - Auth Auth - ApiKey APIKeyStrategy + Auth Auth // Chain Chain // TODO: Make this service instantiable // Checkout Checkout // TODO: Make this service instantiable Cost Cost Executor Executor Geofencing Geofencing - Platform Platform // Sms Sms // TODO: Make this service instantiable Transaction Transaction User User diff --git a/pkg/service/platform.go b/pkg/service/platform.go deleted file mode 100644 index c4b6024e..00000000 --- a/pkg/service/platform.go +++ /dev/null @@ -1,41 +0,0 @@ -package service - -import ( - libcommon "github.com/String-xyz/go-lib/common" - "github.com/String-xyz/string-api/pkg/internal/common" - "github.com/String-xyz/string-api/pkg/model" - "github.com/String-xyz/string-api/pkg/repository" -) - -type CreatePlatform = model.CreatePlatform - -type Platform interface { - Create(CreatePlatform) (model.Platform, error) -} - -type platform struct { - repos repository.Repositories -} - -func NewPlatform(repos repository.Repositories) Platform { - return &platform{repos} -} - -func (a platform) Create(c CreatePlatform) (model.Platform, error) { - uuiKey := "str." + uuidWithoutHyphens() - hashed := common.ToSha256(uuiKey) - m := model.Platform{} - - plat, err := a.repos.Platform.Create(m) - if err != nil { - return model.Platform{}, libcommon.StringError(err) - } - - _, err = a.repos.Auth.CreateAPIKey(plat.Id, c.Authentication, hashed, false) - pt := &plat - if err != nil { - return *pt, libcommon.StringError(err) - } - - return plat, nil -} diff --git a/pkg/test/stubs/service.go b/pkg/test/stubs/service.go index 12a0681d..abe2ca5b 100644 --- a/pkg/test/stubs/service.go +++ b/pkg/test/stubs/service.go @@ -24,7 +24,7 @@ func (v Verification) VerifyEmail(ctx context.Context, encrypted string) error { return v.Error } -func (v Verification) SendDeviceVerification(userId string, email string, deviceId string, deviceDescription string) error { +func (v Verification) SendDeviceVerification(string, userID string, deviceID string, deviceDescription string) error { return v.Error }