This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule OpenIDConnect do | |
@moduledoc """ | |
Handles a majority of the life-cycle concerns with [OpenID Connect](http://openid.net/connect/) | |
""" | |
alias OpenIDConnect.Document | |
@typedoc """ | |
URL to a [OpenID Discovery Document](https://openid.net/specs/openid-connect-discovery-1_0.html) endpoint. | |
""" | |
@type discovery_document_uri :: String.t() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Firezone.OpenAPIDocsWriter do | |
@keep_req_headers [] | |
@keep_resp_headers ["content-type", "location"] | |
def write(conns, path) do | |
file = File.open!(path, [:write, :utf8]) | |
open_api_spec = %{ | |
openapi: "3.0.0", | |
info: %{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Config do | |
@moduledoc """ | |
This module provides set of helper functions that are useful when reading application runtime configuration overrides | |
in test environment. | |
""" | |
if Mix.env() != :test do | |
def maybe_put_env_override(_key, _value), do: :ok | |
def fetch_env!(app, key), do: Application.fetch_env!(app, key) | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<Response> | |
<Dial> | |
<Number>+15671112233</Number> | |
<Number>+15671112234</Number> | |
</Dial> | |
</Response> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule DynamicChangeset do | |
@moduledoc """ | |
This module provides helper functions to extend `Ecto.Changeset` to support | |
dynamic embeds. | |
""" | |
alias Ecto.Changeset | |
@doc """ | |
Casts the given embed with the embedded changeset and field which is used to define it's type. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app_secret = Keyword.fetch!(config, :app_secret) | |
with [encoded_signature, encoded_payload] <- String.split(signed_request, "."), | |
{:ok, signature} <- Base.url_decode64(encoded_signature, padding: false), | |
{:ok, payload} <- Base.url_decode64(encoded_payload, padding: false), | |
{:ok, payload} <- Jason.decode(payload), | |
%{"algorithm" => "HMAC-SHA256"} <- payload, | |
payload_signature = :crypto.hmac(:sha256, app_secret, encoded_payload), | |
true <- Plug.Crypto.secure_compare(signature, payload_signature) do | |
{:ok, payload} | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def book_trip(attrs) do | |
with {:ok, exchange_rates} <- BillingAPI.fetch_currency_exchange_rates(attrs), | |
{:ok, card_authorization} <- BillingAPI.authorize_card(exchange_rates, attrs), | |
{:hotel_booking, {:ok, hotel_booking}, _} <- {:hotel_booking, HotelsBookingAPI.book_hotel(attrs), []}, | |
{:car_booking, {:ok, car_booking}, _} <- {:car_booking, CarsBookingAPI.book_hotel(attrs), [hotel_booking]}, | |
{:flight_booking, {:ok, flight_booking}, _} <- {:flight_booking, FlightsBookingAPI.book_hotel(attrs), [hotel_booking, car_booking]}, | |
:ok <- Mailer.send_email_confirmation(card_authorization, hotel_booking, attrs), | |
{:charge, {:ok, charge}, _} <- {:charge, BillingAPI.charge_card(card_authorization), [...]} do | |
{:ok, %{charge: charge, bookings: [hotel_booking, car_booking, flight_booking]}} | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def book_trip(attrs) do | |
with {:ok, exchange_rates} <- BillingAPI.fetch_currency_exchange_rates(attrs), | |
{:ok, card_authorization} <- BillingAPI.authorize_card(exchange_rates, attrs), | |
{:booking, {:ok, hotel_booking}, _} <- {:booking, HotelsBookingAPI.book_hotel(attrs), []}, | |
{:booking, {:ok, car_booking}, _} <- {:booking, CarsBookingAPI.book_hotel(attrs), [hotel_booking]}, | |
{:booking, {:ok, flight_booking}, _} <- {:booking, FlightsBookingAPI.book_hotel(attrs), [hotel_booking, car_booking]}, | |
:ok <- Mailer.send_email_confirmation(card_authorization, hotel_booking, attrs), | |
{:charge, {:ok, charge}, _} <- {:charge, BillingAPI.charge_card(card_authorization), [...]} do | |
{:ok, %{charge: charge, bookings: [hotel_booking, car_booking, flight_booking]}} | |
else |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def book_trip(attrs) do | |
with {:ok, exchange_rates} <- BillingAPI.fetch_currency_exchange_rates(attrs), | |
{:ok, card_authorization} <- BillingAPI.authorize_card(exchange_rates, attrs), | |
{:ok, hotel_booking} <- HotelsBookingAPI.book_hotel(attrs), | |
:ok <- Mailer.send_email_confirmation(card_authorization, hotel_booking, attrs), | |
{:charge, {:ok, charge}, _} <- {:charge, BillingAPI.charge_card(card_authorization), [hotel_booking]} do | |
{:ok, %{charge: charge, bookings: [hotel_booking]}} | |
else | |
{:charge, {:error, reason], [hotel_booking]} -> | |
:ok = send_excuse_email(authorization) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def book_trip(attrs) do | |
with {:ok, exchange_rates} <- BillingAPI.fetch_currency_exchange_rates(attrs), | |
{:ok, card_authorization} <- BillingAPI.authorize_card(exchange_rates, attrs), | |
{:ok, hotel_booking} <- HotelBookingAPI.book_hotel(attrs), | |
:ok <- Mailer.send_email_confirmation(card_authorization, hotel_booking, attrs), | |
{:ok, charge} <- BillingAPI.charge_card(card_authorization) do | |
{:ok, %{charge: charge, bookings: [hotel_booking]}} | |
end | |
end |
NewerOlder