-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from avantifellows/main
Production Release: 03/10/2023
- Loading branch information
Showing
17 changed files
with
809 additions
and
665 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
defmodule DbserviceWeb.AuthenticationMiddleware do | ||
@moduledoc """ | ||
This module provides a Plug middleware for handling API key-based authentication. | ||
The middleware checks the 'Authorization' header of incoming HTTP requests to ensure that | ||
it matches a predefined API key stored in the 'BEARER_TOKEN' environment variable. | ||
If the API key is valid, the request is allowed to proceed; otherwise, a '401 Unauthorized' | ||
response is sent, and further processing is halted. | ||
""" | ||
import Plug.Conn | ||
import Dotenvy | ||
|
||
def init(_opts), do: %{} | ||
|
||
def call(conn, _opts) do | ||
source(["config/.env", "config/.env"]) | ||
|
||
referer = | ||
get_req_header(conn, "referer") | ||
|> List.first() | ||
|> to_string() | ||
|
||
request_path = conn.request_path | ||
|
||
api_key = get_req_header(conn, "authorization") | ||
|
||
if api_key == ["Bearer " <> env!("BEARER_TOKEN", :string!)] || | ||
is_swagger_request?(referer, request_path) do | ||
conn | ||
else | ||
conn | ||
|> send_resp(401, "Not Authorized") | ||
|> halt() | ||
end | ||
end | ||
|
||
defp is_swagger_request?(referer, request_path) do | ||
String.contains?(referer, "swagger") || String.contains?(request_path, "swagger") | ||
end | ||
end |
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
defmodule Dbservice.Repo.Migrations.AlterFormTable do | ||
use Ecto.Migration | ||
|
||
def change do | ||
alter table(:form_schema) do | ||
add(:meta_data, :map) | ||
end | ||
end | ||
end |
25 changes: 25 additions & 0 deletions
25
priv/repo/migrations/20230905164925_modify_data_types_in_session_table.exs
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule Dbservice.Repo.Migrations.ModifyDataTypesInSessionTable do | ||
use Ecto.Migration | ||
|
||
def up do | ||
execute(""" | ||
ALTER TABLE session | ||
ALTER COLUMN activate_signup TYPE BOOLEAN USING (activate_signup::boolean), | ||
ALTER COLUMN id_generation TYPE BOOLEAN USING (id_generation::boolean), | ||
ALTER COLUMN redirection TYPE BOOLEAN USING (redirection::boolean), | ||
ALTER COLUMN pop_up_form TYPE BOOLEAN USING (pop_up_form::boolean), | ||
ALTER COLUMN number_of_fields_in_pop_form TYPE INTEGER USING (number_of_fields_in_pop_form::integer); | ||
""") | ||
end | ||
|
||
def down do | ||
execute(""" | ||
ALTER TABLE session | ||
ALTER COLUMN activate_signup TYPE VARCHAR, | ||
ALTER COLUMN id_generation TYPE VARCHAR, | ||
ALTER COLUMN redirection TYPE VARCHAR, | ||
ALTER COLUMN pop_up_form TYPE VARCHAR, | ||
ALTER COLUMN number_of_fields_in_pop_form TYPE INTEGER; | ||
""") | ||
end | ||
end |
Oops, something went wrong.