MCPcopy Create free account
hub / github.com/MG-RAST/Shock / Read

Method Read

shock-server/controller/node/single.go:37–554  ·  view source on GitHub ↗

GET: /node/{id}

(id string, ctx context.Context)

Source from the content-addressed store, hash-verified

35
36// GET: /node/{id}
37func (cr *NodeController) Read(id string, ctx context.Context) error {
38 u, err := request.Authenticate(ctx.HttpRequest())
39 if err != nil && err.Error() != e.NoAuth {
40 return request.AuthError(err, ctx)
41 }
42
43 // public user (no auth) can be used in some cases
44 if u == nil {
45 if conf.ANON_READ {
46 u = &user.User{Uuid: "public"}
47 } else {
48 return responder.RespondWithError(ctx, http.StatusUnauthorized, e.NoAuth)
49 }
50 }
51
52 // Load node by id
53 n, err := node.Load(id)
54 if err != nil {
55 if err == mgo.ErrNotFound {
56 logger.Error("err@node_Read: (node.Load) id=" + id + ": " + e.NodeNotFound)
57 return responder.RespondWithError(ctx, http.StatusNotFound, e.NodeNotFound)
58 } else {
59 // In theory the db connection could be lost between
60 // checking user and load but seems unlikely.
61 err_msg := "err@node_Read: (node.Load) id=" + id + ": " + err.Error()
62 logger.Error(err_msg)
63 return responder.RespondWithError(ctx, http.StatusInternalServerError, err_msg)
64 }
65 }
66
67 rights := n.Acl.Check(u.Uuid)
68 prights := n.Acl.Check("public")
69 if rights["read"] == false && u.Admin == false && n.Acl.Owner != u.Uuid && prights["read"] == false {
70 logger.Error("err@node_Read: (Authenticate) id=" + id + ": " + e.UnAuth)
71 return responder.RespondWithError(ctx, http.StatusUnauthorized, e.UnAuth)
72 }
73
74 // Gather query params
75 query := ctx.HttpRequest().URL.Query()
76 // set defaults
77 filename := n.Id
78 if n.File.Name != "" {
79 filename = n.File.Name
80 }
81 var fFunc filter.FilterFunc = nil
82 var compressionFormat string = ""
83 // use query params if exist
84 if _, ok := query["file_name"]; ok {
85 filename = query.Get("file_name")
86 }
87 if _, ok := query["filter"]; ok {
88 if filter.Has(query.Get("filter")) {
89 fFunc = filter.Filter(query.Get("filter"))
90 }
91 }
92 if _, ok := query["compression"]; ok {
93 if archive.IsValidCompress(query.Get("compression")) {
94 compressionFormat = query.Get("compression")

Callers

nothing calls this directly

Calls 15

LoadMethod · 0.80
CheckMethod · 0.80
HasFileLockMethod · 0.80
HasFileMethod · 0.80
FileReaderMethod · 0.80
StreamMethod · 0.80
HasIndexLockMethod · 0.80
StreamSamtoolsMethod · 0.80
FilePathMethod · 0.80
LockNodeMethod · 0.80
UnlockNodeMethod · 0.80
DynamicIndexMethod · 0.80

Tested by

no test coverage detected