Nats Native Behaviors + Peer is Stateless

This commit is contained in:
mr
2026-02-18 14:25:56 +01:00
parent fa5c3a3c60
commit 0b41e2505e
7 changed files with 280 additions and 42 deletions

View File

@@ -8,22 +8,6 @@ import (
"cloud.o-forge.io/core/oc-lib/tools"
)
// now write a go enum for the state partner with self, blacklist, partner
type PeerState int
const (
OFFLINE PeerState = iota
ONLINE
)
func (m PeerState) String() string {
return [...]string{"NONE", "SELF", "PARTNER", "BLACKLIST"}[m]
}
func (m PeerState) EnumIndex() int {
return int(m)
}
type PeerRelation int
const (
@@ -69,7 +53,6 @@ type Peer struct {
NATSAddress string `json:"nats_address" bson:"nats_address" validate:"required"`
WalletAddress string `json:"wallet_address" bson:"wallet_address" validate:"required"` // WalletAddress is the wallet address of the peer
PublicKey string `json:"public_key" bson:"public_key" validate:"required"` // PublicKey is the public key of the peer
State PeerState `json:"state" bson:"state" default:"0"`
Relation PeerRelation `json:"relation" bson:"relation" default:"0"`
ServicesState map[string]int `json:"services_state,omitempty" bson:"services_state,omitempty"`
FailedExecution []PeerExecution `json:"failed_execution" bson:"failed_execution"` // FailedExecution is the list of failed executions, to be retried

View File

@@ -61,9 +61,6 @@ func (a *peerMongoAccessor) GetObjectFilters(search string) *dbs.Filters {
search = ""
}
return &dbs.Filters{
And: map[string][]dbs.Filter{ // search by name if no filters are provided
"state": {{Operator: dbs.EQUAL.String(), Value: ONLINE.EnumIndex()}},
},
Or: map[string][]dbs.Filter{ // search by name if no filters are provided
"abstractobject.name": {{Operator: dbs.LIKE.String(), Value: search}},
"url": {{Operator: dbs.LIKE.String(), Value: search}},

View File

@@ -64,8 +64,6 @@ func (dca *ResourceMongoAccessor[T]) UpdateOne(set utils.DBObject, id string) (u
if d, c, err := utils.GenericUpdateOne(set, id, dca, dca.generateData()); err != nil {
return d, c, err
} else {
d.Unsign()
d.Sign()
return utils.GenericUpdateOne(set, id, dca, dca.generateData())
}
}
@@ -75,11 +73,7 @@ func (dca *ResourceMongoAccessor[T]) StoreOne(data utils.DBObject) (utils.DBObje
return nil, 404, errors.New("can't create a non existing computing units resource not reported onto compute units catalog")
}
data.(T).Trim()
d, c, err := utils.GenericStoreOne(data, dca)
if err != nil {
return d, c, err
}
return dca.UpdateOne(d, d.GetID())
return utils.GenericStoreOne(data, dca)
}
func (dca *ResourceMongoAccessor[T]) CopyOne(data utils.DBObject) (utils.DBObject, int, error) {

View File

@@ -99,8 +99,10 @@ func GenericUpdateOne(set DBObject, id string, a Accessor, new DBObject) (DBObje
}
set = newSet
r.UpToDate(a.GetUser(), a.GetPeerID(), false)
r.Unsign()
r.Sign()
if a.GetPeerID() == r.GetCreatorID() {
r.Unsign()
r.Sign()
}
if a.ShouldVerifyAuth() && !r.VerifyAuth("update", a.GetRequest()) {
return nil, 403, errors.New("you are not allowed to access :" + a.GetType().String())
}