satellite: remove rewards package
Affected packages admin,attribution,console,metainfo,satellitedb,web,payments This change removes the satellite/rewards package and its related usages. It removes references to APIKeyInfo/PartnerID, Project/PartnerID and User/PartnerID. Issue: https://github.com/storj/storj/issues/5432 Change-Id: Ieaa352ee848db45e94f85556febdbcf1444d8c3e
This commit is contained in:
parent
572c5b305b
commit
3a714cefcf
@ -43,7 +43,6 @@ func (server *Server) addAPIKey(w http.ResponseWriter, r *http.Request) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var input struct {
|
var input struct {
|
||||||
PartnerID uuid.UUID `json:"partnerId"`
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +84,6 @@ func (server *Server) addAPIKey(w http.ResponseWriter, r *http.Request) {
|
|||||||
Name: input.Name,
|
Name: input.Name,
|
||||||
ProjectID: projectUUID,
|
ProjectID: projectUUID,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
PartnerID: input.PartnerID,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = server.db.Console().APIKeys().Create(ctx, key.Head(), apikey)
|
_, err = server.db.Console().APIKeys().Create(ctx, key.Head(), apikey)
|
||||||
|
@ -206,7 +206,6 @@ func TestApiKeysList(t *testing.T) {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
ProjectID string `json:"projectId"`
|
ProjectID string `json:"projectId"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
PartnerID string `json:"partnerID"`
|
|
||||||
CreatedAt string `json:"createdAt"`
|
CreatedAt string `json:"createdAt"`
|
||||||
}
|
}
|
||||||
require.NoError(t, json.Unmarshal(body, &apiKeys))
|
require.NoError(t, json.Unmarshal(body, &apiKeys))
|
||||||
@ -216,14 +215,12 @@ func TestApiKeysList(t *testing.T) {
|
|||||||
assert.NotEmpty(t, a.ID, "API key ID")
|
assert.NotEmpty(t, a.ID, "API key ID")
|
||||||
assert.Equal(t, "first", a.Name, "API key name")
|
assert.Equal(t, "first", a.Name, "API key name")
|
||||||
assert.Equal(t, project.ID.String(), a.ProjectID, "API key project ID")
|
assert.Equal(t, project.ID.String(), a.ProjectID, "API key project ID")
|
||||||
assert.Equal(t, uuid.UUID{}.String(), a.PartnerID, "API key partner ID")
|
|
||||||
assert.NotEmpty(t, a.CreatedAt, "API key created at")
|
assert.NotEmpty(t, a.CreatedAt, "API key created at")
|
||||||
|
|
||||||
a = apiKeys[1]
|
a = apiKeys[1]
|
||||||
assert.NotEmpty(t, a.ID, "API key ID")
|
assert.NotEmpty(t, a.ID, "API key ID")
|
||||||
assert.Equal(t, "second", a.Name, "API key name")
|
assert.Equal(t, "second", a.Name, "API key name")
|
||||||
assert.Equal(t, project.ID.String(), a.ProjectID, "API key project ID")
|
assert.Equal(t, project.ID.String(), a.ProjectID, "API key project ID")
|
||||||
assert.Equal(t, uuid.UUID{}.String(), a.PartnerID, "API key partner ID")
|
|
||||||
assert.NotEmpty(t, a.CreatedAt, "API key created at")
|
assert.NotEmpty(t, a.CreatedAt, "API key created at")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,7 +238,6 @@ func TestApiKeysList(t *testing.T) {
|
|||||||
assert.NotEmpty(t, a.ID, "API key ID")
|
assert.NotEmpty(t, a.ID, "API key ID")
|
||||||
assert.Equal(t, "first", a.Name, "API key name")
|
assert.Equal(t, "first", a.Name, "API key name")
|
||||||
assert.Equal(t, project.ID.String(), a.ProjectID, "API key project ID")
|
assert.Equal(t, project.ID.String(), a.ProjectID, "API key project ID")
|
||||||
assert.Equal(t, uuid.UUID{}.String(), a.PartnerID, "API key partner ID")
|
|
||||||
assert.NotEmpty(t, a.CreatedAt, "API key created at")
|
assert.NotEmpty(t, a.CreatedAt, "API key created at")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,12 +47,11 @@ func TestProjectGet(t *testing.T) {
|
|||||||
t.Run("OK", func(t *testing.T) {
|
t.Run("OK", func(t *testing.T) {
|
||||||
link := "http://" + address.String() + "/api/projects/" + project.ID.String()
|
link := "http://" + address.String() + "/api/projects/" + project.ID.String()
|
||||||
expected := fmt.Sprintf(
|
expected := fmt.Sprintf(
|
||||||
`{"id":"%s","publicId":"%s","name":"%s","description":"%s","partnerId":"%s","userAgent":null,"ownerId":"%s","rateLimit":null,"burstLimit":null,"maxBuckets":null,"createdAt":"%s","memberCount":0,"storageLimit":"25.00 GB","bandwidthLimit":"25.00 GB","userSpecifiedStorageLimit":null,"userSpecifiedBandwidthLimit":null,"segmentLimit":150000}`,
|
`{"id":"%s","publicId":"%s","name":"%s","description":"%s","userAgent":null,"ownerId":"%s","rateLimit":null,"burstLimit":null,"maxBuckets":null,"createdAt":"%s","memberCount":0,"storageLimit":"25.00 GB","bandwidthLimit":"25.00 GB","userSpecifiedStorageLimit":null,"userSpecifiedBandwidthLimit":null,"segmentLimit":150000}`,
|
||||||
project.ID.String(),
|
project.ID.String(),
|
||||||
project.PublicID.String(),
|
project.PublicID.String(),
|
||||||
project.Name,
|
project.Name,
|
||||||
project.Description,
|
project.Description,
|
||||||
project.PartnerID.String(),
|
|
||||||
project.OwnerID.String(),
|
project.OwnerID.String(),
|
||||||
project.CreatedAt.Format(time.RFC3339Nano),
|
project.CreatedAt.Format(time.RFC3339Nano),
|
||||||
)
|
)
|
||||||
|
@ -350,7 +350,6 @@ Blank fields will not be updated.`,
|
|||||||
email?: string,
|
email?: string,
|
||||||
fullName?: string,
|
fullName?: string,
|
||||||
shortName?: string,
|
shortName?: string,
|
||||||
partnerID?: string,
|
|
||||||
passwordHash?: string,
|
passwordHash?: string,
|
||||||
projectLimit?: number,
|
projectLimit?: number,
|
||||||
projectStorageLimit?: number,
|
projectStorageLimit?: number,
|
||||||
@ -362,7 +361,6 @@ Blank fields will not be updated.`,
|
|||||||
email,
|
email,
|
||||||
fullName,
|
fullName,
|
||||||
shortName,
|
shortName,
|
||||||
partnerID,
|
|
||||||
passwordHash,
|
passwordHash,
|
||||||
projectLimit,
|
projectLimit,
|
||||||
projectStorageLimit,
|
projectStorageLimit,
|
||||||
|
@ -52,7 +52,6 @@ import (
|
|||||||
"storj.io/storj/satellite/payments/storjscan"
|
"storj.io/storj/satellite/payments/storjscan"
|
||||||
"storj.io/storj/satellite/payments/stripecoinpayments"
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
||||||
"storj.io/storj/satellite/reputation"
|
"storj.io/storj/satellite/reputation"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
"storj.io/storj/satellite/snopayouts"
|
"storj.io/storj/satellite/snopayouts"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -154,10 +153,6 @@ type API struct {
|
|||||||
AuthTokens *consoleauth.Service
|
AuthTokens *consoleauth.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
Marketing struct {
|
|
||||||
PartnersService *rewards.PartnersService
|
|
||||||
}
|
|
||||||
|
|
||||||
NodeStats struct {
|
NodeStats struct {
|
||||||
Endpoint *nodestats.Endpoint
|
Endpoint *nodestats.Endpoint
|
||||||
}
|
}
|
||||||
@ -415,13 +410,6 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
{ // setup marketing partners service
|
|
||||||
peer.Marketing.PartnersService = rewards.NewPartnersService(
|
|
||||||
peer.Log.Named("partners"),
|
|
||||||
rewards.DefaultPartnersDB,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
{ // setup analytics service
|
{ // setup analytics service
|
||||||
peer.Analytics.Service = analytics.NewService(peer.Log.Named("analytics:service"), config.Analytics, config.Console.SatelliteName)
|
peer.Analytics.Service = analytics.NewService(peer.Log.Named("analytics:service"), config.Analytics, config.Console.SatelliteName)
|
||||||
|
|
||||||
@ -467,7 +455,6 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
|
|||||||
peer.Orders.Service,
|
peer.Orders.Service,
|
||||||
peer.Overlay.Service,
|
peer.Overlay.Service,
|
||||||
peer.DB.Attribution(),
|
peer.DB.Attribution(),
|
||||||
peer.Marketing.PartnersService,
|
|
||||||
peer.DB.PeerIdentities(),
|
peer.DB.PeerIdentities(),
|
||||||
peer.DB.Console().APIKeys(),
|
peer.DB.Console().APIKeys(),
|
||||||
peer.Accounting.ProjectUsage,
|
peer.Accounting.ProjectUsage,
|
||||||
@ -618,7 +605,6 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
|
|||||||
peer.DB.ProjectAccounting(),
|
peer.DB.ProjectAccounting(),
|
||||||
peer.Accounting.ProjectUsage,
|
peer.Accounting.ProjectUsage,
|
||||||
peer.Buckets.Service,
|
peer.Buckets.Service,
|
||||||
peer.Marketing.PartnersService,
|
|
||||||
peer.Payments.Accounts,
|
peer.Payments.Accounts,
|
||||||
peer.Payments.DepositWallets,
|
peer.Payments.DepositWallets,
|
||||||
peer.DB.Billing(),
|
peer.DB.Billing(),
|
||||||
@ -640,7 +626,6 @@ func NewAPI(log *zap.Logger, full *identity.FullIdentity, db DB,
|
|||||||
peer.Console.Service,
|
peer.Console.Service,
|
||||||
peer.OIDC.Service,
|
peer.OIDC.Service,
|
||||||
peer.Mail.Service,
|
peer.Mail.Service,
|
||||||
peer.Marketing.PartnersService,
|
|
||||||
peer.Analytics.Service,
|
peer.Analytics.Service,
|
||||||
peer.ABTesting.Service,
|
peer.ABTesting.Service,
|
||||||
accountFreezeService,
|
accountFreezeService,
|
||||||
|
@ -20,14 +20,12 @@ var ErrBucketNotAttributed = errs.Class("bucket not attributed")
|
|||||||
type Info struct {
|
type Info struct {
|
||||||
ProjectID uuid.UUID
|
ProjectID uuid.UUID
|
||||||
BucketName []byte
|
BucketName []byte
|
||||||
PartnerID uuid.UUID
|
|
||||||
UserAgent []byte
|
UserAgent []byte
|
||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
// BucketUsage is the usage data for a single bucket.
|
// BucketUsage is the usage data for a single bucket.
|
||||||
type BucketUsage struct {
|
type BucketUsage struct {
|
||||||
PartnerID []byte
|
|
||||||
UserAgent []byte
|
UserAgent []byte
|
||||||
ProjectID []byte
|
ProjectID []byte
|
||||||
BucketName []byte
|
BucketName []byte
|
||||||
@ -47,7 +45,7 @@ type DB interface {
|
|||||||
// Insert creates and stores new Info.
|
// Insert creates and stores new Info.
|
||||||
Insert(ctx context.Context, info *Info) (*Info, error)
|
Insert(ctx context.Context, info *Info) (*Info, error)
|
||||||
// QueryAttribution queries partner bucket attribution data.
|
// QueryAttribution queries partner bucket attribution data.
|
||||||
QueryAttribution(ctx context.Context, partnerID uuid.UUID, userAgent []byte, start time.Time, end time.Time) ([]*BucketUsage, error)
|
QueryAttribution(ctx context.Context, userAgent []byte, start time.Time, end time.Time) ([]*BucketUsage, error)
|
||||||
// QueryAllAttribution queries all partner bucket usage data.
|
// QueryAllAttribution queries all partner bucket usage data.
|
||||||
QueryAllAttribution(ctx context.Context, start time.Time, end time.Time) ([]*BucketUsage, error)
|
QueryAllAttribution(ctx context.Context, start time.Time, end time.Time) ([]*BucketUsage, error)
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,6 @@ const (
|
|||||||
|
|
||||||
type AttributionTestData struct {
|
type AttributionTestData struct {
|
||||||
name string
|
name string
|
||||||
partnerID uuid.UUID
|
|
||||||
userAgent []byte
|
userAgent []byte
|
||||||
projectID uuid.UUID
|
projectID uuid.UUID
|
||||||
bucketName []byte
|
bucketName []byte
|
||||||
@ -70,14 +69,13 @@ func TestDB(t *testing.T) {
|
|||||||
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
||||||
attributionDB := db.Attribution()
|
attributionDB := db.Attribution()
|
||||||
project1, project2 := testrand.UUID(), testrand.UUID()
|
project1, project2 := testrand.UUID(), testrand.UUID()
|
||||||
partner1, partner2 := testrand.UUID(), testrand.UUID()
|
|
||||||
agent1, agent2 := []byte("agent1"), []byte("agent2")
|
agent1, agent2 := []byte("agent1"), []byte("agent2")
|
||||||
|
|
||||||
infos := []*attribution.Info{
|
infos := []*attribution.Info{
|
||||||
{project1, []byte("alpha"), partner1, agent1, time.Time{}},
|
{project1, []byte("alpha"), agent1, time.Time{}},
|
||||||
{project1, []byte("beta"), partner2, agent2, time.Time{}},
|
{project1, []byte("beta"), agent2, time.Time{}},
|
||||||
{project2, []byte("alpha"), partner2, agent2, time.Time{}},
|
{project2, []byte("alpha"), agent2, time.Time{}},
|
||||||
{project2, []byte("beta"), partner1, agent1, time.Time{}},
|
{project2, []byte("beta"), agent1, time.Time{}},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
@ -91,7 +89,6 @@ func TestDB(t *testing.T) {
|
|||||||
for _, info := range infos {
|
for _, info := range infos {
|
||||||
got, err := attributionDB.Get(ctx, info.ProjectID, info.BucketName)
|
got, err := attributionDB.Get(ctx, info.ProjectID, info.BucketName)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Equal(t, info.PartnerID, got.PartnerID)
|
|
||||||
assert.Equal(t, info.UserAgent, got.UserAgent)
|
assert.Equal(t, info.UserAgent, got.UserAgent)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -102,14 +99,12 @@ func TestQueryAttribution(t *testing.T) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
projectID := testrand.UUID()
|
projectID := testrand.UUID()
|
||||||
partnerID := testrand.UUID()
|
|
||||||
userAgent := []byte("agent1")
|
userAgent := []byte("agent1")
|
||||||
alphaBucket := []byte("alpha")
|
alphaBucket := []byte("alpha")
|
||||||
betaBucket := []byte("beta")
|
betaBucket := []byte("beta")
|
||||||
testData := []AttributionTestData{
|
testData := []AttributionTestData{
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, alpha",
|
name: "new partnerID, userAgent, projectID, alpha",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent2"),
|
userAgent: []byte("agent2"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -124,7 +119,6 @@ func TestQueryAttribution(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent, new projectID, alpha",
|
name: "partnerID, userAgent, new projectID, alpha",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -139,7 +133,6 @@ func TestQueryAttribution(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, beta",
|
name: "new partnerID, userAgent, projectID, beta",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent3"),
|
userAgent: []byte("agent3"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -154,7 +147,6 @@ func TestQueryAttribution(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent new projectID, beta",
|
name: "partnerID, userAgent new projectID, beta",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -171,7 +163,7 @@ func TestQueryAttribution(t *testing.T) {
|
|||||||
for _, td := range testData {
|
for _, td := range testData {
|
||||||
td := td
|
td := td
|
||||||
td.init()
|
td.init()
|
||||||
info := attribution.Info{td.projectID, td.bucketName, td.partnerID, td.userAgent, time.Time{}}
|
info := attribution.Info{td.projectID, td.bucketName, td.userAgent, time.Time{}}
|
||||||
_, err := db.Attribution().Insert(ctx, &info)
|
_, err := db.Attribution().Insert(ctx, &info)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -189,14 +181,12 @@ func TestQueryAllAttribution(t *testing.T) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
projectID := testrand.UUID()
|
projectID := testrand.UUID()
|
||||||
partnerID := testrand.UUID()
|
|
||||||
userAgent := []byte("agent1")
|
userAgent := []byte("agent1")
|
||||||
alphaBucket := []byte("alpha")
|
alphaBucket := []byte("alpha")
|
||||||
betaBucket := []byte("beta")
|
betaBucket := []byte("beta")
|
||||||
testData := []AttributionTestData{
|
testData := []AttributionTestData{
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, alpha",
|
name: "new partnerID, userAgent, projectID, alpha",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent2"),
|
userAgent: []byte("agent2"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -211,7 +201,6 @@ func TestQueryAllAttribution(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent, new projectID, alpha",
|
name: "partnerID, userAgent, new projectID, alpha",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -226,7 +215,6 @@ func TestQueryAllAttribution(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, beta",
|
name: "new partnerID, userAgent, projectID, beta",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent3"),
|
userAgent: []byte("agent3"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -241,7 +229,6 @@ func TestQueryAllAttribution(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent new projectID, beta",
|
name: "partnerID, userAgent new projectID, beta",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -259,7 +246,7 @@ func TestQueryAllAttribution(t *testing.T) {
|
|||||||
td := td
|
td := td
|
||||||
td.init()
|
td.init()
|
||||||
|
|
||||||
info := attribution.Info{td.projectID, td.bucketName, td.partnerID, td.userAgent, time.Time{}}
|
info := attribution.Info{td.projectID, td.bucketName, td.userAgent, time.Time{}}
|
||||||
_, err := db.Attribution().Insert(ctx, &info)
|
_, err := db.Attribution().Insert(ctx, &info)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
for i := 0; i < td.hoursOfData; i++ {
|
for i := 0; i < td.hoursOfData; i++ {
|
||||||
@ -280,14 +267,13 @@ func TestQueryAllAttributionNoStorage(t *testing.T) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
projectID := testrand.UUID()
|
projectID := testrand.UUID()
|
||||||
partnerID := testrand.UUID()
|
|
||||||
userAgent := []byte("agent1")
|
userAgent := []byte("agent1")
|
||||||
alphaBucket := []byte("alpha")
|
alphaBucket := []byte("alpha")
|
||||||
betaBucket := []byte("beta")
|
betaBucket := []byte("beta")
|
||||||
testData := []AttributionTestData{
|
testData := []AttributionTestData{
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, alpha",
|
name: "new partnerID, userAgent, projectID, alpha",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent2"),
|
userAgent: []byte("agent2"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -302,7 +288,7 @@ func TestQueryAllAttributionNoStorage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent, new projectID, alpha",
|
name: "partnerID, userAgent, new projectID, alpha",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -317,7 +303,7 @@ func TestQueryAllAttributionNoStorage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, beta",
|
name: "new partnerID, userAgent, projectID, beta",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent3"),
|
userAgent: []byte("agent3"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -332,7 +318,7 @@ func TestQueryAllAttributionNoStorage(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent new projectID, beta",
|
name: "partnerID, userAgent new projectID, beta",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -350,7 +336,7 @@ func TestQueryAllAttributionNoStorage(t *testing.T) {
|
|||||||
td := td
|
td := td
|
||||||
td.init()
|
td.init()
|
||||||
|
|
||||||
info := attribution.Info{td.projectID, td.bucketName, td.partnerID, td.userAgent, time.Time{}}
|
info := attribution.Info{td.projectID, td.bucketName, td.userAgent, time.Time{}}
|
||||||
_, err := db.Attribution().Insert(ctx, &info)
|
_, err := db.Attribution().Insert(ctx, &info)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -368,14 +354,13 @@ func TestQueryAllAttributionNoBW(t *testing.T) {
|
|||||||
now := time.Now()
|
now := time.Now()
|
||||||
|
|
||||||
projectID := testrand.UUID()
|
projectID := testrand.UUID()
|
||||||
partnerID := testrand.UUID()
|
|
||||||
userAgent := []byte("agent1")
|
userAgent := []byte("agent1")
|
||||||
alphaBucket := []byte("alpha")
|
alphaBucket := []byte("alpha")
|
||||||
betaBucket := []byte("beta")
|
betaBucket := []byte("beta")
|
||||||
testData := []AttributionTestData{
|
testData := []AttributionTestData{
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, alpha",
|
name: "new partnerID, userAgent, projectID, alpha",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent2"),
|
userAgent: []byte("agent2"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -390,7 +375,7 @@ func TestQueryAllAttributionNoBW(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent, new projectID, alpha",
|
name: "partnerID, userAgent, new projectID, alpha",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: alphaBucket,
|
bucketName: alphaBucket,
|
||||||
@ -405,7 +390,7 @@ func TestQueryAllAttributionNoBW(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "new partnerID, userAgent, projectID, beta",
|
name: "new partnerID, userAgent, projectID, beta",
|
||||||
partnerID: testrand.UUID(),
|
|
||||||
userAgent: []byte("agent3"),
|
userAgent: []byte("agent3"),
|
||||||
projectID: projectID,
|
projectID: projectID,
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -420,7 +405,7 @@ func TestQueryAllAttributionNoBW(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "partnerID, userAgent new projectID, beta",
|
name: "partnerID, userAgent new projectID, beta",
|
||||||
partnerID: partnerID,
|
|
||||||
userAgent: userAgent,
|
userAgent: userAgent,
|
||||||
projectID: testrand.UUID(),
|
projectID: testrand.UUID(),
|
||||||
bucketName: betaBucket,
|
bucketName: betaBucket,
|
||||||
@ -438,7 +423,7 @@ func TestQueryAllAttributionNoBW(t *testing.T) {
|
|||||||
td := td
|
td := td
|
||||||
td.init()
|
td.init()
|
||||||
|
|
||||||
info := attribution.Info{td.projectID, td.bucketName, td.partnerID, td.userAgent, time.Time{}}
|
info := attribution.Info{td.projectID, td.bucketName, td.userAgent, time.Time{}}
|
||||||
_, err := db.Attribution().Insert(ctx, &info)
|
_, err := db.Attribution().Insert(ctx, &info)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
@ -452,7 +437,7 @@ func TestQueryAllAttributionNoBW(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func verifyData(ctx *testcontext.Context, t *testing.T, attributionDB attribution.DB, testData *AttributionTestData) {
|
func verifyData(ctx *testcontext.Context, t *testing.T, attributionDB attribution.DB, testData *AttributionTestData) {
|
||||||
results, err := attributionDB.QueryAttribution(ctx, testData.partnerID, testData.userAgent, testData.start, testData.end)
|
results, err := attributionDB.QueryAttribution(ctx, testData.userAgent, testData.start, testData.end)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotEqual(t, 0, len(results), "Results must not be empty.")
|
require.NotEqual(t, 0, len(results), "Results must not be empty.")
|
||||||
count := 0
|
count := 0
|
||||||
@ -466,7 +451,6 @@ func verifyData(ctx *testcontext.Context, t *testing.T, attributionDB attributio
|
|||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
|
||||||
assert.Equal(t, testData.partnerID[:], r.PartnerID, testData.name)
|
|
||||||
assert.Equal(t, testData.userAgent, r.UserAgent, testData.name)
|
assert.Equal(t, testData.userAgent, r.UserAgent, testData.name)
|
||||||
assert.Equal(t, testData.projectID[:], r.ProjectID, testData.name)
|
assert.Equal(t, testData.projectID[:], r.ProjectID, testData.name)
|
||||||
assert.Equal(t, testData.bucketName, r.BucketName, testData.name)
|
assert.Equal(t, testData.bucketName, r.BucketName, testData.name)
|
||||||
@ -492,7 +476,6 @@ func verifyAllData(ctx *testcontext.Context, t *testing.T, attributionDB attribu
|
|||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
|
||||||
assert.Equal(t, tt.partnerID[:], r.PartnerID, tt.name)
|
|
||||||
assert.Equal(t, tt.userAgent, r.UserAgent, tt.name)
|
assert.Equal(t, tt.userAgent, r.UserAgent, tt.name)
|
||||||
assert.Equal(t, tt.projectID[:], r.ProjectID, tt.name)
|
assert.Equal(t, tt.projectID[:], r.ProjectID, tt.name)
|
||||||
assert.Equal(t, tt.bucketName, r.BucketName, tt.name)
|
assert.Equal(t, tt.bucketName, r.BucketName, tt.name)
|
||||||
|
@ -53,7 +53,6 @@ type CreateAPIKeyResponse struct {
|
|||||||
type APIKeyInfo struct {
|
type APIKeyInfo struct {
|
||||||
ID uuid.UUID `json:"id"`
|
ID uuid.UUID `json:"id"`
|
||||||
ProjectID uuid.UUID `json:"projectId"`
|
ProjectID uuid.UUID `json:"projectId"`
|
||||||
PartnerID uuid.UUID `json:"partnerId"`
|
|
||||||
UserAgent []byte `json:"userAgent"`
|
UserAgent []byte `json:"userAgent"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Head []byte `json:"-"`
|
Head []byte `json:"-"`
|
||||||
|
@ -26,19 +26,8 @@ func TestUsers(t *testing.T) {
|
|||||||
// create user
|
// create user
|
||||||
userPassHash := testrand.Bytes(8)
|
userPassHash := testrand.Bytes(8)
|
||||||
|
|
||||||
// create a user with partnerID
|
|
||||||
_, err := consoleDB.Users().Insert(ctx, &console.User{
|
|
||||||
ID: testrand.UUID(),
|
|
||||||
FullName: "John Doe",
|
|
||||||
Email: "john@mail.test",
|
|
||||||
PasswordHash: userPassHash,
|
|
||||||
Status: console.Active,
|
|
||||||
PartnerID: testrand.UUID(),
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// create an user with no partnerID
|
// create an user with no partnerID
|
||||||
_, err = consoleDB.Users().Insert(ctx, &console.User{
|
_, err := consoleDB.Users().Insert(ctx, &console.User{
|
||||||
ID: testrand.UUID(),
|
ID: testrand.UUID(),
|
||||||
FullName: "John Doe",
|
FullName: "John Doe",
|
||||||
Email: "john@mail.test",
|
Email: "john@mail.test",
|
||||||
@ -52,7 +41,6 @@ func TestUsers(t *testing.T) {
|
|||||||
ID: testrand.UUID(),
|
ID: testrand.UUID(),
|
||||||
Name: "John Doe",
|
Name: "John Doe",
|
||||||
Description: "some description",
|
Description: "some description",
|
||||||
PartnerID: testrand.UUID(),
|
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
@ -24,7 +24,6 @@ import (
|
|||||||
"storj.io/storj/satellite/console/consoleweb/consoleapi/utils"
|
"storj.io/storj/satellite/console/consoleweb/consoleapi/utils"
|
||||||
"storj.io/storj/satellite/console/consoleweb/consolewebauth"
|
"storj.io/storj/satellite/console/consoleweb/consolewebauth"
|
||||||
"storj.io/storj/satellite/mailservice"
|
"storj.io/storj/satellite/mailservice"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -59,11 +58,10 @@ type Auth struct {
|
|||||||
analytics *analytics.Service
|
analytics *analytics.Service
|
||||||
mailService *mailservice.Service
|
mailService *mailservice.Service
|
||||||
cookieAuth *consolewebauth.CookieAuth
|
cookieAuth *consolewebauth.CookieAuth
|
||||||
partners *rewards.PartnersService
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAuth is a constructor for api auth controller.
|
// NewAuth is a constructor for api auth controller.
|
||||||
func NewAuth(log *zap.Logger, service *console.Service, accountFreezeService *console.AccountFreezeService, mailService *mailservice.Service, cookieAuth *consolewebauth.CookieAuth, partners *rewards.PartnersService, analytics *analytics.Service, satelliteName string, externalAddress string, letUsKnowURL string, termsAndConditionsURL string, contactInfoURL string, generalRequestURL string) *Auth {
|
func NewAuth(log *zap.Logger, service *console.Service, accountFreezeService *console.AccountFreezeService, mailService *mailservice.Service, cookieAuth *consolewebauth.CookieAuth, analytics *analytics.Service, satelliteName string, externalAddress string, letUsKnowURL string, termsAndConditionsURL string, contactInfoURL string, generalRequestURL string) *Auth {
|
||||||
return &Auth{
|
return &Auth{
|
||||||
log: log,
|
log: log,
|
||||||
ExternalAddress: externalAddress,
|
ExternalAddress: externalAddress,
|
||||||
@ -79,7 +77,6 @@ func NewAuth(log *zap.Logger, service *console.Service, accountFreezeService *co
|
|||||||
accountFreezeService: accountFreezeService,
|
accountFreezeService: accountFreezeService,
|
||||||
mailService: mailService,
|
mailService: mailService,
|
||||||
cookieAuth: cookieAuth,
|
cookieAuth: cookieAuth,
|
||||||
partners: partners,
|
|
||||||
analytics: analytics,
|
analytics: analytics,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,7 +196,6 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
ShortName string `json:"shortName"`
|
ShortName string `json:"shortName"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
Partner string `json:"partner"`
|
Partner string `json:"partner"`
|
||||||
PartnerID string `json:"partnerId"`
|
|
||||||
UserAgent []byte `json:"userAgent"`
|
UserAgent []byte `json:"userAgent"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
SecretInput string `json:"secret"`
|
SecretInput string `json:"secret"`
|
||||||
@ -283,12 +279,6 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
if registerData.Partner != "" {
|
if registerData.Partner != "" {
|
||||||
registerData.UserAgent = []byte(registerData.Partner)
|
registerData.UserAgent = []byte(registerData.Partner)
|
||||||
info, err := a.partners.ByName(ctx, registerData.Partner)
|
|
||||||
if err != nil {
|
|
||||||
a.log.Warn("Invalid partner name", zap.String("Partner name", registerData.Partner), zap.String("User email", registerData.Email), zap.Error(err))
|
|
||||||
} else {
|
|
||||||
registerData.PartnerID = info.ID
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ip, err := web.GetRequestIP(r)
|
ip, err := web.GetRequestIP(r)
|
||||||
@ -302,7 +292,6 @@ func (a *Auth) Register(w http.ResponseWriter, r *http.Request) {
|
|||||||
FullName: registerData.FullName,
|
FullName: registerData.FullName,
|
||||||
ShortName: registerData.ShortName,
|
ShortName: registerData.ShortName,
|
||||||
Email: registerData.Email,
|
Email: registerData.Email,
|
||||||
PartnerID: registerData.PartnerID,
|
|
||||||
UserAgent: registerData.UserAgent,
|
UserAgent: registerData.UserAgent,
|
||||||
Password: registerData.Password,
|
Password: registerData.Password,
|
||||||
IsProfessional: registerData.IsProfessional,
|
IsProfessional: registerData.IsProfessional,
|
||||||
@ -453,7 +442,6 @@ func (a *Auth) GetAccount(w http.ResponseWriter, r *http.Request) {
|
|||||||
FullName string `json:"fullName"`
|
FullName string `json:"fullName"`
|
||||||
ShortName string `json:"shortName"`
|
ShortName string `json:"shortName"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
PartnerID uuid.UUID `json:"partnerId"`
|
|
||||||
UserAgent []byte `json:"userAgent"`
|
UserAgent []byte `json:"userAgent"`
|
||||||
ProjectLimit int `json:"projectLimit"`
|
ProjectLimit int `json:"projectLimit"`
|
||||||
IsProfessional bool `json:"isProfessional"`
|
IsProfessional bool `json:"isProfessional"`
|
||||||
@ -476,7 +464,6 @@ func (a *Auth) GetAccount(w http.ResponseWriter, r *http.Request) {
|
|||||||
user.FullName = consoleUser.FullName
|
user.FullName = consoleUser.FullName
|
||||||
user.Email = consoleUser.Email
|
user.Email = consoleUser.Email
|
||||||
user.ID = consoleUser.ID
|
user.ID = consoleUser.ID
|
||||||
user.PartnerID = consoleUser.PartnerID
|
|
||||||
user.UserAgent = consoleUser.UserAgent
|
user.UserAgent = consoleUser.UserAgent
|
||||||
user.ProjectLimit = consoleUser.ProjectLimit
|
user.ProjectLimit = consoleUser.ProjectLimit
|
||||||
user.IsProfessional = consoleUser.IsProfessional
|
user.IsProfessional = consoleUser.IsProfessional
|
||||||
|
@ -293,7 +293,7 @@ func TestDeleteAccount(t *testing.T) {
|
|||||||
|
|
||||||
actualHandler := func(r *http.Request) (status int, body []byte) {
|
actualHandler := func(r *http.Request) (status int, body []byte) {
|
||||||
rr := httptest.NewRecorder()
|
rr := httptest.NewRecorder()
|
||||||
authController := consoleapi.NewAuth(log, nil, nil, nil, nil, nil, nil, "", "", "", "", "", "")
|
authController := consoleapi.NewAuth(log, nil, nil, nil, nil, nil, "", "", "", "", "", "")
|
||||||
authController.DeleteAccount(rr, r)
|
authController.DeleteAccount(rr, r)
|
||||||
|
|
||||||
//nolint:bodyclose
|
//nolint:bodyclose
|
||||||
|
@ -36,9 +36,6 @@ func graphqlAPIKeyInfo() *graphql.Object {
|
|||||||
FieldCreatedAt: &graphql.Field{
|
FieldCreatedAt: &graphql.Field{
|
||||||
Type: graphql.DateTime,
|
Type: graphql.DateTime,
|
||||||
},
|
},
|
||||||
FieldPartnerID: &graphql.Field{
|
|
||||||
Type: graphql.String,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,6 @@ import (
|
|||||||
"storj.io/storj/satellite/payments"
|
"storj.io/storj/satellite/payments"
|
||||||
"storj.io/storj/satellite/payments/paymentsconfig"
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
||||||
"storj.io/storj/satellite/payments/stripecoinpayments"
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// discardSender discard sending of an actual email.
|
// discardSender discard sending of an actual email.
|
||||||
@ -53,11 +52,6 @@ func TestGraphqlMutation(t *testing.T) {
|
|||||||
db := sat.DB
|
db := sat.DB
|
||||||
log := zaptest.NewLogger(t)
|
log := zaptest.NewLogger(t)
|
||||||
|
|
||||||
partnersService := rewards.NewPartnersService(
|
|
||||||
log.Named("partners"),
|
|
||||||
rewards.DefaultPartnersDB,
|
|
||||||
)
|
|
||||||
|
|
||||||
analyticsService := analytics.NewService(log, analytics.Config{}, "test-satellite")
|
analyticsService := analytics.NewService(log, analytics.Config{}, "test-satellite")
|
||||||
|
|
||||||
redis, err := testredis.Mini(ctx)
|
redis, err := testredis.Mini(ctx)
|
||||||
@ -112,7 +106,6 @@ func TestGraphqlMutation(t *testing.T) {
|
|||||||
db.ProjectAccounting(),
|
db.ProjectAccounting(),
|
||||||
projectUsage,
|
projectUsage,
|
||||||
sat.API.Buckets.Service,
|
sat.API.Buckets.Service,
|
||||||
partnersService,
|
|
||||||
paymentsService.Accounts(),
|
paymentsService.Accounts(),
|
||||||
// TODO: do we need a payment deposit wallet here?
|
// TODO: do we need a payment deposit wallet here?
|
||||||
nil,
|
nil,
|
||||||
@ -242,7 +235,7 @@ func TestGraphqlMutation(t *testing.T) {
|
|||||||
|
|
||||||
project, err := service.GetProject(userCtx, projectID)
|
project, err := service.GetProject(userCtx, projectID)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, rootUser.PartnerID, project.PartnerID)
|
require.Equal(t, rootUser.UserAgent, project.UserAgent)
|
||||||
|
|
||||||
regTokenUser1, err := service.CreateRegToken(ctx, 1)
|
regTokenUser1, err := service.CreateRegToken(ctx, 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -345,7 +338,7 @@ func TestGraphqlMutation(t *testing.T) {
|
|||||||
t.Run("Create api key mutation", func(t *testing.T) {
|
t.Run("Create api key mutation", func(t *testing.T) {
|
||||||
keyName := "key1"
|
keyName := "key1"
|
||||||
query := fmt.Sprintf(
|
query := fmt.Sprintf(
|
||||||
"mutation {createAPIKey(projectID:\"%s\",name:\"%s\"){key,keyInfo{id,name,projectID,partnerId}}}",
|
"mutation {createAPIKey(projectID:\"%s\",name:\"%s\"){key,keyInfo{id,name,projectID}}}",
|
||||||
project.ID.String(),
|
project.ID.String(),
|
||||||
keyName,
|
keyName,
|
||||||
)
|
)
|
||||||
@ -363,7 +356,6 @@ func TestGraphqlMutation(t *testing.T) {
|
|||||||
|
|
||||||
assert.Equal(t, keyName, keyInfo[consoleql.FieldName])
|
assert.Equal(t, keyName, keyInfo[consoleql.FieldName])
|
||||||
assert.Equal(t, project.ID.String(), keyInfo[consoleql.FieldProjectID])
|
assert.Equal(t, project.ID.String(), keyInfo[consoleql.FieldProjectID])
|
||||||
assert.Equal(t, rootUser.PartnerID.String(), keyInfo[consoleql.FieldPartnerID])
|
|
||||||
|
|
||||||
keyID = keyInfo[consoleql.FieldID].(string)
|
keyID = keyInfo[consoleql.FieldID].(string)
|
||||||
})
|
})
|
||||||
|
@ -28,7 +28,6 @@ import (
|
|||||||
"storj.io/storj/satellite/payments"
|
"storj.io/storj/satellite/payments"
|
||||||
"storj.io/storj/satellite/payments/paymentsconfig"
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
||||||
"storj.io/storj/satellite/payments/stripecoinpayments"
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGraphqlQuery(t *testing.T) {
|
func TestGraphqlQuery(t *testing.T) {
|
||||||
@ -37,11 +36,6 @@ func TestGraphqlQuery(t *testing.T) {
|
|||||||
db := sat.DB
|
db := sat.DB
|
||||||
log := zaptest.NewLogger(t)
|
log := zaptest.NewLogger(t)
|
||||||
|
|
||||||
partnersService := rewards.NewPartnersService(
|
|
||||||
log.Named("partners"),
|
|
||||||
rewards.DefaultPartnersDB,
|
|
||||||
)
|
|
||||||
|
|
||||||
analyticsService := analytics.NewService(log, analytics.Config{}, "test-satellite")
|
analyticsService := analytics.NewService(log, analytics.Config{}, "test-satellite")
|
||||||
|
|
||||||
redis, err := testredis.Mini(ctx)
|
redis, err := testredis.Mini(ctx)
|
||||||
@ -96,7 +90,6 @@ func TestGraphqlQuery(t *testing.T) {
|
|||||||
db.ProjectAccounting(),
|
db.ProjectAccounting(),
|
||||||
projectUsage,
|
projectUsage,
|
||||||
sat.API.Buckets.Service,
|
sat.API.Buckets.Service,
|
||||||
partnersService,
|
|
||||||
paymentsService.Accounts(),
|
paymentsService.Accounts(),
|
||||||
// TODO: do we need a payment deposit wallet here?
|
// TODO: do we need a payment deposit wallet here?
|
||||||
nil,
|
nil,
|
||||||
|
@ -24,8 +24,6 @@ const (
|
|||||||
FieldShortName = "shortName"
|
FieldShortName = "shortName"
|
||||||
// FieldCreatedAt is a field name for created at timestamp.
|
// FieldCreatedAt is a field name for created at timestamp.
|
||||||
FieldCreatedAt = "createdAt"
|
FieldCreatedAt = "createdAt"
|
||||||
// FieldPartnerID is a field name for partnerID.
|
|
||||||
FieldPartnerID = "partnerId"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// base graphql config for user.
|
// base graphql config for user.
|
||||||
@ -48,9 +46,6 @@ func baseUserConfig() graphql.ObjectConfig {
|
|||||||
FieldCreatedAt: &graphql.Field{
|
FieldCreatedAt: &graphql.Field{
|
||||||
Type: graphql.DateTime,
|
Type: graphql.DateTime,
|
||||||
},
|
},
|
||||||
FieldPartnerID: &graphql.Field{
|
|
||||||
Type: graphql.String,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -78,9 +73,6 @@ func graphqlUserInput() *graphql.InputObject {
|
|||||||
FieldPassword: &graphql.InputObjectFieldConfig{
|
FieldPassword: &graphql.InputObjectFieldConfig{
|
||||||
Type: graphql.String,
|
Type: graphql.String,
|
||||||
},
|
},
|
||||||
FieldPartnerID: &graphql.InputObjectFieldConfig{
|
|
||||||
Type: graphql.String,
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ import (
|
|||||||
"storj.io/storj/satellite/console/consoleweb/consolewebauth"
|
"storj.io/storj/satellite/console/consoleweb/consolewebauth"
|
||||||
"storj.io/storj/satellite/mailservice"
|
"storj.io/storj/satellite/mailservice"
|
||||||
"storj.io/storj/satellite/oidc"
|
"storj.io/storj/satellite/oidc"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -120,7 +119,6 @@ type Server struct {
|
|||||||
config Config
|
config Config
|
||||||
service *console.Service
|
service *console.Service
|
||||||
mailService *mailservice.Service
|
mailService *mailservice.Service
|
||||||
partners *rewards.PartnersService
|
|
||||||
analytics *analytics.Service
|
analytics *analytics.Service
|
||||||
abTesting *abtesting.Service
|
abTesting *abtesting.Service
|
||||||
|
|
||||||
@ -202,14 +200,13 @@ func (a *apiAuth) RemoveAuthCookie(w http.ResponseWriter) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates new instance of console server.
|
// NewServer creates new instance of console server.
|
||||||
func NewServer(logger *zap.Logger, config Config, service *console.Service, oidcService *oidc.Service, mailService *mailservice.Service, partners *rewards.PartnersService, analytics *analytics.Service, abTesting *abtesting.Service, accountFreezeService *console.AccountFreezeService, listener net.Listener, stripePublicKey string, nodeURL storj.NodeURL) *Server {
|
func NewServer(logger *zap.Logger, config Config, service *console.Service, oidcService *oidc.Service, mailService *mailservice.Service, analytics *analytics.Service, abTesting *abtesting.Service, accountFreezeService *console.AccountFreezeService, listener net.Listener, stripePublicKey string, nodeURL storj.NodeURL) *Server {
|
||||||
server := Server{
|
server := Server{
|
||||||
log: logger,
|
log: logger,
|
||||||
config: config,
|
config: config,
|
||||||
listener: listener,
|
listener: listener,
|
||||||
service: service,
|
service: service,
|
||||||
mailService: mailService,
|
mailService: mailService,
|
||||||
partners: partners,
|
|
||||||
analytics: analytics,
|
analytics: analytics,
|
||||||
abTesting: abTesting,
|
abTesting: abTesting,
|
||||||
stripePublicKey: stripePublicKey,
|
stripePublicKey: stripePublicKey,
|
||||||
@ -273,7 +270,7 @@ func NewServer(logger *zap.Logger, config Config, service *console.Service, oidc
|
|||||||
server.withAuth(http.HandlerFunc(usageLimitsController.DailyUsage)),
|
server.withAuth(http.HandlerFunc(usageLimitsController.DailyUsage)),
|
||||||
).Methods(http.MethodGet)
|
).Methods(http.MethodGet)
|
||||||
|
|
||||||
authController := consoleapi.NewAuth(logger, service, accountFreezeService, mailService, server.cookieAuth, partners, server.analytics, config.SatelliteName, server.config.ExternalAddress, config.LetUsKnowURL, config.TermsAndConditionsURL, config.ContactInfoURL, config.GeneralRequestURL)
|
authController := consoleapi.NewAuth(logger, service, accountFreezeService, mailService, server.cookieAuth, server.analytics, config.SatelliteName, server.config.ExternalAddress, config.LetUsKnowURL, config.TermsAndConditionsURL, config.ContactInfoURL, config.GeneralRequestURL)
|
||||||
authRouter := router.PathPrefix("/api/v0/auth").Subrouter()
|
authRouter := router.PathPrefix("/api/v0/auth").Subrouter()
|
||||||
authRouter.Handle("/account", server.withAuth(http.HandlerFunc(authController.GetAccount))).Methods(http.MethodGet)
|
authRouter.Handle("/account", server.withAuth(http.HandlerFunc(authController.GetAccount))).Methods(http.MethodGet)
|
||||||
authRouter.Handle("/account", server.withAuth(http.HandlerFunc(authController.UpdateAccount))).Methods(http.MethodPatch)
|
authRouter.Handle("/account", server.withAuth(http.HandlerFunc(authController.UpdateAccount))).Methods(http.MethodPatch)
|
||||||
|
@ -87,7 +87,7 @@ func (chore *Chore) Run(ctx context.Context) (err error) {
|
|||||||
chore.log.Error("error generating activation token", zap.Error(err))
|
chore.log.Error("error generating activation token", zap.Error(err))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
authController := consoleapi.NewAuth(chore.log, nil, nil, nil, nil, nil, nil, "", chore.address, "", "", "", "")
|
authController := consoleapi.NewAuth(chore.log, nil, nil, nil, nil, nil, "", chore.address, "", "", "", "")
|
||||||
|
|
||||||
link := authController.ActivateAccountURL + "?token=" + token
|
link := authController.ActivateAccountURL + "?token=" + token
|
||||||
userName := u.ShortName
|
userName := u.ShortName
|
||||||
|
@ -102,7 +102,6 @@ type Project struct {
|
|||||||
|
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
PartnerID uuid.UUID `json:"partnerId"`
|
|
||||||
UserAgent []byte `json:"userAgent"`
|
UserAgent []byte `json:"userAgent"`
|
||||||
OwnerID uuid.UUID `json:"ownerId"`
|
OwnerID uuid.UUID `json:"ownerId"`
|
||||||
RateLimit *int `json:"rateLimit"`
|
RateLimit *int `json:"rateLimit"`
|
||||||
|
@ -38,7 +38,6 @@ import (
|
|||||||
"storj.io/storj/satellite/mailservice"
|
"storj.io/storj/satellite/mailservice"
|
||||||
"storj.io/storj/satellite/payments"
|
"storj.io/storj/satellite/payments"
|
||||||
"storj.io/storj/satellite/payments/billing"
|
"storj.io/storj/satellite/payments/billing"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var mon = monkit.Package()
|
var mon = monkit.Package()
|
||||||
@ -135,7 +134,6 @@ type Service struct {
|
|||||||
projectAccounting accounting.ProjectAccounting
|
projectAccounting accounting.ProjectAccounting
|
||||||
projectUsage *accounting.Service
|
projectUsage *accounting.Service
|
||||||
buckets buckets.DB
|
buckets buckets.DB
|
||||||
partners *rewards.PartnersService
|
|
||||||
accounts payments.Accounts
|
accounts payments.Accounts
|
||||||
depositWallets payments.DepositWallets
|
depositWallets payments.DepositWallets
|
||||||
billing billing.TransactionsDB
|
billing billing.TransactionsDB
|
||||||
@ -208,7 +206,7 @@ type Payments struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns new instance of Service.
|
// NewService returns new instance of Service.
|
||||||
func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting accounting.ProjectAccounting, projectUsage *accounting.Service, buckets buckets.DB, partners *rewards.PartnersService, accounts payments.Accounts, depositWallets payments.DepositWallets, billing billing.TransactionsDB, analytics *analytics.Service, tokens *consoleauth.Service, mailService *mailservice.Service, satelliteAddress string, config Config) (*Service, error) {
|
func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting accounting.ProjectAccounting, projectUsage *accounting.Service, buckets buckets.DB, accounts payments.Accounts, depositWallets payments.DepositWallets, billing billing.TransactionsDB, analytics *analytics.Service, tokens *consoleauth.Service, mailService *mailservice.Service, satelliteAddress string, config Config) (*Service, error) {
|
||||||
if store == nil {
|
if store == nil {
|
||||||
return nil, errs.New("store can't be nil")
|
return nil, errs.New("store can't be nil")
|
||||||
}
|
}
|
||||||
@ -244,7 +242,6 @@ func NewService(log *zap.Logger, store DB, restKeys RESTKeys, projectAccounting
|
|||||||
projectAccounting: projectAccounting,
|
projectAccounting: projectAccounting,
|
||||||
projectUsage: projectUsage,
|
projectUsage: projectUsage,
|
||||||
buckets: buckets,
|
buckets: buckets,
|
||||||
partners: partners,
|
|
||||||
accounts: accounts,
|
accounts: accounts,
|
||||||
depositWallets: depositWallets,
|
depositWallets: depositWallets,
|
||||||
billing: billing,
|
billing: billing,
|
||||||
@ -1220,7 +1217,6 @@ func (s *Service) GenGetUser(ctx context.Context) (*ResponseUser, api.HTTPError)
|
|||||||
FullName: user.FullName,
|
FullName: user.FullName,
|
||||||
ShortName: user.ShortName,
|
ShortName: user.ShortName,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
PartnerID: user.PartnerID,
|
|
||||||
UserAgent: user.UserAgent,
|
UserAgent: user.UserAgent,
|
||||||
ProjectLimit: user.ProjectLimit,
|
ProjectLimit: user.ProjectLimit,
|
||||||
IsProfessional: user.IsProfessional,
|
IsProfessional: user.IsProfessional,
|
||||||
@ -1512,7 +1508,6 @@ func (s *Service) CreateProject(ctx context.Context, projectInfo ProjectInfo) (p
|
|||||||
Description: projectInfo.Description,
|
Description: projectInfo.Description,
|
||||||
Name: projectInfo.Name,
|
Name: projectInfo.Name,
|
||||||
OwnerID: user.ID,
|
OwnerID: user.ID,
|
||||||
PartnerID: user.PartnerID,
|
|
||||||
UserAgent: user.UserAgent,
|
UserAgent: user.UserAgent,
|
||||||
StorageLimit: &storageLimit,
|
StorageLimit: &storageLimit,
|
||||||
BandwidthLimit: &bandwidthLimit,
|
BandwidthLimit: &bandwidthLimit,
|
||||||
@ -1580,7 +1575,6 @@ func (s *Service) GenCreateProject(ctx context.Context, projectInfo ProjectInfo)
|
|||||||
Description: projectInfo.Description,
|
Description: projectInfo.Description,
|
||||||
Name: projectInfo.Name,
|
Name: projectInfo.Name,
|
||||||
OwnerID: user.ID,
|
OwnerID: user.ID,
|
||||||
PartnerID: user.PartnerID,
|
|
||||||
UserAgent: user.UserAgent,
|
UserAgent: user.UserAgent,
|
||||||
StorageLimit: &storageLimit,
|
StorageLimit: &storageLimit,
|
||||||
BandwidthLimit: &bandwidthLimit,
|
BandwidthLimit: &bandwidthLimit,
|
||||||
@ -2045,7 +2039,6 @@ func (s *Service) CreateAPIKey(ctx context.Context, projectID uuid.UUID, name st
|
|||||||
Name: name,
|
Name: name,
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
PartnerID: user.PartnerID,
|
|
||||||
UserAgent: user.UserAgent,
|
UserAgent: user.UserAgent,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2116,7 +2109,6 @@ func (s *Service) GenCreateAPIKey(ctx context.Context, requestInfo CreateAPIKeyR
|
|||||||
Name: requestInfo.Name,
|
Name: requestInfo.Name,
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
PartnerID: user.PartnerID,
|
|
||||||
UserAgent: user.UserAgent,
|
UserAgent: user.UserAgent,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -71,7 +71,6 @@ type CreateUser struct {
|
|||||||
FullName string `json:"fullName"`
|
FullName string `json:"fullName"`
|
||||||
ShortName string `json:"shortName"`
|
ShortName string `json:"shortName"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
PartnerID string `json:"partnerId"`
|
|
||||||
UserAgent []byte `json:"userAgent"`
|
UserAgent []byte `json:"userAgent"`
|
||||||
Password string `json:"password"`
|
Password string `json:"password"`
|
||||||
IsProfessional bool `json:"isProfessional"`
|
IsProfessional bool `json:"isProfessional"`
|
||||||
@ -99,13 +98,6 @@ func (user *CreateUser) IsValid() error {
|
|||||||
_, err := mail.ParseAddress(user.Email)
|
_, err := mail.ParseAddress(user.Email)
|
||||||
errgrp.Add(err)
|
errgrp.Add(err)
|
||||||
|
|
||||||
if user.PartnerID != "" {
|
|
||||||
_, err := uuid.FromString(user.PartnerID)
|
|
||||||
if err != nil {
|
|
||||||
errgrp.Add(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ErrValidation.Wrap(errgrp.Err())
|
return ErrValidation.Wrap(errgrp.Err())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -156,7 +148,6 @@ type User struct {
|
|||||||
PasswordHash []byte `json:"passwordHash"`
|
PasswordHash []byte `json:"passwordHash"`
|
||||||
|
|
||||||
Status UserStatus `json:"status"`
|
Status UserStatus `json:"status"`
|
||||||
PartnerID uuid.UUID `json:"partnerId"`
|
|
||||||
UserAgent []byte `json:"userAgent"`
|
UserAgent []byte `json:"userAgent"`
|
||||||
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
@ -195,7 +186,6 @@ type ResponseUser struct {
|
|||||||
FullName string `json:"fullName"`
|
FullName string `json:"fullName"`
|
||||||
ShortName string `json:"shortName"`
|
ShortName string `json:"shortName"`
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
PartnerID uuid.UUID `json:"partnerId"`
|
|
||||||
UserAgent []byte `json:"userAgent"`
|
UserAgent []byte `json:"userAgent"`
|
||||||
ProjectLimit int `json:"projectLimit"`
|
ProjectLimit int `json:"projectLimit"`
|
||||||
IsProfessional bool `json:"isProfessional"`
|
IsProfessional bool `json:"isProfessional"`
|
||||||
|
@ -43,21 +43,8 @@ const (
|
|||||||
func TestUserRepository(t *testing.T) {
|
func TestUserRepository(t *testing.T) {
|
||||||
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
satellitedbtest.Run(t, func(ctx *testcontext.Context, t *testing.T, db satellite.DB) {
|
||||||
repository := db.Console().Users()
|
repository := db.Console().Users()
|
||||||
partnerID := testrand.UUID()
|
|
||||||
|
|
||||||
// Test with and without partnerID
|
|
||||||
user := &console.User{
|
user := &console.User{
|
||||||
ID: testrand.UUID(),
|
|
||||||
FullName: name,
|
|
||||||
ShortName: lastName,
|
|
||||||
Email: email,
|
|
||||||
PartnerID: partnerID,
|
|
||||||
PasswordHash: []byte(passValid),
|
|
||||||
CreatedAt: time.Now(),
|
|
||||||
}
|
|
||||||
testUsers(ctx, t, repository, user)
|
|
||||||
|
|
||||||
user = &console.User{
|
|
||||||
ID: testrand.UUID(),
|
ID: testrand.UUID(),
|
||||||
FullName: name,
|
FullName: name,
|
||||||
ShortName: lastName,
|
ShortName: lastName,
|
||||||
@ -191,7 +178,6 @@ func testUsers(ctx context.Context, t *testing.T, repository console.Users, user
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, name, userByEmail.FullName)
|
assert.Equal(t, name, userByEmail.FullName)
|
||||||
assert.Equal(t, lastName, userByEmail.ShortName)
|
assert.Equal(t, lastName, userByEmail.ShortName)
|
||||||
assert.Equal(t, user.PartnerID, userByEmail.PartnerID)
|
|
||||||
assert.Equal(t, user.SignupPromoCode, userByEmail.SignupPromoCode)
|
assert.Equal(t, user.SignupPromoCode, userByEmail.SignupPromoCode)
|
||||||
assert.False(t, user.PaidTier)
|
assert.False(t, user.PaidTier)
|
||||||
assert.False(t, user.MFAEnabled)
|
assert.False(t, user.MFAEnabled)
|
||||||
@ -214,7 +200,6 @@ func testUsers(ctx context.Context, t *testing.T, repository console.Users, user
|
|||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, name, userByID.FullName)
|
assert.Equal(t, name, userByID.FullName)
|
||||||
assert.Equal(t, lastName, userByID.ShortName)
|
assert.Equal(t, lastName, userByID.ShortName)
|
||||||
assert.Equal(t, user.PartnerID, userByID.PartnerID)
|
|
||||||
assert.Equal(t, user.SignupPromoCode, userByID.SignupPromoCode)
|
assert.Equal(t, user.SignupPromoCode, userByID.SignupPromoCode)
|
||||||
assert.False(t, user.MFAEnabled)
|
assert.False(t, user.MFAEnabled)
|
||||||
assert.Empty(t, user.MFASecretKey)
|
assert.Empty(t, user.MFASecretKey)
|
||||||
@ -237,7 +222,6 @@ func testUsers(ctx context.Context, t *testing.T, repository console.Users, user
|
|||||||
assert.Equal(t, userByID.ShortName, userByEmail.ShortName)
|
assert.Equal(t, userByID.ShortName, userByEmail.ShortName)
|
||||||
assert.Equal(t, userByID.Email, userByEmail.Email)
|
assert.Equal(t, userByID.Email, userByEmail.Email)
|
||||||
assert.Equal(t, userByID.PasswordHash, userByEmail.PasswordHash)
|
assert.Equal(t, userByID.PasswordHash, userByEmail.PasswordHash)
|
||||||
assert.Equal(t, userByID.PartnerID, userByEmail.PartnerID)
|
|
||||||
assert.Equal(t, userByID.CreatedAt, userByEmail.CreatedAt)
|
assert.Equal(t, userByID.CreatedAt, userByEmail.CreatedAt)
|
||||||
assert.Equal(t, userByID.IsProfessional, userByEmail.IsProfessional)
|
assert.Equal(t, userByID.IsProfessional, userByEmail.IsProfessional)
|
||||||
assert.Equal(t, userByID.WorkingOn, userByEmail.WorkingOn)
|
assert.Equal(t, userByID.WorkingOn, userByEmail.WorkingOn)
|
||||||
@ -291,8 +275,6 @@ func testUsers(ctx context.Context, t *testing.T, repository console.Users, user
|
|||||||
assert.True(t, newUser.MFAEnabled)
|
assert.True(t, newUser.MFAEnabled)
|
||||||
assert.Equal(t, mfaSecretKey, newUser.MFASecretKey)
|
assert.Equal(t, mfaSecretKey, newUser.MFASecretKey)
|
||||||
assert.Equal(t, newUserInfo.MFARecoveryCodes, newUser.MFARecoveryCodes)
|
assert.Equal(t, newUserInfo.MFARecoveryCodes, newUser.MFARecoveryCodes)
|
||||||
// PartnerID should not change
|
|
||||||
assert.Equal(t, user.PartnerID, newUser.PartnerID)
|
|
||||||
assert.Equal(t, oldUser.CreatedAt, newUser.CreatedAt)
|
assert.Equal(t, oldUser.CreatedAt, newUser.CreatedAt)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ func (endpoint *Endpoint) ensureAttribution(ctx context.Context, header *pb.Requ
|
|||||||
if header == nil {
|
if header == nil {
|
||||||
return rpcstatus.Error(rpcstatus.InvalidArgument, "header is nil")
|
return rpcstatus.Error(rpcstatus.InvalidArgument, "header is nil")
|
||||||
}
|
}
|
||||||
if keyInfo.PartnerID.IsZero() && len(header.UserAgent) == 0 && len(keyInfo.UserAgent) == 0 && len(projectUserAgent) == 0 {
|
if len(header.UserAgent) == 0 && len(keyInfo.UserAgent) == 0 && len(projectUserAgent) == 0 {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,14 +47,13 @@ func (endpoint *Endpoint) ensureAttribution(ctx context.Context, header *pb.Requ
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
partnerID := keyInfo.PartnerID
|
|
||||||
userAgent := keyInfo.UserAgent
|
userAgent := keyInfo.UserAgent
|
||||||
if len(projectUserAgent) > 0 {
|
if len(projectUserAgent) > 0 {
|
||||||
userAgent = projectUserAgent
|
userAgent = projectUserAgent
|
||||||
}
|
}
|
||||||
|
|
||||||
// first check keyInfo (user) attribution
|
// first check keyInfo (user) attribution
|
||||||
if partnerID.IsZero() && userAgent == nil {
|
if userAgent == nil {
|
||||||
// otherwise, use header (partner tool) as attribution
|
// otherwise, use header (partner tool) as attribution
|
||||||
userAgent = header.UserAgent
|
userAgent = header.UserAgent
|
||||||
}
|
}
|
||||||
@ -64,7 +63,7 @@ func (endpoint *Endpoint) ensureAttribution(ctx context.Context, header *pb.Requ
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = endpoint.tryUpdateBucketAttribution(ctx, header, keyInfo.ProjectID, bucketName, partnerID, userAgent)
|
err = endpoint.tryUpdateBucketAttribution(ctx, header, keyInfo.ProjectID, bucketName, userAgent)
|
||||||
if errs2.IsRPC(err, rpcstatus.NotFound) || errs2.IsRPC(err, rpcstatus.AlreadyExists) {
|
if errs2.IsRPC(err, rpcstatus.NotFound) || errs2.IsRPC(err, rpcstatus.AlreadyExists) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -112,7 +111,7 @@ func TrimUserAgent(userAgent []byte) ([]byte, error) {
|
|||||||
return userAgent, nil
|
return userAgent, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (endpoint *Endpoint) tryUpdateBucketAttribution(ctx context.Context, header *pb.RequestHeader, projectID uuid.UUID, bucketName []byte, partnerID uuid.UUID, userAgent []byte) (err error) {
|
func (endpoint *Endpoint) tryUpdateBucketAttribution(ctx context.Context, header *pb.RequestHeader, projectID uuid.UUID, bucketName []byte, userAgent []byte) (err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
if header == nil {
|
if header == nil {
|
||||||
@ -137,7 +136,7 @@ func (endpoint *Endpoint) tryUpdateBucketAttribution(ctx context.Context, header
|
|||||||
return rpcstatus.Error(rpcstatus.Internal, Error.Wrap(err).Error())
|
return rpcstatus.Error(rpcstatus.Internal, Error.Wrap(err).Error())
|
||||||
}
|
}
|
||||||
if !empty {
|
if !empty {
|
||||||
return rpcstatus.Errorf(rpcstatus.AlreadyExists, "bucket %q is not empty, PartnerID %q cannot be attributed", bucketName, partnerID)
|
return rpcstatus.Errorf(rpcstatus.AlreadyExists, "bucket %q is not empty, Partner %q cannot be attributed", bucketName, userAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks if bucket exists before updates it or makes a new entry
|
// checks if bucket exists before updates it or makes a new entry
|
||||||
@ -149,12 +148,11 @@ func (endpoint *Endpoint) tryUpdateBucketAttribution(ctx context.Context, header
|
|||||||
endpoint.log.Error("error while getting bucket", zap.ByteString("bucketName", bucketName), zap.Error(err))
|
endpoint.log.Error("error while getting bucket", zap.ByteString("bucketName", bucketName), zap.Error(err))
|
||||||
return rpcstatus.Error(rpcstatus.Internal, "unable to set bucket attribution")
|
return rpcstatus.Error(rpcstatus.Internal, "unable to set bucket attribution")
|
||||||
}
|
}
|
||||||
if !bucket.PartnerID.IsZero() || bucket.UserAgent != nil {
|
if bucket.UserAgent != nil {
|
||||||
return rpcstatus.Errorf(rpcstatus.AlreadyExists, "bucket %q already has attribution, PartnerID %q cannot be attributed", bucketName, partnerID)
|
return rpcstatus.Errorf(rpcstatus.AlreadyExists, "bucket %q already has attribution, Partner %q cannot be attributed", bucketName, userAgent)
|
||||||
}
|
}
|
||||||
|
|
||||||
// update bucket information
|
// update bucket information
|
||||||
bucket.PartnerID = partnerID
|
|
||||||
bucket.UserAgent = userAgent
|
bucket.UserAgent = userAgent
|
||||||
_, err = endpoint.buckets.UpdateBucket(ctx, bucket)
|
_, err = endpoint.buckets.UpdateBucket(ctx, bucket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -166,7 +164,6 @@ func (endpoint *Endpoint) tryUpdateBucketAttribution(ctx context.Context, header
|
|||||||
_, err = endpoint.attributions.Insert(ctx, &attribution.Info{
|
_, err = endpoint.attributions.Insert(ctx, &attribution.Info{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
BucketName: bucketName,
|
BucketName: bucketName,
|
||||||
PartnerID: partnerID,
|
|
||||||
UserAgent: userAgent,
|
UserAgent: userAgent,
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -84,7 +84,6 @@ func TestBucketAttribution(t *testing.T) {
|
|||||||
user1, err := satellite.AddUser(ctx, console.CreateUser{
|
user1, err := satellite.AddUser(ctx, console.CreateUser{
|
||||||
FullName: "Test User " + strconv.Itoa(i),
|
FullName: "Test User " + strconv.Itoa(i),
|
||||||
Email: "user@test" + strconv.Itoa(i),
|
Email: "user@test" + strconv.Itoa(i),
|
||||||
PartnerID: "",
|
|
||||||
UserAgent: tt.signupPartner,
|
UserAgent: tt.signupPartner,
|
||||||
}, 1)
|
}, 1)
|
||||||
require.NoError(t, err, errTag)
|
require.NoError(t, err, errTag)
|
||||||
@ -161,7 +160,6 @@ func TestQueryAttribution(t *testing.T) {
|
|||||||
user, err := satellite.AddUser(ctx, console.CreateUser{
|
user, err := satellite.AddUser(ctx, console.CreateUser{
|
||||||
FullName: "user@test",
|
FullName: "user@test",
|
||||||
Email: "user@test",
|
Email: "user@test",
|
||||||
PartnerID: "",
|
|
||||||
UserAgent: []byte(userAgent),
|
UserAgent: []byte(userAgent),
|
||||||
}, 1)
|
}, 1)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
@ -228,12 +226,10 @@ func TestQueryAttribution(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotZero(t, usage.Egress)
|
require.NotZero(t, usage.Egress)
|
||||||
|
|
||||||
partner, _ := planet.Satellites[0].API.Marketing.PartnersService.ByName(ctx, "")
|
|
||||||
|
|
||||||
userAgent := []byte("Minio")
|
userAgent := []byte("Minio")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
rows, err := planet.Satellites[0].DB.Attribution().QueryAttribution(ctx, partner.UUID, userAgent, before, after)
|
rows, err := planet.Satellites[0].DB.Attribution().QueryAttribution(ctx, userAgent, before, after)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotZero(t, rows[0].ByteHours)
|
require.NotZero(t, rows[0].ByteHours)
|
||||||
require.Equal(t, rows[0].EgressData, usage.Egress)
|
require.Equal(t, rows[0].EgressData, usage.Egress)
|
||||||
@ -312,17 +308,13 @@ func TestAttributionReport(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotZero(t, usage.Egress)
|
require.NotZero(t, usage.Egress)
|
||||||
|
|
||||||
partner, _ := planet.Satellites[0].API.Marketing.PartnersService.ByUserAgent(ctx, "")
|
rows, err := planet.Satellites[0].DB.Attribution().QueryAttribution(ctx, []byte(zenkoStr), before, after)
|
||||||
|
|
||||||
rows, err := planet.Satellites[0].DB.Attribution().QueryAttribution(ctx, partner.UUID, []byte(zenkoStr), before, after)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.NotZero(t, rows[0].ByteHours)
|
require.NotZero(t, rows[0].ByteHours)
|
||||||
require.Equal(t, rows[0].EgressData, usage.Egress)
|
require.Equal(t, rows[0].EgressData, usage.Egress)
|
||||||
|
|
||||||
// Minio should have no attribution because bucket was created by Zenko
|
// Minio should have no attribution because bucket was created by Zenko
|
||||||
partner, _ = planet.Satellites[0].API.Marketing.PartnersService.ByUserAgent(ctx, "")
|
rows, err = planet.Satellites[0].DB.Attribution().QueryAttribution(ctx, []byte(minioStr), before, after)
|
||||||
|
|
||||||
rows, err = planet.Satellites[0].DB.Attribution().QueryAttribution(ctx, partner.UUID, []byte(minioStr), before, after)
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Empty(t, rows)
|
require.Empty(t, rows)
|
||||||
|
|
||||||
|
@ -29,7 +29,6 @@ import (
|
|||||||
"storj.io/storj/satellite/orders"
|
"storj.io/storj/satellite/orders"
|
||||||
"storj.io/storj/satellite/overlay"
|
"storj.io/storj/satellite/overlay"
|
||||||
"storj.io/storj/satellite/revocation"
|
"storj.io/storj/satellite/revocation"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -66,7 +65,6 @@ type Endpoint struct {
|
|||||||
orders *orders.Service
|
orders *orders.Service
|
||||||
overlay *overlay.Service
|
overlay *overlay.Service
|
||||||
attributions attribution.DB
|
attributions attribution.DB
|
||||||
partners *rewards.PartnersService
|
|
||||||
pointerVerification *pointerverification.Service
|
pointerVerification *pointerverification.Service
|
||||||
projectUsage *accounting.Service
|
projectUsage *accounting.Service
|
||||||
projects console.Projects
|
projects console.Projects
|
||||||
@ -83,7 +81,7 @@ type Endpoint struct {
|
|||||||
// NewEndpoint creates new metainfo endpoint instance.
|
// NewEndpoint creates new metainfo endpoint instance.
|
||||||
func NewEndpoint(log *zap.Logger, buckets *buckets.Service, metabaseDB *metabase.DB,
|
func NewEndpoint(log *zap.Logger, buckets *buckets.Service, metabaseDB *metabase.DB,
|
||||||
deletePieces *piecedeletion.Service, orders *orders.Service, cache *overlay.Service,
|
deletePieces *piecedeletion.Service, orders *orders.Service, cache *overlay.Service,
|
||||||
attributions attribution.DB, partners *rewards.PartnersService, peerIdentities overlay.PeerIdentities,
|
attributions attribution.DB, peerIdentities overlay.PeerIdentities,
|
||||||
apiKeys APIKeys, projectUsage *accounting.Service, projects console.Projects,
|
apiKeys APIKeys, projectUsage *accounting.Service, projects console.Projects,
|
||||||
satellite signing.Signer, revocations revocation.DB, config Config) (*Endpoint, error) {
|
satellite signing.Signer, revocations revocation.DB, config Config) (*Endpoint, error) {
|
||||||
// TODO do something with too many params
|
// TODO do something with too many params
|
||||||
@ -113,7 +111,6 @@ func NewEndpoint(log *zap.Logger, buckets *buckets.Service, metabaseDB *metabase
|
|||||||
orders: orders,
|
orders: orders,
|
||||||
overlay: cache,
|
overlay: cache,
|
||||||
attributions: attributions,
|
attributions: attributions,
|
||||||
partners: partners,
|
|
||||||
pointerVerification: pointerverification.NewService(peerIdentities),
|
pointerVerification: pointerverification.NewService(peerIdentities),
|
||||||
apiKeys: apiKeys,
|
apiKeys: apiKeys,
|
||||||
projectUsage: projectUsage,
|
projectUsage: projectUsage,
|
||||||
|
@ -166,7 +166,7 @@ func (endpoint *Endpoint) validateBasic(ctx context.Context, header *pb.RequestH
|
|||||||
ek.Event("auth",
|
ek.Event("auth",
|
||||||
eventkit.String("user-agent", userAgent),
|
eventkit.String("user-agent", userAgent),
|
||||||
eventkit.String("project", keyInfo.ProjectID.String()),
|
eventkit.String("project", keyInfo.ProjectID.String()),
|
||||||
eventkit.String("partner", keyInfo.PartnerID.String()),
|
eventkit.String("partner", string(keyInfo.UserAgent)),
|
||||||
)
|
)
|
||||||
|
|
||||||
if err = endpoint.checkRate(ctx, keyInfo.ProjectID); err != nil {
|
if err = endpoint.checkRate(ctx, keyInfo.ProjectID); err != nil {
|
||||||
|
@ -23,7 +23,6 @@ import (
|
|||||||
"storj.io/storj/satellite/payments"
|
"storj.io/storj/satellite/payments"
|
||||||
"storj.io/storj/satellite/payments/paymentsconfig"
|
"storj.io/storj/satellite/payments/paymentsconfig"
|
||||||
"storj.io/storj/satellite/payments/stripecoinpayments"
|
"storj.io/storj/satellite/payments/stripecoinpayments"
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestSignupCouponCodes(t *testing.T) {
|
func TestSignupCouponCodes(t *testing.T) {
|
||||||
@ -32,11 +31,6 @@ func TestSignupCouponCodes(t *testing.T) {
|
|||||||
db := sat.DB
|
db := sat.DB
|
||||||
log := zaptest.NewLogger(t)
|
log := zaptest.NewLogger(t)
|
||||||
|
|
||||||
partnersService := rewards.NewPartnersService(
|
|
||||||
log.Named("partners"),
|
|
||||||
rewards.DefaultPartnersDB,
|
|
||||||
)
|
|
||||||
|
|
||||||
analyticsService := analytics.NewService(log, analytics.Config{}, "test-satellite")
|
analyticsService := analytics.NewService(log, analytics.Config{}, "test-satellite")
|
||||||
|
|
||||||
redis, err := testredis.Mini(ctx)
|
redis, err := testredis.Mini(ctx)
|
||||||
@ -90,7 +84,6 @@ func TestSignupCouponCodes(t *testing.T) {
|
|||||||
db.ProjectAccounting(),
|
db.ProjectAccounting(),
|
||||||
projectUsage,
|
projectUsage,
|
||||||
sat.API.Buckets.Service,
|
sat.API.Buckets.Service,
|
||||||
partnersService,
|
|
||||||
paymentsService.Accounts(),
|
paymentsService.Accounts(),
|
||||||
// TODO: do we need a payment deposit wallet here?
|
// TODO: do we need a payment deposit wallet here?
|
||||||
nil,
|
nil,
|
||||||
|
@ -1,47 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package rewards
|
|
||||||
|
|
||||||
import (
|
|
||||||
"encoding/json"
|
|
||||||
"os"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/zeebo/errs"
|
|
||||||
|
|
||||||
"storj.io/common/uuid"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PartnerList defines a json struct for defining partners.
|
|
||||||
type PartnerList struct {
|
|
||||||
Partners []PartnerInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartnerInfo contains information about a partner.
|
|
||||||
type PartnerInfo struct {
|
|
||||||
Name string
|
|
||||||
ID string
|
|
||||||
UUID uuid.UUID
|
|
||||||
}
|
|
||||||
|
|
||||||
// UserAgent returns canonical user agent.
|
|
||||||
func (p *PartnerInfo) UserAgent() string { return p.Name }
|
|
||||||
|
|
||||||
// CanonicalUserAgentProduct returns canonicalizes the user agent product, which is suitable for lookups.
|
|
||||||
func CanonicalUserAgentProduct(product string) string { return strings.ToLower(product) }
|
|
||||||
|
|
||||||
// PartnersListFromJSONFile loads a json definition of partners.
|
|
||||||
func PartnersListFromJSONFile(path string) (*PartnerList, error) {
|
|
||||||
file, err := os.Open(path)
|
|
||||||
if err != nil {
|
|
||||||
return nil, ErrPartners.Wrap(err)
|
|
||||||
}
|
|
||||||
defer func() {
|
|
||||||
err = errs.Combine(err, ErrPartners.Wrap(file.Close()))
|
|
||||||
}()
|
|
||||||
|
|
||||||
var list PartnerList
|
|
||||||
err = json.NewDecoder(file).Decode(&list)
|
|
||||||
return &list, ErrPartners.Wrap(err)
|
|
||||||
}
|
|
@ -1,223 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package rewards
|
|
||||||
|
|
||||||
import "storj.io/common/uuid"
|
|
||||||
|
|
||||||
// DefaultPartnersDB is current default settings.
|
|
||||||
var DefaultPartnersDB = func() PartnersDB {
|
|
||||||
list := DefaultPartners()
|
|
||||||
db, err := NewPartnersStaticDB(&list)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return db
|
|
||||||
}()
|
|
||||||
|
|
||||||
// parseUUID parse string to UUID, should be used ONLY with hardcoded partner UUID's.
|
|
||||||
func parseUUID(s string) uuid.UUID {
|
|
||||||
u, err := uuid.FromString(s)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
return u
|
|
||||||
}
|
|
||||||
|
|
||||||
// DefaultPartners lists Storj default open-source partners.
|
|
||||||
func DefaultPartners() PartnerList {
|
|
||||||
return PartnerList{
|
|
||||||
Partners: []PartnerInfo{{
|
|
||||||
Name: "Blocknify",
|
|
||||||
ID: "120bf202-8252-437e-ac12-0e364bee852e",
|
|
||||||
UUID: parseUUID("120bf202-8252-437e-ac12-0e364bee852e"),
|
|
||||||
}, {
|
|
||||||
Name: "Breaker",
|
|
||||||
ID: "53688ea5-8695-4060-a2c6-b56969217909",
|
|
||||||
UUID: parseUUID("53688ea5-8695-4060-a2c6-b56969217909"),
|
|
||||||
}, {
|
|
||||||
Name: "CloudBloq",
|
|
||||||
ID: "ba1feac3-5457-4fd0-bba3-9c7e673902ca",
|
|
||||||
UUID: parseUUID("ba1feac3-5457-4fd0-bba3-9c7e673902ca"),
|
|
||||||
}, {
|
|
||||||
Name: "Confluent",
|
|
||||||
ID: "2fb801c6-a6d7-4d82-a838-32fef98cc398",
|
|
||||||
UUID: parseUUID("2fb801c6-a6d7-4d82-a838-32fef98cc398"),
|
|
||||||
}, {
|
|
||||||
Name: "Consensys",
|
|
||||||
ID: "e28c8847-b323-4a7d-8111-25a0578a58bb",
|
|
||||||
UUID: parseUUID("e28c8847-b323-4a7d-8111-25a0578a58bb"),
|
|
||||||
}, {
|
|
||||||
Name: "Couchbase",
|
|
||||||
ID: "0af89ac1-0189-42c6-a47c-e169780b3818",
|
|
||||||
UUID: parseUUID("0af89ac1-0189-42c6-a47c-e169780b3818"),
|
|
||||||
}, {
|
|
||||||
Name: "Digital Ocean",
|
|
||||||
ID: "881b92f6-77aa-42ee-961a-b80009d45dd8",
|
|
||||||
UUID: parseUUID("881b92f6-77aa-42ee-961a-b80009d45dd8"),
|
|
||||||
}, {
|
|
||||||
Name: "Deloitte",
|
|
||||||
ID: "cadac3fb-6a3f-4d17-9748-cc66d0617d55",
|
|
||||||
UUID: parseUUID("cadac3fb-6a3f-4d17-9748-cc66d0617d55"),
|
|
||||||
}, {
|
|
||||||
Name: "Duplicati",
|
|
||||||
ID: "261e368e-d888-4d8e-8aa7-694aed20043a",
|
|
||||||
UUID: parseUUID("261e368e-d888-4d8e-8aa7-694aed20043a"),
|
|
||||||
}, {
|
|
||||||
Name: "DVLabs",
|
|
||||||
ID: "53fb82d7-73ff-4a1a-ab0c-6968cffc850e",
|
|
||||||
UUID: parseUUID("53fb82d7-73ff-4a1a-ab0c-6968cffc850e"),
|
|
||||||
}, {
|
|
||||||
Name: "Fastly",
|
|
||||||
ID: "464699ba-301a-4c92-a740-692926d57661",
|
|
||||||
UUID: parseUUID("464699ba-301a-4c92-a740-692926d57661"),
|
|
||||||
}, {
|
|
||||||
Name: "Fluree",
|
|
||||||
ID: "86c33256-cded-434c-aaac-405343974394",
|
|
||||||
UUID: parseUUID("86c33256-cded-434c-aaac-405343974394"),
|
|
||||||
}, {
|
|
||||||
Name: "Flexential",
|
|
||||||
ID: "3e1b911a-c778-47ea-878c-9f3f264f8bc1",
|
|
||||||
UUID: parseUUID("3e1b911a-c778-47ea-878c-9f3f264f8bc1"),
|
|
||||||
}, {
|
|
||||||
Name: "GroundX",
|
|
||||||
ID: "e56c6a65-d5bf-457a-a414-e55c36624f73",
|
|
||||||
UUID: parseUUID("e56c6a65-d5bf-457a-a414-e55c36624f73"),
|
|
||||||
}, {
|
|
||||||
Name: "Heroku",
|
|
||||||
ID: "706011f3-400e-45eb-a796-90cce2a7d67e",
|
|
||||||
UUID: parseUUID("706011f3-400e-45eb-a796-90cce2a7d67e"),
|
|
||||||
}, {
|
|
||||||
Name: "Hypernet",
|
|
||||||
ID: "5abfc372-1d59-44fa-bbcc-bc3aa03a9542",
|
|
||||||
UUID: parseUUID("5abfc372-1d59-44fa-bbcc-bc3aa03a9542"),
|
|
||||||
}, {
|
|
||||||
Name: "Infura",
|
|
||||||
ID: "1519bdee-ed18-45fe-86c6-4c7fa9668a14",
|
|
||||||
UUID: parseUUID("1519bdee-ed18-45fe-86c6-4c7fa9668a14"),
|
|
||||||
}, {
|
|
||||||
Name: "Innovoedge",
|
|
||||||
ID: "bc1276a5-4ba8-4761-a164-e5a4a9f8593c",
|
|
||||||
UUID: parseUUID("bc1276a5-4ba8-4761-a164-e5a4a9f8593c"),
|
|
||||||
}, {
|
|
||||||
Name: "Jaxcom",
|
|
||||||
ID: "efb7b35a-9765-4e74-855f-5004336dc951",
|
|
||||||
UUID: parseUUID("efb7b35a-9765-4e74-855f-5004336dc951"),
|
|
||||||
}, {
|
|
||||||
Name: "key4web",
|
|
||||||
ID: "9af99cf8-d68b-48c8-95ab-ef39641b8b06",
|
|
||||||
UUID: parseUUID("9af99cf8-d68b-48c8-95ab-ef39641b8b06"),
|
|
||||||
}, {
|
|
||||||
Name: "MariaDB",
|
|
||||||
ID: "8ee019ef-2aae-4867-9c18-41c65ea318c4",
|
|
||||||
UUID: parseUUID("8ee019ef-2aae-4867-9c18-41c65ea318c4"),
|
|
||||||
}, {
|
|
||||||
Name: "MAXN",
|
|
||||||
ID: "3934efec-2857-4703-8ce3-aabf2d3285c4",
|
|
||||||
UUID: parseUUID("3934efec-2857-4703-8ce3-aabf2d3285c4"),
|
|
||||||
}, {
|
|
||||||
Name: "MongoDB",
|
|
||||||
ID: "bbd340b2-0ae4-4254-af90-eaba6c273abb",
|
|
||||||
UUID: parseUUID("bbd340b2-0ae4-4254-af90-eaba6c273abb"),
|
|
||||||
}, {
|
|
||||||
Name: "Netki",
|
|
||||||
ID: "3405a882-0cb2-4f91-a6e0-21be193b80e5",
|
|
||||||
UUID: parseUUID("3405a882-0cb2-4f91-a6e0-21be193b80e5"),
|
|
||||||
}, {
|
|
||||||
Name: "FileZilla",
|
|
||||||
ID: "a1ba07a4-e095-4a43-914c-1d56c9ff5afd",
|
|
||||||
UUID: parseUUID("a1ba07a4-e095-4a43-914c-1d56c9ff5afd"),
|
|
||||||
}, {
|
|
||||||
Name: "InfluxDB",
|
|
||||||
ID: "e50a17b3-4d82-4da7-8719-09312a83685d",
|
|
||||||
UUID: parseUUID("e50a17b3-4d82-4da7-8719-09312a83685d"),
|
|
||||||
}, {
|
|
||||||
Name: "Mysterium Network",
|
|
||||||
ID: "c10228c2-af70-4e4d-be49-e8bfbe9ca8ef",
|
|
||||||
UUID: parseUUID("c10228c2-af70-4e4d-be49-e8bfbe9ca8ef"),
|
|
||||||
}, {
|
|
||||||
Name: "Kafka",
|
|
||||||
ID: "OSPP005",
|
|
||||||
}, {
|
|
||||||
Name: "Kesque",
|
|
||||||
ID: "c6b01830-920c-4895-93f5-c0bd74fb44d8",
|
|
||||||
UUID: parseUUID("c6b01830-920c-4895-93f5-c0bd74fb44d8"),
|
|
||||||
}, {
|
|
||||||
Name: "Minio",
|
|
||||||
ID: "5bffe844-5da7-4aa9-bf37-7d695cf819f2",
|
|
||||||
UUID: parseUUID("5bffe844-5da7-4aa9-bf37-7d695cf819f2"),
|
|
||||||
}, {
|
|
||||||
Name: "MSP360",
|
|
||||||
ID: "f184948c-06e8-4edb-9a19-96667572d120",
|
|
||||||
UUID: parseUUID("f184948c-06e8-4edb-9a19-96667572d120"),
|
|
||||||
}, {
|
|
||||||
Name: "Nextcloud",
|
|
||||||
ID: "42f588fb-f39d-4886-81af-b614ca16ce37",
|
|
||||||
UUID: parseUUID("42f588fb-f39d-4886-81af-b614ca16ce37"),
|
|
||||||
}, {
|
|
||||||
Name: "Node Haven",
|
|
||||||
ID: "3b53a9b3-2005-476c-9ffd-894ed832abe4",
|
|
||||||
UUID: parseUUID("3b53a9b3-2005-476c-9ffd-894ed832abe4"),
|
|
||||||
}, {
|
|
||||||
Name: "Plesk",
|
|
||||||
ID: "dc01ed96-2990-4819-9cb3-45d4846b9ad1",
|
|
||||||
UUID: parseUUID("dc01ed96-2990-4819-9cb3-45d4846b9ad1"),
|
|
||||||
}, {
|
|
||||||
Name: "Pydio",
|
|
||||||
ID: "b02b9f0d-fac7-439c-8ba2-0c4634d5826f",
|
|
||||||
UUID: parseUUID("b02b9f0d-fac7-439c-8ba2-0c4634d5826f"),
|
|
||||||
}, {
|
|
||||||
Name: "Raiden Network",
|
|
||||||
ID: "57855387-5a58-4a2b-97d2-15b1d76eea3c",
|
|
||||||
UUID: parseUUID("57855387-5a58-4a2b-97d2-15b1d76eea3c"),
|
|
||||||
}, {
|
|
||||||
Name: "Rclone",
|
|
||||||
ID: "f746681d-91c1-4226-85c5-0cea4b66473b",
|
|
||||||
UUID: parseUUID("f746681d-91c1-4226-85c5-0cea4b66473b"),
|
|
||||||
}, {
|
|
||||||
Name: "Restic",
|
|
||||||
ID: "c59d86e9-3d23-406c-a97a-9751b552df75",
|
|
||||||
UUID: parseUUID("c59d86e9-3d23-406c-a97a-9751b552df75"),
|
|
||||||
}, {
|
|
||||||
Name: "Satoshi Soup",
|
|
||||||
ID: "4400d796-3777-4964-8536-22a4ae439ed3",
|
|
||||||
UUID: parseUUID("4400d796-3777-4964-8536-22a4ae439ed3"),
|
|
||||||
}, {
|
|
||||||
Name: "SeaweedFS",
|
|
||||||
ID: "4d704e1f-2432-426b-b2ca-61950f9db5c6",
|
|
||||||
UUID: parseUUID("4d704e1f-2432-426b-b2ca-61950f9db5c6"),
|
|
||||||
}, {
|
|
||||||
Name: "Sirin Labs",
|
|
||||||
ID: "6e40f882-ef77-4a5d-b5ad-18525d3df023",
|
|
||||||
UUID: parseUUID("6e40f882-ef77-4a5d-b5ad-18525d3df023"),
|
|
||||||
}, {
|
|
||||||
Name: "Status Messenger",
|
|
||||||
ID: "b6114126-c06d-49f9-8d23-3e0dd2e350ab",
|
|
||||||
UUID: parseUUID("b6114126-c06d-49f9-8d23-3e0dd2e350ab"),
|
|
||||||
}, {
|
|
||||||
Name: "Solutico",
|
|
||||||
ID: "64dad10a-afad-454e-a045-fbae043469e7",
|
|
||||||
UUID: parseUUID("64dad10a-afad-454e-a045-fbae043469e7"),
|
|
||||||
}, {
|
|
||||||
Name: "Taloflow",
|
|
||||||
ID: "72ef94a4-c8ab-49fa-b5f1-4824532c4205",
|
|
||||||
UUID: parseUUID("72ef94a4-c8ab-49fa-b5f1-4824532c4205"),
|
|
||||||
}, {
|
|
||||||
Name: "Temporal",
|
|
||||||
ID: "aeedbe32-1519-4320-b2f4-33725c65af54",
|
|
||||||
UUID: parseUUID("aeedbe32-1519-4320-b2f4-33725c65af54"),
|
|
||||||
}, {
|
|
||||||
Name: "Terminal.co",
|
|
||||||
ID: "7bf23e53-6393-4bd0-8bf9-53ecf0de742f",
|
|
||||||
UUID: parseUUID("7bf23e53-6393-4bd0-8bf9-53ecf0de742f"),
|
|
||||||
}, {
|
|
||||||
Name: "Videocoin",
|
|
||||||
ID: "76db19c1-f777-4334-912c-1d3e563e4e21",
|
|
||||||
UUID: parseUUID("76db19c1-f777-4334-912c-1d3e563e4e21"),
|
|
||||||
}, {
|
|
||||||
Name: "Zenko",
|
|
||||||
ID: "8cd605fa-ad00-45b6-823e-550eddc611d6",
|
|
||||||
UUID: parseUUID("8cd605fa-ad00-45b6-823e-550eddc611d6"),
|
|
||||||
}},
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,50 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package rewards_test
|
|
||||||
|
|
||||||
import (
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
"github.com/stretchr/testify/require"
|
|
||||||
|
|
||||||
"storj.io/common/testcontext"
|
|
||||||
"storj.io/storj/satellite/rewards"
|
|
||||||
)
|
|
||||||
|
|
||||||
func TestStaticDB(t *testing.T) {
|
|
||||||
ctx := testcontext.New(t)
|
|
||||||
defer ctx.Cleanup()
|
|
||||||
|
|
||||||
world := rewards.PartnerInfo{
|
|
||||||
Name: "World",
|
|
||||||
ID: "WORLD0",
|
|
||||||
}
|
|
||||||
|
|
||||||
hello := rewards.PartnerInfo{
|
|
||||||
Name: "Hello",
|
|
||||||
ID: "11111111-1111-1111-1111-111111111111",
|
|
||||||
}
|
|
||||||
|
|
||||||
db, err := rewards.NewPartnersStaticDB(&rewards.PartnerList{
|
|
||||||
Partners: []rewards.PartnerInfo{world, hello},
|
|
||||||
})
|
|
||||||
require.NotNil(t, db)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
byID, err := db.ByID(ctx, "WORLD0")
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, world, byID)
|
|
||||||
|
|
||||||
byName, err := db.ByName(ctx, "World")
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, world, byName)
|
|
||||||
|
|
||||||
byUserAgent, err := db.ByUserAgent(ctx, "wOrLd")
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, world, byUserAgent)
|
|
||||||
|
|
||||||
all, err := db.All(ctx)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.EqualValues(t, []rewards.PartnerInfo{hello, world}, all)
|
|
||||||
}
|
|
@ -1,71 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package rewards
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
|
|
||||||
"github.com/zeebo/errs"
|
|
||||||
"go.uber.org/zap"
|
|
||||||
|
|
||||||
"storj.io/common/useragent"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
|
||||||
// ErrPartners is the default error class for partners package.
|
|
||||||
ErrPartners = errs.Class("partners")
|
|
||||||
|
|
||||||
// ErrPartnerNotExist is returned when a particular partner does not exist.
|
|
||||||
ErrPartnerNotExist = errs.Class("partner does not exist")
|
|
||||||
)
|
|
||||||
|
|
||||||
// PartnersDB allows access to partners database.
|
|
||||||
//
|
|
||||||
// architecture: Database
|
|
||||||
type PartnersDB interface {
|
|
||||||
// All returns all partners.
|
|
||||||
All(ctx context.Context) ([]PartnerInfo, error)
|
|
||||||
// ByName returns partner definitions for a given name.
|
|
||||||
ByName(ctx context.Context, name string) (PartnerInfo, error)
|
|
||||||
// ByID returns partner definition corresponding to an id.
|
|
||||||
ByID(ctx context.Context, id string) (PartnerInfo, error)
|
|
||||||
// ByUserAgent returns partner definition corresponding to an user agent string.
|
|
||||||
ByUserAgent(ctx context.Context, agent string) (PartnerInfo, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
// PartnersService allows manipulating and accessing partner information.
|
|
||||||
//
|
|
||||||
// architecture: Service
|
|
||||||
type PartnersService struct {
|
|
||||||
log *zap.Logger
|
|
||||||
db PartnersDB
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewPartnersService returns a service for handling partner information.
|
|
||||||
func NewPartnersService(log *zap.Logger, db PartnersDB) *PartnersService {
|
|
||||||
return &PartnersService{
|
|
||||||
log: log,
|
|
||||||
db: db,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByName looks up partner by name.
|
|
||||||
func (service *PartnersService) ByName(ctx context.Context, name string) (PartnerInfo, error) {
|
|
||||||
return service.db.ByName(ctx, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByUserAgent looks up partner by user agent.
|
|
||||||
func (service *PartnersService) ByUserAgent(ctx context.Context, userAgentString string) (PartnerInfo, error) {
|
|
||||||
info, err := useragent.Parse(userAgentString)
|
|
||||||
if err != nil {
|
|
||||||
return PartnerInfo{}, ErrPartners.Wrap(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return service.db.ByUserAgent(ctx, info.Product.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// All returns all partners.
|
|
||||||
func (service *PartnersService) All(ctx context.Context) ([]PartnerInfo, error) {
|
|
||||||
return service.db.All(ctx)
|
|
||||||
}
|
|
@ -1,95 +0,0 @@
|
|||||||
// Copyright (C) 2019 Storj Labs, Inc.
|
|
||||||
// See LICENSE for copying information.
|
|
||||||
|
|
||||||
package rewards
|
|
||||||
|
|
||||||
import (
|
|
||||||
"context"
|
|
||||||
"sort"
|
|
||||||
"strings"
|
|
||||||
|
|
||||||
"github.com/zeebo/errs"
|
|
||||||
)
|
|
||||||
|
|
||||||
// PartnersStaticDB implements partner lookup based on a static definition.
|
|
||||||
//
|
|
||||||
// architecture: Database Implementation
|
|
||||||
type PartnersStaticDB struct {
|
|
||||||
list *PartnerList
|
|
||||||
byName map[string]PartnerInfo
|
|
||||||
byID map[string]PartnerInfo
|
|
||||||
byUserAgent map[string]PartnerInfo
|
|
||||||
}
|
|
||||||
|
|
||||||
var _ PartnersDB = (*PartnersStaticDB)(nil)
|
|
||||||
|
|
||||||
// NewPartnersStaticDB creates a new PartnersStaticDB.
|
|
||||||
func NewPartnersStaticDB(list *PartnerList) (*PartnersStaticDB, error) {
|
|
||||||
db := &PartnersStaticDB{
|
|
||||||
list: list,
|
|
||||||
byName: map[string]PartnerInfo{},
|
|
||||||
byID: map[string]PartnerInfo{},
|
|
||||||
byUserAgent: map[string]PartnerInfo{},
|
|
||||||
}
|
|
||||||
|
|
||||||
sort.Slice(list.Partners, func(i, k int) bool {
|
|
||||||
return list.Partners[i].Name < list.Partners[k].Name
|
|
||||||
})
|
|
||||||
|
|
||||||
var errg errs.Group
|
|
||||||
for _, p := range list.Partners {
|
|
||||||
name := strings.ToLower(p.Name)
|
|
||||||
if _, exists := db.byName[name]; exists {
|
|
||||||
errg.Add(ErrPartners.New("name %q already exists", p.Name))
|
|
||||||
} else {
|
|
||||||
db.byName[name] = p
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, exists := db.byID[p.ID]; exists {
|
|
||||||
errg.Add(ErrPartners.New("id %q already exists", p.ID))
|
|
||||||
} else {
|
|
||||||
db.byID[p.ID] = p
|
|
||||||
}
|
|
||||||
|
|
||||||
useragent := CanonicalUserAgentProduct(p.UserAgent())
|
|
||||||
if _, exists := db.byUserAgent[useragent]; exists {
|
|
||||||
errg.Add(ErrPartners.New("user agent %q already exists", useragent))
|
|
||||||
} else {
|
|
||||||
db.byUserAgent[useragent] = p
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return db, errg.Err()
|
|
||||||
}
|
|
||||||
|
|
||||||
// All returns all partners.
|
|
||||||
func (db *PartnersStaticDB) All(ctx context.Context) ([]PartnerInfo, error) {
|
|
||||||
return append([]PartnerInfo{}, db.list.Partners...), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByName returns partner definitions for a given name. Name is case insensitive.
|
|
||||||
func (db *PartnersStaticDB) ByName(ctx context.Context, name string) (PartnerInfo, error) {
|
|
||||||
partner, ok := db.byName[strings.ToLower(name)]
|
|
||||||
if !ok {
|
|
||||||
return PartnerInfo{}, ErrPartnerNotExist.New("%q", name)
|
|
||||||
}
|
|
||||||
return partner, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByID returns partner definition corresponding to an id.
|
|
||||||
func (db *PartnersStaticDB) ByID(ctx context.Context, id string) (PartnerInfo, error) {
|
|
||||||
partner, ok := db.byID[id]
|
|
||||||
if !ok {
|
|
||||||
return PartnerInfo{}, ErrPartnerNotExist.New("%q", id)
|
|
||||||
}
|
|
||||||
return partner, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ByUserAgent returns partner definition corresponding to an user agent product string.
|
|
||||||
func (db *PartnersStaticDB) ByUserAgent(ctx context.Context, agent string) (PartnerInfo, error) {
|
|
||||||
partner, ok := db.byUserAgent[CanonicalUserAgentProduct(agent)]
|
|
||||||
if !ok {
|
|
||||||
return PartnerInfo{}, ErrPartnerNotExist.New("%q", agent)
|
|
||||||
}
|
|
||||||
return partner, nil
|
|
||||||
}
|
|
@ -74,7 +74,7 @@ func (keys *apikeys) GetPagedByProjectID(ctx context.Context, projectID uuid.UUI
|
|||||||
}
|
}
|
||||||
|
|
||||||
repoundQuery := keys.db.Rebind(`
|
repoundQuery := keys.db.Rebind(`
|
||||||
SELECT ak.id, ak.project_id, ak.name, ak.partner_id, ak.user_agent, ak.created_at
|
SELECT ak.id, ak.project_id, ak.name, ak.user_agent, ak.created_at
|
||||||
FROM api_keys ak
|
FROM api_keys ak
|
||||||
WHERE ak.project_id = ?
|
WHERE ak.project_id = ?
|
||||||
AND lower(ak.name) LIKE ?
|
AND lower(ak.name) LIKE ?
|
||||||
@ -97,14 +97,12 @@ func (keys *apikeys) GetPagedByProjectID(ctx context.Context, projectID uuid.UUI
|
|||||||
var apiKeys []console.APIKeyInfo
|
var apiKeys []console.APIKeyInfo
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
ak := console.APIKeyInfo{}
|
ak := console.APIKeyInfo{}
|
||||||
var partnerID uuid.NullUUID
|
|
||||||
|
|
||||||
err = rows.Scan(&ak.ID, &ak.ProjectID, &ak.Name, &partnerID, &ak.UserAgent, &ak.CreatedAt)
|
err = rows.Scan(&ak.ID, &ak.ProjectID, &ak.Name, &ak.UserAgent, &ak.CreatedAt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
ak.PartnerID = partnerID.UUID
|
|
||||||
apiKeys = append(apiKeys, ak)
|
apiKeys = append(apiKeys, ak)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -176,10 +174,6 @@ func (keys *apikeys) Create(ctx context.Context, head []byte, info console.APIKe
|
|||||||
}
|
}
|
||||||
|
|
||||||
optional := dbx.ApiKey_Create_Fields{}
|
optional := dbx.ApiKey_Create_Fields{}
|
||||||
if !info.PartnerID.IsZero() {
|
|
||||||
optional.PartnerId = dbx.ApiKey_PartnerId(info.PartnerID[:])
|
|
||||||
}
|
|
||||||
|
|
||||||
if info.UserAgent != nil {
|
if info.UserAgent != nil {
|
||||||
optional.UserAgent = dbx.ApiKey_UserAgent(info.UserAgent)
|
optional.UserAgent = dbx.ApiKey_UserAgent(info.UserAgent)
|
||||||
}
|
}
|
||||||
@ -242,13 +236,6 @@ func fromDBXAPIKey(ctx context.Context, key *dbx.ApiKey) (_ *console.APIKeyInfo,
|
|||||||
Secret: key.Secret,
|
Secret: key.Secret,
|
||||||
}
|
}
|
||||||
|
|
||||||
if key.PartnerId != nil {
|
|
||||||
result.PartnerID, err = uuid.FromBytes(key.PartnerId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if key.UserAgent != nil {
|
if key.UserAgent != nil {
|
||||||
result.UserAgent = key.UserAgent
|
result.UserAgent = key.UserAgent
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ const (
|
|||||||
-- A union of both the storage tally and bandwidth rollups.
|
-- A union of both the storage tally and bandwidth rollups.
|
||||||
-- Should be 1 row per project/bucket by partner within the timeframe specified
|
-- Should be 1 row per project/bucket by partner within the timeframe specified
|
||||||
SELECT
|
SELECT
|
||||||
o.partner_id as partner_id,
|
|
||||||
o.user_agent as user_agent,
|
o.user_agent as user_agent,
|
||||||
o.project_id as project_id,
|
o.project_id as project_id,
|
||||||
o.bucket_name as bucket_name,
|
o.bucket_name as bucket_name,
|
||||||
@ -39,7 +38,6 @@ const (
|
|||||||
-- SUM the storage and hours
|
-- SUM the storage and hours
|
||||||
-- Hours are used to calculate byte hours above
|
-- Hours are used to calculate byte hours above
|
||||||
SELECT
|
SELECT
|
||||||
bsti.partner_id as partner_id,
|
|
||||||
bsti.user_agent as user_agent,
|
bsti.user_agent as user_agent,
|
||||||
bsto.project_id as project_id,
|
bsto.project_id as project_id,
|
||||||
bsto.bucket_name as bucket_name,
|
bsto.bucket_name as bucket_name,
|
||||||
@ -55,7 +53,6 @@ const (
|
|||||||
-- Collapse entries by the latest record in the hour
|
-- Collapse entries by the latest record in the hour
|
||||||
-- If there are more than 1 records within the hour, only the latest will be considered
|
-- If there are more than 1 records within the hour, only the latest will be considered
|
||||||
SELECT
|
SELECT
|
||||||
va.partner_id,
|
|
||||||
va.user_agent,
|
va.user_agent,
|
||||||
date_trunc('hour', bst.interval_start) as hours,
|
date_trunc('hour', bst.interval_start) as hours,
|
||||||
bst.project_id,
|
bst.project_id,
|
||||||
@ -68,12 +65,10 @@ const (
|
|||||||
AND bst.bucket_name = va.bucket_name
|
AND bst.bucket_name = va.bucket_name
|
||||||
)
|
)
|
||||||
WHERE
|
WHERE
|
||||||
va.partner_id = ?
|
va.user_agent = ?
|
||||||
AND va.user_agent = ?
|
|
||||||
AND bst.interval_start >= ?
|
AND bst.interval_start >= ?
|
||||||
AND bst.interval_start < ?
|
AND bst.interval_start < ?
|
||||||
GROUP BY
|
GROUP BY
|
||||||
va.partner_id,
|
|
||||||
va.user_agent,
|
va.user_agent,
|
||||||
bst.project_id,
|
bst.project_id,
|
||||||
bst.bucket_name,
|
bst.bucket_name,
|
||||||
@ -87,14 +82,12 @@ const (
|
|||||||
AND bsto.interval_start = bsti.max_interval
|
AND bsto.interval_start = bsti.max_interval
|
||||||
)
|
)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
bsti.partner_id,
|
|
||||||
bsti.user_agent,
|
bsti.user_agent,
|
||||||
bsto.project_id,
|
bsto.project_id,
|
||||||
bsto.bucket_name
|
bsto.bucket_name
|
||||||
UNION
|
UNION
|
||||||
-- SUM the bandwidth for the timeframe specified grouping by the partner_id, user_agent, project_id, and bucket_name
|
-- SUM the bandwidth for the timeframe specified grouping by the user_agent, project_id, and bucket_name
|
||||||
SELECT
|
SELECT
|
||||||
va.partner_id as partner_id,
|
|
||||||
va.user_agent as user_agent,
|
va.user_agent as user_agent,
|
||||||
bbr.project_id as project_id,
|
bbr.project_id as project_id,
|
||||||
bbr.bucket_name as bucket_name,
|
bbr.bucket_name as bucket_name,
|
||||||
@ -112,20 +105,17 @@ const (
|
|||||||
AND bbr.bucket_name = va.bucket_name
|
AND bbr.bucket_name = va.bucket_name
|
||||||
)
|
)
|
||||||
WHERE
|
WHERE
|
||||||
va.partner_id = ?
|
va.user_agent = ?
|
||||||
AND va.user_agent = ?
|
|
||||||
AND bbr.interval_start >= ?
|
AND bbr.interval_start >= ?
|
||||||
AND bbr.interval_start < ?
|
AND bbr.interval_start < ?
|
||||||
-- action 2 is GET
|
-- action 2 is GET
|
||||||
AND bbr.action = 2
|
AND bbr.action = 2
|
||||||
GROUP BY
|
GROUP BY
|
||||||
va.partner_id,
|
|
||||||
va.user_agent,
|
va.user_agent,
|
||||||
bbr.project_id,
|
bbr.project_id,
|
||||||
bbr.bucket_name
|
bbr.bucket_name
|
||||||
) AS o
|
) AS o
|
||||||
GROUP BY
|
GROUP BY
|
||||||
o.partner_id,
|
|
||||||
o.user_agent,
|
o.user_agent,
|
||||||
o.project_id,
|
o.project_id,
|
||||||
o.bucket_name;
|
o.bucket_name;
|
||||||
@ -134,7 +124,6 @@ const (
|
|||||||
-- A union of both the storage tally and bandwidth rollups.
|
-- A union of both the storage tally and bandwidth rollups.
|
||||||
-- Should be 1 row per project/bucket by partner within the timeframe specified
|
-- Should be 1 row per project/bucket by partner within the timeframe specified
|
||||||
SELECT
|
SELECT
|
||||||
o.partner_id as partner_id,
|
|
||||||
o.user_agent as user_agent,
|
o.user_agent as user_agent,
|
||||||
o.project_id as project_id,
|
o.project_id as project_id,
|
||||||
o.bucket_name as bucket_name,
|
o.bucket_name as bucket_name,
|
||||||
@ -150,7 +139,6 @@ const (
|
|||||||
-- SUM the storage and hours
|
-- SUM the storage and hours
|
||||||
-- Hours are used to calculate byte hours above
|
-- Hours are used to calculate byte hours above
|
||||||
SELECT
|
SELECT
|
||||||
bsti.partner_id as partner_id,
|
|
||||||
bsti.user_agent as user_agent,
|
bsti.user_agent as user_agent,
|
||||||
bsto.project_id as project_id,
|
bsto.project_id as project_id,
|
||||||
bsto.bucket_name as bucket_name,
|
bsto.bucket_name as bucket_name,
|
||||||
@ -166,7 +154,6 @@ const (
|
|||||||
-- Collapse entries by the latest record in the hour
|
-- Collapse entries by the latest record in the hour
|
||||||
-- If there are more than 1 records within the hour, only the latest will be considered
|
-- If there are more than 1 records within the hour, only the latest will be considered
|
||||||
SELECT
|
SELECT
|
||||||
va.partner_id,
|
|
||||||
va.user_agent,
|
va.user_agent,
|
||||||
date_trunc('hour', bst.interval_start) as hours,
|
date_trunc('hour', bst.interval_start) as hours,
|
||||||
bst.project_id,
|
bst.project_id,
|
||||||
@ -182,7 +169,6 @@ const (
|
|||||||
bst.interval_start >= $1
|
bst.interval_start >= $1
|
||||||
AND bst.interval_start < $2
|
AND bst.interval_start < $2
|
||||||
GROUP BY
|
GROUP BY
|
||||||
va.partner_id,
|
|
||||||
va.user_agent,
|
va.user_agent,
|
||||||
bst.project_id,
|
bst.project_id,
|
||||||
bst.bucket_name,
|
bst.bucket_name,
|
||||||
@ -196,14 +182,12 @@ const (
|
|||||||
AND bsto.interval_start = bsti.max_interval
|
AND bsto.interval_start = bsti.max_interval
|
||||||
)
|
)
|
||||||
GROUP BY
|
GROUP BY
|
||||||
bsti.partner_id,
|
|
||||||
bsti.user_agent,
|
bsti.user_agent,
|
||||||
bsto.project_id,
|
bsto.project_id,
|
||||||
bsto.bucket_name
|
bsto.bucket_name
|
||||||
UNION
|
UNION
|
||||||
-- SUM the bandwidth for the timeframe specified grouping by the partner_id, user_agent, project_id, and bucket_name
|
-- SUM the bandwidth for the timeframe specified grouping by the user_agent, project_id, and bucket_name
|
||||||
SELECT
|
SELECT
|
||||||
va.partner_id as partner_id,
|
|
||||||
va.user_agent as user_agent,
|
va.user_agent as user_agent,
|
||||||
bbr.project_id as project_id,
|
bbr.project_id as project_id,
|
||||||
bbr.bucket_name as bucket_name,
|
bbr.bucket_name as bucket_name,
|
||||||
@ -226,13 +210,11 @@ const (
|
|||||||
-- action 2 is GET
|
-- action 2 is GET
|
||||||
AND bbr.action = 2
|
AND bbr.action = 2
|
||||||
GROUP BY
|
GROUP BY
|
||||||
va.partner_id,
|
|
||||||
va.user_agent,
|
va.user_agent,
|
||||||
bbr.project_id,
|
bbr.project_id,
|
||||||
bbr.bucket_name
|
bbr.bucket_name
|
||||||
) AS o
|
) AS o
|
||||||
GROUP BY
|
GROUP BY
|
||||||
o.partner_id,
|
|
||||||
o.user_agent,
|
o.user_agent,
|
||||||
o.project_id,
|
o.project_id,
|
||||||
o.bucket_name;
|
o.bucket_name;
|
||||||
@ -270,7 +252,7 @@ func (keys *attributionDB) Insert(ctx context.Context, info *attribution.Info) (
|
|||||||
VALUES ($1, $2, $3, $4, now())
|
VALUES ($1, $2, $3, $4, now())
|
||||||
ON CONFLICT (project_id, bucket_name) DO NOTHING
|
ON CONFLICT (project_id, bucket_name) DO NOTHING
|
||||||
RETURNING last_updated
|
RETURNING last_updated
|
||||||
`, info.ProjectID[:], info.BucketName, info.PartnerID[:], info.UserAgent).Scan(&info.CreatedAt)
|
`, info.ProjectID[:], info.BucketName, "", info.UserAgent).Scan(&info.CreatedAt)
|
||||||
// TODO when sql.ErrNoRows is returned then CreatedAt is not set
|
// TODO when sql.ErrNoRows is returned then CreatedAt is not set
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return info, nil
|
return info, nil
|
||||||
@ -283,10 +265,10 @@ func (keys *attributionDB) Insert(ctx context.Context, info *attribution.Info) (
|
|||||||
}
|
}
|
||||||
|
|
||||||
// QueryAttribution queries partner bucket attribution data.
|
// QueryAttribution queries partner bucket attribution data.
|
||||||
func (keys *attributionDB) QueryAttribution(ctx context.Context, partnerID uuid.UUID, userAgent []byte, start time.Time, end time.Time) (_ []*attribution.BucketUsage, err error) {
|
func (keys *attributionDB) QueryAttribution(ctx context.Context, userAgent []byte, start time.Time, end time.Time) (_ []*attribution.BucketUsage, err error) {
|
||||||
defer mon.Task()(&ctx)(&err)
|
defer mon.Task()(&ctx)(&err)
|
||||||
|
|
||||||
rows, err := keys.db.DB.QueryContext(ctx, keys.db.Rebind(valueAttrQuery), partnerID[:], userAgent, start.UTC(), end.UTC(), partnerID[:], userAgent, start.UTC(), end.UTC())
|
rows, err := keys.db.DB.QueryContext(ctx, keys.db.Rebind(valueAttrQuery), userAgent, start.UTC(), end.UTC(), userAgent, start.UTC(), end.UTC())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Error.Wrap(err)
|
return nil, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -296,7 +278,7 @@ func (keys *attributionDB) QueryAttribution(ctx context.Context, partnerID uuid.
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
r := &attribution.BucketUsage{}
|
r := &attribution.BucketUsage{}
|
||||||
var inline, remote float64
|
var inline, remote float64
|
||||||
err := rows.Scan(&r.PartnerID, &r.UserAgent, &r.ProjectID, &r.BucketName, &r.ByteHours, &inline, &remote, &r.SegmentHours, &r.ObjectHours, &r.EgressData, &r.Hours)
|
err := rows.Scan(&r.UserAgent, &r.ProjectID, &r.BucketName, &r.ByteHours, &inline, &remote, &r.SegmentHours, &r.ObjectHours, &r.EgressData, &r.Hours)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return results, Error.Wrap(err)
|
return results, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -324,7 +306,7 @@ func (keys *attributionDB) QueryAllAttribution(ctx context.Context, start time.T
|
|||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
r := &attribution.BucketUsage{}
|
r := &attribution.BucketUsage{}
|
||||||
var inline, remote float64
|
var inline, remote float64
|
||||||
err := rows.Scan(&r.PartnerID, &r.UserAgent, &r.ProjectID, &r.BucketName, &r.ByteHours, &inline, &remote, &r.SegmentHours, &r.ObjectHours, &r.EgressData, &r.Hours)
|
err := rows.Scan(&r.UserAgent, &r.ProjectID, &r.BucketName, &r.ByteHours, &inline, &remote, &r.SegmentHours, &r.ObjectHours, &r.EgressData, &r.Hours)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return results, Error.Wrap(err)
|
return results, Error.Wrap(err)
|
||||||
}
|
}
|
||||||
@ -338,14 +320,7 @@ func (keys *attributionDB) QueryAllAttribution(ctx context.Context, start time.T
|
|||||||
}
|
}
|
||||||
|
|
||||||
func attributionFromDBX(info *dbx.ValueAttribution) (*attribution.Info, error) {
|
func attributionFromDBX(info *dbx.ValueAttribution) (*attribution.Info, error) {
|
||||||
partnerID, err := uuid.FromBytes(info.PartnerId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, Error.Wrap(err)
|
|
||||||
}
|
|
||||||
userAgent := info.UserAgent
|
userAgent := info.UserAgent
|
||||||
if err != nil {
|
|
||||||
return nil, Error.Wrap(err)
|
|
||||||
}
|
|
||||||
projectID, err := uuid.FromBytes(info.ProjectId)
|
projectID, err := uuid.FromBytes(info.ProjectId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, Error.Wrap(err)
|
return nil, Error.Wrap(err)
|
||||||
@ -354,7 +329,6 @@ func attributionFromDBX(info *dbx.ValueAttribution) (*attribution.Info, error) {
|
|||||||
return &attribution.Info{
|
return &attribution.Info{
|
||||||
ProjectID: projectID,
|
ProjectID: projectID,
|
||||||
BucketName: info.BucketName,
|
BucketName: info.BucketName,
|
||||||
PartnerID: partnerID,
|
|
||||||
UserAgent: userAgent,
|
UserAgent: userAgent,
|
||||||
CreatedAt: info.LastUpdated,
|
CreatedAt: info.LastUpdated,
|
||||||
}, nil
|
}, nil
|
||||||
|
@ -151,9 +151,6 @@ func (projects *projects) Insert(ctx context.Context, project *console.Project)
|
|||||||
}
|
}
|
||||||
|
|
||||||
createFields := dbx.Project_Create_Fields{}
|
createFields := dbx.Project_Create_Fields{}
|
||||||
if !project.PartnerID.IsZero() {
|
|
||||||
createFields.PartnerId = dbx.Project_PartnerId(project.PartnerID[:])
|
|
||||||
}
|
|
||||||
if project.UserAgent != nil {
|
if project.UserAgent != nil {
|
||||||
createFields.UserAgent = dbx.Project_UserAgent(project.UserAgent)
|
createFields.UserAgent = dbx.Project_UserAgent(project.UserAgent)
|
||||||
}
|
}
|
||||||
@ -402,14 +399,6 @@ func projectFromDBX(ctx context.Context, project *dbx.Project) (_ *console.Proje
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var partnerID uuid.UUID
|
|
||||||
if len(project.PartnerId) > 0 {
|
|
||||||
partnerID, err = uuid.FromBytes(project.PartnerId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var userAgent []byte
|
var userAgent []byte
|
||||||
if len(project.UserAgent) > 0 {
|
if len(project.UserAgent) > 0 {
|
||||||
userAgent = project.UserAgent
|
userAgent = project.UserAgent
|
||||||
@ -425,7 +414,6 @@ func projectFromDBX(ctx context.Context, project *dbx.Project) (_ *console.Proje
|
|||||||
PublicID: publicID,
|
PublicID: publicID,
|
||||||
Name: project.Name,
|
Name: project.Name,
|
||||||
Description: project.Description,
|
Description: project.Description,
|
||||||
PartnerID: partnerID,
|
|
||||||
UserAgent: userAgent,
|
UserAgent: userAgent,
|
||||||
OwnerID: ownerID,
|
OwnerID: ownerID,
|
||||||
RateLimit: project.RateLimit,
|
RateLimit: project.RateLimit,
|
||||||
|
@ -150,9 +150,6 @@ func (users *users) Insert(ctx context.Context, user *console.User) (_ *console.
|
|||||||
IsProfessional: dbx.User_IsProfessional(user.IsProfessional),
|
IsProfessional: dbx.User_IsProfessional(user.IsProfessional),
|
||||||
SignupPromoCode: dbx.User_SignupPromoCode(user.SignupPromoCode),
|
SignupPromoCode: dbx.User_SignupPromoCode(user.SignupPromoCode),
|
||||||
}
|
}
|
||||||
if !user.PartnerID.IsZero() {
|
|
||||||
optional.PartnerId = dbx.User_PartnerId(user.PartnerID[:])
|
|
||||||
}
|
|
||||||
if user.UserAgent != nil {
|
if user.UserAgent != nil {
|
||||||
optional.UserAgent = dbx.User_UserAgent(user.UserAgent)
|
optional.UserAgent = dbx.User_UserAgent(user.UserAgent)
|
||||||
}
|
}
|
||||||
@ -404,13 +401,6 @@ func userFromDBX(ctx context.Context, user *dbx.User) (_ *console.User, err erro
|
|||||||
SignupCaptcha: user.SignupCaptcha,
|
SignupCaptcha: user.SignupCaptcha,
|
||||||
}
|
}
|
||||||
|
|
||||||
if user.PartnerId != nil {
|
|
||||||
result.PartnerID, err = uuid.FromBytes(user.PartnerId)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if user.UserAgent != nil {
|
if user.UserAgent != nil {
|
||||||
result.UserAgent = user.UserAgent
|
result.UserAgent = user.UserAgent
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,6 @@ export class AuthHttpApi implements UsersApi {
|
|||||||
userResponse.shortName,
|
userResponse.shortName,
|
||||||
userResponse.email,
|
userResponse.email,
|
||||||
userResponse.partner,
|
userResponse.partner,
|
||||||
userResponse.partnerId,
|
|
||||||
userResponse.password,
|
userResponse.password,
|
||||||
userResponse.projectLimit,
|
userResponse.projectLimit,
|
||||||
userResponse.paidTier,
|
userResponse.paidTier,
|
||||||
@ -256,7 +255,6 @@ export class AuthHttpApi implements UsersApi {
|
|||||||
shortName: user.shortName,
|
shortName: user.shortName,
|
||||||
email: user.email,
|
email: user.email,
|
||||||
partner: user.partner || '',
|
partner: user.partner || '',
|
||||||
partnerId: user.partnerId || '',
|
|
||||||
isProfessional: user.isProfessional,
|
isProfessional: user.isProfessional,
|
||||||
position: user.position,
|
position: user.position,
|
||||||
companyName: user.companyName,
|
companyName: user.companyName,
|
||||||
|
@ -6,7 +6,6 @@ import { HttpClient } from '@/utils/httpClient';
|
|||||||
class APIKeyInfo {
|
class APIKeyInfo {
|
||||||
id: string;
|
id: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
partnerId: string;
|
|
||||||
userAgent: string;
|
userAgent: string;
|
||||||
name: string;
|
name: string;
|
||||||
createdAt: string;
|
createdAt: string;
|
||||||
@ -53,7 +52,6 @@ class Project {
|
|||||||
publicId: string;
|
publicId: string;
|
||||||
name: string;
|
name: string;
|
||||||
description: string;
|
description: string;
|
||||||
partnerId: string;
|
|
||||||
userAgent: string;
|
userAgent: string;
|
||||||
ownerId: string;
|
ownerId: string;
|
||||||
rateLimit: number;
|
rateLimit: number;
|
||||||
@ -63,6 +61,8 @@ class Project {
|
|||||||
memberCount: number;
|
memberCount: number;
|
||||||
storageLimit: string;
|
storageLimit: string;
|
||||||
bandwidthLimit: string;
|
bandwidthLimit: string;
|
||||||
|
userSpecifiedStorageLimit: string;
|
||||||
|
userSpecifiedBandwidthLimit: string;
|
||||||
segmentLimit: number;
|
segmentLimit: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,7 +79,6 @@ class ResponseUser {
|
|||||||
fullName: string;
|
fullName: string;
|
||||||
shortName: string;
|
shortName: string;
|
||||||
email: string;
|
email: string;
|
||||||
partnerId: string;
|
|
||||||
userAgent: string;
|
userAgent: string;
|
||||||
projectLimit: number;
|
projectLimit: number;
|
||||||
isProfessional: boolean;
|
isProfessional: boolean;
|
||||||
|
@ -63,7 +63,6 @@ export class User {
|
|||||||
public shortName: string = '',
|
public shortName: string = '',
|
||||||
public email: string = '',
|
public email: string = '',
|
||||||
public partner: string = '',
|
public partner: string = '',
|
||||||
public partnerId: string = '',
|
|
||||||
public password: string = '',
|
public password: string = '',
|
||||||
public projectLimit: number = 0,
|
public projectLimit: number = 0,
|
||||||
public paidTier: boolean = false,
|
public paidTier: boolean = false,
|
||||||
|
@ -35,7 +35,7 @@ localVue.use(Vuex);
|
|||||||
const usersApi = new UsersApiMock();
|
const usersApi = new UsersApiMock();
|
||||||
const projectsApi = new ProjectsApiMock();
|
const projectsApi = new ProjectsApiMock();
|
||||||
|
|
||||||
usersApi.setMockUser(new User('1', '2', '3', '4', '5', '6', '7', 1));
|
usersApi.setMockUser(new User('1', '2', '3', '4', '5', '6', 1));
|
||||||
projectsApi.setMockProjects([]);
|
projectsApi.setMockProjects([]);
|
||||||
|
|
||||||
const usersModule = makeUsersModule(usersApi);
|
const usersModule = makeUsersModule(usersApi);
|
||||||
|
@ -208,7 +208,6 @@ describe('actions', () => {
|
|||||||
expect(state.page.projectMembers[0].joinedAt).toBe(projectMember1.joinedAt);
|
expect(state.page.projectMembers[0].joinedAt).toBe(projectMember1.joinedAt);
|
||||||
expect(state.page.projectMembers[0].user.email).toBe(projectMember1.user.email);
|
expect(state.page.projectMembers[0].user.email).toBe(projectMember1.user.email);
|
||||||
expect(state.page.projectMembers[0].user.id).toBe(projectMember1.user.id);
|
expect(state.page.projectMembers[0].user.id).toBe(projectMember1.user.id);
|
||||||
expect(state.page.projectMembers[0].user.partnerId).toBe(projectMember1.user.partnerId);
|
|
||||||
expect(state.page.projectMembers[0].user.fullName).toBe(projectMember1.user.fullName);
|
expect(state.page.projectMembers[0].user.fullName).toBe(projectMember1.user.fullName);
|
||||||
expect(state.page.projectMembers[0].user.shortName).toBe(projectMember1.user.shortName);
|
expect(state.page.projectMembers[0].user.shortName).toBe(projectMember1.user.shortName);
|
||||||
});
|
});
|
||||||
|
@ -88,7 +88,6 @@ describe('actions', () => {
|
|||||||
expect(store.state.user.fullName).toBe('');
|
expect(store.state.user.fullName).toBe('');
|
||||||
expect(store.state.user.shortName).toBe('');
|
expect(store.state.user.shortName).toBe('');
|
||||||
expect(store.state.user.email).toBe('');
|
expect(store.state.user.email).toBe('');
|
||||||
expect(store.state.user.partnerId).toBe('');
|
|
||||||
expect(store.state.user.id).toBe('');
|
expect(store.state.user.id).toBe('');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user