This repository has been archived by the owner on Jun 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
42 changed files
with
232 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
defmodule AdminAPI.Config do | ||
@moduledoc """ | ||
Provides a configuration function that are called during application startup. | ||
""" | ||
|
||
@headers [ | ||
"Authorization", | ||
"Content-Type", | ||
"Accept", | ||
"Origin", | ||
"User-Agent", | ||
"DNT", | ||
"Cache-Control", | ||
"X-Mx-ReqToken", | ||
"Keep-Alive", | ||
"X-Requested-With", | ||
"If-Modified-Since", | ||
"X-CSRF-Token", | ||
"OMGAdmin-Account-ID" | ||
] | ||
|
||
def configure_cors_plug do | ||
max_age = System.get_env("CORS_MAX_AGE") || 600 | ||
cors_origin = System.get_env("CORS_ORIGIN") | ||
|
||
Application.put_env(:cors_plug, :max_age, max_age) | ||
Application.put_env(:cors_plug, :headers, @headers) | ||
Application.put_env(:cors_plug, :methods, ["POST"]) | ||
Application.put_env(:cors_plug, :origin, cors_plug_origin(cors_origin)) | ||
end | ||
|
||
defp cors_plug_origin(nil), do: [] | ||
|
||
defp cors_plug_origin(origins) do | ||
origins | ||
|> String.trim() | ||
|> String.split(~r{\s*,\s*}) | ||
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
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,43 @@ | ||
defmodule EWalletDB.Config do | ||
@moduledoc """ | ||
Provides a configuration function that are called during application startup. | ||
""" | ||
|
||
def configure_file_storage do | ||
storage_adapter = System.get_env("FILE_STORAGE_ADAPTER") || "local" | ||
configure_file_storage(storage_adapter) | ||
end | ||
|
||
defp configure_file_storage("aws") do | ||
aws_bucket = System.get_env("AWS_BUCKET") | ||
aws_region = System.get_env("AWS_REGION") | ||
aws_access_key_id = System.get_env("AWS_ACCESS_KEY_ID") | ||
aws_secret_access_key = System.get_env("AWS_SECRET_ACCESS_KEY") | ||
|
||
aws_domain = "s3-#{aws_region}.amazonaws.com" | ||
|
||
Application.put_env(:ex_aws, :access_key_id, [aws_access_key_id, :instance_role]) | ||
Application.put_env(:ex_aws, :secret_access_key, [aws_secret_access_key, :instance_role]) | ||
Application.put_env(:ex_aws, :region, aws_region) | ||
Application.put_env(:ex_aws, :s3, scheme: "https://", host: aws_domain, region: aws_region) | ||
Application.put_env(:ex_aws, :debug_requests, true) | ||
Application.put_env(:ex_aws, :recv_timeout, 60_000) | ||
Application.put_env(:ex_aws, :hackney, recv_timeout: 60_000, pool: false) | ||
Application.put_env(:arc, :storage, Arc.Storage.S3) | ||
Application.put_env(:arc, :bucket, aws_bucket) | ||
Application.put_env(:arc, :asset_host, "https://#{aws_domain}/#{aws_bucket}") | ||
end | ||
|
||
defp configure_file_storage("gcs") do | ||
gcs_bucket = System.get_env("GCS_BUCKET") | ||
gcs_credentials = System.get_env("GCS_CREDENTIALS") | ||
|
||
Application.put_env(:arc, :storage, Arc.Storage.GCS) | ||
Application.put_env(:arc, :bucket, gcs_bucket) | ||
Application.put_env(:goth, :json, gcs_credentials) | ||
end | ||
|
||
defp configure_file_storage("local") do | ||
Application.put_env(:arc, :storage, EWallet.Storage.Local) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,17 @@ | ||
defmodule EWalletDB.Repo do | ||
use Ecto.Repo, otp_app: :ewallet_db | ||
|
||
# Workaround an issue where ecto.migrate task won't start the app | ||
# thus DeferredConfig.populate is not getting called. | ||
# | ||
# Ecto itself only supports {:system, ENV_VAR} tuple, but not | ||
# DeferredConfig's {:system, ENV_VAR, DEFAULT} tuple nor the | ||
# {:apply, MFA} tuple. | ||
# | ||
# See also: https://github.com/mrluc/deferred_config/issues/2 | ||
def init(_, config) do | ||
config | ||
|> DeferredConfig.transform_cfg() | ||
|> (fn updated -> {:ok, updated} end).() | ||
end | ||
end |
Oops, something went wrong.