1
1
package auth
2
2
3
3
import (
4
+ "context"
4
5
"net/http"
5
6
6
7
"github.com/spaceuptech/space-cloud/config"
@@ -9,7 +10,7 @@ import (
9
10
)
10
11
11
12
// IsCreateOpAuthorised checks if the crud operation is authorised
12
- func (m * Module ) IsCreateOpAuthorised (project , dbType , col , token string , req * model.CreateRequest ) (int , error ) {
13
+ func (m * Module ) IsCreateOpAuthorised (ctx context. Context , project , dbType , col , token string , req * model.CreateRequest ) (int , error ) {
13
14
m .RLock ()
14
15
defer m .RUnlock ()
15
16
@@ -32,7 +33,7 @@ func (m *Module) IsCreateOpAuthorised(project, dbType, col, token string, req *m
32
33
33
34
for _ , row := range rows {
34
35
args ["doc" ] = row
35
- err := m .matchRule (project , rule , map [string ]interface {}{"args" : args }, auth )
36
+ err := m .matchRule (ctx , project , rule , map [string ]interface {}{"args" : args }, auth )
36
37
if err != nil {
37
38
return http .StatusForbidden , err
38
39
}
@@ -46,7 +47,7 @@ func (m *Module) IsCreateOpAuthorised(project, dbType, col, token string, req *m
46
47
}
47
48
48
49
// IsReadOpAuthorised checks if the crud operation is authorised
49
- func (m * Module ) IsReadOpAuthorised (project , dbType , col , token string , req * model.ReadRequest ) (int , error ) {
50
+ func (m * Module ) IsReadOpAuthorised (ctx context. Context , project , dbType , col , token string , req * model.ReadRequest ) (int , error ) {
50
51
m .RLock ()
51
52
defer m .RUnlock ()
52
53
@@ -56,7 +57,7 @@ func (m *Module) IsReadOpAuthorised(project, dbType, col, token string, req *mod
56
57
}
57
58
58
59
args := map [string ]interface {}{"op" : req .Operation , "auth" : auth , "find" : req .Find , "token" : token }
59
- err = m .matchRule (project , rule , map [string ]interface {}{"args" : args }, auth )
60
+ err = m .matchRule (ctx , project , rule , map [string ]interface {}{"args" : args }, auth )
60
61
if err != nil {
61
62
return http .StatusForbidden , err
62
63
}
@@ -65,7 +66,7 @@ func (m *Module) IsReadOpAuthorised(project, dbType, col, token string, req *mod
65
66
}
66
67
67
68
// IsUpdateOpAuthorised checks if the crud operation is authorised
68
- func (m * Module ) IsUpdateOpAuthorised (project , dbType , col , token string , req * model.UpdateRequest ) (int , error ) {
69
+ func (m * Module ) IsUpdateOpAuthorised (ctx context. Context , project , dbType , col , token string , req * model.UpdateRequest ) (int , error ) {
69
70
m .RLock ()
70
71
defer m .RUnlock ()
71
72
@@ -75,7 +76,7 @@ func (m *Module) IsUpdateOpAuthorised(project, dbType, col, token string, req *m
75
76
}
76
77
77
78
args := map [string ]interface {}{"op" : req .Operation , "auth" : auth , "find" : req .Find , "update" : req .Update , "token" : token }
78
- err = m .matchRule (project , rule , map [string ]interface {}{"args" : args }, auth )
79
+ err = m .matchRule (ctx , project , rule , map [string ]interface {}{"args" : args }, auth )
79
80
if err != nil {
80
81
return http .StatusForbidden , err
81
82
}
@@ -88,7 +89,7 @@ func (m *Module) IsUpdateOpAuthorised(project, dbType, col, token string, req *m
88
89
}
89
90
90
91
// IsDeleteOpAuthorised checks if the crud operation is authorised
91
- func (m * Module ) IsDeleteOpAuthorised (project , dbType , col , token string , req * model.DeleteRequest ) (int , error ) {
92
+ func (m * Module ) IsDeleteOpAuthorised (ctx context. Context , project , dbType , col , token string , req * model.DeleteRequest ) (int , error ) {
92
93
m .RLock ()
93
94
defer m .RUnlock ()
94
95
@@ -98,7 +99,7 @@ func (m *Module) IsDeleteOpAuthorised(project, dbType, col, token string, req *m
98
99
}
99
100
100
101
args := map [string ]interface {}{"op" : req .Operation , "auth" : auth , "find" : req .Find , "token" : token }
101
- err = m .matchRule (project , rule , map [string ]interface {}{"args" : args }, auth )
102
+ err = m .matchRule (ctx , project , rule , map [string ]interface {}{"args" : args }, auth )
102
103
if err != nil {
103
104
return http .StatusForbidden , err
104
105
}
@@ -107,7 +108,7 @@ func (m *Module) IsDeleteOpAuthorised(project, dbType, col, token string, req *m
107
108
}
108
109
109
110
// IsAggregateOpAuthorised checks if the crud operation is authorised
110
- func (m * Module ) IsAggregateOpAuthorised (project , dbType , col , token string , req * model.AggregateRequest ) (int , error ) {
111
+ func (m * Module ) IsAggregateOpAuthorised (ctx context. Context , project , dbType , col , token string , req * model.AggregateRequest ) (int , error ) {
111
112
m .RLock ()
112
113
defer m .RUnlock ()
113
114
@@ -117,7 +118,7 @@ func (m *Module) IsAggregateOpAuthorised(project, dbType, col, token string, req
117
118
}
118
119
119
120
args := map [string ]interface {}{"op" : req .Operation , "auth" : auth , "pipeline" : req .Pipeline , "token" : token }
120
- err = m .matchRule (project , rule , map [string ]interface {}{"args" : args }, auth )
121
+ err = m .matchRule (ctx , project , rule , map [string ]interface {}{"args" : args }, auth )
121
122
if err != nil {
122
123
return http .StatusForbidden , err
123
124
}
0 commit comments