-
Notifications
You must be signed in to change notification settings - Fork 64
/
router.ex
122 lines (107 loc) · 3.2 KB
/
router.ex
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
defmodule RigApi.Router do
use RigApi, :router
import Phoenix.LiveDashboard.Router
pipeline :body_parser do
plug(Plug.Parsers,
parsers: [:urlencoded, :multipart, :json],
# return "415 Unsupported Media Type" if not handled by any parser
pass: [],
json_decoder: Jason
)
end
scope "/health", RigApi do
pipe_through(:body_parser)
get("/", Health, :check_health)
end
scope "/swagger-ui" do
forward("/", PhoenixSwagger.Plug.SwaggerUI,
otp_app: :rig,
swagger_file: "rig_api_swagger.json"
)
end
scope "/" do
pipe_through(:body_parser)
live_dashboard("/dashboard", metrics: RigMetrics.Telemetry)
end
scope "/v2", RigApi.V2 do
scope "/apis" do
pipe_through(:body_parser)
get("/", APIs, :list_apis)
post("/", APIs, :add_api)
get("/:id", APIs, :get_api_detail)
put("/:id", APIs, :update_api)
delete("/:id", APIs, :deactivate_api)
end
scope "/messages" do
post("/", Messages, :publish)
end
scope "/responses" do
pipe_through(:body_parser)
resources("/", Responses, only: [:create])
end
scope "/session-blacklist" do
pipe_through(:body_parser)
post("/", SessionBlacklist, :blacklist_session)
get("/:session_id", SessionBlacklist, :check_status)
end
end
scope "/v3", RigApi.V3 do
scope "/apis" do
pipe_through(:body_parser)
get("/", APIs, :list_apis)
post("/", APIs, :add_api)
get("/:id", APIs, :get_api_detail)
put("/:id", APIs, :update_api)
delete("/:id", APIs, :deactivate_api)
end
scope "/messages" do
post("/", Messages, :publish)
end
scope "/responses" do
pipe_through(:body_parser)
resources("/", Responses, only: [:create])
end
scope "/session-blacklist" do
pipe_through(:body_parser)
post("/", SessionBlacklist, :blacklist_session)
get("/:session_id", SessionBlacklist, :check_status)
end
end
def swagger_info do
%{
info: %{
version: RIG.MixProject.project()[:version],
title: "Reactive Interaction Gateway: API",
description: """
The Reactive Interaction Gateway provides an API that allows backend services
to query internal state and control behavior (e.g., by blacklisting a JWT).
The port can be configured using the `API_PORT` environment variable.
Please note that there is no authentication or authorization on this API;
therefore, consider exposing it to your internal network only.
"""
},
# Documentation for paths without Controller go here
paths: %{
"/metrics": %{
get: %{
tags: ["Metrics"],
summary:
"Providing metrics for monitoring in Prometheus Format (please change Scheme to http if you want to try it)",
responses: %{
"200": %{
description: "Response in Prometheus format",
content: %{
"text/plain": %{
schema: %{
type: "string"
}
}
}
}
}
}
}
}
}
end
end