Skip to content

Commit 2593878

Browse files
authored
Merge pull request #1238 from YourTechBud/metrics-fix
Minor fixes
2 parents 57e1f68 + 7f46f38 commit 2593878

File tree

6 files changed

+29
-21
lines changed

6 files changed

+29
-21
lines changed

gateway/modules/crud/sql/update.go

+5-8
Original file line numberDiff line numberDiff line change
@@ -78,18 +78,15 @@ func (s *SQL) update(ctx context.Context, col string, req *model.UpdateRequest,
7878
doc := make(map[string]interface{})
7979
dates := make(map[string]interface{})
8080
for k, v := range req.Find {
81-
if reflect.TypeOf(v).Kind() == reflect.Array {
82-
return 0, utils.ErrInvalidParams
83-
}
84-
85-
// implicit equality operator in where e.g -> "id" : "1"
86-
if !strings.HasPrefix(k, "$") && reflect.TypeOf(v).Kind() != reflect.Map {
81+
obj, ok := v.(map[string]interface{})
82+
if !ok {
8783
doc[k] = v
8884
continue
8985
}
9086

91-
for colName, colValue := range v.(map[string]interface{}) {
92-
doc[colName] = colValue
87+
// Required when v is a map. Eg. {"id": { "$eq": "some-value" }}
88+
for _, colValue := range obj {
89+
doc[k] = colValue
9390
}
9491
}
9592
for op := range req.Update {

gateway/modules/eventing/handle_staged.go

+7
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ func (m *Module) processStagedEvent(eventDoc *model.EventDocument) {
119119
doc = structs.Map(&cloudEvent)
120120
doc, err = m.adjustReqBody(name, "", rule, nil, doc)
121121
if err != nil {
122+
if err := m.logInvocation(ctx, eventDoc.ID, []byte("{}"), 0, "", err.Error()); err != nil {
123+
logrus.Errorf("eventing module couldn't log the invocation - %s", err.Error())
124+
return
125+
}
126+
if err := m.crud.InternalUpdate(context.Background(), m.config.DBAlias, m.project, utils.TableEventingLogs, m.generateFailedEventRequest(eventDoc.ID, "Max retires limit reached")); err != nil {
127+
logrus.Errorf("Eventing staged event handler could not update event doc - %s", err.Error())
128+
}
122129
_ = utils.LogError(fmt.Sprintf("Unable to adjust request body according to template for trigger (%s)", name), "eventing", "process-staged", err)
123130
return
124131
}

gateway/modules/filestore/operations.go

+7-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package filestore
33
import (
44
"context"
55
"errors"
6-
"fmt"
76
"io"
87
"net/http"
98

@@ -21,7 +20,7 @@ func (m *Module) CreateDir(ctx context.Context, project, token string, req *mode
2120
// Check if the user is authorised to make this request
2221
_, err := m.auth.IsFileOpAuthorised(ctx, project, token, req.Path, utils.FileCreate, map[string]interface{}{})
2322
if err != nil {
24-
return http.StatusForbidden, errors.New("You are not authorized to make this request")
23+
return http.StatusForbidden, err
2524
}
2625

2726
m.RLock()
@@ -52,7 +51,7 @@ func (m *Module) DeleteFile(ctx context.Context, project, token string, path str
5251
// Check if the user is authorised to make this request
5352
_, err := m.auth.IsFileOpAuthorised(ctx, project, token, path, utils.FileDelete, map[string]interface{}{})
5453
if err != nil {
55-
return http.StatusForbidden, errors.New("You are not authorized to make this request")
54+
return http.StatusForbidden, err
5655
}
5756

5857
m.RLock()
@@ -83,7 +82,7 @@ func (m *Module) ListFiles(ctx context.Context, project, token string, req *mode
8382
// Check if the user is authorised to make this request
8483
_, err := m.auth.IsFileOpAuthorised(ctx, project, token, req.Path, utils.FileRead, map[string]interface{}{})
8584
if err != nil {
86-
return http.StatusForbidden, nil, fmt.Errorf("You are not authorized to make this request - %v", err)
85+
return http.StatusForbidden, nil, err
8786
}
8887

8988
m.RLock()
@@ -106,9 +105,9 @@ func (m *Module) UploadFile(ctx context.Context, project, token string, req *mod
106105
}
107106

108107
// Check if the user is authorised to make this request
109-
_, err := m.auth.IsFileOpAuthorised(ctx, project, token, req.Path, utils.FileCreate, map[string]interface{}{})
108+
_, err := m.auth.IsFileOpAuthorised(ctx, project, token, req.Path, utils.FileCreate, map[string]interface{}{"meta": req.Meta})
110109
if err != nil {
111-
return http.StatusForbidden, errors.New("You are not authorized to make this request")
110+
return http.StatusForbidden, err
112111
}
113112

114113
m.RLock()
@@ -139,7 +138,7 @@ func (m *Module) DownloadFile(ctx context.Context, project, token, path string)
139138
// Check if the user is authorised to make this request
140139
_, err := m.auth.IsFileOpAuthorised(ctx, project, token, path, utils.FileRead, map[string]interface{}{})
141140
if err != nil {
142-
return http.StatusForbidden, nil, errors.New("You are not authorized to make this request")
141+
return http.StatusForbidden, nil, err
143142
}
144143

145144
m.RLock()
@@ -165,7 +164,7 @@ func (m *Module) DoesExists(ctx context.Context, project, token, path string) er
165164
// Check if the user is authorised to make this request
166165
_, err := m.auth.IsFileOpAuthorised(ctx, project, token, path, utils.FileRead, map[string]interface{}{})
167166
if err != nil {
168-
return errors.New("You are not authorized to make this request")
167+
return err
169168
}
170169

171170
m.RLock()

gateway/modules/global/metrics/projects.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ func (m *Module) updateSCMetrics(id string, set, min map[string]interface{}) {
100100
defer cancel()
101101
result, err := m.sink.Upsert("config_metrics").Where(types.Cond("id", "==", id)).Set(set).Min(min).Apply(ctx)
102102
if err != nil {
103-
logrus.Errorf("error querying database got error")
103+
logrus.Errorln("Unable to push metrics:", err)
104104
}
105105
if result == nil {
106106
// when space api go is not able to connect to server, the result is empty
107107
return
108108
}
109109
if result.Status != http.StatusOK {
110-
logrus.Errorf("error querying database got status (%d) (%s)", result.Status, result.Error)
110+
logrus.Errorf("Unable to push metrics - (%d) (%s)", result.Status, result.Error)
111111
}
112112
}

gateway/modules/global/metrics/sink.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ func (m *Module) flushMetrics(docs []interface{}) {
6363
defer cancel()
6464
result, err := m.sink.Insert("operation_metrics").Docs(docs).Apply(ctx)
6565
if err != nil {
66-
logrus.Debugln("Unable to push metrics:", err)
66+
logrus.Errorln("Unable to push metrics:", err)
6767
return
6868
}
6969
if result.Status != http.StatusOK {
70-
logrus.Debugln("Unable to push metrics:", result.Error)
70+
logrus.Errorln("Unable to push metrics:", result.Error)
7171
}
7272
}

gateway/utils/http.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,12 @@ func GetTokenFromHeader(r *http.Request) string {
7777
tokens = []string{""}
7878
}
7979

80-
return strings.TrimPrefix(tokens[0], "Bearer ")
80+
arr := strings.Split(tokens[0], " ")
81+
if strings.ToLower(arr[0]) == "bearer" {
82+
return arr[1]
83+
}
84+
85+
return ""
8186
}
8287

8388
// CreateCorsObject creates a cors object with the required config

0 commit comments

Comments
 (0)