-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmaas.yml
889 lines (889 loc) · 24.6 KB
/
maas.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
openapi: 3.0.0
info:
title: MaaS
description: MaaS (Matomat as a Service) API definition
version: 0.5.2
servers:
- url: https://maas.intern.k4cg.org/v0
description: The production server
- url: https://localhost:8443/v0
description: Local test setup
tags:
- name: auth
description: Authentication and authorization related operations
- name: users
description: User management related operations
- name: items
description: Item related operations
paths:
/auth/login:
post:
tags:
- auth
summary: Logs a user in and returns an JWT token for authentication
description: Logs a user in and returns an JWT token for authentication. The passes along validitiyseconds determine how long the token should be available.
requestBody:
description: User information required for login
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
username:
type: string
password:
type: string
validityseconds:
type: integer
format: int32
minimum: 0
required:
- username
- password
responses:
200:
description: Success
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/AuthSuccess'
400:
description: Invalid username/password supplied
/items:
get:
security:
- jwtTokenAuth: []
tags:
- items
summary: List all available items
description: Returns a map of item objects, with the item ID as key and the object as value
responses:
200:
description: List of items
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Item'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
security:
- jwtTokenAuth: []
tags:
- items
summary: Add a new item
description: Adds a new item to matomat. This can only be done by admins
requestBody:
description: Information required to create an item
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: The name of the item
type: string
cost:
description: The number of credits a single consumption of this Item requires (unit for credits is smallest unit in currency used)
type: integer
format: int32
minimum: 0
required:
- name
- cost
responses:
201:
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/items/stats:
get:
security:
- jwtTokenAuth: []
tags:
- items
summary: Get consumption stats of all items
description: Get the matomat stats for all items
responses:
200:
description: Success
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ItemStats'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/items/{itemId}:
get:
security:
- jwtTokenAuth: []
tags:
- items
summary: Get a certain Item
description: Get a certain Item
parameters:
- in: path
name: itemId
schema:
type: integer
format: int32
required: true
description: The ID of the Item that needs to be fetched
responses:
200:
description: successful operation
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
put:
security:
- jwtTokenAuth: []
tags:
- items
summary: Update Item
description: Update Item. This can only be done by admins
parameters:
- in: path
name: itemId
schema:
type: integer
format: int32
required: true
description: The ID of the Item that needs to be updated
requestBody:
description: Information required to update an item
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: The name of the item
type: string
cost:
description: The number of credits a single consumption of this Item requires (unit for credits is smallest unit in currency used)
type: integer
format: int32
minimum: 0
required:
- name
- cost
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
security:
- jwtTokenAuth: []
tags:
- items
summary: Delete Item
description: Delete the Item. This can only be done by admins. (Should only mark a Item as deleted to not loose reference for stats)
parameters:
- in: path
name: itemId
schema:
type: integer
format: int32
required: true
description: The ID of the Item that needs to be deleted
responses:
200:
description: Success. Returns the deleted item object
content:
application/json:
schema:
$ref: '#/components/schemas/Item'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/items/{itemId}/consume:
put:
security:
- jwtTokenAuth: []
tags:
- items
summary: Consumes a Item
description: Consumes a Item and subtracts the cost of the Item from the credit of the user.
parameters:
- in: path
name: itemId
schema:
type: integer
format: int32
required: true
description: The ID of the Item that needs to be consumed
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/ItemStats'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/items/{itemId}/stats:
get:
security:
- jwtTokenAuth: []
tags:
- items
summary: Get consumption stats
description: Get the matomat stats for a certain Item
parameters:
- in: path
name: itemId
schema:
type: integer
format: int32
required: true
description: The ID of the Item for which to fetch the stats
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/ItemStats'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users:
get:
security:
- jwtTokenAuth: []
tags:
- users
summary: List all users
description: List all users
responses:
200:
description: List of user objects
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/User'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
post:
security:
- jwtTokenAuth: []
tags:
- users
summary: Add a new user
description: Add a new user. Only admin users are allowed to do this. If "admin" is greater than 0, the new user will be created as admin user.
requestBody:
description: Information required to create an user
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
name:
description: The name of the user
type: string
password:
type: string
passwordrepeat:
type: string
admin:
type: integer
required:
- name
- password
- passwordrepeat
- admin
responses:
201:
description: Created
content:
application/json:
schema:
$ref: '#/components/schemas/User'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}:
get:
security:
- jwtTokenAuth: []
tags:
- users
summary: Get user by user ID
description: Get user by user ID. Returns a user object
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The user ID that needs to be fetched
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
delete:
security:
- jwtTokenAuth: []
tags:
- users
summary: Delete user
description: Delete user. This can only be done by the logged in user (for self) or an admin
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user to be deleted
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/credits/add:
put:
security:
- jwtTokenAuth: []
tags:
- users
summary: Add users credits
description: Add users credits. This can only be done by the logged in user or a admin.
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user for which the credits should be changed
requestBody:
description: Credits withdrawl information
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
credits:
type: integer
format: int32
minimum: 0
required:
- credits
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/admin/set:
put:
security:
- jwtTokenAuth: []
tags:
- users
summary: Promote a user to admin
description: Promote a user to admin. This can only be done by other admin users.
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user to promote to admin
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
403:
description: Logged in user is not allowed to promote given user to admin
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/admin/unset:
put:
security:
- jwtTokenAuth: []
tags:
- users
summary: Remove admin capabilities from an user
description: Remove admin capabilities from an user. This can only be done by other admin users.
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user to remove admin capabilities from
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
403:
description: Logged in user is not allowed to remove the admin capabilities from the given user
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/credits/withdraw:
put:
security:
- jwtTokenAuth: []
tags:
- users
summary: Widthdraw users credits
description: Widthdraw users credits. A user can only withdraw as many credits as she currently has, if more than available are attempted to withdraw, an error is returned and no withdrawl performed. This can only be done by the logged in user or a admin.
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user for which the credits should be changed
requestBody:
description: A - not negative - amount of credits
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
credits:
type: integer
format: int32
minimum: 0
required:
- credits
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
412:
description: Not enough credits to withdraw desired amount
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/credits/transfer:
put:
security:
- jwtTokenAuth: []
tags:
- users
summary: Transfer credits
description: Transfers credits from logged in user to given user
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user to transfer credits to
requestBody:
description: A - not negative - amount of credits to transfer
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
credits:
type: integer
format: int32
minimum: 0
required:
- credits
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/TransferredCredits'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/stats:
get:
security:
- jwtTokenAuth: []
tags:
- users
summary: Get matomat stats for user
description: Get the matomat stats for user. A user can only request the stats for herself
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user for which to fetch the stats
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/UserStats'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/password:
put:
security:
- jwtTokenAuth: []
tags:
- users
summary: Change password for currently logged in user.
description: Change password for currently logged in user. Must provide old and new passwords (twice) in order to be allowed to change it.
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user for which the password should be changed
requestBody:
description: The new password
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
password:
type: string
passwordnew:
type: string
passwordrepeat:
type: string
required:
- password
- passwordnew
- passwordrepeat
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/users/{userId}/resetpassword:
put:
security:
- jwtTokenAuth: []
tags:
- users
summary: Set password for user ID
description: Set password for user ID. This can only be done by a logged in admin for a different user than self.
parameters:
- in: path
name: userId
schema:
type: integer
format: int32
required: true
description: The ID of the user for which the password should be changed
requestBody:
description: The new password
required: true
content:
application/x-www-form-urlencoded:
schema:
type: object
properties:
passwordnew:
type: string
passwordrepeat:
type: string
required:
- passwordnew
- passwordrepeat
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/User'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/service/stats:
get:
security:
- jwtTokenAuth: []
tags:
- service
summary: Total service stats
description: Total service stats
responses:
200:
description: Success
content:
application/json:
schema:
$ref: '#/components/schemas/ServiceStats'
default:
description: An error occured
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
components:
securitySchemes:
jwtTokenAuth: # faking JWT bearer authentication using api key type
type: apiKey
in: header
name: Authorization
schemas:
AuthSuccess:
type: object
properties:
token:
type: string
expires:
type: integer
format: int32
user:
$ref: '#/components/schemas/User'
User:
type: object
properties:
id:
type: integer
format: int32
username:
type: string
credits:
type: integer
format: int32
admin:
type: boolean
TransferredCredits:
description: The information on the sending user after the transaction, as well as the amount transferred
type: object
properties:
sender:
$ref: '#/components/schemas/User'
credits:
type: integer
format: int32
UserStats:
description: Consumption stats of a user
type: array
items:
$ref: '#/components/schemas/ItemStats'
Item:
description: Represenation of a Item, containing its name and cost (in credits)
type: object
properties:
id:
type: integer
format: int32
name:
type: string
cost:
type: integer
format: int32
ItemStats:
description: Stats on a certain item
type: object
properties:
id:
type: integer
format: int32
name:
type: string
cost:
type: integer
format: int32
consumed:
type: integer
format: int32
ServiceStats:
description: Stats on the service
type: object
properties:
items:
type: object
properties:
count:
type: integer
format: int32
cost:
type: object
properties:
avg:
type: integer
format: int32
min:
type: integer
format: int32
max:
type: integer
format: int32
users:
type: object
properties:
count:
type: integer
format: int32
credits:
type: object
properties:
sum:
type: integer
format: int32
avg:
type: integer
format: int32
min:
type: integer
format: int32
max:
type: integer
format: int32
Error:
description: Represenation of an error
type: object
properties:
message:
type: string