neno oclib
This commit is contained in:
@@ -234,6 +234,11 @@ func (o *ResourceController) Post() {
|
||||
user, peerID, groups := oclib.ExtractTokenInfo(*o.Ctx.Request)
|
||||
var res map[string]interface{}
|
||||
json.Unmarshal(o.Ctx.Input.CopyBody(100000), &res)
|
||||
|
||||
// Remplace les sources privées (isReachable=false) par des clés opaques
|
||||
// avant la persistance : le vrai path ne doit jamais sortir de ce peer.
|
||||
replacePrivateSources(res)
|
||||
|
||||
data := oclib.NewRequest(libs[0], user, peerID, groups, nil).StoreOne(res)
|
||||
fmt.Println(data.Data, res["name"], libs[0])
|
||||
if data.Err == "" {
|
||||
@@ -248,6 +253,50 @@ func (o *ResourceController) Post() {
|
||||
o.ServeJSON()
|
||||
}
|
||||
|
||||
// replacePrivateSources parcourt les instances de la ressource dans le body
|
||||
// et remplace chaque source privée (is_reachable=false) par une clé opaque.
|
||||
// Modifie res en place.
|
||||
func replacePrivateSources(res map[string]interface{}) {
|
||||
instances, ok := res["instances"].([]interface{})
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
resourceID, _ := res["id"].(string) // vide au POST, c'est normal
|
||||
for _, raw := range instances {
|
||||
inst, ok := raw.(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
access, ok := inst["access"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
sourceMap, ok := access["source"].(map[string]interface{})
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
// Seulement les sources privées.
|
||||
isReachable, _ := sourceMap["is_reachable"].(bool)
|
||||
if isReachable {
|
||||
continue
|
||||
}
|
||||
realPath, _ := sourceMap["source"].(string)
|
||||
if realPath == "" {
|
||||
continue
|
||||
}
|
||||
// Déjà une clé opaque — ne pas re-enregistrer.
|
||||
if len(realPath) > 4 && realPath[:4] == "src-" {
|
||||
continue
|
||||
}
|
||||
opaqueKey, err := infrastructure.RegisterSource(resourceID, realPath)
|
||||
if err != nil {
|
||||
fmt.Println("[source-key] RegisterSource failed:", err)
|
||||
continue
|
||||
}
|
||||
sourceMap["source"] = opaqueKey
|
||||
}
|
||||
}
|
||||
|
||||
// @Title Put
|
||||
// @Description search resources across all types
|
||||
// @Param type path string true "the type you want to get"
|
||||
|
||||
Reference in New Issue
Block a user