Skip to content

Commit d2fc685

Browse files
committed
221 - added new /v3 internal api to support response code
1 parent e7e78ec commit d2fc685

File tree

15 files changed

+1512
-89
lines changed

15 files changed

+1512
-89
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
- Added validation for reverse proxy configuration. Now it crashes RIG on start when configuration is not valid or returns `400` when using REST API to update configuration. [#277](https://github.com/Accenture/reactive-interaction-gateway/issues/277)
1414
- Added basic distributed tracing support in [W3C Trace Context specification](https://www.w3.org/TR/trace-context/) with Jaeger and Openzipkin exporters. RIG opens a span at the API Gateway and emits trace context in Cloud Events following the [distributed tracing spec](https://github.com/cloudevents/spec/blob/v1.0/extensions/distributed-tracing.md). [#281](https://github.com/Accenture/reactive-interaction-gateway/issues/281)
1515
- Added possibility to set response code for `response_from` messages in reverse proxy (`kafka` and `http_async`). [#321](https://github.com/Accenture/reactive-interaction-gateway/pull/321)
16+
- Added new version - `v3` - for internal endpoints to support response code in the `/responses` endpoint
1617

1718
### Changed
1819

config/rig_api/config.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ config :phoenix, :serve_endpoints, true
4545

4646
config :rig, RigApi.V1.APIs, rig_proxy: RigInboundGateway.Proxy
4747
config :rig, RigApi.V2.APIs, rig_proxy: RigInboundGateway.Proxy
48+
config :rig, RigApi.V3.APIs, rig_proxy: RigInboundGateway.Proxy
4849

4950
config :rig, :event_filter, Rig.EventFilter
5051

config/rig_api/test.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@ config :rig, RigApi.Endpoint,
1010

1111
config :rig, RigApi.V1.APIs, rig_proxy: RigInboundGateway.ProxyMock
1212
config :rig, RigApi.V2.APIs, rig_proxy: RigInboundGateway.ProxyMock
13+
config :rig, RigApi.V3.APIs, rig_proxy: RigInboundGateway.ProxyMock
1314

1415
config :rig, :event_filter, Rig.EventFilterMock

lib/rig_api/router.ex

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,32 @@ defmodule RigApi.Router do
7575
end
7676
end
7777

78+
scope "/v3", RigApi.V3 do
79+
scope "/apis" do
80+
pipe_through(:body_parser)
81+
get("/", APIs, :list_apis)
82+
post("/", APIs, :add_api)
83+
get("/:id", APIs, :get_api_detail)
84+
put("/:id", APIs, :update_api)
85+
delete("/:id", APIs, :deactivate_api)
86+
end
87+
88+
scope "/messages" do
89+
post("/", Messages, :publish)
90+
end
91+
92+
scope "/responses" do
93+
pipe_through(:body_parser)
94+
resources("/", Responses, only: [:create])
95+
end
96+
97+
scope "/session-blacklist" do
98+
pipe_through(:body_parser)
99+
post("/", SessionBlacklist, :blacklist_session)
100+
get("/:session_id", SessionBlacklist, :check_status)
101+
end
102+
end
103+
78104
def swagger_info do
79105
%{
80106
info: %{

lib/rig_api/v1/responses.ex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ defmodule RigApi.V1.Responses do
55
use RigApi, :controller
66
use PhoenixSwagger
77

8-
alias RigInboundGateway.ApiProxy.ResponseFromParser
8+
alias Rig.Connection.Codec
9+
alias RigCloudEvents.CloudEvent
910

1011
@prefix "/v1"
1112

@@ -32,19 +33,20 @@ defmodule RigApi.V1.Responses do
3233

3334
@doc """
3435
Accepts message to be sent to correlated HTTP process.
35-
3636
Note that body has to contain following field `"rig": { "correlation": "_id_" }`.
3737
"""
38-
def create(%{req_headers: req_headers} = conn, message) do
39-
case ResponseFromParser.parse(req_headers, message) do
40-
{deserialized_pid, response_code, response} ->
41-
Logger.debug(fn ->
42-
"HTTP response via internal HTTP to #{inspect(deserialized_pid)}: #{inspect(message)}"
43-
end)
44-
45-
send(deserialized_pid, {:response_received, response, response_code})
46-
send_resp(conn, :accepted, "message sent to correlated reverse proxy request")
47-
38+
def create(conn, message) do
39+
with {:ok, cloud_event} <- CloudEvent.parse(message),
40+
{:ok, rig_metadata} <- Map.fetch(message, "rig"),
41+
{:ok, correlation_id} <- Map.fetch(rig_metadata, "correlation"),
42+
{:ok, deserialized_pid} <- Codec.deserialize(correlation_id) do
43+
Logger.debug(fn ->
44+
"HTTP response via internal HTTP to #{inspect(deserialized_pid)}: #{inspect(message)}"
45+
end)
46+
47+
send(deserialized_pid, {:response_received, cloud_event.json})
48+
send_resp(conn, :accepted, "message sent to correlated reverse proxy request")
49+
else
4850
err ->
4951
Logger.warn(fn -> "Parse error #{inspect(err)} for #{inspect(message)}" end)
5052

lib/rig_api/v2/responses.ex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ defmodule RigApi.V2.Responses do
55
use RigApi, :controller
66
use PhoenixSwagger
77

8-
alias RigInboundGateway.ApiProxy.ResponseFromParser
8+
alias Rig.Connection.Codec
9+
alias RigCloudEvents.CloudEvent
910

1011
@prefix "/v2"
1112

@@ -32,19 +33,20 @@ defmodule RigApi.V2.Responses do
3233

3334
@doc """
3435
Accepts message to be sent to correlated HTTP process.
35-
3636
Note that body has to contain following field `"rig": { "correlation": "_id_" }`.
3737
"""
38-
def create(%{req_headers: req_headers} = conn, message) do
39-
case ResponseFromParser.parse(req_headers, message) do
40-
{deserialized_pid, response_code, response} ->
41-
Logger.debug(fn ->
42-
"HTTP response via internal HTTP to #{inspect(deserialized_pid)}: #{inspect(message)}"
43-
end)
44-
45-
send(deserialized_pid, {:response_received, response, response_code})
46-
send_resp(conn, :accepted, "message sent to correlated reverse proxy request")
47-
38+
def create(conn, message) do
39+
with {:ok, cloud_event} <- CloudEvent.parse(message),
40+
{:ok, rig_metadata} <- Map.fetch(message, "rig"),
41+
{:ok, correlation_id} <- Map.fetch(rig_metadata, "correlation"),
42+
{:ok, deserialized_pid} <- Codec.deserialize(correlation_id) do
43+
Logger.debug(fn ->
44+
"HTTP response via internal HTTP to #{inspect(deserialized_pid)}: #{inspect(message)}"
45+
end)
46+
47+
send(deserialized_pid, {:response_received, cloud_event.json})
48+
send_resp(conn, :accepted, "message sent to correlated reverse proxy request")
49+
else
4850
err ->
4951
Logger.warn(fn -> "Parse error #{inspect(err)} for #{inspect(message)}" end)
5052

0 commit comments

Comments
 (0)