add username to our trip
This commit is contained in:
@@ -23,8 +23,8 @@ type ComputeResource struct {
|
||||
GPUs []*GPU `bson:"gpus,omitempty" json:"gpus,omitempty"` // GPUs is the list of GPUs
|
||||
}
|
||||
|
||||
func (d *ComputeResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*ComputeResource](tools.COMPUTE_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &ComputeResource{} })
|
||||
func (d *ComputeResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*ComputeResource](tools.COMPUTE_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &ComputeResource{} })
|
||||
}
|
||||
|
||||
// CPU is a struct that represents a CPU
|
||||
|
||||
@@ -37,6 +37,6 @@ type DataResource struct {
|
||||
Example string `json:"example,omitempty" bson:"example,omitempty" description:"base64 encoded data"` // Example is an example of the data
|
||||
}
|
||||
|
||||
func (d *DataResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*DataResource](tools.DATA_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor
|
||||
func (d *DataResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*DataResource](tools.DATA_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &DataResource{} }) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
@@ -38,6 +38,6 @@ type ProcessingResource struct {
|
||||
Expose []Expose `bson:"expose,omitempty" json:"expose,omitempty"` // Expose is the execution
|
||||
}
|
||||
|
||||
func (d *ProcessingResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*ProcessingResource](tools.PROCESSING_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &ProcessingResource{} }) // Create a new instance of the accessor
|
||||
func (d *ProcessingResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*ProcessingResource](tools.PROCESSING_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &ProcessingResource{} }) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ func (r *ResourceSet) Clear() {
|
||||
r.WorkflowResources = nil
|
||||
}
|
||||
|
||||
func (r *ResourceSet) Fill(peerID string, groups []string) {
|
||||
func (r *ResourceSet) Fill(username string, peerID string, groups []string) {
|
||||
for k, v := range map[utils.DBObject][]string{
|
||||
(&DataResource{}): r.Datas,
|
||||
(&ComputeResource{}): r.Computes,
|
||||
@@ -47,7 +47,7 @@ func (r *ResourceSet) Fill(peerID string, groups []string) {
|
||||
(&WorkflowResource{}): r.Workflows,
|
||||
} {
|
||||
for _, id := range v {
|
||||
d, _, e := k.GetAccessor(peerID, groups, nil).LoadOne(id)
|
||||
d, _, e := k.GetAccessor(username, peerID, groups, nil).LoadOne(id)
|
||||
if e == nil {
|
||||
switch k.(type) {
|
||||
case *DataResource:
|
||||
|
||||
@@ -14,14 +14,15 @@ type resourceMongoAccessor[T ResourceInterface] struct {
|
||||
}
|
||||
|
||||
// New creates a new instance of the computeMongoAccessor
|
||||
func New[T ResourceInterface](t tools.DataType, peerID string, groups []string, caller *tools.HTTPCaller, g func() utils.DBObject) *resourceMongoAccessor[T] {
|
||||
func New[T ResourceInterface](t tools.DataType, username string, peerID string, groups []string, caller *tools.HTTPCaller, g func() utils.DBObject) *resourceMongoAccessor[T] {
|
||||
return &resourceMongoAccessor[T]{
|
||||
AbstractAccessor: utils.AbstractAccessor{
|
||||
ResourceModelAccessor: resource_model.New(),
|
||||
Logger: logs.CreateLogger(t.String()), // Create a logger with the data type
|
||||
Caller: caller,
|
||||
PeerID: peerID,
|
||||
Groups: groups, // Set the caller
|
||||
User: username, // Set the caller
|
||||
Groups: groups, // Set the caller
|
||||
Type: t,
|
||||
},
|
||||
generateData: g,
|
||||
|
||||
@@ -38,7 +38,7 @@ type AbstractResource struct {
|
||||
Currency string `json:"currency,omitempty" bson:"currency,omitempty"` // Currency is the currency of the price
|
||||
}
|
||||
|
||||
func (ao *AbstractResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
func (ao *AbstractResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ func (abs *AbstractResource) SetResourceModel(model *ResourceModel) {
|
||||
abs.ResourceModel = model
|
||||
}
|
||||
|
||||
func (abs *AbstractResource) VerifyAuth(peerID string, groups []string) bool {
|
||||
func (abs *AbstractResource) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||
if grps, ok := abs.AllowedPeersGroup[peerID]; ok || config.GetConfig().Whitelist {
|
||||
if (ok && slices.Contains(grps, "*")) || (!ok && config.GetConfig().Whitelist) {
|
||||
return true
|
||||
@@ -135,16 +135,17 @@ func (d *ResourceModel) GetName() string {
|
||||
return d.UUID
|
||||
}
|
||||
|
||||
func (abs *ResourceModel) VerifyAuth(peerID string, groups []string) bool {
|
||||
func (abs *ResourceModel) VerifyAuth(username string, peerID string, groups []string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (d *ResourceModel) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
func (d *ResourceModel) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return &ResourceModelMongoAccessor{
|
||||
utils.AbstractAccessor{
|
||||
Type: tools.RESOURCE_MODEL,
|
||||
PeerID: peerID,
|
||||
Groups: groups,
|
||||
User: username,
|
||||
Caller: caller,
|
||||
},
|
||||
}
|
||||
|
||||
@@ -56,6 +56,6 @@ type StorageResource struct {
|
||||
Throughput string `bson:"throughput,omitempty" json:"throughput,omitempty"` // Throughput is the throughput of the storage
|
||||
}
|
||||
|
||||
func (d *StorageResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*StorageResource](tools.STORAGE_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor
|
||||
func (d *StorageResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*StorageResource](tools.STORAGE_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &StorageResource{} }) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
@@ -13,6 +13,6 @@ type WorkflowResource struct {
|
||||
WorkflowID string `bson:"workflow_id,omitempty" json:"workflow_id,omitempty"` // WorkflowID is the ID of the native workflow
|
||||
}
|
||||
|
||||
func (d *WorkflowResource) GetAccessor(peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*WorkflowResource](tools.WORKFLOW_RESOURCE, peerID, groups, caller, func() utils.DBObject { return &WorkflowResource{} }) // Create a new instance of the accessor
|
||||
func (d *WorkflowResource) GetAccessor(username string, peerID string, groups []string, caller *tools.HTTPCaller) utils.Accessor {
|
||||
return New[*WorkflowResource](tools.WORKFLOW_RESOURCE, username, peerID, groups, caller, func() utils.DBObject { return &WorkflowResource{} }) // Create a new instance of the accessor
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user