-
Notifications
You must be signed in to change notification settings - Fork 36
/
SwaggerController.scala
3093 lines (2920 loc) · 124 KB
/
SwaggerController.scala
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
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package otoroshi.controllers
import controllers.{Assets, AssetsBuilder}
import otoroshi.env.Env
import play.api.Logger
import play.api.libs.json._
import play.api.mvc._
object Implicits {
implicit class EnhancedJsValue(val value: JsValue) extends AnyVal {
def ~~>(description: String): JsValue =
value.as[JsObject] ++ Json.obj(
"description" -> description
)
}
}
class SwaggerController(cc: ControllerComponents, assetsBuilder: AssetsBuilder)(implicit env: Env)
extends AbstractController(cc) {
import Implicits._
implicit lazy val ec = env.otoroshiExecutionContext
lazy val logger = Logger("otoroshi-swagger-controller")
def swagger =
Action { req =>
Ok(Json.prettyPrint(swaggerDescriptor())).as("application/json").withHeaders("Access-Control-Allow-Origin" -> "*")
}
def swaggerUi =
Action { req =>
Ok(
otoroshi.views.html.oto.documentationframe(
s"${env.exposedRootScheme}://${env.backOfficeHost}${env.privateAppsPort}/api/swagger.json"
)
)
}
def openapi = assetsBuilder.at("openapi.json")
def openapiUi =
Action { req =>
Ok(
otoroshi.views.html.oto.documentationframe(
//s"${env.exposedRootScheme}://${env.backOfficeHost}${env.privateAppsPort}/assets/openapi.json"
s"${env.exposedRootScheme}://${env.backOfficeHost}${env.privateAppsPort}/apis/openapi.json"
)
)
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Types definitions
def SimpleObjectType =
Json.obj(
"type" -> "object",
//"required" -> Json.arr(),
"example" -> Json.obj("key" -> "value"),
"additionalProperties" -> Json.obj("type" -> "string")
)
def SimpleArrayType =
Json.obj("type" -> "array", "items" -> SimpleStringType, "example" -> Json.arr("a string value"))
def SimpleStringType = Json.obj("type" -> "string", "example" -> "a string value")
def SimpleDoubleType = Json.obj("type" -> "integer", "format" -> "double", "example" -> 42.2)
def OptionalStringType = Json.obj("type" -> "string", "example" -> "a string value")
def SimpleBooleanType = Json.obj("type" -> "boolean", "example" -> true)
def SimpleDateType = Json.obj("type" -> "string", "format" -> "date", "example" -> "2017-07-21")
def SimpleDateTimeType = Json.obj("type" -> "string", "format" -> "date-time", "example" -> "2017-07-21T17:32:28Z")
def SimpleTimeType = Json.obj("type" -> "string", "format" -> "time", "example" -> "17:32:28.000")
def SimpleLongType = Json.obj("type" -> "integer", "format" -> "int64", "example" -> 123)
def SimpleIntType = Json.obj("type" -> "integer", "format" -> "int32", "example" -> 123123)
def SimpleHostType = Json.obj("type" -> "string", "format" -> "hostname", "example" -> "www.google.com")
def SimpleIpv4Type = Json.obj("type" -> "string", "format" -> "ipv4", "example" -> "192.192.192.192")
def SimpleUriType = Json.obj("type" -> "string", "format" -> "uri", "example" -> "http://www.google.com")
def SimpleEmailType = Json.obj("type" -> "string", "format" -> "email", "example" -> "admin@otoroshi.io")
def SimpleUuidType =
Json.obj("type" -> "string", "format" -> "uuid", "example" -> "110e8400-e29b-11d4-a716-446655440000")
def Ref(name: String): JsObject = Json.obj("$ref" -> s"#/components/schemas/$name")
def Constant(str: String) =
Json.obj(
"type" -> "string",
"enum" -> Json.arr(str)
)
def ArrayOf(ref: JsValue) =
Json.obj(
"type" -> "array",
"items" -> ref
)
def OneOf(refs: JsValue*) =
Json.obj(
"oneOf" -> JsArray(refs.toSeq)
)
def RequestBody(typ: JsValue) =
Json.obj(
"required" -> true,
"content" -> Json.obj(
"application/json" -> Json.obj(
"schema" -> typ
)
)
)
def FormBody(typ: JsValue) =
Json.obj(
"required" -> true,
"content" -> Json.obj(
"application/x-www-form-urlencoded" -> Json.obj(
"schema" -> typ
)
)
)
def QueryParam(name: String, desc: String) =
Json.obj(
"in" -> "query",
"name" -> name,
"required" -> false,
"description" -> desc,
"schema" -> Json.obj("type" -> "string")
)
def PathParam(name: String, desc: String) =
Json.obj(
"in" -> "path",
"name" -> name,
"required" -> true,
"description" -> desc,
"schema" -> Json.obj("type" -> "string")
)
def BodyParam(desc: String, typ: JsValue) =
Some(
Json.obj(
"schema" -> typ
)
)
def GoodResponse(ref: JsValue, contents: JsArray = Json.arr("application/json")) =
Json.obj(
"description" -> "Successful operation",
"content" -> contents.value
.map(_.as[String])
.foldLeft(Json.obj())((result, label) => {
result ++ Json.obj(
label -> Json.obj(
"schema" -> ref
)
)
})
)
def BulkResponse(action: String, status: String, actionIdDescription: String) =
GoodResponse(
ArrayOf(
Json.obj(
"description" -> "The bulk response",
"type" -> "object",
"properties" -> Json.obj(
"status" -> Constant(status) ~~> "Status",
action -> SimpleBooleanType ~~> "Whether the action was carried out correctly or not",
"id" -> SimpleBooleanType ~~> actionIdDescription
)
)
)
)
def Tag(name: String, description: String) =
Json.obj(
"name" -> name,
"description" -> description
)
def Operation(
summary: String,
tag: String,
description: String = "",
operationId: String = "",
parameters: JsArray = Json.arr(),
goodCode: String = "200",
goodResponse: JsObject,
produces: JsArray = Json.arr("application/json"),
body: Option[JsObject] = None
): JsValue =
Json.obj(
"deprecated" -> false,
"tags" -> Json.arr(tag),
"summary" -> summary,
"description" -> description,
"operationId" -> operationId,
"parameters" -> parameters,
"responses" -> Json.obj(
"401" -> Json.obj(
"description" -> "You have to provide an Api Key. Api Key can be passed with 'Otoroshi-Client-Id' and 'Otoroshi-Client-Secret' headers, or use basic http authentication"
),
"400" -> Json.obj(
"description" -> "Bad resource format. Take another look to the swagger, or open an issue :)"
),
"404" -> Json.obj(
"description" -> "Resource not found or does not exist"
),
goodCode -> goodResponse
),
"security" -> Json.arr(
Json.obj(
"otoroshi_auth" -> Json.arr()
)
)
) ++ body.fold(Json.obj())(b => {
Json.obj(
"requestBody" -> Json.obj(
"content" -> produces.value
.map(_.as[String])
.foldLeft(Json.obj())((result, label) => {
result ++ Json.obj(label -> b)
})
)
)
})
def NoAuthOperation(
summary: String,
tag: String,
description: String = "",
operationId: String = "",
parameters: JsArray = Json.arr(),
goodCode: String = "200",
goodResponse: JsObject
): JsValue =
Json.obj(
"deprecated" -> false,
"tags" -> Json.arr(tag),
"summary" -> summary,
"description" -> description,
"operationId" -> operationId,
"parameters" -> parameters,
"responses" -> Json.obj(
"400" -> Json.obj(
"description" -> "Bad resource format. Take another look to the swagger, or open an issue :)"
),
"404" -> Json.obj(
"description" -> "Resource not found or does not exist"
),
goodCode -> goodResponse
)
)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Models definition
def LargeRequestFaultConfig =
Json.obj(
"description" -> "Config for large request injection fault",
"type" -> "object",
"required" -> Json.arr("ratio", "additionalRequestSize"),
"properties" -> Json.obj(
"ratio" -> SimpleDoubleType ~~> "The percentage of requests affected by this fault. Value should be between 0.0 and 1.0",
"additionalRequestSize" -> SimpleIntType ~~> "The size added to the request body in bytes. Added payload will be spaces only."
)
)
def BadResponse =
Json.obj(
"description" -> "An HTTP response that is not supposed to be returned by a service",
"type" -> "object",
"required" -> Json.arr("status", "body", "headers"),
"properties" -> Json.obj(
"status" -> SimpleIntType ~~> "The HTTP status for the response",
"body" -> SimpleStringType ~~> "The body of the HTTP response",
"headers" -> SimpleObjectType ~~> "The HTTP headers of the response"
)
)
def LargeResponseFaultConfig =
Json.obj(
"description" -> "Config for large response injection fault",
"type" -> "object",
"required" -> Json.arr("ratio", "additionalResponseSize"),
"properties" -> Json.obj(
"ratio" -> SimpleDoubleType ~~> "The percentage of requests affected by this fault. Value should be between 0.0 and 1.0",
"additionalRequestSize" -> SimpleIntType ~~> "The size added to the response body in bytes. Added payload will be spaces only."
)
)
def LatencyInjectionFaultConfig =
Json.obj(
"description" -> "Config for large latency injection fault",
"type" -> "object",
"required" -> Json.arr("ratio", "from", "to"),
"properties" -> Json.obj(
"ratio" -> SimpleDoubleType ~~> "The percentage of requests affected by this fault. Value should be between 0.0 and 1.0",
"from" -> SimpleIntType ~~> "The start range of latency added to the request",
"to" -> SimpleIntType ~~> "The end range of latency added to the request"
)
)
def BadResponsesFaultConfig =
Json.obj(
"description" -> "Config for bad requests injection fault",
"type" -> "object",
"required" -> Json.arr("ratio", "responses"),
"properties" -> Json.obj(
"ratio" -> SimpleDoubleType ~~> "The percentage of requests affected by this fault. Value should be between 0.0 and 1.0",
"responses" -> ArrayOf(Ref("BadResponse")) ~~> "The possibles responses"
)
)
def ChaosConfig =
Json.obj(
"description" -> "Configuration for the faults that can be injected in requests",
"type" -> "object",
"required" -> Json.arr(
"enabled"
),
"properties" -> Json.obj(
"enabled" -> SimpleBooleanType ~~> "Whether or not this config is enabled",
"largeRequestFaultConfig" -> Ref("LargeRequestFaultConfig"),
"largeResponseFaultConfig" -> Ref("LargeResponseFaultConfig"),
"latencyInjectionFaultConfig" -> Ref("LatencyInjectionFaultConfig"),
"badResponsesFaultConfig" -> Ref("BadResponsesFaultConfig")
)
)
def OutageStrategy =
Json.obj(
"type" -> "string",
"enum" -> Json.arr("OneServicePerGroup", "AllServicesPerGroup")
)
def SnowMonkeyConfig =
Json.obj(
"description" -> """Configuration for the faults that can be injected in requests. The name Snow Monkey is an hommage to Netflix's Chaos Monkey 😉""",
"type" -> "object",
"required" -> Json.arr(
"enabled",
"outageStrategy",
"includeUserFacingDescriptors",
"dryRun",
"timesPerDay",
"startTime",
"stopTime",
"outageDurationFrom",
"outageDurationTo",
"targetGroups",
"chaosConfig"
),
"properties" -> Json.obj(
"enabled" -> SimpleBooleanType ~~> "Whether or not this config is enabled",
"outageStrategy" -> Ref("OutageStrategy") ~~> "",
"includeUserFacingDescriptors" -> SimpleBooleanType ~~> "Whether or not user facing apps. will be impacted by Snow Monkey",
"dryRun" -> SimpleBooleanType ~~> "Whether or not outages will actualy impact requests",
"timesPerDay" -> SimpleIntType ~~> "Number of time per day each service will be outage",
"startTime" -> SimpleTimeType ~~> "Start time of Snow Monkey each day",
"stopTime" -> SimpleTimeType ~~> "Stop time of Snow Monkey each day",
"outageDurationFrom" -> SimpleIntType ~~> "Start of outage duration range",
"outageDurationTo" -> SimpleIntType ~~> "End of outage duration range",
"targetGroups" -> ArrayOf(
SimpleStringType
) ~~> "Groups impacted by Snow Monkey. If empty, all groups will be impacted",
"chaosConfig" -> Ref("ChaosConfig")
)
)
def Outage =
Json.obj(
"description" -> "An outage by the Snow Monkey on a service",
"type" -> "object",
"required" -> Json.arr("descriptorId", "descriptorName", "until", "duration"),
"properties" -> Json.obj(
"descriptorId" -> SimpleStringType ~~> "The service impacted by outage",
"descriptorName" -> SimpleStringType ~~> "The name of service impacted by outage",
"until" -> SimpleTimeType ~~> "The end of the outage",
"duration" -> SimpleIntType ~~> "The duration of the outage"
)
)
def Target =
Json.obj(
"description" -> "A Target is where an HTTP call will be forwarded in the end from a service domain",
"type" -> "object",
"required" -> Json.arr("host", "scheme"),
"properties" -> Json.obj(
"host" -> SimpleHostType ~~> "The host on which the HTTP call will be forwarded. Can be a domain name, or an IP address. Can also have a port",
"scheme" -> SimpleStringType ~~> "The protocol used for communication. Can be http or https"
)
)
def IpFiltering =
Json.obj(
"description" -> "The filtering configuration block for a service of globally.",
"type" -> "object",
"required" -> Json.arr("whitelist", "blacklist"),
"properties" -> Json.obj(
"whitelist" -> ArrayOf(SimpleIpv4Type) ~~> "Whitelisted IP addresses",
"blacklist" -> ArrayOf(SimpleIpv4Type) ~~> "Blacklisted IP addresses"
)
)
def ExposedApi =
Json.obj(
"description" -> "The Open API configuration for your service (if one)",
"type" -> "object",
"required" -> Json.arr("exposeApi"),
"properties" -> Json.obj(
"exposeApi" -> SimpleBooleanType ~~> "Whether or not the current service expose an API with an Open API descriptor",
"openApiDescriptorUrl" -> SimpleUriType ~~> "The URL of the Open API descriptor"
)
)
def HealthCheck =
Json.obj(
"description" -> "The configuration for checking health of a service. Otoroshi will perform GET call on the URL to check if the service is still alive",
"type" -> "object",
"required" -> Json.arr("enabled"),
"properties" -> Json.obj(
"enabled" -> SimpleBooleanType ~~> "Whether or not healthcheck is enabled on the current service descriptor",
"url" -> SimpleUriType ~~> "The URL to check"
)
)
def StatsdConfig =
Json.obj(
"description" -> "The configuration for statsd metrics push",
"type" -> "object",
"required" -> Json.arr("host", "port", "datadog"),
"properties" -> Json.obj(
"host" -> SimpleStringType ~~> "The host of the StatsD agent",
"port" -> SimpleIntType ~~> "The port of the StatsD agent",
"datadog" -> SimpleBooleanType ~~> "Datadog agent"
)
)
def CorsSettings =
Json.obj(
"description" -> "The configuration for cors support",
"type" -> "object",
"required" -> Json.arr(
"enabled",
"allowOrigin",
"exposeHeaders",
"allowHeaders",
"allowMethods",
"excludedPatterns",
"maxAge",
"allowCredentials"
),
"properties" -> Json.obj(
"enabled" -> SimpleBooleanType ~~> "Whether or not cors is enabled",
"allowOrigin" -> SimpleStringType ~~> "The cors allowed origin",
"exposeHeaders" -> ArrayOf(SimpleStringType) ~~> "The cors exposed header",
"allowHeaders" -> ArrayOf(SimpleStringType) ~~> "The cors allowed headers",
"allowMethods" -> ArrayOf(SimpleStringType) ~~> "The cors allowed methods",
"excludedPatterns" -> ArrayOf(SimpleStringType) ~~> "The cors excluded patterns",
"maxAge" -> SimpleIntType ~~> "Cors max age",
"allowCredentials" -> SimpleBooleanType ~~> "Allow to pass credentials"
)
)
def RedirectionSettings =
Json.obj(
"description" -> "The configuration for redirection per service",
"type" -> "object",
"required" -> Json.arr(
"enabled",
"to",
"code"
),
"properties" -> Json.obj(
"enabled" -> SimpleBooleanType ~~> "Whether or not redirection is enabled",
"to" -> SimpleStringType ~~> "The location for redirection",
"code" -> SimpleIntType ~~> "The http redirect code"
)
)
def ValidationAuthority =
Json.obj(
"description" -> "Settings to access a validation authority server",
"type" -> "object",
"required" -> Json.arr(
"id",
"name",
"description",
"url",
"host",
"goodTtl",
"badTtl",
"method",
"path",
"timeout",
"noCache",
"alwaysValid",
"headers"
),
"properties" -> Json.obj(
"id" -> SimpleStringType ~~> "The id of the settings",
"name" -> SimpleStringType ~~> "The name of the settings",
"description" -> SimpleStringType ~~> "The description of the settings",
"url" -> SimpleStringType ~~> "The URL of the server",
"host" -> SimpleStringType ~~> "The host of the server",
"goodTtl" -> SimpleLongType ~~> "The TTL for valid access response caching",
"badTtl" -> SimpleLongType ~~> "The TTL for invalid access response caching",
"method" -> SimpleStringType ~~> "The HTTP method",
"path" -> SimpleStringType ~~> "The URL path",
"timeout" -> SimpleLongType ~~> "The call timeout",
"noCache" -> SimpleBooleanType ~~> "Avoid caching responses",
"alwaysValid" -> SimpleBooleanType ~~> "Bypass http calls, every certificates are valids",
"headers" -> SimpleObjectType ~~> "HTTP call headers"
)
)
def DataExporterConfig =
Json.obj(
"description" -> "Settings to export Otorshi events",
"type" -> "object",
"properties" -> Json.obj(
"enabled" -> SimpleStringType ~~> "Boolean",
"typ" -> Json.obj(
"type" -> "string",
"enum" -> Json.arr(
"kafka",
"pulsar",
"file",
"mailer",
"elastic",
"console",
"custom"
),
"description" -> "Type of data exporter"
),
"id" -> SimpleStringType ~~> "Id",
"name" -> SimpleStringType ~~> "Name",
"desc" -> SimpleStringType ~~> "Description",
"metadata" -> SimpleObjectType ~~> "Metadata",
"location" -> Ref("Location") ~~> "location",
"bufferSize" -> SimpleIntType ~~> "buffer size",
"jsonWorkers" -> SimpleIntType ~~> "nb workers",
"sendWorkers" -> SimpleIntType ~~> "send workers",
"groupSize" -> SimpleIntType ~~> "Group size",
"groupDuration" -> SimpleLongType ~~> "duration",
"filtering" -> Ref("Filtering") ~~> "filtering",
"projection" -> SimpleObjectType ~~> "projection",
"config" -> OneOf(
Ref("ElasticConfig"),
Ref("KafkaConfig"),
Ref("PulsarDataExporterConfig"),
Ref("FileDataExporterConfig"),
Ref("MailerGenericExporterConfig"),
Ref("MailerConsoleExporterConfig"),
Ref("MailerMailgunExporterConfig"),
Ref("MailerMailjetExporterConfig"),
Ref("MailerSendgridExporterConfig"),
Ref("ConsoleDataExporterConfig"),
Ref("CustomDataExporterConfig")
) ~~> "Data Exporter config"
)
)
def Filtering =
Json.obj(
"type" -> "object",
"required" -> Json.arr("include, exclude"),
"properties" -> Json.obj(
"include" -> ArrayOf(SimpleObjectType) ~~> "Including pattern",
"exclude" -> ArrayOf(SimpleObjectType) ~~> "Excluding pattern"
)
)
def Location =
Json.obj(
"type" -> "object",
"required" -> Json.arr("tenant", "teams"),
"properties" -> Json.obj(
"tenant" -> SimpleStringType ~~> "Tenant id",
"teams" -> ArrayOf(SimpleObjectType) ~~> "Team ids"
)
)
def KafkaConfig =
Json.obj(
"description" -> "The configuration for kafka access",
"type" -> "object",
"required" -> Json.arr("servers"),
"properties" -> Json.obj(
"servers" -> ArrayOf(SimpleStringType) ~~> "URLs of the kafka servers",
"keyPass" -> OptionalStringType ~~> "Optional keypass",
"keyStore" -> OptionalStringType ~~> "Optional path to keystore",
"trustore" -> OptionalStringType ~~> "Optional path to trustore",
"topic" -> OptionalStringType ~~> "Optional kafka topic (otoroshi-events by default)"
)
)
def WebhookConfig =
Json.obj(
"description" -> "The configuration for webhook",
"type" -> "object",
"required" -> Json.arr("servers"),
"properties" -> Json.obj(
"url" -> ArrayOf(SimpleStringType) ~~> "URLs of the webhook",
"headers" -> SimpleObjectType ~~> "Optional headers"
)
)
def PulsarDataExporterConfig =
Json.obj(
"description" -> "The configuration for kafka access",
"type" -> "object",
"required" -> Json.arr("uri", "tenant", "namespace", "topic"),
"properties" -> Json.obj(
"uri" -> ArrayOf(SimpleStringType) ~~> "URI of the pulsar server",
"tenant" -> OptionalStringType ~~> "Tenant",
"namespace" -> OptionalStringType ~~> "Namespace",
"topic" -> OptionalStringType ~~> "Topic"
)
)
def FileDataExporterConfig =
Json.obj(
"type" -> "object",
"required" -> Json.arr("path"),
"properties" -> Json.obj(
"path" -> SimpleStringType ~~> "Path to file"
)
)
def MailerGenericExporterConfig =
Json.obj(
"type" -> "object",
"required" -> Json.arr("type"),
"properties" -> Json.obj(
"type" -> Constant("generic") ~~> "Type of mailer",
"url" -> SimpleStringType ~~> "Url of mailer",
"headers" -> SimpleObjectType ~~> "Optional headers",
"to" -> ArrayOf(SimpleStringType) ~~> "Email adresses of recipents"
)
)
def MailerConsoleExporterConfig =
Json.obj(
"type" -> "object",
"properties" -> Json.obj(
"type" -> Constant("generic") ~~> "Type of mailer"
)
)
def MailerMailgunExporterConfig =
Json.obj(
"type" -> "object",
"required" -> Json.arr("type"),
"properties" -> Json.obj(
"type" -> Constant("mailgun") ~~> "Type of mailer",
"eu" -> SimpleBooleanType ~~> "Whether the mailgun server is european",
"apiKey" -> SimpleStringType ~~> "Mailgun apiKey",
"domain" -> SimpleStringType ~~> "Mailgun domain",
"to" -> ArrayOf(SimpleEmailType) ~~> "Email adresses of recipents"
)
)
def MailerMailjetExporterConfig =
Json.obj(
"type" -> "object",
"required" -> Json.arr("type"),
"properties" -> Json.obj(
"type" -> Constant("mailjet") ~~> "Type of mailer",
"apiKeyPublic" -> SimpleStringType ~~> "Mailjet public apiKey",
"apiKeyPrivate" -> SimpleStringType ~~> "Mailjet private apiKey",
"to" -> ArrayOf(SimpleEmailType) ~~> "Email adresses of recipents"
)
)
def MailerSendgridExporterConfig =
Json.obj(
"type" -> "object",
"required" -> Json.arr("type"),
"properties" -> Json.obj(
"type" -> Constant("sendgrid") ~~> "Type of mailer",
"apiKeyPublic" -> SimpleStringType ~~> "Sendgrid apiKey",
"to" -> ArrayOf(SimpleEmailType) ~~> "Email adresses of recipents"
)
)
def ConsoleDataExporterConfig =
Json.obj(
"type" -> "object",
"properties" -> Json.obj()
)
def CustomDataExporterConfig =
Json.obj(
"type" -> "object",
"required" -> Json.arr("ref", "config"),
"properties" -> Json.obj(
"ref" -> SimpleStringType ~~> "Script Ref",
"config" -> SimpleObjectType ~~> "Custom data exporter config"
)
)
def ElasticConfig =
Json.obj(
"description" -> "The configuration for elastic access",
"type" -> "object",
"required" -> Json.arr("clusterUri", "index", "type", "user", "password", "headers"),
"properties" -> Json.obj(
"clusterUri" -> SimpleStringType ~~> "URL of the elastic cluster",
"index" -> OptionalStringType ~~> "Index for events. Default is otoroshi-events",
"type" -> OptionalStringType ~~> "Type of events. Default is event",
"user" -> OptionalStringType ~~> "Optional user",
"password" -> OptionalStringType ~~> "Optional password",
"headers" -> SimpleObjectType ~~> "Additionnal http headers"
)
)
def ClientConfig =
Json.obj(
"description" -> "The configuration of the circuit breaker for a service descriptor",
"type" -> "object",
"required" -> Json.arr(
"useCircuitBreaker",
"retries",
"maxErrors",
"retryInitialDelay",
"backoffFactor",
"callTimeout",
"globalTimeout",
"sampleInterval"
),
"properties" -> Json.obj(
"useCircuitBreaker" -> SimpleBooleanType ~~> "Use a circuit breaker to avoid cascading failure when calling chains of services. Highly recommended !",
"retries" -> SimpleIntType ~~> "Specify how many times the client will try to fetch the result of the request after an error before giving up.",
"maxErrors" -> SimpleIntType ~~> "Specify how many errors can pass before opening the circuit breaker",
"retryInitialDelay" -> SimpleIntType ~~> "Specify the delay between two retries. Each retry, the delay is multiplied by the backoff factor",
"backoffFactor" -> SimpleIntType ~~> "Specify the factor to multiply the delay for each retry",
"callTimeout" -> SimpleIntType ~~> "Specify how long each call should last at most in milliseconds",
"globalTimeout" -> SimpleIntType ~~> "Specify how long the global call (with retries) should last at most in milliseconds",
"sampleInterval" -> SimpleIntType ~~> "Specify the sliding window time for the circuit breaker in milliseconds, after this time, error count will be reseted"
)
)
def Canary =
Json.obj(
"description" -> "The configuration of the canary mode for a service descriptor",
"type" -> "object",
"required" -> Json.arr("enabled", "traffic", "targets", "root"),
"properties" -> Json.obj(
"enabled" -> SimpleBooleanType ~~> "Use canary mode for this service",
"traffic" -> SimpleIntType ~~> "Ratio of traffic that will be sent to canary targets.",
"targets" -> ArrayOf(
Ref("Target")
) ~~> "The list of target that Otoroshi will proxy and expose through the subdomain defined before. Otoroshi will do round-robin load balancing between all those targets with circuit breaker mecanism to avoid cascading failures",
"root" -> SimpleStringType ~~> "Otoroshi will append this root to any target choosen. If the specified root is '/api/foo', then a request to https://yyyyyyy/bar will actually hit https://xxxxxxxxx/api/foo/bar"
)
)
def Service =
Json.obj(
"description" -> "An otoroshi service descriptor. Represent a forward HTTP call on a domain to another location with some optional api management mecanism",
"type" -> "object",
"required" -> Json.arr(
"id",
"groups",
"name",
"env",
"domain",
"subdomain",
"targets",
"root",
"enabled",
"privateApp",
"forceHttps",
"maintenanceMode",
"buildMode",
"enforceSecureCommunication"
),
"properties" -> Json.obj(
"id" -> SimpleUuidType ~~> "A unique random string to identify your service",
"groups" -> SimpleArrayType ~~> "Each service descriptor is attached to groups. A group can have one or more services. Each API key is linked to a group and allow access to every service in the group",
"name" -> SimpleStringType ~~> "The name of your service. Only for debug and human readability purposes",
"env" -> SimpleStringType ~~> "The line on which the service is available. Based on that value, the name of the line will be appended to the subdomain. For line prod, nothing will be appended. For example, if the subdomain is 'foo' and line is 'preprod', then the exposed service will be available at 'foo.preprod.mydomain'",
"domain" -> SimpleStringType ~~> "The domain on which the service is available.",
"subdomain" -> SimpleStringType ~~> "The subdomain on which the service is available",
"targets" -> ArrayOf(
Ref("Target")
) ~~> "The list of target that Otoroshi will proxy and expose through the subdomain defined before. Otoroshi will do round-robin load balancing between all those targets with circuit breaker mecanism to avoid cascading failures",
"root" -> SimpleStringType ~~> "Otoroshi will append this root to any target choosen. If the specified root is '/api/foo', then a request to https://yyyyyyy/bar will actually hit https://xxxxxxxxx/api/foo/bar",
"matchingRoot" -> SimpleStringType ~~> "The root path on which the service is available",
"localHost" -> SimpleStringType ~~> "The host used localy, mainly localhost:xxxx",
"localScheme" -> SimpleStringType ~~> "The scheme used localy, mainly http",
"redirectToLocal" -> SimpleBooleanType ~~> "If you work locally with Otoroshi, you may want to use that feature to redirect one particuliar service to a local host. For example, you can relocate https://foo.preprod.bar.com to http://localhost:8080 to make some tests",
"enabled" -> SimpleBooleanType ~~> "Activate or deactivate your service. Once disabled, users will get an error page saying the service does not exist",
"userFacing" -> SimpleBooleanType ~~> "The fact that this service will be seen by users and cannot be impacted by the Snow Monkey",
"privateApp" -> SimpleBooleanType ~~> "When enabled, user will be allowed to use the service (UI) only if they are registered users of the private apps domain",
"forceHttps" -> SimpleBooleanType ~~> "Will force redirection to https:// if not present",
"maintenanceMode" -> SimpleBooleanType ~~> "Display a maintainance page when a user try to use the service",
"buildMode" -> SimpleBooleanType ~~> "Display a construction page when a user try to use the service",
"enforceSecureCommunication" -> SimpleBooleanType ~~> "When enabled, Otoroshi will try to exchange headers with backend service to ensure no one else can use the service from outside",
"sendOtoroshiHeadersBack" -> SimpleBooleanType ~~> "When enabled, Otoroshi will send headers to consumer like request id, client latency, overhead, etc ...",
"xForwardedHeaders" -> SimpleBooleanType ~~> "When enabled, Otoroshi will send X-Forwarded-* headers to target",
"overrideHost" -> SimpleBooleanType ~~> "When enabled, Otoroshi will automatically set the Host header to corresponding target host",
"secComExcludedPatterns" -> ArrayOf(SimpleStringType) ~~> "URI patterns excluded from secured communications",
"publicPatterns" -> ArrayOf(
SimpleStringType
) ~~> "By default, every services are private only and you'll need an API key to access it. However, if you want to expose a public UI, you can define one or more public patterns (regex) to allow access to anybody. For example if you want to allow anybody on any URL, just use '/.*'",
"privatePatterns" -> ArrayOf(
SimpleStringType
) ~~> "If you define a public pattern that is a little bit too much, you can make some of public URL private again",
"ipFiltering" -> Ref("IpFiltering"),
"api" -> Ref("ExposedApi"),
"healthCheck" -> Ref("HealthCheck"),
"clientConfig" -> Ref("ClientConfig"),
"Canary" -> Ref("Canary"),
"statsdConfig" -> Ref("StatsdConfig"),
"chaosConfig" -> Ref("ChaosConfig"),
"jwtVerifier" -> OneOf(Ref("LocalJwtVerifier"), Ref("RefJwtVerifier")),
"secComSettings" -> OneOf(
Ref("HSAlgoSettings"),
Ref("RSAlgoSettings"),
Ref("ESAlgoSettings"),
Ref("JWKSAlgoSettings")
),
"metadata" -> SimpleObjectType ~~> "Just a bunch of random properties",
"matchingHeaders" -> SimpleObjectType ~~> "Specify headers that MUST be present on client request to route it. Useful to implement versioning",
"additionalHeaders" -> SimpleObjectType ~~> "Specify headers that will be added to each client request. Useful to add authentication",
"authConfigRef" -> SimpleStringType ~~> "A reference to a global auth module config",
"transformerRef" -> SimpleStringType ~~> "A reference to a request transformer",
"clientValidatorRef" -> SimpleStringType ~~> "A reference to validation authority",
"clientValidatorRef" -> SimpleStringType ~~> "A reference to validation authority",
"cors" -> Ref("CorsSettings"),
"redirection" -> Ref("RedirectionSettings"),
"overrideHost" -> SimpleBooleanType ~~> "Host header will be overriden with Host of the target",
"xForwardedHeaders" -> SimpleBooleanType ~~> "Send X-Forwarded-* headers",
"gzip" -> Ref("Gzip"),
"headersVerification" -> SimpleObjectType ~~> "Specify headers that will be verified after routing."
)
)
def Gzip =
Json.obj(
"description" -> "Configuration for gzip of service responses",
"type" -> "object",
"required" -> Json.arr(
"enabled",
"excludedPatterns",
"whiteList",
"blackList",
"bufferSize",
"chunkedThreshold",
"compressionLevel"
),
"properties" -> Json.obj(
"enabled" -> SimpleBooleanType ~~> "Whether gzip compression is enabled or not",
"excludedPatterns" -> ArrayOf(SimpleStringType) ~~> "Patterns that are excluded from gzipping",
"whiteList" -> ArrayOf(SimpleStringType) ~~> "Whitelisted mime types. Wildcard supported",
"blackList" -> ArrayOf(SimpleStringType) ~~> "Blacklisted mime types. Wildcard supported",
"bufferSize" -> SimpleLongType ~~> "Size of the GZip buffer",
"chunkedThreshold" -> SimpleLongType ~~> "Threshold for chunking data",
"compressionLevel" -> SimpleIntType ~~> "Compression level. From 0 to 9"
)
)
def ApiKey =
Json.obj(
"description" -> "An Otoroshi Api Key. An Api Key is defined for a group of services to allow usage of the same Api Key for multiple services.",
"type" -> "object",
"required" -> Json.arr("clientId", "clientSecret", "clientName", "authorizedEntities", "enabled"),
"properties" -> Json.obj(
"clientId" -> SimpleStringType ~~> "The unique id of the Api Key. Usually 16 random alpha numerical characters, but can be anything",
"clientSecret" -> SimpleStringType ~~> "The secret of the Api Key. Usually 64 random alpha numerical characters, but can be anything",
"clientName" -> SimpleStringType ~~> "The name of the api key, for humans ;-)",
"authorizedEntities" -> SimpleArrayType ~~> "The group/service ids (prefixed by group_ or service_ on which the key is authorized",
"enabled" -> SimpleBooleanType ~~> "Whether or not the key is enabled. If disabled, resources won't be available to calls using this key",
"throttlingQuota" -> SimpleLongType ~~> "Authorized number of calls per second, measured on 10 seconds",
"dailyQuota" -> SimpleLongType ~~> "Authorized number of calls per day",
"monthlyQuota" -> SimpleLongType ~~> "Authorized number of calls per month",
"metadata" -> SimpleObjectType ~~> "Bunch of metadata for the key"
)
)
def Group =
Json.obj(
"description" -> "An Otoroshi service group is just a group of service descriptor. It is useful to be able to define Api Keys for the whole group",
"type" -> "object",
"required" -> Json.arr("id", "name"),
"properties" -> Json.obj(
"id" -> SimpleStringType ~~> "The unique id of the group. Usually 64 random alpha numerical characters, but can be anything",
"name" -> SimpleStringType ~~> "The name of the group",
"description" -> SimpleStringType ~~> "The descriptoin of the group"
)
)
def Auth0Config =
Json.obj(
"description" -> "Configuration for Auth0 domain",
"type" -> "object",
"required" -> Json.arr("clientId", "clientSecret", "domain", "callbackUrl"),
"properties" -> Json.obj(
"clientId" -> SimpleStringType ~~> "Auth0 client id",
"clientSecret" -> SimpleStringType ~~> "Auth0 client secret",
"domain" -> SimpleStringType ~~> "Auth0 domain",
"callbackUrl" -> SimpleStringType ~~> "Auth0 callback URL"
)
)
def MailerSettings =
Json.obj(
"description" -> "Configuration for mailgun api client",
"type" -> "object",
"required" -> Json.arr("apiKey", "domain"),
"properties" -> Json.obj(
"type" -> SimpleStringType ~~> "Type of the mailer: console, generic, mailgun, mailjet",
"eu" -> SimpleBooleanType ~~> "Mailgun mailer, use EU tenant api",
"apiKey" -> SimpleStringType ~~> "Mailgun mailer api key",
"domain" -> SimpleStringType ~~> "Mailgun mailer domain",
"apiKeyPublic" -> SimpleStringType ~~> "Mailjet mailer public api key",
"apiKeyPrivate" -> SimpleStringType ~~> "Mailjet mailer private api key",
"url" -> SimpleStringType ~~> "Generic mailer url",
"header" -> SimpleObjectType ~~> "Generic mailer headers"
)
)
def CleverSettings =
Json.obj(
"description" -> "Configuration for CleverCloud client",
"type" -> "object",
"required" -> Json.arr("consumerKey", "consumerSecret", "token", "secret", "orgaId"),
"properties" -> Json.obj(
"consumerKey" -> SimpleStringType ~~> "CleverCloud consumer key",
"consumerSecret" -> SimpleStringType ~~> "CleverCloud consumer token",
"token" -> SimpleStringType ~~> "CleverCloud oauth token",
"secret" -> SimpleStringType ~~> "CleverCloud oauth secret",
"orgaId" -> SimpleStringType ~~> "CleverCloud organization id"
)
)
def GlobalConfig =
Json.obj(
"type" -> "object",
"required" -> Json.arr(
"streamEntityOnly",
"autoLinkToDefaultGroup",
"limitConcurrentRequests",
"maxConcurrentRequests",
"useCircuitBreakers",
"apiReadOnly",
"u2fLoginOnly",
"ipFiltering",
"throttlingQuota",
"perIpThrottlingQuota",
"analyticsWebhooks",
"alertsWebhooks",
"alertsEmails",
"endlessIpAddresses"
),
"description" -> "The global config object of Otoroshi, used to customize settings of the current Otoroshi instance",
"properties" -> Json.obj(
"lines" -> ArrayOf(SimpleStringType) ~~> "Possibles lines for Otoroshi",
"streamEntityOnly" -> SimpleBooleanType ~~> "HTTP will be streamed only. Doesn't work with old browsers",
"autoLinkToDefaultGroup" -> SimpleBooleanType ~~> "If not defined, every new service descriptor will be added to the default group",
"limitConcurrentRequests" -> SimpleBooleanType ~~> "If enabled, Otoroshi will reject new request if too much at the same time",
"maxConcurrentRequests" -> SimpleLongType ~~> "The number of authorized request processed at the same time",
"maxHttp10ResponseSize" -> SimpleLongType ~~> "The max size in bytes of an HTTP 1.0 response",
"useCircuitBreakers" -> SimpleBooleanType ~~> "If enabled, services will be authorized to use circuit breakers",
"apiReadOnly" -> SimpleBooleanType ~~> "If enabled, Admin API won't be able to write/update/delete entities",
"u2fLoginOnly" -> SimpleBooleanType ~~> "If enabled, login to backoffice through Auth0 will be disabled",
"ipFiltering" -> Ref("IpFiltering"),
"throttlingQuota" -> SimpleLongType ~~> "Authorized number of calls per second globally, measured on 10 seconds",
"perIpThrottlingQuota" -> SimpleLongType ~~> "Authorized number of calls per second globally per IP address, measured on 10 seconds",
"elasticWritesConfigs" -> ArrayOf(Ref("ElasticConfig")) ~~> "Configs. for Elastic writes",
"elasticReadsConfig" -> Ref("ElasticConfig") ~~> "Config. for elastic reads",
"analyticsWebhooks" -> ArrayOf(Ref("Webhook")) ~~> "Webhook that will receive all internal Otoroshi events",
"alertsWebhooks" -> ArrayOf(Ref("Webhook")) ~~> "Webhook that will receive all Otoroshi alert events",
"alertsEmails" -> ArrayOf(SimpleEmailType) ~~> "Email addresses that will receive all Otoroshi alert events",
"endlessIpAddresses" -> ArrayOf(