Skip to content

Commit 6a5f6d0

Browse files
authored
Suppression code inutilisé (support expérimental pour SIRI) (#5523)
1 parent a8c665a commit 6a5f6d0

13 files changed

Lines changed: 12 additions & 519 deletions

File tree

apps/transport/lib/transport_web/live/backoffice/proxy_config_live.ex

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,16 +164,6 @@ defmodule TransportWeb.Backoffice.ProxyConfigLive do
164164
}
165165
end
166166

167-
defp extract_config(proxy_base_url, %Unlock.Config.Item.SIRI{} = resource) do
168-
%{
169-
unique_slug: resource.identifier,
170-
proxy_url: Transport.Proxy.resource_url(proxy_base_url, resource.identifier),
171-
original_url: resource.target_url,
172-
ttl: nil,
173-
type: "SIRI"
174-
}
175-
end
176-
177167
defp extract_config(proxy_base_url, %module{} = resource)
178168
when module == Unlock.Config.Item.DynamicIRVEAggregate do
179169
%{

apps/transport/lib/unlock/config.ex

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,6 @@ defmodule Unlock.Config do
2727
]
2828
end
2929

30-
defmodule Item.SIRI do
31-
@moduledoc """
32-
Intermediate structure for SIRI configured items.
33-
"""
34-
@enforce_keys [:identifier, :target_url, :requestor_ref]
35-
36-
@type t :: %__MODULE__{identifier: binary(), target_url: binary(), requestor_ref: binary(), request_headers: list()}
37-
defstruct [:identifier, :target_url, :requestor_ref, request_headers: []]
38-
end
39-
4030
defmodule Item.DynamicIRVEAggregate do
4131
@moduledoc """
4232
Intermediate structure for dynamic IRVE aggregated configured items.
@@ -102,15 +92,6 @@ defmodule Unlock.Config do
10292
}
10393
end
10494

105-
def convert_yaml_item_to_struct(%{"type" => "siri"} = item) do
106-
%Item.SIRI{
107-
identifier: Map.fetch!(item, "identifier"),
108-
target_url: Map.fetch!(item, "target_url"),
109-
requestor_ref: Map.fetch!(item, "requestor_ref"),
110-
request_headers: parse_config_http_headers(Map.get(item, "request_headers", []))
111-
}
112-
end
113-
11495
@doc """
11596
At the moment, GTFS-RT is just an alias for HTTP generic. This is done
11697
to make it easier to achieve alternate processing later if needed.

apps/transport/lib/unlock/controller.ex

Lines changed: 1 addition & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ defmodule Unlock.Controller do
1414

1515
use Phoenix.Controller, formats: [html: "View", json: "View"]
1616
require Logger
17-
import Unlock.GunzipTools
17+
import Unlock.GunzipTools, only: [lowercase_headers: 1]
1818

1919
@doc """
2020
A simple index "page", useful to verify that the proxy is up, since it is served
@@ -39,7 +39,6 @@ defmodule Unlock.Controller do
3939
- `%Unlock.Config.Item.Generic.HTTP{}` for HTTP-provided single GTFS-RT & CSV feeds
4040
- `%Unlock.Config.Item.DynamicIRVEAggregate{}` for the on-the-fly dynamic IRVE consolidation
4141
- `%Unlock.Config.Item.S3{}` for internal-S3-backed single file feeds (CSV or anything really)
42-
- `%Unlock.Config.Item.SIRI{}` for SIRI proxying (experimental)
4342
- `%Unlock.Config.Item.GBFS{}` for GBFS feeds (with multiple endpoints)
4443
4544
Once the item is found in configuration, different `process_resource` pattern-matching variants
@@ -203,41 +202,6 @@ defmodule Unlock.Controller do
203202

204203
defp process_resource(conn, %Unlock.Config.Item.Generic.HTTP{}), do: send_not_allowed(conn)
205204

206-
# NOTE: this code is designed for private use for now. I have tracked
207-
# what is required or useful for public opening later here:
208-
# https://github.com/etalab/transport-site/issues/2476
209-
#
210-
# SIRI support is experimental. For now we are encouraging instead SIRI provider to
211-
# get their game up and improve their ops & software, so that they can directly handle
212-
# SIRI loads without the proxy.
213-
#
214-
# For SIRI, only `POST` is allowed since this is the protocol.
215-
#
216-
# The code analyses the incoming XML payload, & replace the `requestor_ref` (used sometimes
217-
# as an API key) transparently with the one we have configured.
218-
#
219-
defp process_resource(%Plug.Conn{method: "POST"} = conn, %Unlock.Config.Item.SIRI{} = item) do
220-
{:ok, body, conn} = Plug.Conn.read_body(conn, length: 1_000_000)
221-
222-
parsed = Unlock.SIRI.parse_incoming(body)
223-
224-
{modified_xml, external_requestor_refs} =
225-
Unlock.SIRI.RequestorRefReplacer.replace_requestor_ref(parsed, item.requestor_ref)
226-
227-
# NOTE: here we assert both that the requestor ref is what is expected, but also that it
228-
# is met once only. I am not deduping them at the moment on purpose, maybe we'll do that
229-
# later based on experience.
230-
if external_requestor_refs == [Application.fetch_env!(:transport, :unlock_siri_public_requestor_ref)] do
231-
handle_authorized_siri_call(conn, item, modified_xml)
232-
else
233-
send_resp(conn, 403, "Forbidden")
234-
end
235-
end
236-
237-
# Forbid `GET` calls for SIRI, explicitely, since this is not the way to issue a SIRI call.
238-
defp process_resource(%Plug.Conn{method: "GET"} = conn, %Unlock.Config.Item.SIRI{}),
239-
do: send_not_allowed(conn)
240-
241205
defp process_resource(%Plug.Conn{method: "GET"} = conn, %Unlock.Config.Item.GBFS{endpoint: nil}) do
242206
conn |> send_resp(404, "Not Found")
243207
end
@@ -277,30 +241,6 @@ defmodule Unlock.Controller do
277241
|> override_resp_headers_if_configured(item)
278242
end
279243

280-
@spec handle_authorized_siri_call(Plug.Conn.t(), Unlock.Config.Item.SIRI.t(), Saxy.XML.element()) :: Plug.Conn.t()
281-
# The SIRI query is serialized into iodata, then a `POST` query is issued.
282-
#
283-
# On completion, we unzip if needed to smooth out implementations, filter response headers,
284-
# and send back the answer to the client.
285-
defp handle_authorized_siri_call(conn, %Unlock.Config.Item.SIRI{} = item, xml) do
286-
body = Saxy.encode_to_iodata!(xml, version: "1.0")
287-
288-
response = Unlock.HTTP.Client.impl().post!(item.target_url, item.request_headers, body)
289-
290-
headers = response.headers |> lowercase_headers()
291-
292-
# NOTE: for now, we unzip systematically. This will make it easier
293-
# to analyse payloads & later remove sensitive data, even if we
294-
# re-zip afterwards.
295-
body = maybe_gunzip(response.body, headers)
296-
297-
headers
298-
|> filter_response_headers()
299-
|> Enum.reduce(conn, fn {h, v}, c -> put_resp_header(c, h, v) end)
300-
# No content-disposition as attachment for now
301-
|> send_resp(response.status, body)
302-
end
303-
304244
# A wrapper grouping reused logic for two cases:
305245
# - `%Unlock.Config.Item.Generic.HTTP{}` (GTFS-RT, external CSV etc)
306246
# - `%Unlock.Config.Item.S3{}` (internal S3 backend)

apps/transport/lib/unlock/http_client.ex

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ defmodule Unlock.HTTP do
2929
@type headers() :: [{header_name :: String.t(), header_value :: String.t()}]
3030

3131
@callback get!(url :: binary, headers :: headers(), options :: keyword()) :: any()
32-
@callback post!(url :: binary, headers :: headers(), body :: binary) :: any()
3332
@callback stream!(url :: binary, headers :: headers(), path :: binary) :: Unlock.HTTP.Response.t()
3433

3534
def impl, do: Application.fetch_env!(:transport, :unlock_http_client)
@@ -119,18 +118,5 @@ defmodule Unlock.HTTP do
119118
response
120119
end
121120
end
122-
123-
def post!(url, headers, body) do
124-
{:ok, response} =
125-
:post
126-
|> Finch.build(url, headers, body)
127-
|> Finch.request(@my_finch)
128-
129-
%Response{
130-
body: response.body,
131-
status: response.status,
132-
headers: response.headers
133-
}
134-
end
135121
end
136122
end

apps/transport/lib/unlock/siri.ex

Lines changed: 0 additions & 95 deletions
This file was deleted.

apps/transport/lib/unlock/xml_helper.ex

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/transport/test/support/siri_queries.ex

Lines changed: 0 additions & 79 deletions
This file was deleted.

apps/transport/test/transport/siri_queries_test.exs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,8 @@ defmodule Transport.SIRITest do
2323
Elixir structures, and removing the non-significant newlines.
2424
"""
2525
def parse_xml(payload) do
26-
payload
27-
|> Unlock.SIRI.parse_incoming()
28-
|> XMLNewlinesRemover.filter_newlines_from_model()
26+
{:ok, parsed} = Saxy.SimpleForm.parse_string(payload, cdata_as_characters: false)
27+
XMLNewlinesRemover.filter_newlines_from_model(parsed)
2928
end
3029

3130
test "CheckStatus" do

0 commit comments

Comments
 (0)