@@ -19,7 +19,7 @@ func IsAdmin(w http.ResponseWriter, r *http.Request) (isAdminFlag bool) {
19
19
20
20
var admin Admin
21
21
22
- if DB .db .Debug (). Where ("email = ?" , googTok .Email ).First (& admin ).RecordNotFound () {
22
+ if DB .db .Where ("email = ?" , googTok .Email ).First (& admin ).RecordNotFound () {
23
23
return false
24
24
} else {
25
25
return true
@@ -50,13 +50,13 @@ func AcceptAdminRequest(w http.ResponseWriter, r *http.Request, ps httprouter.Pa
50
50
51
51
// gives admin privilege to user by adding entry to admins table
52
52
// while deleting entry from admin_requests table
53
- if DB .db .Debug (). Where ("admin_request_id = ?" , ps .ByName ("id" )).First (& admin_request ).RecordNotFound () {
53
+ if DB .db .Where ("admin_request_id = ?" , ps .ByName ("id" )).First (& admin_request ).RecordNotFound () {
54
54
response = Response {
55
55
false ,
56
56
"Unable to accept, request does not exists" ,
57
57
}
58
58
} else {
59
- DB .db .Debug (). Where ("admin_request_id = ?" , ps .ByName ("id" )).First (& admin_request )
59
+ DB .db .Where ("admin_request_id = ?" , ps .ByName ("id" )).First (& admin_request )
60
60
admin = Admin {
61
61
Name : admin_request .Name ,
62
62
Email : admin_request .Email ,
@@ -68,6 +68,7 @@ func AcceptAdminRequest(w http.ResponseWriter, r *http.Request, ps httprouter.Pa
68
68
true ,
69
69
"Request accepted, new admin created" ,
70
70
}
71
+ log .Printf ("New admin created. Name: %v | Email: %v" , admin .Name , admin .Email )
71
72
}
72
73
73
74
} else {
@@ -98,13 +99,13 @@ func RejectAdminRequest(w http.ResponseWriter, r *http.Request, ps httprouter.Pa
98
99
if IsAdmin (w , r ) == true {
99
100
100
101
// deletes entry from admin_requests table
101
- if DB .db .Debug (). Where ("admin_request_id = ?" , ps .ByName ("id" )).First (& admin_request ).RecordNotFound () {
102
+ if DB .db .Where ("admin_request_id = ?" , ps .ByName ("id" )).First (& admin_request ).RecordNotFound () {
102
103
response = Response {
103
104
false ,
104
105
"Unable to delete, request does not exists" ,
105
106
}
106
107
} else {
107
- DB .db .Debug (). Where ("admin_request_id = ?" , ps .ByName ("id" )).Delete (& admin_request )
108
+ DB .db .Where ("admin_request_id = ?" , ps .ByName ("id" )).Delete (& admin_request )
108
109
response = Response {
109
110
true ,
110
111
"Admin request successfully rejected" ,
@@ -139,13 +140,14 @@ func RevokeAdminPrivilege(w http.ResponseWriter, r *http.Request, ps httprouter.
139
140
if IsAdmin (w , r ) == true {
140
141
141
142
// deletes entry from admins table
142
- if DB .db .Debug (). Where ("admin_id = ?" , ps .ByName ("id" )).First (& admin ).RecordNotFound () {
143
+ if DB .db .Where ("admin_id = ?" , ps .ByName ("id" )).First (& admin ).RecordNotFound () {
143
144
response = Response {
144
145
false ,
145
146
"Unable to delete, admin does not exists" ,
146
147
}
147
148
} else {
148
- DB .db .Debug ().Where ("admin_id = ?" , ps .ByName ("id" )).Delete (& admin )
149
+ log .Printf ("An admin's privileges revoked. Name: %v | Email: %v" , admin .Name , admin .Email )
150
+ DB .db .Where ("admin_id = ?" , ps .ByName ("id" )).Delete (& admin )
149
151
response = Response {
150
152
true ,
151
153
"Admin privileges successfully revoked" ,
@@ -197,7 +199,7 @@ func AcceptAccessRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P
197
199
// gives access privilege to user by adding entry to accesses table
198
200
// executes shell script which copies user's ssh key to desired dest server over ssh
199
201
// while deleting entry from access_requests table
200
- if DB .db .Debug (). Where ("access_request_id = ?" , ps .ByName ("id" )).First (& access_request ).RecordNotFound () {
202
+ if DB .db .Where ("access_request_id = ?" , ps .ByName ("id" )).First (& access_request ).RecordNotFound () {
201
203
response = Response {
202
204
false ,
203
205
"Unable to accept, request does not exists" ,
@@ -215,7 +217,7 @@ func AcceptAccessRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P
215
217
216
218
} else {
217
219
218
- DB .db .Debug (). Where ("access_request_id = ?" , ps .ByName ("id" )).First (& access_request )
220
+ DB .db .Where ("access_request_id = ?" , ps .ByName ("id" )).First (& access_request )
219
221
220
222
// execute shell script to copy ssh key to specified server over ssh
221
223
sh .Command ("./scripts/copy_key_to_server.sh" , receive .IP , access_request .SshKey ).Run ()
@@ -234,6 +236,8 @@ func AcceptAccessRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P
234
236
"Request accepted, new access created" ,
235
237
}
236
238
239
+ log .Printf ("New access granted. Name: %v | Email: %v | To: %v" , access .Name , access .Email , access .IP )
240
+
237
241
}
238
242
239
243
}
@@ -266,13 +270,13 @@ func RejectAccessRequest(w http.ResponseWriter, r *http.Request, ps httprouter.P
266
270
if IsAdmin (w , r ) == true {
267
271
268
272
// deletes entry from access_requests table
269
- if DB .db .Debug (). Where ("access_request_id = ?" , ps .ByName ("id" )).First (& access_request ).RecordNotFound () {
273
+ if DB .db .Where ("access_request_id = ?" , ps .ByName ("id" )).First (& access_request ).RecordNotFound () {
270
274
response = Response {
271
275
false ,
272
276
"Unable to delete, request does not exists" ,
273
277
}
274
278
} else {
275
- DB .db .Debug (). Where ("access_request_id = ?" , ps .ByName ("id" )).Delete (& access_request )
279
+ DB .db .Where ("access_request_id = ?" , ps .ByName ("id" )).Delete (& access_request )
276
280
response = Response {
277
281
true ,
278
282
"Access request successfully rejected" ,
@@ -308,7 +312,7 @@ func RevokeAccessPrivilege(w http.ResponseWriter, r *http.Request, ps httprouter
308
312
309
313
// revokes access privilege to user by deleting entry from accesses table
310
314
// executes shell script which removes user's ssh key from intended dest server over ssh
311
- if DB .db .Debug (). Where ("access_id = ?" , ps .ByName ("id" )).First (& access ).RecordNotFound () {
315
+ if DB .db .Where ("access_id = ?" , ps .ByName ("id" )).First (& access ).RecordNotFound () {
312
316
response = Response {
313
317
false ,
314
318
"Unable to delete, access does not exists" ,
@@ -326,7 +330,9 @@ func RevokeAccessPrivilege(w http.ResponseWriter, r *http.Request, ps httprouter
326
330
327
331
} else {
328
332
329
- DB .db .Debug ().Where ("access_id = ?" , ps .ByName ("id" )).Delete (& access )
333
+ log .Printf ("Access privilege revoked. Name: %v | Email: %v | From: %v" , access .Name , access .Email , access .IP )
334
+
335
+ DB .db .Where ("access_id = ?" , ps .ByName ("id" )).Delete (& access )
330
336
331
337
// execute shell script to remove ssh key from the specified server
332
338
sh .Command ("./scripts/remove_key_from_server.sh" , access .IP , access .SshKey ).Run ()
0 commit comments