storj/satellite/attribution/db.go
Vitalii 1eee2fad69 satellite/{db, admin}: added endpoints to update user's and project's user_agent
Added backend (for now) implementation for updating user's and projects's user_agent using admin API.
Updating both user and project also updates bucket_metainfo and value_attribution tables.

Issue:
https://github.com/storj/storj-private/issues/297

Change-Id: I40244bbaa08b46834c1b1d0720e7d84d0c2a0330
2023-06-16 19:41:05 +00:00

54 lines
1.7 KiB
Go

// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
// Package attribution implements value attribution from docs/design/value-attribution.md
package attribution
import (
"context"
"time"
"github.com/zeebo/errs"
"storj.io/common/uuid"
)
// ErrBucketNotAttributed is returned if a requested bucket not attributed(entry not found).
var ErrBucketNotAttributed = errs.Class("bucket not attributed")
// Info describing value attribution from partner to bucket.
type Info struct {
ProjectID uuid.UUID
BucketName []byte
UserAgent []byte
CreatedAt time.Time
}
// BucketUsage is the usage data for a single bucket.
type BucketUsage struct {
UserAgent []byte
ProjectID []byte
BucketName []byte
ByteHours float64
SegmentHours float64
ObjectHours float64
EgressData int64
Hours int
}
// DB implements the database for value attribution table.
//
// architecture: Database
type DB interface {
// Get retrieves attribution info using project id and bucket name.
Get(ctx context.Context, projectID uuid.UUID, bucketName []byte) (*Info, error)
// Insert creates and stores new Info.
Insert(ctx context.Context, info *Info) (*Info, error)
// UpdateUserAgent updates bucket attribution data.
UpdateUserAgent(ctx context.Context, projectID uuid.UUID, bucketName string, userAgent []byte) error
// QueryAttribution queries partner bucket attribution data.
QueryAttribution(ctx context.Context, userAgent []byte, start time.Time, end time.Time) ([]*BucketUsage, error)
// QueryAllAttribution queries all partner bucket usage data.
QueryAllAttribution(ctx context.Context, start time.Time, end time.Time) ([]*BucketUsage, error)
}