Renaming and moving pkg/satellite to satellite/console (#1054)
* [WIP] V3-853 Merge the satellite DB into the master database * Removing consoleDB from satelliteDB * Fixing tests for satellite/console * fixing linter * sorting imports in satellite/console * fixing console config * fixing linter
This commit is contained in:
parent
2aebbeed34
commit
e38cf8f50d
@ -33,9 +33,9 @@ import (
|
||||
"storj.io/storj/pkg/pointerdb"
|
||||
"storj.io/storj/pkg/process"
|
||||
"storj.io/storj/pkg/provider"
|
||||
"storj.io/storj/pkg/satellite/satelliteweb"
|
||||
"storj.io/storj/pkg/server"
|
||||
"storj.io/storj/pkg/statdb"
|
||||
"storj.io/storj/satellite/console/consoleweb"
|
||||
)
|
||||
|
||||
// Captplanet defines Captain Planet configuration
|
||||
@ -50,6 +50,7 @@ type Captplanet struct {
|
||||
StartingPort int `help:"all providers will listen on ports consecutively starting with this one" default:"7777" setup:"true"`
|
||||
APIKey string `default:"abc123" help:"the api key to use for the satellite" setup:"true"`
|
||||
EncKey string `default:"insecure-default-encryption-key" help:"your root encryption key" setup:"true"`
|
||||
Overwrite bool `help:"whether to overwrite pre-existing configuration files" default:"false" setup:"true"`
|
||||
GenerateMinioCerts bool `default:"false" help:"generate sample TLS certs for Minio GW" setup:"true"`
|
||||
|
||||
Satellite Satellite
|
||||
@ -67,7 +68,7 @@ type Satellite struct {
|
||||
Repairer repairer.Config
|
||||
Audit audit.Config
|
||||
BwAgreement bwagreement.Config
|
||||
Web satelliteweb.Config
|
||||
Web consoleweb.Config
|
||||
Discovery discovery.Config
|
||||
Tally tally.Config
|
||||
Rollup rollup.Config
|
||||
|
@ -1,17 +0,0 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package dbx
|
||||
|
||||
//go:generate dbx.v1 golang -d sqlite3 -p dbx satellitedb.dbx .
|
||||
//go:generate dbx.v1 schema -d sqlite3 satellitedb.dbx .
|
||||
|
||||
import (
|
||||
"github.com/zeebo/errs"
|
||||
)
|
||||
|
||||
func init() {
|
||||
// catch dbx errors
|
||||
c := errs.Class("satellitedb")
|
||||
WrapErr = func(e *Error) error { return c.Wrap(e) }
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -9,7 +9,7 @@ import (
|
||||
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/pkg/satellite/satelliteauth"
|
||||
"storj.io/storj/satellite/console/consoleauth"
|
||||
)
|
||||
|
||||
//TODO: change to JWT or Macaroon based auth
|
||||
@ -20,7 +20,7 @@ type Signer interface {
|
||||
}
|
||||
|
||||
// signToken signs token with given signer
|
||||
func signToken(token *satelliteauth.Token, signer Signer) error {
|
||||
func signToken(token *consoleauth.Token, signer Signer) error {
|
||||
encoded := base64.URLEncoding.EncodeToString(token.Payload)
|
||||
|
||||
signature, err := signer.Sign([]byte(encoded))
|
||||
@ -44,7 +44,7 @@ var ErrUnauthorized = errs.Class("unauthorized error")
|
||||
// Authorization contains auth info of authorized User
|
||||
type Authorization struct {
|
||||
User User
|
||||
Claims satelliteauth.Claims
|
||||
Claims consoleauth.Claims
|
||||
}
|
||||
|
||||
// WithAuth creates new context with Authorization
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteauth
|
||||
package consoleauth
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteauth
|
||||
package consoleauth
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteauth
|
||||
package consoleauth
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteauth
|
||||
package consoleauth
|
||||
|
||||
import (
|
||||
"bytes"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteauth
|
||||
package consoleauth
|
||||
|
||||
import (
|
||||
"testing"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteweb
|
||||
package consoleweb
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -14,9 +14,9 @@ import (
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/pkg/auth"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satelliteweb/satelliteql"
|
||||
"storj.io/storj/pkg/utils"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/console/consoleweb/consoleql"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -50,9 +50,9 @@ func (gw *gateway) grapqlHandler(w http.ResponseWriter, req *http.Request) {
|
||||
ctx := auth.WithAPIKey(context.Background(), []byte(token))
|
||||
auth, err := gw.service.Authorize(ctx)
|
||||
if err != nil {
|
||||
ctx = satellite.WithAuthFailure(ctx, err)
|
||||
ctx = console.WithAuthFailure(ctx, err)
|
||||
} else {
|
||||
ctx = satellite.WithAuth(ctx, auth)
|
||||
ctx = console.WithAuth(ctx, auth)
|
||||
}
|
||||
|
||||
result := graphql.Do(graphql.Params{
|
||||
@ -92,7 +92,7 @@ func getToken(req *http.Request) string {
|
||||
func getQuery(req *http.Request) (query graphqlJSON, err error) {
|
||||
switch req.Method {
|
||||
case http.MethodGet:
|
||||
query.Query = req.URL.Query().Get(satelliteql.Query)
|
||||
query.Query = req.URL.Query().Get(consoleql.Query)
|
||||
return query, nil
|
||||
case http.MethodPost:
|
||||
return queryPOST(req)
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteweb
|
||||
package consoleweb
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -10,11 +10,11 @@ import (
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/storj/pkg/provider"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satelliteauth"
|
||||
"storj.io/storj/pkg/satellite/satellitedb"
|
||||
"storj.io/storj/pkg/satellite/satelliteweb/satelliteql"
|
||||
"storj.io/storj/pkg/utils"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/console/consoleauth"
|
||||
"storj.io/storj/satellite/console/consoleweb/consoleql"
|
||||
"storj.io/storj/satellite/satellitedb"
|
||||
)
|
||||
|
||||
// Config contains info needed for satellite account related services
|
||||
@ -34,7 +34,7 @@ func (c Config) Run(ctx context.Context, server *provider.Provider) error {
|
||||
return err
|
||||
}
|
||||
|
||||
db, err := satellitedb.New(driver, source)
|
||||
db, err := satellitedb.NewConsoleDB(driver, source)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -44,9 +44,9 @@ func (c Config) Run(ctx context.Context, server *provider.Provider) error {
|
||||
log.Error(err.Error())
|
||||
}
|
||||
|
||||
service, err := satellite.NewService(
|
||||
service, err := console.NewService(
|
||||
log,
|
||||
&satelliteauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
||||
&consoleauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
||||
db,
|
||||
)
|
||||
|
||||
@ -54,7 +54,7 @@ func (c Config) Run(ctx context.Context, server *provider.Provider) error {
|
||||
return err
|
||||
}
|
||||
|
||||
creator := satelliteql.TypeCreator{}
|
||||
creator := consoleql.TypeCreator{}
|
||||
err = creator.Create(service)
|
||||
if err != nil {
|
||||
return err
|
@ -1,12 +1,12 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -54,6 +54,6 @@ func graphqlCreateAPIKey(types Types) *graphql.Object {
|
||||
|
||||
// createAPIKey holds satellite.APIKey and satellite.APIKeyInfo
|
||||
type createAPIKey struct {
|
||||
Key *satellite.APIKey
|
||||
KeyInfo *satellite.APIKeyInfo
|
||||
Key *console.APIKey
|
||||
KeyInfo *console.APIKeyInfo
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -37,7 +37,7 @@ const (
|
||||
)
|
||||
|
||||
// rootMutation creates mutation for graphql populated by AccountsClient
|
||||
func rootMutation(service *satellite.Service, types Types) *graphql.Object {
|
||||
func rootMutation(service *console.Service, types Types) *graphql.Object {
|
||||
return graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: Mutation,
|
||||
Fields: graphql.Fields{
|
||||
@ -71,7 +71,7 @@ func rootMutation(service *satellite.Service, types Types) *graphql.Object {
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
input, _ := p.Args[input].(map[string]interface{})
|
||||
|
||||
auth, err := satellite.GetAuth(p.Context)
|
||||
auth, err := console.GetAuth(p.Context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -100,7 +100,7 @@ func rootMutation(service *satellite.Service, types Types) *graphql.Object {
|
||||
pass, _ := p.Args[fieldPassword].(string)
|
||||
newPass, _ := p.Args[fieldNewPassword].(string)
|
||||
|
||||
auth, err := satellite.GetAuth(p.Context)
|
||||
auth, err := console.GetAuth(p.Context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -123,7 +123,7 @@ func rootMutation(service *satellite.Service, types Types) *graphql.Object {
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
password, _ := p.Args[fieldPassword].(string)
|
||||
|
||||
auth, err := satellite.GetAuth(p.Context)
|
||||
auth, err := console.GetAuth(p.Context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -16,9 +16,9 @@ import (
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/pkg/auth"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satelliteauth"
|
||||
"storj.io/storj/pkg/satellite/satellitedb"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/console/consoleauth"
|
||||
"storj.io/storj/satellite/satellitedb"
|
||||
)
|
||||
|
||||
func TestGrapqhlMutation(t *testing.T) {
|
||||
@ -27,7 +27,7 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
|
||||
log := zap.NewExample()
|
||||
|
||||
db, err := satellitedb.New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := satellitedb.NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -36,9 +36,9 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
service, err := satellite.NewService(
|
||||
service, err := console.NewService(
|
||||
log,
|
||||
&satelliteauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
||||
&consoleauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
||||
db,
|
||||
)
|
||||
|
||||
@ -60,8 +60,8 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
createUser := satellite.CreateUser{
|
||||
UserInfo: satellite.UserInfo{
|
||||
createUser := console.CreateUser{
|
||||
UserInfo: console.UserInfo{
|
||||
FirstName: "John",
|
||||
LastName: "Roll",
|
||||
Email: "test@email.com",
|
||||
@ -84,11 +84,11 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
authCtx := satellite.WithAuth(ctx, sauth)
|
||||
authCtx := console.WithAuth(ctx, sauth)
|
||||
|
||||
t.Run("Create user mutation", func(t *testing.T) {
|
||||
newUser := satellite.CreateUser{
|
||||
UserInfo: satellite.UserInfo{
|
||||
newUser := console.CreateUser{
|
||||
UserInfo: console.UserInfo{
|
||||
FirstName: "Mickey",
|
||||
LastName: "Green",
|
||||
Email: "u1@email.com",
|
||||
@ -282,11 +282,11 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
authCtx = satellite.WithAuth(ctx, sauth)
|
||||
authCtx = console.WithAuth(ctx, sauth)
|
||||
|
||||
var projectID string
|
||||
t.Run("Create project mutation", func(t *testing.T) {
|
||||
projectInfo := satellite.ProjectInfo{
|
||||
projectInfo := console.ProjectInfo{
|
||||
Name: "Project name",
|
||||
Description: "desc",
|
||||
}
|
||||
@ -335,8 +335,8 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
assert.Equal(t, "", proj[fieldDescription])
|
||||
})
|
||||
|
||||
user1, err := service.CreateUser(authCtx, satellite.CreateUser{
|
||||
UserInfo: satellite.UserInfo{
|
||||
user1, err := service.CreateUser(authCtx, console.CreateUser{
|
||||
UserInfo: console.UserInfo{
|
||||
FirstName: "User1",
|
||||
Email: "u1@email.net",
|
||||
},
|
||||
@ -347,8 +347,8 @@ func TestGrapqhlMutation(t *testing.T) {
|
||||
t.Fatal(err, project)
|
||||
}
|
||||
|
||||
user2, err := service.CreateUser(authCtx, satellite.CreateUser{
|
||||
UserInfo: satellite.UserInfo{
|
||||
user2, err := service.CreateUser(authCtx, console.CreateUser{
|
||||
UserInfo: console.UserInfo{
|
||||
FirstName: "User1",
|
||||
Email: "u2@email.net",
|
||||
},
|
@ -1,12 +1,12 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -28,7 +28,7 @@ const (
|
||||
)
|
||||
|
||||
// graphqlProject creates *graphql.Object type representation of satellite.ProjectInfo
|
||||
func graphqlProject(service *satellite.Service, types Types) *graphql.Object {
|
||||
func graphqlProject(service *console.Service, types Types) *graphql.Object {
|
||||
return graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: projectType,
|
||||
Fields: graphql.Fields{
|
||||
@ -64,18 +64,18 @@ func graphqlProject(service *satellite.Service, types Types) *graphql.Object {
|
||||
},
|
||||
},
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
project, _ := p.Source.(*satellite.Project)
|
||||
project, _ := p.Source.(*console.Project)
|
||||
|
||||
offs, _ := p.Args[offset].(int)
|
||||
lim, _ := p.Args[limit].(int)
|
||||
search, _ := p.Args[search].(string)
|
||||
order, _ := p.Args[order].(int)
|
||||
|
||||
pagination := satellite.Pagination{
|
||||
pagination := console.Pagination{
|
||||
Limit: lim,
|
||||
Offset: int64(offs),
|
||||
Search: search,
|
||||
Order: satellite.ProjectMemberOrder(order),
|
||||
Order: console.ProjectMemberOrder(order),
|
||||
}
|
||||
|
||||
members, err := service.GetProjectMembers(p.Context, project.ID, pagination)
|
||||
@ -102,7 +102,7 @@ func graphqlProject(service *satellite.Service, types Types) *graphql.Object {
|
||||
fieldAPIKeys: &graphql.Field{
|
||||
Type: graphql.NewList(types.APIKeyInfo()),
|
||||
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
|
||||
project, _ := p.Source.(*satellite.Project)
|
||||
project, _ := p.Source.(*console.Project)
|
||||
|
||||
return service.GetAPIKeysInfoByProjectID(p.Context, project.ID)
|
||||
},
|
||||
@ -130,7 +130,7 @@ func graphqlProjectInput() *graphql.InputObject {
|
||||
}
|
||||
|
||||
// fromMapProjectInfo creates satellite.ProjectInfo from input args
|
||||
func fromMapProjectInfo(args map[string]interface{}) (project satellite.ProjectInfo) {
|
||||
func fromMapProjectInfo(args map[string]interface{}) (project console.ProjectInfo) {
|
||||
project.Name, _ = args[fieldName].(string)
|
||||
project.Description, _ = args[fieldDescription].(string)
|
||||
project.IsTermsAccepted, _ = args[fieldIsTermsAccepted].(bool)
|
@ -1,14 +1,14 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/graphql-go/graphql"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -18,7 +18,7 @@ const (
|
||||
)
|
||||
|
||||
// graphqlProjectMember creates projectMember type
|
||||
func graphqlProjectMember(service *satellite.Service, types Types) *graphql.Object {
|
||||
func graphqlProjectMember(service *console.Service, types Types) *graphql.Object {
|
||||
return graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: projectMemberType,
|
||||
Fields: graphql.Fields{
|
||||
@ -39,6 +39,6 @@ func graphqlProjectMember(service *satellite.Service, types Types) *graphql.Obje
|
||||
|
||||
// projectMember encapsulates User and joinedAt
|
||||
type projectMember struct {
|
||||
User *satellite.User
|
||||
User *console.User
|
||||
JoinedAt time.Time
|
||||
}
|
@ -1,13 +1,13 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -21,7 +21,7 @@ const (
|
||||
)
|
||||
|
||||
// rootQuery creates query for graphql populated by AccountsClient
|
||||
func rootQuery(service *satellite.Service, types Types) *graphql.Object {
|
||||
func rootQuery(service *console.Service, types Types) *graphql.Object {
|
||||
return graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: Query,
|
||||
Fields: graphql.Fields{
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -14,9 +14,9 @@ import (
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/pkg/auth"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satelliteauth"
|
||||
"storj.io/storj/pkg/satellite/satellitedb"
|
||||
"storj.io/storj/satellite/console"
|
||||
"storj.io/storj/satellite/console/consoleauth"
|
||||
"storj.io/storj/satellite/satellitedb"
|
||||
)
|
||||
|
||||
func TestGraphqlQuery(t *testing.T) {
|
||||
@ -25,7 +25,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
|
||||
log := zap.NewExample()
|
||||
|
||||
db, err := satellitedb.New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := satellitedb.NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -34,9 +34,9 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
service, err := satellite.NewService(
|
||||
service, err := console.NewService(
|
||||
log,
|
||||
&satelliteauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
||||
&consoleauth.Hmac{Secret: []byte("my-suppa-secret-key")},
|
||||
db,
|
||||
)
|
||||
|
||||
@ -58,8 +58,8 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
createUser := satellite.CreateUser{
|
||||
UserInfo: satellite.UserInfo{
|
||||
createUser := console.CreateUser{
|
||||
UserInfo: console.UserInfo{
|
||||
FirstName: "John",
|
||||
LastName: "",
|
||||
Email: "test@email.com",
|
||||
@ -82,7 +82,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
authCtx := satellite.WithAuth(ctx, sauth)
|
||||
authCtx := console.WithAuth(ctx, sauth)
|
||||
|
||||
testQuery := func(t *testing.T, query string) interface{} {
|
||||
result := graphql.Do(graphql.Params{
|
||||
@ -104,7 +104,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
}
|
||||
|
||||
t.Run("User query", func(t *testing.T) {
|
||||
testUser := func(t *testing.T, actual map[string]interface{}, expected *satellite.User) {
|
||||
testUser := func(t *testing.T, actual map[string]interface{}, expected *console.User) {
|
||||
assert.Equal(t, expected.ID.String(), actual[fieldID])
|
||||
assert.Equal(t, expected.Email, actual[fieldEmail])
|
||||
assert.Equal(t, expected.FirstName, actual[fieldFirstName])
|
||||
@ -143,7 +143,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
})
|
||||
})
|
||||
|
||||
createdProject, err := service.CreateProject(authCtx, satellite.ProjectInfo{
|
||||
createdProject, err := service.CreateProject(authCtx, console.ProjectInfo{
|
||||
Name: "TestProject",
|
||||
IsTermsAccepted: true,
|
||||
})
|
||||
@ -175,8 +175,8 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
assert.Equal(t, createdProject.CreatedAt, createdAt)
|
||||
})
|
||||
|
||||
user1, err := service.CreateUser(authCtx, satellite.CreateUser{
|
||||
UserInfo: satellite.UserInfo{
|
||||
user1, err := service.CreateUser(authCtx, console.CreateUser{
|
||||
UserInfo: console.UserInfo{
|
||||
FirstName: "Mickey",
|
||||
LastName: "Last",
|
||||
Email: "uu1@email.com",
|
||||
@ -188,8 +188,8 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
user2, err := service.CreateUser(authCtx, satellite.CreateUser{
|
||||
UserInfo: satellite.UserInfo{
|
||||
user2, err := service.CreateUser(authCtx, console.CreateUser{
|
||||
UserInfo: console.UserInfo{
|
||||
FirstName: "Dubas",
|
||||
LastName: "Name",
|
||||
Email: "uu2@email.com",
|
||||
@ -224,7 +224,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 3, len(members))
|
||||
|
||||
testUser := func(t *testing.T, actual map[string]interface{}, expected *satellite.User) {
|
||||
testUser := func(t *testing.T, actual map[string]interface{}, expected *console.User) {
|
||||
assert.Equal(t, expected.Email, actual[fieldEmail])
|
||||
assert.Equal(t, expected.FirstName, actual[fieldFirstName])
|
||||
assert.Equal(t, expected.LastName, actual[fieldLastName])
|
||||
@ -285,7 +285,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 2, len(keys))
|
||||
|
||||
testAPIKey := func(t *testing.T, actual map[string]interface{}, expected *satellite.APIKeyInfo) {
|
||||
testAPIKey := func(t *testing.T, actual map[string]interface{}, expected *console.APIKeyInfo) {
|
||||
assert.Equal(t, expected.Name, actual[fieldName])
|
||||
assert.Equal(t, expected.ProjectID.String(), actual[fieldProjectID])
|
||||
|
||||
@ -316,7 +316,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
assert.True(t, foundKey2)
|
||||
})
|
||||
|
||||
project2, err := service.CreateProject(authCtx, satellite.ProjectInfo{
|
||||
project2, err := service.CreateProject(authCtx, console.ProjectInfo{
|
||||
Name: "Project2",
|
||||
Description: "Test desc",
|
||||
IsTermsAccepted: true,
|
||||
@ -336,7 +336,7 @@ func TestGraphqlQuery(t *testing.T) {
|
||||
|
||||
assert.Equal(t, 2, len(projectsList))
|
||||
|
||||
testProject := func(t *testing.T, actual map[string]interface{}, expected *satellite.Project) {
|
||||
testProject := func(t *testing.T, actual map[string]interface{}, expected *console.Project) {
|
||||
assert.Equal(t, expected.Name, actual[fieldName])
|
||||
assert.Equal(t, expected.Description, actual[fieldDescription])
|
||||
|
@ -1,13 +1,13 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
|
||||
"storj.io/storj/pkg/auth"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -15,7 +15,7 @@ const (
|
||||
)
|
||||
|
||||
// graphqlToken creates *graphql.Object type that encapsulates user and token string
|
||||
func graphqlToken(service *satellite.Service, types Types) *graphql.Object {
|
||||
func graphqlToken(service *console.Service, types Types) *graphql.Object {
|
||||
return graphql.NewObject(graphql.ObjectConfig{
|
||||
Name: tokenType,
|
||||
Fields: graphql.Fields{
|
||||
@ -36,7 +36,7 @@ func graphqlToken(service *satellite.Service, types Types) *graphql.Object {
|
||||
|
||||
// pass context to root value so child resolvers could get auth auth
|
||||
rootValue := p.Info.RootValue.(map[string]interface{})
|
||||
rootValue["context"] = satellite.WithAuth(ctx, auth)
|
||||
rootValue["context"] = console.WithAuth(ctx, auth)
|
||||
|
||||
return &auth.User, nil
|
||||
},
|
@ -1,12 +1,12 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
// Types return graphql type objects
|
||||
@ -44,7 +44,7 @@ type TypeCreator struct {
|
||||
}
|
||||
|
||||
// Create create types and check for error
|
||||
func (c *TypeCreator) Create(service *satellite.Service) error {
|
||||
func (c *TypeCreator) Create(service *console.Service) error {
|
||||
// inputs
|
||||
c.userInput = graphqlUserInput(c)
|
||||
if err := c.userInput.Error(); err != nil {
|
@ -1,12 +1,12 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -73,22 +73,22 @@ func graphqlUserInput(types Types) *graphql.InputObject {
|
||||
}
|
||||
|
||||
// fromMapUserInfo creates UserInput from input args
|
||||
func fromMapUserInfo(args map[string]interface{}) (user satellite.UserInfo) {
|
||||
func fromMapUserInfo(args map[string]interface{}) (user console.UserInfo) {
|
||||
user.Email, _ = args[fieldEmail].(string)
|
||||
user.FirstName, _ = args[fieldFirstName].(string)
|
||||
user.LastName, _ = args[fieldLastName].(string)
|
||||
return
|
||||
}
|
||||
|
||||
func fromMapCreateUser(args map[string]interface{}) (user satellite.CreateUser) {
|
||||
func fromMapCreateUser(args map[string]interface{}) (user console.CreateUser) {
|
||||
user.UserInfo = fromMapUserInfo(args)
|
||||
user.Password, _ = args[fieldPassword].(string)
|
||||
return
|
||||
}
|
||||
|
||||
// fillUserInfo fills satellite.UserInfo from satellite.User and input args
|
||||
func fillUserInfo(user *satellite.User, args map[string]interface{}) satellite.UserInfo {
|
||||
info := satellite.UserInfo{
|
||||
func fillUserInfo(user *console.User, args map[string]interface{}) console.UserInfo {
|
||||
info := console.UserInfo{
|
||||
Email: user.Email,
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
@ -1,13 +1,13 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteql
|
||||
package consoleql
|
||||
|
||||
import (
|
||||
"github.com/graphql-go/graphql"
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
// uuidIDAuthFallback returns auth user id if no id argument provided
|
||||
@ -18,7 +18,7 @@ func uuidIDAuthFallback(p graphql.ResolveParams, field string) (*uuid.UUID, erro
|
||||
}
|
||||
|
||||
// else get id of authorized user
|
||||
auth, err := satellite.GetAuth(p.Context)
|
||||
auth, err := console.GetAuth(p.Context)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satelliteweb
|
||||
package consoleweb
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
@ -10,7 +10,7 @@ import (
|
||||
"github.com/graphql-go/graphql"
|
||||
"go.uber.org/zap"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
// GatewayConfig contains configuration for gateway
|
||||
@ -23,7 +23,7 @@ type GatewayConfig struct {
|
||||
type gateway struct {
|
||||
log *zap.Logger
|
||||
|
||||
service *satellite.Service
|
||||
service *console.Service
|
||||
|
||||
schema graphql.Schema
|
||||
config GatewayConfig
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import "context"
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import (
|
||||
"context"
|
||||
@ -15,7 +15,7 @@ import (
|
||||
monkit "gopkg.in/spacemonkeygo/monkit.v2"
|
||||
|
||||
"storj.io/storj/pkg/auth"
|
||||
"storj.io/storj/pkg/satellite/satelliteauth"
|
||||
"storj.io/storj/satellite/console/consoleauth"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -93,7 +93,7 @@ func (s *Service) Token(ctx context.Context, email, password string) (token stri
|
||||
}
|
||||
|
||||
// TODO: move expiration time to constants
|
||||
claims := satelliteauth.Claims{
|
||||
claims := consoleauth.Claims{
|
||||
ID: user.ID,
|
||||
Expiration: time.Now().Add(time.Minute * 15),
|
||||
}
|
||||
@ -511,7 +511,7 @@ func (s *Service) Authorize(ctx context.Context) (a Authorization, err error) {
|
||||
return Authorization{}, ErrUnauthorized.New("no api key was provided")
|
||||
}
|
||||
|
||||
token, err := satelliteauth.FromBase64URLString(string(tokenS))
|
||||
token, err := consoleauth.FromBase64URLString(string(tokenS))
|
||||
if err != nil {
|
||||
return Authorization{}, ErrUnauthorized.Wrap(err)
|
||||
}
|
||||
@ -533,13 +533,13 @@ func (s *Service) Authorize(ctx context.Context) (a Authorization, err error) {
|
||||
}
|
||||
|
||||
// createToken creates string representation
|
||||
func (s *Service) createToken(claims *satelliteauth.Claims) (string, error) {
|
||||
func (s *Service) createToken(claims *consoleauth.Claims) (string, error) {
|
||||
json, err := claims.JSON()
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
token := satelliteauth.Token{Payload: json}
|
||||
token := consoleauth.Token{Payload: json}
|
||||
err = signToken(&token, s.Signer)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@ -549,7 +549,7 @@ func (s *Service) createToken(claims *satelliteauth.Claims) (string, error) {
|
||||
}
|
||||
|
||||
// authenticate validates token signature and returns authenticated *satelliteauth.Authorization
|
||||
func (s *Service) authenticate(token satelliteauth.Token) (*satelliteauth.Claims, error) {
|
||||
func (s *Service) authenticate(token consoleauth.Token) (*consoleauth.Claims, error) {
|
||||
signature := token.Signature
|
||||
|
||||
err := signToken(&token, s.Signer)
|
||||
@ -561,7 +561,7 @@ func (s *Service) authenticate(token satelliteauth.Token) (*satelliteauth.Claims
|
||||
return nil, errs.New("incorrect signature")
|
||||
}
|
||||
|
||||
claims, err := satelliteauth.FromJSON(token.Payload)
|
||||
claims, err := consoleauth.FromJSON(token.Payload)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -570,7 +570,7 @@ func (s *Service) authenticate(token satelliteauth.Token) (*satelliteauth.Claims
|
||||
}
|
||||
|
||||
// authorize checks claims and returns authorized User
|
||||
func (s *Service) authorize(ctx context.Context, claims *satelliteauth.Claims) (*User, error) {
|
||||
func (s *Service) authorize(ctx context.Context, claims *consoleauth.Claims) (*User, error) {
|
||||
if !claims.Expiration.IsZero() && claims.Expiration.Before(time.Now()) {
|
||||
return nil, errs.New("token is outdated")
|
||||
}
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import (
|
||||
"context"
|
@ -1,7 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package satellite
|
||||
package console
|
||||
|
||||
import (
|
||||
"strings"
|
@ -9,8 +9,8 @@ import (
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/satellite/console"
|
||||
dbx "storj.io/storj/satellite/satellitedb/consoledbx"
|
||||
)
|
||||
|
||||
// apikeys is an implementation of satellite.APIKeys
|
||||
@ -19,13 +19,13 @@ type apikeys struct {
|
||||
}
|
||||
|
||||
// GetByProjectID implements satellite.APIKeys ordered by name
|
||||
func (keys *apikeys) GetByProjectID(ctx context.Context, projectID uuid.UUID) ([]satellite.APIKeyInfo, error) {
|
||||
func (keys *apikeys) GetByProjectID(ctx context.Context, projectID uuid.UUID) ([]console.APIKeyInfo, error) {
|
||||
dbKeys, err := keys.db.All_ApiKey_By_ProjectId_OrderBy_Asc_Name(ctx, dbx.ApiKey_ProjectId(projectID[:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var apiKeys []satellite.APIKeyInfo
|
||||
var apiKeys []console.APIKeyInfo
|
||||
var parseErr errs.Group
|
||||
|
||||
for _, key := range dbKeys {
|
||||
@ -46,7 +46,7 @@ func (keys *apikeys) GetByProjectID(ctx context.Context, projectID uuid.UUID) ([
|
||||
}
|
||||
|
||||
// Get implements satellite.APIKeys
|
||||
func (keys *apikeys) Get(ctx context.Context, id uuid.UUID) (*satellite.APIKeyInfo, error) {
|
||||
func (keys *apikeys) Get(ctx context.Context, id uuid.UUID) (*console.APIKeyInfo, error) {
|
||||
dbKey, err := keys.db.Get_ApiKey_By_Id(ctx, dbx.ApiKey_Id(id[:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -56,7 +56,7 @@ func (keys *apikeys) Get(ctx context.Context, id uuid.UUID) (*satellite.APIKeyIn
|
||||
}
|
||||
|
||||
// Create implements satellite.APIKeys
|
||||
func (keys *apikeys) Create(ctx context.Context, key satellite.APIKey, info satellite.APIKeyInfo) (*satellite.APIKeyInfo, error) {
|
||||
func (keys *apikeys) Create(ctx context.Context, key console.APIKey, info console.APIKeyInfo) (*console.APIKeyInfo, error) {
|
||||
id, err := uuid.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -78,7 +78,7 @@ func (keys *apikeys) Create(ctx context.Context, key satellite.APIKey, info sate
|
||||
}
|
||||
|
||||
// Update implements satellite.APIKeys
|
||||
func (keys *apikeys) Update(ctx context.Context, key satellite.APIKeyInfo) error {
|
||||
func (keys *apikeys) Update(ctx context.Context, key console.APIKeyInfo) error {
|
||||
_, err := keys.db.Update_ApiKey_By_Id(
|
||||
ctx,
|
||||
dbx.ApiKey_Id(key.ID[:]),
|
||||
@ -97,7 +97,7 @@ func (keys *apikeys) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
}
|
||||
|
||||
// fromDBXAPIKey converts dbx.ApiKey to satellite.APIKeyInfo
|
||||
func fromDBXAPIKey(key *dbx.ApiKey) (*satellite.APIKeyInfo, error) {
|
||||
func fromDBXAPIKey(key *dbx.ApiKey) (*console.APIKeyInfo, error) {
|
||||
id, err := bytesToUUID(key.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -108,7 +108,7 @@ func fromDBXAPIKey(key *dbx.ApiKey) (*satellite.APIKeyInfo, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &satellite.APIKeyInfo{
|
||||
return &console.APIKeyInfo{
|
||||
ID: id,
|
||||
ProjectID: projectID,
|
||||
Name: key.Name,
|
@ -7,9 +7,10 @@ import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"storj.io/storj/satellite/console"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
)
|
||||
|
||||
func TestApiKeysRepository(t *testing.T) {
|
||||
@ -17,7 +18,7 @@ func TestApiKeysRepository(t *testing.T) {
|
||||
defer ctx.Cleanup()
|
||||
|
||||
// creating in-memory db and opening connection
|
||||
db, err := New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -32,7 +33,7 @@ func TestApiKeysRepository(t *testing.T) {
|
||||
projects := db.Projects()
|
||||
apikeys := db.APIKeys()
|
||||
|
||||
project, err := projects.Insert(ctx, &satellite.Project{
|
||||
project, err := projects.Insert(ctx, &console.Project{
|
||||
Name: "ProjectName",
|
||||
TermsAccepted: 1,
|
||||
Description: "projects description",
|
||||
@ -42,10 +43,10 @@ func TestApiKeysRepository(t *testing.T) {
|
||||
|
||||
t.Run("Creation success", func(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
key, err := satellite.CreateAPIKey()
|
||||
key, err := console.CreateAPIKey()
|
||||
assert.NoError(t, err)
|
||||
|
||||
keyInfo := satellite.APIKeyInfo{
|
||||
keyInfo := console.APIKeyInfo{
|
||||
Name: fmt.Sprintf("key %d", i),
|
||||
ProjectID: project.ID,
|
||||
}
|
@ -9,32 +9,27 @@ import (
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/internal/migrate"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/satellite/console"
|
||||
dbx "storj.io/storj/satellite/satellitedb/consoledbx"
|
||||
)
|
||||
|
||||
var (
|
||||
// Error is the default satellitedb errs class
|
||||
Error = errs.Class("satellitedb")
|
||||
)
|
||||
|
||||
// Database contains access to different satellite databases
|
||||
type Database struct {
|
||||
// ConsoleDB contains access to different satellite databases
|
||||
type ConsoleDB struct {
|
||||
db *dbx.DB
|
||||
tx *dbx.Tx
|
||||
|
||||
methods dbx.Methods
|
||||
}
|
||||
|
||||
// New - constructor for DB
|
||||
func New(driver, source string) (*Database, error) {
|
||||
// NewConsoleDB - constructor for ConsoleDB
|
||||
func NewConsoleDB(driver, source string) (*ConsoleDB, error) {
|
||||
db, err := dbx.Open(driver, source)
|
||||
if err != nil {
|
||||
return nil, Error.New("failed opening database %q, %q: %v",
|
||||
driver, source, err)
|
||||
}
|
||||
|
||||
database := &Database{
|
||||
database := &ConsoleDB{
|
||||
db: db,
|
||||
methods: db,
|
||||
}
|
||||
@ -43,27 +38,27 @@ func New(driver, source string) (*Database, error) {
|
||||
}
|
||||
|
||||
// Users is getter a for Users repository
|
||||
func (db *Database) Users() satellite.Users {
|
||||
func (db *ConsoleDB) Users() console.Users {
|
||||
return &users{db.methods}
|
||||
}
|
||||
|
||||
// Projects is a getter for Projects repository
|
||||
func (db *Database) Projects() satellite.Projects {
|
||||
func (db *ConsoleDB) Projects() console.Projects {
|
||||
return &projects{db.methods}
|
||||
}
|
||||
|
||||
// ProjectMembers is a getter for ProjectMembers repository
|
||||
func (db *Database) ProjectMembers() satellite.ProjectMembers {
|
||||
func (db *ConsoleDB) ProjectMembers() console.ProjectMembers {
|
||||
return &projectMembers{db.methods, db.db}
|
||||
}
|
||||
|
||||
// APIKeys is a getter for APIKeys repository
|
||||
func (db *Database) APIKeys() satellite.APIKeys {
|
||||
func (db *ConsoleDB) APIKeys() console.APIKeys {
|
||||
return &apikeys{db.methods}
|
||||
}
|
||||
|
||||
// CreateTables is a method for creating all tables for satellitedb
|
||||
func (db *Database) CreateTables() error {
|
||||
func (db *ConsoleDB) CreateTables() error {
|
||||
if db.db == nil {
|
||||
return errs.New("Connection is closed")
|
||||
}
|
||||
@ -71,7 +66,7 @@ func (db *Database) CreateTables() error {
|
||||
}
|
||||
|
||||
// Close is used to close db connection
|
||||
func (db *Database) Close() error {
|
||||
func (db *ConsoleDB) Close() error {
|
||||
if db.db == nil {
|
||||
return errs.New("Connection is closed")
|
||||
}
|
||||
@ -79,7 +74,7 @@ func (db *Database) Close() error {
|
||||
}
|
||||
|
||||
// BeginTx is a method for opening transaction
|
||||
func (db *Database) BeginTx(ctx context.Context) (satellite.DBTx, error) {
|
||||
func (db *ConsoleDB) BeginTx(ctx context.Context) (console.DBTx, error) {
|
||||
if db.db == nil {
|
||||
return nil, errs.New("DB is not initialized!")
|
||||
}
|
||||
@ -90,7 +85,7 @@ func (db *Database) BeginTx(ctx context.Context) (satellite.DBTx, error) {
|
||||
}
|
||||
|
||||
return &DBTx{
|
||||
Database: &Database{
|
||||
ConsoleDB: &ConsoleDB{
|
||||
tx: tx,
|
||||
methods: tx,
|
||||
},
|
||||
@ -99,7 +94,7 @@ func (db *Database) BeginTx(ctx context.Context) (satellite.DBTx, error) {
|
||||
|
||||
// DBTx extends Database with transaction scope
|
||||
type DBTx struct {
|
||||
*Database
|
||||
*ConsoleDB
|
||||
}
|
||||
|
||||
// Commit is a method for committing and closing transaction
|
@ -7,6 +7,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
)
|
||||
|
||||
@ -15,7 +16,7 @@ func TestDatabase(t *testing.T) {
|
||||
defer ctx.Cleanup()
|
||||
|
||||
t.Run("BeginTx return err when db is nil", func(t *testing.T) {
|
||||
db := &Database{
|
||||
db := &ConsoleDB{
|
||||
db: nil,
|
||||
}
|
||||
|
||||
@ -25,7 +26,7 @@ func TestDatabase(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BeginTx and Commit success", func(t *testing.T) {
|
||||
db, err := New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -42,7 +43,7 @@ func TestDatabase(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("BeginTx and Rollback success", func(t *testing.T) {
|
||||
db, err := New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -60,7 +61,7 @@ func TestDatabase(t *testing.T) {
|
||||
|
||||
t.Run("Commit fails", func(t *testing.T) {
|
||||
transaction := &DBTx{
|
||||
Database: &Database{
|
||||
ConsoleDB: &ConsoleDB{
|
||||
tx: nil,
|
||||
},
|
||||
}
|
||||
@ -71,7 +72,7 @@ func TestDatabase(t *testing.T) {
|
||||
|
||||
t.Run("Rollback fails", func(t *testing.T) {
|
||||
transaction := &DBTx{
|
||||
Database: &Database{
|
||||
ConsoleDB: &ConsoleDB{
|
||||
tx: nil,
|
||||
},
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// dbx.v1 golang satellitedb.dbx .
|
||||
//--- satellite console ---//
|
||||
|
||||
model user (
|
||||
key id
|
@ -1,7 +1,7 @@
|
||||
// AUTOGENERATED BY gopkg.in/spacemonkeygo/dbx.v1
|
||||
// DO NOT EDIT.
|
||||
|
||||
package dbx
|
||||
package consoledbx
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
@ -17,6 +17,8 @@ import (
|
||||
"time"
|
||||
"unicode"
|
||||
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/mattn/go-sqlite3"
|
||||
"math/rand"
|
||||
)
|
||||
@ -141,6 +143,8 @@ type DB struct {
|
||||
func Open(driver, source string) (db *DB, err error) {
|
||||
var sql_db *sql.DB
|
||||
switch driver {
|
||||
case "postgres":
|
||||
sql_db, err = openpostgres(source)
|
||||
case "sqlite3":
|
||||
sql_db, err = opensqlite3(source)
|
||||
default:
|
||||
@ -165,6 +169,8 @@ func Open(driver, source string) (db *DB, err error) {
|
||||
db.Hooks.Now = time.Now
|
||||
|
||||
switch driver {
|
||||
case "postgres":
|
||||
db.dbMethods = newpostgres(db)
|
||||
case "sqlite3":
|
||||
db.dbMethods = newsqlite3(db)
|
||||
default:
|
||||
@ -229,6 +235,103 @@ func (tx *dialectTx) Rollback() (err error) {
|
||||
return makeErr(tx.tx.Rollback())
|
||||
}
|
||||
|
||||
type postgresImpl struct {
|
||||
db *DB
|
||||
dialect __sqlbundle_postgres
|
||||
driver driver
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Rebind(s string) string {
|
||||
return obj.dialect.Rebind(s)
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) logStmt(stmt string, args ...interface{}) {
|
||||
postgresLogStmt(stmt, args...)
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) makeErr(err error) error {
|
||||
constraint, ok := obj.isConstraintError(err)
|
||||
if ok {
|
||||
return constraintViolation(err, constraint)
|
||||
}
|
||||
return makeErr(err)
|
||||
}
|
||||
|
||||
type postgresDB struct {
|
||||
db *DB
|
||||
*postgresImpl
|
||||
}
|
||||
|
||||
func newpostgres(db *DB) *postgresDB {
|
||||
return &postgresDB{
|
||||
db: db,
|
||||
postgresImpl: &postgresImpl{
|
||||
db: db,
|
||||
driver: db.DB,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (obj *postgresDB) Schema() string {
|
||||
return `CREATE TABLE projects (
|
||||
id bytea NOT NULL,
|
||||
name text NOT NULL,
|
||||
description text NOT NULL,
|
||||
terms_accepted integer NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( id )
|
||||
);
|
||||
CREATE TABLE users (
|
||||
id bytea NOT NULL,
|
||||
first_name text NOT NULL,
|
||||
last_name text NOT NULL,
|
||||
email text NOT NULL,
|
||||
password_hash bytea NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( id ),
|
||||
UNIQUE ( email )
|
||||
);
|
||||
CREATE TABLE api_keys (
|
||||
id bytea NOT NULL,
|
||||
project_id bytea NOT NULL REFERENCES projects( id ) ON DELETE CASCADE,
|
||||
key bytea NOT NULL,
|
||||
name text NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( id ),
|
||||
UNIQUE ( key ),
|
||||
UNIQUE ( name, project_id )
|
||||
);
|
||||
CREATE TABLE project_members (
|
||||
member_id bytea NOT NULL REFERENCES users( id ) ON DELETE CASCADE,
|
||||
project_id bytea NOT NULL REFERENCES projects( id ) ON DELETE CASCADE,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( member_id, project_id )
|
||||
);`
|
||||
}
|
||||
|
||||
func (obj *postgresDB) wrapTx(tx *sql.Tx) txMethods {
|
||||
return &postgresTx{
|
||||
dialectTx: dialectTx{tx: tx},
|
||||
postgresImpl: &postgresImpl{
|
||||
db: obj.db,
|
||||
driver: tx,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type postgresTx struct {
|
||||
dialectTx
|
||||
*postgresImpl
|
||||
}
|
||||
|
||||
func postgresLogStmt(stmt string, args ...interface{}) {
|
||||
// TODO: render placeholders
|
||||
if Logger != nil {
|
||||
out := fmt.Sprintf("stmt: %s\nargs: %v\n", stmt, pretty(args))
|
||||
Logger(out)
|
||||
}
|
||||
}
|
||||
|
||||
type sqlite3Impl struct {
|
||||
db *DB
|
||||
dialect __sqlbundle_sqlite3
|
||||
@ -950,6 +1053,670 @@ func (h *__sqlbundle_Hole) Render() string { return h.SQL.Render() }
|
||||
// end runtime support for building sql statements
|
||||
//
|
||||
|
||||
func (obj *postgresImpl) Create_User(ctx context.Context,
|
||||
user_id User_Id_Field,
|
||||
user_first_name User_FirstName_Field,
|
||||
user_last_name User_LastName_Field,
|
||||
user_email User_Email_Field,
|
||||
user_password_hash User_PasswordHash_Field) (
|
||||
user *User, err error) {
|
||||
|
||||
__now := obj.db.Hooks.Now().UTC()
|
||||
__id_val := user_id.value()
|
||||
__first_name_val := user_first_name.value()
|
||||
__last_name_val := user_last_name.value()
|
||||
__email_val := user_email.value()
|
||||
__password_hash_val := user_password_hash.value()
|
||||
__created_at_val := __now
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("INSERT INTO users ( id, first_name, last_name, email, password_hash, created_at ) VALUES ( ?, ?, ?, ?, ?, ? ) RETURNING users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at")
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __id_val, __first_name_val, __last_name_val, __email_val, __password_hash_val, __created_at_val)
|
||||
|
||||
user = &User{}
|
||||
err = obj.driver.QueryRow(__stmt, __id_val, __first_name_val, __last_name_val, __email_val, __password_hash_val, __created_at_val).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return user, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Create_Project(ctx context.Context,
|
||||
project_id Project_Id_Field,
|
||||
project_name Project_Name_Field,
|
||||
project_description Project_Description_Field,
|
||||
project_terms_accepted Project_TermsAccepted_Field) (
|
||||
project *Project, err error) {
|
||||
|
||||
__now := obj.db.Hooks.Now().UTC()
|
||||
__id_val := project_id.value()
|
||||
__name_val := project_name.value()
|
||||
__description_val := project_description.value()
|
||||
__terms_accepted_val := project_terms_accepted.value()
|
||||
__created_at_val := __now
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("INSERT INTO projects ( id, name, description, terms_accepted, created_at ) VALUES ( ?, ?, ?, ?, ? ) RETURNING projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at")
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __id_val, __name_val, __description_val, __terms_accepted_val, __created_at_val)
|
||||
|
||||
project = &Project{}
|
||||
err = obj.driver.QueryRow(__stmt, __id_val, __name_val, __description_val, __terms_accepted_val, __created_at_val).Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return project, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Create_ProjectMember(ctx context.Context,
|
||||
project_member_member_id ProjectMember_MemberId_Field,
|
||||
project_member_project_id ProjectMember_ProjectId_Field) (
|
||||
project_member *ProjectMember, err error) {
|
||||
|
||||
__now := obj.db.Hooks.Now().UTC()
|
||||
__member_id_val := project_member_member_id.value()
|
||||
__project_id_val := project_member_project_id.value()
|
||||
__created_at_val := __now
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("INSERT INTO project_members ( member_id, project_id, created_at ) VALUES ( ?, ?, ? ) RETURNING project_members.member_id, project_members.project_id, project_members.created_at")
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __member_id_val, __project_id_val, __created_at_val)
|
||||
|
||||
project_member = &ProjectMember{}
|
||||
err = obj.driver.QueryRow(__stmt, __member_id_val, __project_id_val, __created_at_val).Scan(&project_member.MemberId, &project_member.ProjectId, &project_member.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return project_member, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Create_ApiKey(ctx context.Context,
|
||||
api_key_id ApiKey_Id_Field,
|
||||
api_key_project_id ApiKey_ProjectId_Field,
|
||||
api_key_key ApiKey_Key_Field,
|
||||
api_key_name ApiKey_Name_Field) (
|
||||
api_key *ApiKey, err error) {
|
||||
|
||||
__now := obj.db.Hooks.Now().UTC()
|
||||
__id_val := api_key_id.value()
|
||||
__project_id_val := api_key_project_id.value()
|
||||
__key_val := api_key_key.value()
|
||||
__name_val := api_key_name.value()
|
||||
__created_at_val := __now
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("INSERT INTO api_keys ( id, project_id, key, name, created_at ) VALUES ( ?, ?, ?, ?, ? ) RETURNING api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at")
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __id_val, __project_id_val, __key_val, __name_val, __created_at_val)
|
||||
|
||||
api_key = &ApiKey{}
|
||||
err = obj.driver.QueryRow(__stmt, __id_val, __project_id_val, __key_val, __name_val, __created_at_val).Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return api_key, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Get_User_By_Email(ctx context.Context,
|
||||
user_email User_Email_Field) (
|
||||
user *User, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at FROM users WHERE users.email = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, user_email.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
user = &User{}
|
||||
err = obj.driver.QueryRow(__stmt, __values...).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return user, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Get_User_By_Id(ctx context.Context,
|
||||
user_id User_Id_Field) (
|
||||
user *User, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at FROM users WHERE users.id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, user_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
user = &User{}
|
||||
err = obj.driver.QueryRow(__stmt, __values...).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return user, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) All_Project(ctx context.Context) (
|
||||
rows []*Project, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values)
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__rows, err := obj.driver.Query(__stmt, __values...)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
defer __rows.Close()
|
||||
|
||||
for __rows.Next() {
|
||||
project := &Project{}
|
||||
err = __rows.Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
rows = append(rows, project)
|
||||
}
|
||||
if err := __rows.Err(); err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return rows, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Get_Project_By_Id(ctx context.Context,
|
||||
project_id Project_Id_Field) (
|
||||
project *Project, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects WHERE projects.id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, project_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
project = &Project{}
|
||||
err = obj.driver.QueryRow(__stmt, __values...).Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return project, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) All_Project_By_ProjectMember_MemberId_OrderBy_Asc_Project_Name(ctx context.Context,
|
||||
project_member_member_id ProjectMember_MemberId_Field) (
|
||||
rows []*Project, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at FROM projects JOIN project_members ON projects.id = project_members.project_id WHERE project_members.member_id = ? ORDER BY projects.name")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, project_member_member_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__rows, err := obj.driver.Query(__stmt, __values...)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
defer __rows.Close()
|
||||
|
||||
for __rows.Next() {
|
||||
project := &Project{}
|
||||
err = __rows.Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
rows = append(rows, project)
|
||||
}
|
||||
if err := __rows.Err(); err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return rows, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) All_ProjectMember_By_MemberId(ctx context.Context,
|
||||
project_member_member_id ProjectMember_MemberId_Field) (
|
||||
rows []*ProjectMember, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT project_members.member_id, project_members.project_id, project_members.created_at FROM project_members WHERE project_members.member_id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, project_member_member_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__rows, err := obj.driver.Query(__stmt, __values...)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
defer __rows.Close()
|
||||
|
||||
for __rows.Next() {
|
||||
project_member := &ProjectMember{}
|
||||
err = __rows.Scan(&project_member.MemberId, &project_member.ProjectId, &project_member.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
rows = append(rows, project_member)
|
||||
}
|
||||
if err := __rows.Err(); err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return rows, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Limited_ProjectMember_By_ProjectId(ctx context.Context,
|
||||
project_member_project_id ProjectMember_ProjectId_Field,
|
||||
limit int, offset int64) (
|
||||
rows []*ProjectMember, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT project_members.member_id, project_members.project_id, project_members.created_at FROM project_members WHERE project_members.project_id = ? LIMIT ? OFFSET ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, project_member_project_id.value())
|
||||
|
||||
__values = append(__values, limit, offset)
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__rows, err := obj.driver.Query(__stmt, __values...)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
defer __rows.Close()
|
||||
|
||||
for __rows.Next() {
|
||||
project_member := &ProjectMember{}
|
||||
err = __rows.Scan(&project_member.MemberId, &project_member.ProjectId, &project_member.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
rows = append(rows, project_member)
|
||||
}
|
||||
if err := __rows.Err(); err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return rows, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Get_ApiKey_By_Id(ctx context.Context,
|
||||
api_key_id ApiKey_Id_Field) (
|
||||
api_key *ApiKey, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at FROM api_keys WHERE api_keys.id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, api_key_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
api_key = &ApiKey{}
|
||||
err = obj.driver.QueryRow(__stmt, __values...).Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return api_key, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) All_ApiKey_By_ProjectId_OrderBy_Asc_Name(ctx context.Context,
|
||||
api_key_project_id ApiKey_ProjectId_Field) (
|
||||
rows []*ApiKey, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("SELECT api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at FROM api_keys WHERE api_keys.project_id = ? ORDER BY api_keys.name")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, api_key_project_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__rows, err := obj.driver.Query(__stmt, __values...)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
defer __rows.Close()
|
||||
|
||||
for __rows.Next() {
|
||||
api_key := &ApiKey{}
|
||||
err = __rows.Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
rows = append(rows, api_key)
|
||||
}
|
||||
if err := __rows.Err(); err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return rows, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Update_User_By_Id(ctx context.Context,
|
||||
user_id User_Id_Field,
|
||||
update User_Update_Fields) (
|
||||
user *User, err error) {
|
||||
var __sets = &__sqlbundle_Hole{}
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE users SET "), __sets, __sqlbundle_Literal(" WHERE users.id = ? RETURNING users.id, users.first_name, users.last_name, users.email, users.password_hash, users.created_at")}}
|
||||
|
||||
__sets_sql := __sqlbundle_Literals{Join: ", "}
|
||||
var __values []interface{}
|
||||
var __args []interface{}
|
||||
|
||||
if update.FirstName._set {
|
||||
__values = append(__values, update.FirstName.value())
|
||||
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("first_name = ?"))
|
||||
}
|
||||
|
||||
if update.LastName._set {
|
||||
__values = append(__values, update.LastName.value())
|
||||
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("last_name = ?"))
|
||||
}
|
||||
|
||||
if update.Email._set {
|
||||
__values = append(__values, update.Email.value())
|
||||
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("email = ?"))
|
||||
}
|
||||
|
||||
if update.PasswordHash._set {
|
||||
__values = append(__values, update.PasswordHash.value())
|
||||
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("password_hash = ?"))
|
||||
}
|
||||
|
||||
if len(__sets_sql.SQLs) == 0 {
|
||||
return nil, emptyUpdate()
|
||||
}
|
||||
|
||||
__args = append(__args, user_id.value())
|
||||
|
||||
__values = append(__values, __args...)
|
||||
__sets.SQL = __sets_sql
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
user = &User{}
|
||||
err = obj.driver.QueryRow(__stmt, __values...).Scan(&user.Id, &user.FirstName, &user.LastName, &user.Email, &user.PasswordHash, &user.CreatedAt)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return user, nil
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Update_Project_By_Id(ctx context.Context,
|
||||
project_id Project_Id_Field,
|
||||
update Project_Update_Fields) (
|
||||
project *Project, err error) {
|
||||
var __sets = &__sqlbundle_Hole{}
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE projects SET "), __sets, __sqlbundle_Literal(" WHERE projects.id = ? RETURNING projects.id, projects.name, projects.description, projects.terms_accepted, projects.created_at")}}
|
||||
|
||||
__sets_sql := __sqlbundle_Literals{Join: ", "}
|
||||
var __values []interface{}
|
||||
var __args []interface{}
|
||||
|
||||
if update.Description._set {
|
||||
__values = append(__values, update.Description.value())
|
||||
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("description = ?"))
|
||||
}
|
||||
|
||||
if update.TermsAccepted._set {
|
||||
__values = append(__values, update.TermsAccepted.value())
|
||||
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("terms_accepted = ?"))
|
||||
}
|
||||
|
||||
if len(__sets_sql.SQLs) == 0 {
|
||||
return nil, emptyUpdate()
|
||||
}
|
||||
|
||||
__args = append(__args, project_id.value())
|
||||
|
||||
__values = append(__values, __args...)
|
||||
__sets.SQL = __sets_sql
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
project = &Project{}
|
||||
err = obj.driver.QueryRow(__stmt, __values...).Scan(&project.Id, &project.Name, &project.Description, &project.TermsAccepted, &project.CreatedAt)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return project, nil
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Update_ApiKey_By_Id(ctx context.Context,
|
||||
api_key_id ApiKey_Id_Field,
|
||||
update ApiKey_Update_Fields) (
|
||||
api_key *ApiKey, err error) {
|
||||
var __sets = &__sqlbundle_Hole{}
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literals{Join: "", SQLs: []__sqlbundle_SQL{__sqlbundle_Literal("UPDATE api_keys SET "), __sets, __sqlbundle_Literal(" WHERE api_keys.id = ? RETURNING api_keys.id, api_keys.project_id, api_keys.key, api_keys.name, api_keys.created_at")}}
|
||||
|
||||
__sets_sql := __sqlbundle_Literals{Join: ", "}
|
||||
var __values []interface{}
|
||||
var __args []interface{}
|
||||
|
||||
if update.Name._set {
|
||||
__values = append(__values, update.Name.value())
|
||||
__sets_sql.SQLs = append(__sets_sql.SQLs, __sqlbundle_Literal("name = ?"))
|
||||
}
|
||||
|
||||
if len(__sets_sql.SQLs) == 0 {
|
||||
return nil, emptyUpdate()
|
||||
}
|
||||
|
||||
__args = append(__args, api_key_id.value())
|
||||
|
||||
__values = append(__values, __args...)
|
||||
__sets.SQL = __sets_sql
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
api_key = &ApiKey{}
|
||||
err = obj.driver.QueryRow(__stmt, __values...).Scan(&api_key.Id, &api_key.ProjectId, &api_key.Key, &api_key.Name, &api_key.CreatedAt)
|
||||
if err == sql.ErrNoRows {
|
||||
return nil, nil
|
||||
}
|
||||
if err != nil {
|
||||
return nil, obj.makeErr(err)
|
||||
}
|
||||
return api_key, nil
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Delete_User_By_Id(ctx context.Context,
|
||||
user_id User_Id_Field) (
|
||||
deleted bool, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("DELETE FROM users WHERE users.id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, user_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__res, err := obj.driver.Exec(__stmt, __values...)
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err := __res.RowsAffected()
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
return __count > 0, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Delete_Project_By_Id(ctx context.Context,
|
||||
project_id Project_Id_Field) (
|
||||
deleted bool, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("DELETE FROM projects WHERE projects.id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, project_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__res, err := obj.driver.Exec(__stmt, __values...)
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err := __res.RowsAffected()
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
return __count > 0, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Delete_ProjectMember_By_MemberId_And_ProjectId(ctx context.Context,
|
||||
project_member_member_id ProjectMember_MemberId_Field,
|
||||
project_member_project_id ProjectMember_ProjectId_Field) (
|
||||
deleted bool, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("DELETE FROM project_members WHERE project_members.member_id = ? AND project_members.project_id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, project_member_member_id.value(), project_member_project_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__res, err := obj.driver.Exec(__stmt, __values...)
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err := __res.RowsAffected()
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
return __count > 0, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) Delete_ApiKey_By_Id(ctx context.Context,
|
||||
api_key_id ApiKey_Id_Field) (
|
||||
deleted bool, err error) {
|
||||
|
||||
var __embed_stmt = __sqlbundle_Literal("DELETE FROM api_keys WHERE api_keys.id = ?")
|
||||
|
||||
var __values []interface{}
|
||||
__values = append(__values, api_key_id.value())
|
||||
|
||||
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
|
||||
obj.logStmt(__stmt, __values...)
|
||||
|
||||
__res, err := obj.driver.Exec(__stmt, __values...)
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err := __res.RowsAffected()
|
||||
if err != nil {
|
||||
return false, obj.makeErr(err)
|
||||
}
|
||||
|
||||
return __count > 0, nil
|
||||
|
||||
}
|
||||
|
||||
func (impl postgresImpl) isConstraintError(err error) (
|
||||
constraint string, ok bool) {
|
||||
if e, ok := err.(*pq.Error); ok {
|
||||
if e.Code.Class() == "23" {
|
||||
return e.Constraint, true
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
|
||||
func (obj *postgresImpl) deleteAll(ctx context.Context) (count int64, err error) {
|
||||
var __res sql.Result
|
||||
var __count int64
|
||||
__res, err = obj.driver.Exec("DELETE FROM project_members;")
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err = __res.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
count += __count
|
||||
__res, err = obj.driver.Exec("DELETE FROM api_keys;")
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err = __res.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
count += __count
|
||||
__res, err = obj.driver.Exec("DELETE FROM users;")
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err = __res.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
count += __count
|
||||
__res, err = obj.driver.Exec("DELETE FROM projects;")
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
|
||||
__count, err = __res.RowsAffected()
|
||||
if err != nil {
|
||||
return 0, obj.makeErr(err)
|
||||
}
|
||||
count += __count
|
||||
|
||||
return count, nil
|
||||
|
||||
}
|
||||
|
||||
func (obj *sqlite3Impl) Create_User(ctx context.Context,
|
||||
user_id User_Id_Field,
|
||||
user_first_name User_FirstName_Field,
|
||||
@ -2120,6 +2887,10 @@ type dbMethods interface {
|
||||
makeErr(err error) error
|
||||
}
|
||||
|
||||
func openpostgres(source string) (*sql.DB, error) {
|
||||
return sql.Open("postgres", source)
|
||||
}
|
||||
|
||||
var sqlite3DriverName = func() string {
|
||||
var id [16]byte
|
||||
rand.Read(id[:])
|
36
satellite/satellitedb/consoledbx/consoledb.dbx.postgres.sql
Normal file
36
satellite/satellitedb/consoledbx/consoledb.dbx.postgres.sql
Normal file
@ -0,0 +1,36 @@
|
||||
-- AUTOGENERATED BY gopkg.in/spacemonkeygo/dbx.v1
|
||||
-- DO NOT EDIT
|
||||
CREATE TABLE projects (
|
||||
id bytea NOT NULL,
|
||||
name text NOT NULL,
|
||||
description text NOT NULL,
|
||||
terms_accepted integer NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( id )
|
||||
);
|
||||
CREATE TABLE users (
|
||||
id bytea NOT NULL,
|
||||
first_name text NOT NULL,
|
||||
last_name text NOT NULL,
|
||||
email text NOT NULL,
|
||||
password_hash bytea NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( id ),
|
||||
UNIQUE ( email )
|
||||
);
|
||||
CREATE TABLE api_keys (
|
||||
id bytea NOT NULL,
|
||||
project_id bytea NOT NULL REFERENCES projects( id ) ON DELETE CASCADE,
|
||||
key bytea NOT NULL,
|
||||
name text NOT NULL,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( id ),
|
||||
UNIQUE ( key ),
|
||||
UNIQUE ( name, project_id )
|
||||
);
|
||||
CREATE TABLE project_members (
|
||||
member_id bytea NOT NULL REFERENCES users( id ) ON DELETE CASCADE,
|
||||
project_id bytea NOT NULL REFERENCES projects( id ) ON DELETE CASCADE,
|
||||
created_at timestamp with time zone NOT NULL,
|
||||
PRIMARY KEY ( member_id, project_id )
|
||||
);
|
7
satellite/satellitedb/consoledbx/gen.go
Normal file
7
satellite/satellitedb/consoledbx/gen.go
Normal file
@ -0,0 +1,7 @@
|
||||
// Copyright (C) 2018 Storj Labs, Inc.
|
||||
// See LICENSE for copying information.
|
||||
|
||||
package consoledbx
|
||||
|
||||
//go:generate dbx.v1 schema -d postgres -d sqlite3 consoledb.dbx .
|
||||
//go:generate dbx.v1 golang -d postgres -d sqlite3 consoledb.dbx .
|
@ -9,9 +9,9 @@ import (
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/pkg/utils"
|
||||
"storj.io/storj/satellite/console"
|
||||
dbx "storj.io/storj/satellite/satellitedb/consoledbx"
|
||||
)
|
||||
|
||||
// ProjectMembers exposes methods to manage ProjectMembers table in database.
|
||||
@ -21,7 +21,7 @@ type projectMembers struct {
|
||||
}
|
||||
|
||||
// GetByMemberID is a method for querying project member from the database by memberID.
|
||||
func (pm *projectMembers) GetByMemberID(ctx context.Context, memberID uuid.UUID) ([]satellite.ProjectMember, error) {
|
||||
func (pm *projectMembers) GetByMemberID(ctx context.Context, memberID uuid.UUID) ([]console.ProjectMember, error) {
|
||||
projectMembersDbx, err := pm.methods.All_ProjectMember_By_MemberId(ctx, dbx.ProjectMember_MemberId(memberID[:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -31,12 +31,12 @@ func (pm *projectMembers) GetByMemberID(ctx context.Context, memberID uuid.UUID)
|
||||
}
|
||||
|
||||
// GetByProjectID is a method for querying project members from the database by projectID, offset and limit.
|
||||
func (pm *projectMembers) GetByProjectID(ctx context.Context, projectID uuid.UUID, pagination satellite.Pagination) ([]satellite.ProjectMember, error) {
|
||||
func (pm *projectMembers) GetByProjectID(ctx context.Context, projectID uuid.UUID, pagination console.Pagination) ([]console.ProjectMember, error) {
|
||||
if pagination.Limit < 0 || pagination.Offset < 0 {
|
||||
return nil, errs.New("invalid pagination argument")
|
||||
}
|
||||
|
||||
var projectMembers []satellite.ProjectMember
|
||||
var projectMembers []console.ProjectMember
|
||||
searchSubQuery := "%" + pagination.Search + "%"
|
||||
//`+getOrder(pagination.Order)+`
|
||||
|
||||
@ -63,7 +63,7 @@ func (pm *projectMembers) GetByProjectID(ctx context.Context, projectID uuid.UUI
|
||||
}
|
||||
|
||||
for rows.Next() {
|
||||
pm := satellite.ProjectMember{}
|
||||
pm := console.ProjectMember{}
|
||||
var memberIDBytes, projectIDBytes []uint8
|
||||
var memberID, projectID uuid.UUID
|
||||
|
||||
@ -95,7 +95,7 @@ func (pm *projectMembers) GetByProjectID(ctx context.Context, projectID uuid.UUI
|
||||
}
|
||||
|
||||
// Insert is a method for inserting project member into the database.
|
||||
func (pm *projectMembers) Insert(ctx context.Context, memberID, projectID uuid.UUID) (*satellite.ProjectMember, error) {
|
||||
func (pm *projectMembers) Insert(ctx context.Context, memberID, projectID uuid.UUID) (*console.ProjectMember, error) {
|
||||
createdProjectMember, err := pm.methods.Create_ProjectMember(ctx,
|
||||
dbx.ProjectMember_MemberId(memberID[:]),
|
||||
dbx.ProjectMember_ProjectId(projectID[:]))
|
||||
@ -118,7 +118,7 @@ func (pm *projectMembers) Delete(ctx context.Context, memberID, projectID uuid.U
|
||||
}
|
||||
|
||||
// projectMemberFromDBX is used for creating ProjectMember entity from autogenerated dbx.ProjectMember struct
|
||||
func projectMemberFromDBX(projectMember *dbx.ProjectMember) (*satellite.ProjectMember, error) {
|
||||
func projectMemberFromDBX(projectMember *dbx.ProjectMember) (*console.ProjectMember, error) {
|
||||
if projectMember == nil {
|
||||
return nil, errs.New("projectMember parameter is nil")
|
||||
}
|
||||
@ -133,7 +133,7 @@ func projectMemberFromDBX(projectMember *dbx.ProjectMember) (*satellite.ProjectM
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &satellite.ProjectMember{
|
||||
return &console.ProjectMember{
|
||||
MemberID: memberID,
|
||||
ProjectID: projectID,
|
||||
CreatedAt: projectMember.CreatedAt,
|
||||
@ -141,7 +141,7 @@ func projectMemberFromDBX(projectMember *dbx.ProjectMember) (*satellite.ProjectM
|
||||
}
|
||||
|
||||
// sanitizedOrderColumnName return valid order by column
|
||||
func sanitizedOrderColumnName(pmo satellite.ProjectMemberOrder) string {
|
||||
func sanitizedOrderColumnName(pmo console.ProjectMemberOrder) string {
|
||||
switch pmo {
|
||||
case 2:
|
||||
return "u.email"
|
||||
@ -153,8 +153,8 @@ func sanitizedOrderColumnName(pmo satellite.ProjectMemberOrder) string {
|
||||
}
|
||||
|
||||
// projectMembersFromDbxSlice is used for creating []ProjectMember entities from autogenerated []*dbx.ProjectMember struct
|
||||
func projectMembersFromDbxSlice(projectMembersDbx []*dbx.ProjectMember) ([]satellite.ProjectMember, error) {
|
||||
var projectMembers []satellite.ProjectMember
|
||||
func projectMembersFromDbxSlice(projectMembersDbx []*dbx.ProjectMember) ([]console.ProjectMember, error) {
|
||||
var projectMembers []console.ProjectMember
|
||||
var errors []error
|
||||
|
||||
// Generating []dbo from []dbx and collecting all errors
|
@ -11,7 +11,7 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/satellite/console"
|
||||
)
|
||||
|
||||
func TestProjectMembersRepository(t *testing.T) {
|
||||
@ -19,7 +19,7 @@ func TestProjectMembersRepository(t *testing.T) {
|
||||
defer ctx.Cleanup()
|
||||
|
||||
// creating in-memory db and opening connection
|
||||
db, err := New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -95,37 +95,37 @@ func TestProjectMembersRepository(t *testing.T) {
|
||||
|
||||
t.Run("Get paged", func(t *testing.T) {
|
||||
// sql injection test. F.E '%SomeText%' = > ''%SomeText%' OR 'x' != '%'' will be true
|
||||
members, err := projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{Limit: 6, Offset: 0, Search: "son%' OR 'x' != '", Order: 2})
|
||||
members, err := projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{Limit: 6, Offset: 0, Search: "son%' OR 'x' != '", Order: 2})
|
||||
assert.NoError(t, err)
|
||||
assert.Nil(t, members)
|
||||
assert.Equal(t, 0, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{Limit: 3, Offset: 0, Search: "", Order: 1})
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{Limit: 3, Offset: 0, Search: "", Order: 1})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 3, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{Limit: 2, Offset: 0, Search: "Liam", Order: 2})
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{Limit: 2, Offset: 0, Search: "Liam", Order: 2})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 2, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{Limit: 2, Offset: 0, Search: "Liam", Order: 1})
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{Limit: 2, Offset: 0, Search: "Liam", Order: 1})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 2, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{Limit: 6, Offset: 0, Search: "son", Order: 123})
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{Limit: 6, Offset: 0, Search: "son", Order: 123})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 5, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{Limit: 6, Offset: 3, Search: "son", Order: 2})
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{Limit: 6, Offset: 3, Search: "son", Order: 2})
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, members)
|
||||
assert.Equal(t, 2, len(members))
|
||||
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{Limit: -123, Offset: -14, Search: "son", Order: 2})
|
||||
members, err = projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{Limit: -123, Offset: -14, Search: "son", Order: 2})
|
||||
assert.Error(t, err)
|
||||
assert.Nil(t, members)
|
||||
assert.Equal(t, 0, len(members))
|
||||
@ -151,7 +151,7 @@ func TestProjectMembersRepository(t *testing.T) {
|
||||
err := projectMembers.Delete(ctx, createdUsers[0].ID, createdProjects[0].ID)
|
||||
assert.NoError(t, err)
|
||||
|
||||
projMembers, err := projectMembers.GetByProjectID(ctx, createdProjects[0].ID, satellite.Pagination{
|
||||
projMembers, err := projectMembers.GetByProjectID(ctx, createdProjects[0].ID, console.Pagination{
|
||||
Order: 1,
|
||||
Search: "",
|
||||
Offset: 0,
|
||||
@ -163,8 +163,8 @@ func TestProjectMembersRepository(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func prepareUsersAndProjects(ctx context.Context, t *testing.T, users satellite.Users, projects satellite.Projects) ([]*satellite.User, []*satellite.Project) {
|
||||
usersList := []*satellite.User{{
|
||||
func prepareUsersAndProjects(ctx context.Context, t *testing.T, users console.Users, projects console.Projects) ([]*console.User, []*console.Project) {
|
||||
usersList := []*console.User{{
|
||||
Email: "2email2@ukr.net",
|
||||
PasswordHash: []byte("some_readable_hash"),
|
||||
LastName: "Liam",
|
||||
@ -205,7 +205,7 @@ func prepareUsersAndProjects(ctx context.Context, t *testing.T, users satellite.
|
||||
}
|
||||
}
|
||||
|
||||
projectList := []*satellite.Project{
|
||||
projectList := []*console.Project{
|
||||
{
|
||||
Name: "projName1",
|
||||
TermsAccepted: 1,
|
||||
@ -241,6 +241,6 @@ func TestSanitizedOrderColumnName(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
assert.Equal(t, tc.orderColumn, sanitizedOrderColumnName(satellite.ProjectMemberOrder(tc.orderNumber)))
|
||||
assert.Equal(t, tc.orderColumn, sanitizedOrderColumnName(console.ProjectMemberOrder(tc.orderNumber)))
|
||||
}
|
||||
}
|
@ -9,9 +9,9 @@ import (
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/pkg/utils"
|
||||
"storj.io/storj/satellite/console"
|
||||
dbx "storj.io/storj/satellite/satellitedb/consoledbx"
|
||||
)
|
||||
|
||||
// implementation of Projects interface repository using spacemonkeygo/dbx orm
|
||||
@ -20,7 +20,7 @@ type projects struct {
|
||||
}
|
||||
|
||||
// GetAll is a method for querying all projects from the database.
|
||||
func (projects *projects) GetAll(ctx context.Context) ([]satellite.Project, error) {
|
||||
func (projects *projects) GetAll(ctx context.Context) ([]console.Project, error) {
|
||||
projectsDbx, err := projects.db.All_Project(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -30,7 +30,7 @@ func (projects *projects) GetAll(ctx context.Context) ([]satellite.Project, erro
|
||||
}
|
||||
|
||||
// GetByUserID is a method for querying all projects from the database by userID.
|
||||
func (projects *projects) GetByUserID(ctx context.Context, userID uuid.UUID) ([]satellite.Project, error) {
|
||||
func (projects *projects) GetByUserID(ctx context.Context, userID uuid.UUID) ([]console.Project, error) {
|
||||
projectsDbx, err := projects.db.All_Project_By_ProjectMember_MemberId_OrderBy_Asc_Project_Name(ctx, dbx.ProjectMember_MemberId(userID[:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -40,7 +40,7 @@ func (projects *projects) GetByUserID(ctx context.Context, userID uuid.UUID) ([]
|
||||
}
|
||||
|
||||
// Get is a method for querying project from the database by id.
|
||||
func (projects *projects) Get(ctx context.Context, id uuid.UUID) (*satellite.Project, error) {
|
||||
func (projects *projects) Get(ctx context.Context, id uuid.UUID) (*console.Project, error) {
|
||||
project, err := projects.db.Get_Project_By_Id(ctx, dbx.Project_Id(id[:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -50,7 +50,7 @@ func (projects *projects) Get(ctx context.Context, id uuid.UUID) (*satellite.Pro
|
||||
}
|
||||
|
||||
// Insert is a method for inserting project into the database.
|
||||
func (projects *projects) Insert(ctx context.Context, project *satellite.Project) (*satellite.Project, error) {
|
||||
func (projects *projects) Insert(ctx context.Context, project *console.Project) (*console.Project, error) {
|
||||
projectID, err := uuid.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -77,7 +77,7 @@ func (projects *projects) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
}
|
||||
|
||||
// Update is a method for updating project entity
|
||||
func (projects *projects) Update(ctx context.Context, project *satellite.Project) error {
|
||||
func (projects *projects) Update(ctx context.Context, project *console.Project) error {
|
||||
updateFields := dbx.Project_Update_Fields{
|
||||
Description: dbx.Project_Description(project.Description),
|
||||
TermsAccepted: dbx.Project_TermsAccepted(project.TermsAccepted),
|
||||
@ -91,7 +91,7 @@ func (projects *projects) Update(ctx context.Context, project *satellite.Project
|
||||
}
|
||||
|
||||
// projectFromDBX is used for creating Project entity from autogenerated dbx.Project struct
|
||||
func projectFromDBX(project *dbx.Project) (*satellite.Project, error) {
|
||||
func projectFromDBX(project *dbx.Project) (*console.Project, error) {
|
||||
if project == nil {
|
||||
return nil, errs.New("project parameter is nil")
|
||||
}
|
||||
@ -101,7 +101,7 @@ func projectFromDBX(project *dbx.Project) (*satellite.Project, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
u := &satellite.Project{
|
||||
u := &console.Project{
|
||||
ID: id,
|
||||
Name: project.Name,
|
||||
Description: project.Description,
|
||||
@ -113,8 +113,8 @@ func projectFromDBX(project *dbx.Project) (*satellite.Project, error) {
|
||||
}
|
||||
|
||||
// projectsFromDbxSlice is used for creating []Project entities from autogenerated []*dbx.Project struct
|
||||
func projectsFromDbxSlice(projectsDbx []*dbx.Project) ([]satellite.Project, error) {
|
||||
var projects []satellite.Project
|
||||
func projectsFromDbxSlice(projectsDbx []*dbx.Project) ([]console.Project, error) {
|
||||
var projects []console.Project
|
||||
var errors []error
|
||||
|
||||
// Generating []dbo from []dbx and collecting all errors
|
@ -9,8 +9,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/satellite/console"
|
||||
dbx "storj.io/storj/satellite/satellitedb/consoledbx"
|
||||
)
|
||||
|
||||
func TestProjectsRepository(t *testing.T) {
|
||||
@ -35,7 +35,7 @@ func TestProjectsRepository(t *testing.T) {
|
||||
|
||||
// creating in-memory db and opening connection
|
||||
// to test with real db3 file use this connection string - "../db/accountdb.db3"
|
||||
db, err := New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -50,11 +50,11 @@ func TestProjectsRepository(t *testing.T) {
|
||||
// repositories
|
||||
users := db.Users()
|
||||
projects := db.Projects()
|
||||
var project *satellite.Project
|
||||
var owner *satellite.User
|
||||
var project *console.Project
|
||||
var owner *console.User
|
||||
|
||||
t.Run("Insert project successfully", func(t *testing.T) {
|
||||
owner, err = users.Insert(ctx, &satellite.User{
|
||||
owner, err = users.Insert(ctx, &console.User{
|
||||
FirstName: userName,
|
||||
LastName: lastName,
|
||||
Email: email,
|
||||
@ -63,7 +63,7 @@ func TestProjectsRepository(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, owner)
|
||||
|
||||
project = &satellite.Project{
|
||||
project = &console.Project{
|
||||
Name: name,
|
||||
Description: description,
|
||||
TermsAccepted: 1,
|
||||
@ -98,7 +98,7 @@ func TestProjectsRepository(t *testing.T) {
|
||||
assert.NotNil(t, oldProject)
|
||||
|
||||
// creating new project with updated values
|
||||
newProject := &satellite.Project{
|
||||
newProject := &console.Project{
|
||||
ID: oldProject.ID,
|
||||
Description: newDescription,
|
||||
TermsAccepted: 2,
|
||||
@ -132,7 +132,7 @@ func TestProjectsRepository(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(allProjects), 0)
|
||||
|
||||
newProject := &satellite.Project{
|
||||
newProject := &console.Project{
|
||||
Description: description,
|
||||
Name: name,
|
||||
TermsAccepted: 1,
|
||||
@ -145,7 +145,7 @@ func TestProjectsRepository(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, len(allProjects), 1)
|
||||
|
||||
newProject2 := &satellite.Project{
|
||||
newProject2 := &console.Project{
|
||||
Description: description,
|
||||
Name: name,
|
||||
TermsAccepted: 1,
|
@ -9,8 +9,8 @@ import (
|
||||
"github.com/skyrings/skyring-common/tools/uuid"
|
||||
"github.com/zeebo/errs"
|
||||
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/satellite/console"
|
||||
dbx "storj.io/storj/satellite/satellitedb/consoledbx"
|
||||
)
|
||||
|
||||
// implementation of Users interface repository using spacemonkeygo/dbx orm
|
||||
@ -19,7 +19,7 @@ type users struct {
|
||||
}
|
||||
|
||||
// Get is a method for querying user from the database by id
|
||||
func (users *users) Get(ctx context.Context, id uuid.UUID) (*satellite.User, error) {
|
||||
func (users *users) Get(ctx context.Context, id uuid.UUID) (*console.User, error) {
|
||||
user, err := users.db.Get_User_By_Id(ctx, dbx.User_Id(id[:]))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -29,7 +29,7 @@ func (users *users) Get(ctx context.Context, id uuid.UUID) (*satellite.User, err
|
||||
}
|
||||
|
||||
// GetByEmail is a method for querying user by email from the database.
|
||||
func (users *users) GetByEmail(ctx context.Context, email string) (*satellite.User, error) {
|
||||
func (users *users) GetByEmail(ctx context.Context, email string) (*console.User, error) {
|
||||
user, err := users.db.Get_User_By_Email(ctx, dbx.User_Email(email))
|
||||
|
||||
if err != nil {
|
||||
@ -40,7 +40,7 @@ func (users *users) GetByEmail(ctx context.Context, email string) (*satellite.Us
|
||||
}
|
||||
|
||||
// Insert is a method for inserting user into the database
|
||||
func (users *users) Insert(ctx context.Context, user *satellite.User) (*satellite.User, error) {
|
||||
func (users *users) Insert(ctx context.Context, user *console.User) (*console.User, error) {
|
||||
userID, err := uuid.New()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@ -68,7 +68,7 @@ func (users *users) Delete(ctx context.Context, id uuid.UUID) error {
|
||||
}
|
||||
|
||||
// Update is a method for updating user entity
|
||||
func (users *users) Update(ctx context.Context, user *satellite.User) error {
|
||||
func (users *users) Update(ctx context.Context, user *console.User) error {
|
||||
_, err := users.db.Update_User_By_Id(
|
||||
ctx,
|
||||
dbx.User_Id(user.ID[:]),
|
||||
@ -79,7 +79,7 @@ func (users *users) Update(ctx context.Context, user *satellite.User) error {
|
||||
}
|
||||
|
||||
// toUpdateUser creates dbx.User_Update_Fields with only non-empty fields as updatable
|
||||
func toUpdateUser(user *satellite.User) dbx.User_Update_Fields {
|
||||
func toUpdateUser(user *console.User) dbx.User_Update_Fields {
|
||||
update := dbx.User_Update_Fields{
|
||||
Email: dbx.User_Email(user.Email),
|
||||
FirstName: dbx.User_FirstName(user.FirstName),
|
||||
@ -95,7 +95,7 @@ func toUpdateUser(user *satellite.User) dbx.User_Update_Fields {
|
||||
}
|
||||
|
||||
// userFromDBX is used for creating User entity from autogenerated dbx.User struct
|
||||
func userFromDBX(user *dbx.User) (*satellite.User, error) {
|
||||
func userFromDBX(user *dbx.User) (*console.User, error) {
|
||||
if user == nil {
|
||||
return nil, errs.New("user parameter is nil")
|
||||
}
|
||||
@ -105,7 +105,7 @@ func userFromDBX(user *dbx.User) (*satellite.User, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &satellite.User{
|
||||
return &console.User{
|
||||
ID: id,
|
||||
FirstName: user.FirstName,
|
||||
LastName: user.LastName,
|
@ -11,8 +11,8 @@ import (
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"storj.io/storj/internal/testcontext"
|
||||
"storj.io/storj/pkg/satellite"
|
||||
"storj.io/storj/pkg/satellite/satellitedb/dbx"
|
||||
"storj.io/storj/satellite/console"
|
||||
dbx "storj.io/storj/satellite/satellitedb/consoledbx"
|
||||
)
|
||||
|
||||
func TestUserRepository(t *testing.T) {
|
||||
@ -33,7 +33,7 @@ func TestUserRepository(t *testing.T) {
|
||||
|
||||
// creating in-memory db and opens connection
|
||||
// to test with real db3 file use this connection string - "../db/accountdb.db3"
|
||||
db, err := New("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
db, err := NewConsoleDB("sqlite3", "file::memory:?mode=memory&cache=shared")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@ -51,7 +51,7 @@ func TestUserRepository(t *testing.T) {
|
||||
id, err := uuid.New()
|
||||
assert.NoError(t, err)
|
||||
|
||||
user := &satellite.User{
|
||||
user := &console.User{
|
||||
ID: *id,
|
||||
FirstName: name,
|
||||
LastName: lastName,
|
||||
@ -65,7 +65,7 @@ func TestUserRepository(t *testing.T) {
|
||||
})
|
||||
|
||||
t.Run("Can't insert user with same email twice", func(t *testing.T) {
|
||||
user := &satellite.User{
|
||||
user := &console.User{
|
||||
FirstName: name,
|
||||
LastName: lastName,
|
||||
Email: email,
|
||||
@ -100,7 +100,7 @@ func TestUserRepository(t *testing.T) {
|
||||
oldUser, err := repository.GetByEmail(ctx, email)
|
||||
assert.NoError(t, err)
|
||||
|
||||
newUser := &satellite.User{
|
||||
newUser := &console.User{
|
||||
ID: oldUser.ID,
|
||||
FirstName: newName,
|
||||
LastName: newLastName,
|
Loading…
Reference in New Issue
Block a user