add username to our trip
This commit is contained in:
@@ -118,6 +118,7 @@ func InitDaemon(appName string) {
|
||||
}
|
||||
|
||||
type IDTokenClaims struct {
|
||||
UserID string `json:"user_id"`
|
||||
PeerID string `json:"peer_id"`
|
||||
Groups []string `json:"groups"`
|
||||
}
|
||||
@@ -133,7 +134,7 @@ type Claims struct {
|
||||
Session SessionClaims `json:"session"`
|
||||
}
|
||||
|
||||
func ExtractTokenInfo(request http.Request) (string, []string) {
|
||||
func ExtractTokenInfo(request http.Request) (string, string, []string) {
|
||||
reqToken := request.Header.Get("Authorization")
|
||||
splitToken := strings.Split(reqToken, "Bearer ")
|
||||
if len(splitToken) < 2 {
|
||||
@@ -146,17 +147,17 @@ func ExtractTokenInfo(request http.Request) (string, []string) {
|
||||
if len(token) > 2 {
|
||||
bytes, err := base64.StdEncoding.DecodeString(token[2])
|
||||
if err != nil {
|
||||
return "", []string{}
|
||||
return "", "", []string{}
|
||||
}
|
||||
var c Claims
|
||||
err = json.Unmarshal(bytes, &c)
|
||||
if err != nil {
|
||||
return "", []string{}
|
||||
return "", "", []string{}
|
||||
}
|
||||
return c.Session.IDToken.PeerID, c.Session.IDToken.Groups
|
||||
return c.Session.IDToken.UserID, c.Session.IDToken.PeerID, c.Session.IDToken.Groups
|
||||
}
|
||||
}
|
||||
return "", []string{}
|
||||
return "", "", []string{}
|
||||
}
|
||||
|
||||
func Init(appName string) {
|
||||
@@ -199,7 +200,7 @@ func SetConfig(mongoUrl string, database string, natsUrl string, lokiUrl string,
|
||||
If not we will store it
|
||||
Resource model is the model that will define the structure of the resources
|
||||
*/
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor("", []string{}, nil)
|
||||
accessor := (&resource_model.ResourceModel{}).GetAccessor("", "", []string{}, nil)
|
||||
for _, model := range []string{tools.DATA_RESOURCE.String(), tools.PROCESSING_RESOURCE.String(), tools.STORAGE_RESOURCE.String(), tools.COMPUTE_RESOURCE.String(), tools.WORKFLOW_RESOURCE.String()} {
|
||||
data, code, _ := accessor.Search(nil, model)
|
||||
if code == 404 || len(data) == 0 {
|
||||
@@ -268,13 +269,14 @@ func GetConfLoader() *onion.Onion {
|
||||
|
||||
type Request struct {
|
||||
collection LibDataEnum
|
||||
user string
|
||||
peerID string
|
||||
groups []string
|
||||
caller *tools.HTTPCaller
|
||||
}
|
||||
|
||||
func NewRequest(collection LibDataEnum, peerID string, groups []string, caller *tools.HTTPCaller) *Request {
|
||||
return &Request{collection: collection, peerID: peerID, groups: groups, caller: caller}
|
||||
func NewRequest(collection LibDataEnum, user string, peerID string, groups []string, caller *tools.HTTPCaller) *Request {
|
||||
return &Request{collection: collection, user: user, peerID: peerID, groups: groups, caller: caller}
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -292,7 +294,7 @@ func (r *Request) Search(filters *dbs.Filters, word string) (data LibDataShallow
|
||||
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).Search(filters, word)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).Search(filters, word)
|
||||
if err != nil {
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -314,7 +316,7 @@ func (r *Request) LoadAll() (data LibDataShallow) {
|
||||
data = LibDataShallow{Data: nil, Code: 500, Err: "Panic recovered in LoadAll : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).LoadAll()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadAll()
|
||||
if err != nil {
|
||||
data = LibDataShallow{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -337,7 +339,7 @@ func (r *Request) LoadOne(id string) (data LibData) {
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in LoadOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).LoadOne(id)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).LoadOne(id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -362,7 +364,7 @@ func (r *Request) UpdateOne(set map[string]interface{}, id string) (data LibData
|
||||
}
|
||||
}()
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).UpdateOne(model.Deserialize(set, model), id)
|
||||
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).UpdateOne(model.Deserialize(set, model), id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -385,7 +387,7 @@ func (r *Request) DeleteOne(id string) (data LibData) {
|
||||
data = LibData{Data: nil, Code: 500, Err: "Panic recovered in DeleteOne : " + fmt.Sprintf("%v", r) + " - " + string(debug.Stack())}
|
||||
}
|
||||
}()
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.peerID, r.groups, r.caller).DeleteOne(id)
|
||||
d, code, err := models.Model(r.collection.EnumIndex()).GetAccessor(r.user, r.peerID, r.groups, r.caller).DeleteOne(id)
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -409,7 +411,7 @@ func (r *Request) StoreOne(object map[string]interface{}) (data LibData) {
|
||||
}
|
||||
}()
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).StoreOne(model.Deserialize(object, model))
|
||||
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).StoreOne(model.Deserialize(object, model))
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -433,7 +435,7 @@ func (r *Request) CopyOne(object map[string]interface{}) (data LibData) {
|
||||
}
|
||||
}()
|
||||
model := models.Model(r.collection.EnumIndex())
|
||||
d, code, err := model.GetAccessor(r.peerID, r.groups, r.caller).CopyOne(model.Deserialize(object, model))
|
||||
d, code, err := model.GetAccessor(r.user, r.peerID, r.groups, r.caller).CopyOne(model.Deserialize(object, model))
|
||||
if err != nil {
|
||||
data = LibData{Data: d, Code: code, Err: err.Error()}
|
||||
return
|
||||
@@ -445,72 +447,72 @@ func (r *Request) CopyOne(object map[string]interface{}) (data LibData) {
|
||||
// ================ CAST ========================= //
|
||||
|
||||
func (l *LibData) ToDataResource() *resources.DataResource {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.DATA_RESOURCE {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.DATA_RESOURCE {
|
||||
return l.Data.(*resources.DataResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToComputeResource() *resources.ComputeResource {
|
||||
if l.Data != nil && l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COMPUTE_RESOURCE {
|
||||
if l.Data != nil && l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COMPUTE_RESOURCE {
|
||||
return l.Data.(*resources.ComputeResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToStorageResource() *resources.StorageResource {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.STORAGE_RESOURCE {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.STORAGE_RESOURCE {
|
||||
return l.Data.(*resources.StorageResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToProcessingResource() *resources.ProcessingResource {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.PROCESSING_RESOURCE {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PROCESSING_RESOURCE {
|
||||
return l.Data.(*resources.ProcessingResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkflowResource() *resources.WorkflowResource {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW_RESOURCE {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_RESOURCE {
|
||||
return l.Data.(*resources.WorkflowResource)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToPeer() *peer.Peer {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.PEER {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.PEER {
|
||||
return l.Data.(*peer.Peer)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflow() *w2.Workflow {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW {
|
||||
return l.Data.(*w2.Workflow)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (l *LibData) ToWorkspace() *workspace.Workspace {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKSPACE {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKSPACE {
|
||||
return l.Data.(*workspace.Workspace)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToCollaborativeArea() *collaborative_area.CollaborativeArea {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
return l.Data.(*collaborative_area.CollaborativeArea)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToRule() *rule.Rule {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.COLLABORATIVE_AREA {
|
||||
return l.Data.(*rule.Rule)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (l *LibData) ToWorkflowExecution() *workflow_execution.WorkflowExecution {
|
||||
if l.Data.GetAccessor("", []string{}, nil).GetType() == tools.WORKFLOW_EXECUTION {
|
||||
if l.Data.GetAccessor("", "", []string{}, nil).GetType() == tools.WORKFLOW_EXECUTION {
|
||||
return l.Data.(*workflow_execution.WorkflowExecution)
|
||||
}
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user