satellites reject expired BWAs (#1015)

* add 45 day expiration to PBAs

* add expiration field to relevant areas, DeleteExpired placeholder

* reject expired BWAs

* test for expired BWAs

* add BwExpiration config value
This commit is contained in:
Cameron 2019-01-10 13:30:55 -05:00 committed by GitHub
parent 0642592420
commit ef50bbf8b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 187 additions and 50 deletions

View File

@ -77,7 +77,7 @@ func TestQueryWithBw(t *testing.T) {
func makeBWA(ctx context.Context, t *testing.T, bwDb bwagreement.DB, serialNum string, k *ecdsa.PrivateKey, action pb.PayerBandwidthAllocation_Action) {
//generate an agreement with the key
pba, err := test.GeneratePayerBandwidthAllocation(action, k, k)
pba, err := test.GeneratePayerBandwidthAllocation(action, k, k, false)
assert.NoError(t, err)
rba, err := test.GenerateRenterBandwidthAllocation(pba, teststorj.NodeIDFromString("StorageNodeID"), k)
assert.NoError(t, err)

View File

@ -40,6 +40,7 @@ type Agreement struct {
Agreement []byte
Signature []byte
CreatedAt time.Time
ExpiresAt time.Time
}
// NewServer creates instance of Server
@ -65,7 +66,6 @@ func (s *Server) BandwidthAgreements(ctx context.Context, ba *pb.RenterBandwidth
return reply, err
}
//Deserealize RenterBandwidthAllocation.GetData() so we can get public key
rbad := &pb.RenterBandwidthAllocation_Data{}
if err = proto.Unmarshal(ba.GetData(), rbad); err != nil {
return reply, BwAgreementError.New("Failed to unmarshal RenterBandwidthAllocation: %+v", err)
@ -83,13 +83,20 @@ func (s *Server) BandwidthAgreements(ctx context.Context, ba *pb.RenterBandwidth
serialNum := pbad.GetSerialNumber() + rbad.StorageNodeId.String()
// get and check expiration
exp := time.Unix(pbad.GetExpirationUnixSec(), 0).UTC()
if exp.Before(time.Now().UTC()) {
return reply, BwAgreementError.New("Bandwidth agreement is expired (%v)", exp)
}
err = s.db.CreateAgreement(ctx, serialNum, Agreement{
Signature: ba.GetSignature(),
Agreement: ba.GetData(),
ExpiresAt: exp,
})
if err != nil {
return reply, BwAgreementError.New("SerialNumber already exist in the PayerBandwidthAllocation")
return reply, BwAgreementError.New("SerialNumber already exists in the PayerBandwidthAllocation")
}
reply.Status = pb.AgreementsSummary_OK

View File

@ -20,7 +20,7 @@ import (
)
//GeneratePayerBandwidthAllocation creates a signed PayerBandwidthAllocation from a PayerBandwidthAllocation_Action
func GeneratePayerBandwidthAllocation(action pb.PayerBandwidthAllocation_Action, satelliteKey crypto.PrivateKey, uplinkKey crypto.PrivateKey) (*pb.PayerBandwidthAllocation, error) {
func GeneratePayerBandwidthAllocation(action pb.PayerBandwidthAllocation_Action, satelliteKey crypto.PrivateKey, uplinkKey crypto.PrivateKey, expired bool) (*pb.PayerBandwidthAllocation, error) {
satelliteKeyEcdsa, ok := satelliteKey.(*ecdsa.PrivateKey)
if !ok {
return nil, errs.New("Satellite Private Key is not a valid *ecdsa.PrivateKey")
@ -36,12 +36,20 @@ func GeneratePayerBandwidthAllocation(action pb.PayerBandwidthAllocation_Action,
return nil, err
}
// generate expiration date
var exp int64
if expired {
exp = time.Now().AddDate(0, 0, -5).Unix()
} else {
exp = time.Now().Add(time.Hour * 24 * 10).Unix()
}
// Generate PayerBandwidthAllocation_Data
data, _ := proto.Marshal(
&pb.PayerBandwidthAllocation_Data{
SatelliteId: teststorj.NodeIDFromString("SatelliteID"),
UplinkId: teststorj.NodeIDFromString("UplinkID"),
ExpirationUnixSec: time.Now().Add(time.Hour * 24 * 10).Unix(),
ExpirationUnixSec: exp,
SerialNumber: serialNum.String(),
Action: action,
CreatedUnixSec: time.Now().Unix(),

View File

@ -33,7 +33,7 @@ func TestSameSerialNumberBandwidthAgreements(t *testing.T) {
satellitePubKey, satellitePrivKey, uplinkPrivKey := generateKeys(ctx, t)
server := bwagreement.NewServer(db.BandwidthAgreement(), zap.NewNop(), satellitePubKey)
pbaFile1, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey, uplinkPrivKey)
pbaFile1, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey, uplinkPrivKey, false)
assert.NoError(t, err)
rbaNode1, err := GenerateRenterBandwidthAllocation(pbaFile1, teststorj.NodeIDFromString("Storage node 1"), uplinkPrivKey)
@ -52,7 +52,7 @@ func TestSameSerialNumberBandwidthAgreements(t *testing.T) {
/* Storage node can submit a second bwagreement with a different sequence value.
Uplink downloads another file. New PayerBandwidthAllocation with a new sequence. */
pbaFile2, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey, uplinkPrivKey)
pbaFile2, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey, uplinkPrivKey, false)
assert.NoError(t, err)
rbaNode1, err = GenerateRenterBandwidthAllocation(pbaFile2, teststorj.NodeIDFromString("Storage node 1"), uplinkPrivKey)
@ -66,41 +66,50 @@ func TestSameSerialNumberBandwidthAgreements(t *testing.T) {
rbaNode1, err = GenerateRenterBandwidthAllocation(pbaFile1, teststorj.NodeIDFromString("Storage node 1"), uplinkPrivKey)
assert.NoError(t, err)
//TODO: return custom error message in the event of "UNIQUE constraint failed..."
reply, err = server.BandwidthAgreements(ctx, rbaNode1)
assert.EqualError(t, err, "bwagreement error: SerialNumber already exist in the PayerBandwidthAllocation")
assert.EqualError(t, err, "bwagreement error: SerialNumber already exists in the PayerBandwidthAllocation")
assert.Equal(t, pb.AgreementsSummary_FAIL, reply.Status)
/* Storage nodes can't submit the same bwagreement twice.
This test is kind of duplicate cause it will most likely trigger the same sequence error.
For safety we will try it anyway to make sure nothing strange will happen */
reply, err = server.BandwidthAgreements(ctx, rbaNode2)
assert.EqualError(t, err, "bwagreement error: SerialNumber already exist in the PayerBandwidthAllocation")
assert.EqualError(t, err, "bwagreement error: SerialNumber already exists in the PayerBandwidthAllocation")
assert.Equal(t, pb.AgreementsSummary_FAIL, reply.Status)
})
}
func TestInvalidBandwidthAgreements(t *testing.T) {
satellitedbtest.Run(t, func(t *testing.T, db satellite.DB) {
/* Todo: Add more tests for bwagreement manipulations
ctx := testcontext.New(t)
defer ctx.Cleanup()
satellitePubKey, satellitePrivKey, uplinkPrivKey := generateKeys(ctx, t)
server := bwagreement.NewServer(db.BandwidthAgreement(), zap.NewNop(), satellitePubKey)
pba, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey, uplinkPrivKey)
pba, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey, uplinkPrivKey, false)
assert.NoError(t, err)
rba, err := GenerateRenterBandwidthAllocation(pba, teststorj.NodeIDFromString("Storage node 1"), uplinkPrivKey)
assert.NoError(t, err)
Make sure the bwagreement we are using as bluleprint is valid and avoid false positives that way.
// Make sure the bwagreement we are using as blueprint is valid and avoid false positives that way.
reply, err := server.BandwidthAgreements(ctx, rba)
assert.NoError(t, err)
assert.Equal(t, pb.AgreementsSummary_OK, reply.Status)
*/
// storage nodes can't submit an expired bwagreement
expPBA, err := GeneratePayerBandwidthAllocation(pb.PayerBandwidthAllocation_GET, satellitePrivKey, uplinkPrivKey, true)
assert.NoError(t, err)
rba, err = GenerateRenterBandwidthAllocation(expPBA, teststorj.NodeIDFromString("Storage node 1"), uplinkPrivKey)
assert.NoError(t, err)
reply, err = server.BandwidthAgreements(ctx, rba)
assert.Error(t, err)
assert.Equal(t, pb.AgreementsSummary_FAIL, reply.Status)
/* Todo: Add more tests for bwagreement manipulations
/* copy and unmarshal pba and rba to manipulate it without overwriting it */

View File

@ -34,6 +34,7 @@ type Config struct {
MinRemoteSegmentSize int `default:"1240" help:"minimum remote segment size"`
MaxInlineSegmentSize int `default:"8000" help:"maximum inline segment size"`
Overlay bool `default:"true" help:"toggle flag if overlay is enabled"`
BwExpiration int `default:"45" help:"lifespan of bandwidth agreements in days"`
}
func newKeyValueStore(dbURLString string) (db storage.KeyValueStore, err error) {

View File

@ -337,13 +337,20 @@ func (s *Server) PayerBandwidthAllocation(ctx context.Context, req *pb.PayerBand
return nil, err
}
created := time.Now().Unix()
// convert ttl from days to seconds
ttl := s.config.BwExpiration
ttl *= 86400
pbad := &pb.PayerBandwidthAllocation_Data{
SatelliteId: payer,
UplinkId: pi.ID,
CreatedUnixSec: time.Now().Unix(),
Action: req.GetAction(),
SerialNumber: serialNum.String(),
PubKey: pubbytes,
SatelliteId: payer,
UplinkId: pi.ID,
CreatedUnixSec: created,
ExpirationUnixSec: created + int64(ttl),
Action: req.GetAction(),
SerialNumber: serialNum.String(),
PubKey: pubbytes,
}
data, err := proto.Marshal(pbad)

View File

@ -21,6 +21,7 @@ func (b *bandwidthagreement) CreateAgreement(ctx context.Context, serialNum stri
dbx.Bwagreement_Signature(agreement.Signature),
dbx.Bwagreement_Serialnum(serialNum),
dbx.Bwagreement_Data(agreement.Agreement),
dbx.Bwagreement_ExpiresAt(agreement.ExpiresAt),
)
return err
}
@ -56,3 +57,8 @@ func (b *bandwidthagreement) GetAgreementsSince(ctx context.Context, since time.
}
return agreements, nil
}
func (b *bandwidthagreement) DeletePaidAndExpired(ctx context.Context) error {
// TODO: implement deletion of paid and expired BWAs
return Error.New("DeletePaidAndExpired not implemented")
}

View File

@ -10,10 +10,12 @@ model bwagreement (
field serialnum text
field data blob
field created_at timestamp ( autoinsert )
field expires_at timestamp
)
create bwagreement ( )
delete bwagreement ( where bwagreement.signature = ? )
delete bwagreement ( where bwagreement.expires_at <= ?)
read one (
select bwagreement

View File

@ -303,6 +303,7 @@ CREATE TABLE bwagreements (
serialnum text NOT NULL,
data bytea NOT NULL,
created_at timestamp with time zone NOT NULL,
expires_at timestamp with time zone NOT NULL,
PRIMARY KEY ( signature ),
UNIQUE ( serialnum )
);
@ -430,6 +431,7 @@ CREATE TABLE bwagreements (
serialnum TEXT NOT NULL,
data BLOB NOT NULL,
created_at TIMESTAMP NOT NULL,
expires_at TIMESTAMP NOT NULL,
PRIMARY KEY ( signature ),
UNIQUE ( serialnum )
);
@ -876,6 +878,7 @@ type Bwagreement struct {
Serialnum string
Data []byte
CreatedAt time.Time
ExpiresAt time.Time
}
func (Bwagreement) _Table() string { return "bwagreements" }
@ -959,6 +962,25 @@ func (f Bwagreement_CreatedAt_Field) value() interface{} {
func (Bwagreement_CreatedAt_Field) _Column() string { return "created_at" }
type Bwagreement_ExpiresAt_Field struct {
_set bool
_null bool
_value time.Time
}
func Bwagreement_ExpiresAt(v time.Time) Bwagreement_ExpiresAt_Field {
return Bwagreement_ExpiresAt_Field{_set: true, _value: v}
}
func (f Bwagreement_ExpiresAt_Field) value() interface{} {
if !f._set || f._null {
return nil
}
return f._value
}
func (Bwagreement_ExpiresAt_Field) _Column() string { return "expires_at" }
type Injuredsegment struct {
Id int64
Info []byte
@ -1537,7 +1559,8 @@ type Value_Row struct {
func (obj *postgresImpl) Create_Bwagreement(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field,
bwagreement_serialnum Bwagreement_Serialnum_Field,
bwagreement_data Bwagreement_Data_Field) (
bwagreement_data Bwagreement_Data_Field,
bwagreement_expires_at Bwagreement_ExpiresAt_Field) (
bwagreement *Bwagreement, err error) {
__now := obj.db.Hooks.Now().UTC()
@ -1545,14 +1568,15 @@ func (obj *postgresImpl) Create_Bwagreement(ctx context.Context,
__serialnum_val := bwagreement_serialnum.value()
__data_val := bwagreement_data.value()
__created_at_val := __now
__expires_at_val := bwagreement_expires_at.value()
var __embed_stmt = __sqlbundle_Literal("INSERT INTO bwagreements ( signature, serialnum, data, created_at ) VALUES ( ?, ?, ?, ? ) RETURNING bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at")
var __embed_stmt = __sqlbundle_Literal("INSERT INTO bwagreements ( signature, serialnum, data, created_at, expires_at ) VALUES ( ?, ?, ?, ?, ? ) RETURNING bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at")
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val)
obj.logStmt(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val, __expires_at_val)
bwagreement = &Bwagreement{}
err = obj.driver.QueryRow(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = obj.driver.QueryRow(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val, __expires_at_val).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1745,7 +1769,7 @@ func (obj *postgresImpl) Get_Bwagreement_By_Signature(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field) (
bwagreement *Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements WHERE bwagreements.signature = ?")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements WHERE bwagreements.signature = ?")
var __values []interface{}
__values = append(__values, bwagreement_signature.value())
@ -1754,7 +1778,7 @@ func (obj *postgresImpl) Get_Bwagreement_By_Signature(ctx context.Context,
obj.logStmt(__stmt, __values...)
bwagreement = &Bwagreement{}
err = obj.driver.QueryRow(__stmt, __values...).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = obj.driver.QueryRow(__stmt, __values...).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1766,7 +1790,7 @@ func (obj *postgresImpl) Limited_Bwagreement(ctx context.Context,
limit int, offset int64) (
rows []*Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements LIMIT ? OFFSET ?")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements LIMIT ? OFFSET ?")
var __values []interface{}
__values = append(__values)
@ -1784,7 +1808,7 @@ func (obj *postgresImpl) Limited_Bwagreement(ctx context.Context,
for __rows.Next() {
bwagreement := &Bwagreement{}
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1800,7 +1824,7 @@ func (obj *postgresImpl) Limited_Bwagreement(ctx context.Context,
func (obj *postgresImpl) All_Bwagreement(ctx context.Context) (
rows []*Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements")
var __values []interface{}
__values = append(__values)
@ -1816,7 +1840,7 @@ func (obj *postgresImpl) All_Bwagreement(ctx context.Context) (
for __rows.Next() {
bwagreement := &Bwagreement{}
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -1833,7 +1857,7 @@ func (obj *postgresImpl) All_Bwagreement_By_CreatedAt_Greater(ctx context.Contex
bwagreement_created_at_greater Bwagreement_CreatedAt_Field) (
rows []*Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements WHERE bwagreements.created_at > ?")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements WHERE bwagreements.created_at > ?")
var __values []interface{}
__values = append(__values, bwagreement_created_at_greater.value())
@ -1849,7 +1873,7 @@ func (obj *postgresImpl) All_Bwagreement_By_CreatedAt_Greater(ctx context.Contex
for __rows.Next() {
bwagreement := &Bwagreement{}
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -2496,6 +2520,32 @@ func (obj *postgresImpl) Delete_Bwagreement_By_Signature(ctx context.Context,
}
func (obj *postgresImpl) Delete_Bwagreement_By_ExpiresAt_LessOrEqual(ctx context.Context,
bwagreement_expires_at_less_or_equal Bwagreement_ExpiresAt_Field) (
count int64, err error) {
var __embed_stmt = __sqlbundle_Literal("DELETE FROM bwagreements WHERE bwagreements.expires_at <= ?")
var __values []interface{}
__values = append(__values, bwagreement_expires_at_less_or_equal.value())
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
__res, err := obj.driver.Exec(__stmt, __values...)
if err != nil {
return 0, obj.makeErr(err)
}
count, err = __res.RowsAffected()
if err != nil {
return 0, obj.makeErr(err)
}
return count, nil
}
func (obj *postgresImpl) Delete_Irreparabledb_By_Segmentpath(ctx context.Context,
irreparabledb_segmentpath Irreparabledb_Segmentpath_Field) (
deleted bool, err error) {
@ -2753,7 +2803,8 @@ func (obj *postgresImpl) deleteAll(ctx context.Context) (count int64, err error)
func (obj *sqlite3Impl) Create_Bwagreement(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field,
bwagreement_serialnum Bwagreement_Serialnum_Field,
bwagreement_data Bwagreement_Data_Field) (
bwagreement_data Bwagreement_Data_Field,
bwagreement_expires_at Bwagreement_ExpiresAt_Field) (
bwagreement *Bwagreement, err error) {
__now := obj.db.Hooks.Now().UTC()
@ -2761,13 +2812,14 @@ func (obj *sqlite3Impl) Create_Bwagreement(ctx context.Context,
__serialnum_val := bwagreement_serialnum.value()
__data_val := bwagreement_data.value()
__created_at_val := __now
__expires_at_val := bwagreement_expires_at.value()
var __embed_stmt = __sqlbundle_Literal("INSERT INTO bwagreements ( signature, serialnum, data, created_at ) VALUES ( ?, ?, ?, ? )")
var __embed_stmt = __sqlbundle_Literal("INSERT INTO bwagreements ( signature, serialnum, data, created_at, expires_at ) VALUES ( ?, ?, ?, ?, ? )")
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val)
obj.logStmt(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val, __expires_at_val)
__res, err := obj.driver.Exec(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val)
__res, err := obj.driver.Exec(__stmt, __signature_val, __serialnum_val, __data_val, __created_at_val, __expires_at_val)
if err != nil {
return nil, obj.makeErr(err)
}
@ -2985,7 +3037,7 @@ func (obj *sqlite3Impl) Get_Bwagreement_By_Signature(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field) (
bwagreement *Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements WHERE bwagreements.signature = ?")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements WHERE bwagreements.signature = ?")
var __values []interface{}
__values = append(__values, bwagreement_signature.value())
@ -2994,7 +3046,7 @@ func (obj *sqlite3Impl) Get_Bwagreement_By_Signature(ctx context.Context,
obj.logStmt(__stmt, __values...)
bwagreement = &Bwagreement{}
err = obj.driver.QueryRow(__stmt, __values...).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = obj.driver.QueryRow(__stmt, __values...).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -3006,7 +3058,7 @@ func (obj *sqlite3Impl) Limited_Bwagreement(ctx context.Context,
limit int, offset int64) (
rows []*Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements LIMIT ? OFFSET ?")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements LIMIT ? OFFSET ?")
var __values []interface{}
__values = append(__values)
@ -3024,7 +3076,7 @@ func (obj *sqlite3Impl) Limited_Bwagreement(ctx context.Context,
for __rows.Next() {
bwagreement := &Bwagreement{}
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -3040,7 +3092,7 @@ func (obj *sqlite3Impl) Limited_Bwagreement(ctx context.Context,
func (obj *sqlite3Impl) All_Bwagreement(ctx context.Context) (
rows []*Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements")
var __values []interface{}
__values = append(__values)
@ -3056,7 +3108,7 @@ func (obj *sqlite3Impl) All_Bwagreement(ctx context.Context) (
for __rows.Next() {
bwagreement := &Bwagreement{}
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -3073,7 +3125,7 @@ func (obj *sqlite3Impl) All_Bwagreement_By_CreatedAt_Greater(ctx context.Context
bwagreement_created_at_greater Bwagreement_CreatedAt_Field) (
rows []*Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements WHERE bwagreements.created_at > ?")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements WHERE bwagreements.created_at > ?")
var __values []interface{}
__values = append(__values, bwagreement_created_at_greater.value())
@ -3089,7 +3141,7 @@ func (obj *sqlite3Impl) All_Bwagreement_By_CreatedAt_Greater(ctx context.Context
for __rows.Next() {
bwagreement := &Bwagreement{}
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = __rows.Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -3796,6 +3848,32 @@ func (obj *sqlite3Impl) Delete_Bwagreement_By_Signature(ctx context.Context,
}
func (obj *sqlite3Impl) Delete_Bwagreement_By_ExpiresAt_LessOrEqual(ctx context.Context,
bwagreement_expires_at_less_or_equal Bwagreement_ExpiresAt_Field) (
count int64, err error) {
var __embed_stmt = __sqlbundle_Literal("DELETE FROM bwagreements WHERE bwagreements.expires_at <= ?")
var __values []interface{}
__values = append(__values, bwagreement_expires_at_less_or_equal.value())
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, __values...)
__res, err := obj.driver.Exec(__stmt, __values...)
if err != nil {
return 0, obj.makeErr(err)
}
count, err = __res.RowsAffected()
if err != nil {
return 0, obj.makeErr(err)
}
return count, nil
}
func (obj *sqlite3Impl) Delete_Irreparabledb_By_Segmentpath(ctx context.Context,
irreparabledb_segmentpath Irreparabledb_Segmentpath_Field) (
deleted bool, err error) {
@ -3956,13 +4034,13 @@ func (obj *sqlite3Impl) getLastBwagreement(ctx context.Context,
pk int64) (
bwagreement *Bwagreement, err error) {
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at FROM bwagreements WHERE _rowid_ = ?")
var __embed_stmt = __sqlbundle_Literal("SELECT bwagreements.signature, bwagreements.serialnum, bwagreements.data, bwagreements.created_at, bwagreements.expires_at FROM bwagreements WHERE _rowid_ = ?")
var __stmt = __sqlbundle_Render(obj.dialect, __embed_stmt)
obj.logStmt(__stmt, pk)
bwagreement = &Bwagreement{}
err = obj.driver.QueryRow(__stmt, pk).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt)
err = obj.driver.QueryRow(__stmt, pk).Scan(&bwagreement.Signature, &bwagreement.Serialnum, &bwagreement.Data, &bwagreement.CreatedAt, &bwagreement.ExpiresAt)
if err != nil {
return nil, obj.makeErr(err)
}
@ -4323,13 +4401,14 @@ func (rx *Rx) Create_AccountingTimestamps(ctx context.Context,
func (rx *Rx) Create_Bwagreement(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field,
bwagreement_serialnum Bwagreement_Serialnum_Field,
bwagreement_data Bwagreement_Data_Field) (
bwagreement_data Bwagreement_Data_Field,
bwagreement_expires_at Bwagreement_ExpiresAt_Field) (
bwagreement *Bwagreement, err error) {
var tx *Tx
if tx, err = rx.getTx(ctx); err != nil {
return
}
return tx.Create_Bwagreement(ctx, bwagreement_signature, bwagreement_serialnum, bwagreement_data)
return tx.Create_Bwagreement(ctx, bwagreement_signature, bwagreement_serialnum, bwagreement_data, bwagreement_expires_at)
}
@ -4408,6 +4487,17 @@ func (rx *Rx) Delete_AccountingRollup_By_Id(ctx context.Context,
return tx.Delete_AccountingRollup_By_Id(ctx, accounting_rollup_id)
}
func (rx *Rx) Delete_Bwagreement_By_ExpiresAt_LessOrEqual(ctx context.Context,
bwagreement_expires_at_less_or_equal Bwagreement_ExpiresAt_Field) (
count int64, err error) {
var tx *Tx
if tx, err = rx.getTx(ctx); err != nil {
return
}
return tx.Delete_Bwagreement_By_ExpiresAt_LessOrEqual(ctx, bwagreement_expires_at_less_or_equal)
}
func (rx *Rx) Delete_Bwagreement_By_Signature(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field) (
deleted bool, err error) {
@ -4682,7 +4772,8 @@ type Methods interface {
Create_Bwagreement(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field,
bwagreement_serialnum Bwagreement_Serialnum_Field,
bwagreement_data Bwagreement_Data_Field) (
bwagreement_data Bwagreement_Data_Field,
bwagreement_expires_at Bwagreement_ExpiresAt_Field) (
bwagreement *Bwagreement, err error)
Create_Injuredsegment(ctx context.Context,
@ -4720,6 +4811,10 @@ type Methods interface {
accounting_rollup_id AccountingRollup_Id_Field) (
deleted bool, err error)
Delete_Bwagreement_By_ExpiresAt_LessOrEqual(ctx context.Context,
bwagreement_expires_at_less_or_equal Bwagreement_ExpiresAt_Field) (
count int64, err error)
Delete_Bwagreement_By_Signature(ctx context.Context,
bwagreement_signature Bwagreement_Signature_Field) (
deleted bool, err error)

View File

@ -30,6 +30,7 @@ CREATE TABLE bwagreements (
serialnum text NOT NULL,
data bytea NOT NULL,
created_at timestamp with time zone NOT NULL,
expires_at timestamp with time zone NOT NULL,
PRIMARY KEY ( signature ),
UNIQUE ( serialnum )
);

View File

@ -30,6 +30,7 @@ CREATE TABLE bwagreements (
serialnum TEXT NOT NULL,
data BLOB NOT NULL,
created_at TIMESTAMP NOT NULL,
expires_at TIMESTAMP NOT NULL,
PRIMARY KEY ( signature ),
UNIQUE ( serialnum )
);