@@ -49,15 +49,18 @@ type Service interface {
49
49
GetChaosHubStats (ctx context.Context , projectID string ) (* model.GetChaosHubStatsResponse , error )
50
50
}
51
51
52
+
52
53
type chaosHubService struct {
53
- chaosHubOperator * dbSchemaChaosHub.Operator
54
+ chaosHubOperator * dbSchemaChaosHub.Operator
55
+ authConfigOperator * authorization.Operator
54
56
}
55
57
56
58
// NewService returns a new instance of Service
57
- func NewService (chaosHubOperator * dbSchemaChaosHub.Operator ) Service {
58
- return & chaosHubService {
59
- chaosHubOperator : chaosHubOperator ,
60
- }
59
+ func NewService (chaosHubOperator * dbSchemaChaosHub.Operator , authConfigOperator * authorization.Operator ) Service {
60
+ return & chaosHubService {
61
+ chaosHubOperator : chaosHubOperator ,
62
+ authConfigOperator : authConfigOperator ,
63
+ }
61
64
}
62
65
63
66
// AddChaosHub is used for Adding a new ChaosHub
@@ -75,7 +78,7 @@ func (c *chaosHubService) AddChaosHub(ctx context.Context, chaosHub model.Create
75
78
}
76
79
77
80
tkn := ctx .Value (authorization .AuthKey ).(string )
78
- username , err := authorization .GetUsername (tkn )
81
+ username , err := c . authConfigOperator .GetUsername (tkn )
79
82
if err != nil {
80
83
log .Error ("error getting username: " , err )
81
84
return nil , err
@@ -129,7 +132,7 @@ func (c *chaosHubService) AddChaosHub(ctx context.Context, chaosHub model.Create
129
132
return newHub .GetOutputChaosHub (), nil
130
133
}
131
134
132
- func (c * chaosHubService ) AddRemoteChaosHub (ctx context.Context , chaosHub model.CreateRemoteChaosHub , projectID string ) (* model.ChaosHub , error ) {
135
+ func (c * chaosHubService ) AddRemoteChaosHub (ctx context.Context , chaosHub model.CreateRemoteChaosHub , projectID string , authConfigOperator * authorization. Operator ) (* model.ChaosHub , error ) {
133
136
IsExist , err := c .IsChaosHubAvailable (ctx , chaosHub .Name , projectID )
134
137
if err != nil {
135
138
return nil , err
@@ -144,7 +147,7 @@ func (c *chaosHubService) AddRemoteChaosHub(ctx context.Context, chaosHub model.
144
147
currentTime := time .Now ()
145
148
146
149
tkn := ctx .Value (authorization .AuthKey ).(string )
147
- username , err := authorization .GetUsername (tkn )
150
+ username , err := c . authConfigOperator .GetUsername (tkn )
148
151
149
152
if err != nil {
150
153
log .Error ("error getting userID: " , err )
@@ -198,7 +201,7 @@ func (c *chaosHubService) AddRemoteChaosHub(ctx context.Context, chaosHub model.
198
201
}
199
202
200
203
// SaveChaosHub is used for Adding a new ChaosHub
201
- func (c * chaosHubService ) SaveChaosHub (ctx context.Context , chaosHub model.CreateChaosHubRequest , projectID string ) (* model.ChaosHub , error ) {
204
+ func (c * chaosHubService ) SaveChaosHub (ctx context.Context , chaosHub model.CreateChaosHubRequest , projectID string , authConfigOperator * authorization. Operator ) (* model.ChaosHub , error ) {
202
205
203
206
IsExist , err := c .IsChaosHubAvailable (ctx , chaosHub .Name , projectID )
204
207
if err != nil {
@@ -211,7 +214,7 @@ func (c *chaosHubService) SaveChaosHub(ctx context.Context, chaosHub model.Creat
211
214
// Initialize a UID for new Hub.
212
215
uuid := uuid .New ()
213
216
tkn := ctx .Value (authorization .AuthKey ).(string )
214
- username , err := authorization .GetUsername (tkn )
217
+ username , err := c . authConfigOperator .GetUsername (tkn )
215
218
216
219
if err != nil {
217
220
log .Error ("error getting userID: " , err )
@@ -310,7 +313,7 @@ func (c *chaosHubService) SyncChaosHub(ctx context.Context, hubID string, projec
310
313
return "Successfully synced ChaosHub" , nil
311
314
}
312
315
313
- func (c * chaosHubService ) UpdateChaosHub (ctx context.Context , chaosHub model.UpdateChaosHubRequest , projectID string ) (* model.ChaosHub , error ) {
316
+ func (c * chaosHubService ) UpdateChaosHub (ctx context.Context , chaosHub model.UpdateChaosHubRequest , projectID string , authConfigOperator * authorization. Operator ) (* model.ChaosHub , error ) {
314
317
315
318
cloneHub := model.CloningInput {
316
319
RepoBranch : chaosHub .RepoBranch ,
@@ -367,7 +370,7 @@ func (c *chaosHubService) UpdateChaosHub(ctx context.Context, chaosHub model.Upd
367
370
368
371
time := time .Now ().UnixMilli ()
369
372
tkn := ctx .Value (authorization .AuthKey ).(string )
370
- username , err := authorization .GetUsername (tkn )
373
+ username , err := c . authConfigOperator .GetUsername (tkn )
371
374
372
375
query := bson.D {{"hub_id" , chaosHub .ID }, {"is_removed" , false }}
373
376
update := bson.D {
@@ -408,9 +411,9 @@ func (c *chaosHubService) UpdateChaosHub(ctx context.Context, chaosHub model.Upd
408
411
return & newChaosHub , nil
409
412
}
410
413
411
- func (c * chaosHubService ) DeleteChaosHub (ctx context.Context , hubID string , projectID string ) (bool , error ) {
414
+ func (c * chaosHubService ) DeleteChaosHub (ctx context.Context , hubID string , projectID string , authConfigOperator * authorization. Operator ) (bool , error ) {
412
415
tkn := ctx .Value (authorization .AuthKey ).(string )
413
- username , err := authorization .GetUsername (tkn )
416
+ username , err := c . authConfigOperator .GetUsername (tkn )
414
417
if err != nil {
415
418
return false , err
416
419
}
0 commit comments