8f4a6afc8a
* Move value attribution to satellite/ * remove unnecessary conversion
67 lines
1.6 KiB
Go
67 lines
1.6 KiB
Go
// Copyright (C) 2019 Storj Labs, Inc.
|
|
// See LICENSE for copying information.
|
|
|
|
package satellitedb
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/skyrings/skyring-common/tools/uuid"
|
|
|
|
"storj.io/storj/satellite/attribution"
|
|
dbx "storj.io/storj/satellite/satellitedb/dbx"
|
|
)
|
|
|
|
type attributionDB struct {
|
|
db *dbx.DB
|
|
}
|
|
|
|
// Get reads the partner info
|
|
func (keys *attributionDB) Get(ctx context.Context, projectID uuid.UUID, bucketName []byte) (info *attribution.Info, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
dbxInfo, err := keys.db.Get_ValueAttribution_By_ProjectId_And_BucketName(ctx,
|
|
dbx.ValueAttribution_ProjectId(projectID[:]),
|
|
dbx.ValueAttribution_BucketName(bucketName),
|
|
)
|
|
if err != nil {
|
|
return nil, Error.Wrap(err)
|
|
}
|
|
|
|
return attributionFromDBX(dbxInfo)
|
|
}
|
|
|
|
// Insert implements create partner info
|
|
func (keys *attributionDB) Insert(ctx context.Context, info *attribution.Info) (_ *attribution.Info, err error) {
|
|
defer mon.Task()(&ctx)(&err)
|
|
|
|
dbxInfo, err := keys.db.Create_ValueAttribution(ctx,
|
|
dbx.ValueAttribution_ProjectId(info.ProjectID[:]),
|
|
dbx.ValueAttribution_BucketName(info.BucketName),
|
|
dbx.ValueAttribution_PartnerId(info.PartnerID[:]),
|
|
)
|
|
if err != nil {
|
|
return nil, Error.Wrap(err)
|
|
}
|
|
|
|
return attributionFromDBX(dbxInfo)
|
|
}
|
|
|
|
func attributionFromDBX(info *dbx.ValueAttribution) (*attribution.Info, error) {
|
|
partnerID, err := bytesToUUID(info.PartnerId)
|
|
if err != nil {
|
|
return nil, Error.Wrap(err)
|
|
}
|
|
projectID, err := bytesToUUID(info.ProjectId)
|
|
if err != nil {
|
|
return nil, Error.Wrap(err)
|
|
}
|
|
|
|
return &attribution.Info{
|
|
ProjectID: projectID,
|
|
BucketName: info.BucketName,
|
|
PartnerID: partnerID,
|
|
CreatedAt: info.LastUpdated,
|
|
}, nil
|
|
}
|