Skip to content

Commit 873ec18

Browse files
committed
Use runtime configuration
1 parent bf02792 commit 873ec18

File tree

8 files changed

+105
-44
lines changed

8 files changed

+105
-44
lines changed

config/cadet.exs.example

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
# Example production configuration file
2+
3+
import Config
4+
5+
config :cadet, CadetWeb.Endpoint,
6+
cors_endpoints: "example.com",
7+
server: true,
8+
load_from_system_env: true,
9+
url: [host: "api.example.com", port: 80],
10+
http: [compress: true],
11+
secret_key_base: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
12+
13+
config :cadet, Cadet.Auth.Guardian,
14+
issuer: "cadet",
15+
secret_key: "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"
16+
17+
config :cadet, Cadet.Repo,
18+
adapter: Ecto.Adapters.Postgres,
19+
rds_secret_name: "prod-cadet-db",
20+
pool_size: 10
21+
22+
config :cadet,
23+
identity_providers: %{
24+
# # To use authentication with LumiNUS.
25+
# "nusnet_id" =>
26+
# {Cadet.Auth.Providers.LumiNUS,
27+
# %{
28+
# # The LumiNUS API key
29+
# api_key: "",
30+
# # The module code to check for enrolment.
31+
# module_code: "CS1101S",
32+
# # The term of the module to check
33+
# module_term: "2010"
34+
# }},
35+
# # An example of OpenID authentication with Cognito. Any OpenID-compliant
36+
# # provider should work.
37+
# "cognito" =>
38+
# {Cadet.Auth.Providers.OpenID,
39+
# %{
40+
# # This should match a key in openid_connect_providers below
41+
# openid_provider: :cognito,
42+
# # You may need to write your own claim extractor for other providers
43+
# claim_extractor: Cadet.Auth.Providers.CognitoClaimExtractor
44+
# }},
45+
"test" =>
46+
{Cadet.Auth.Providers.Config,
47+
[
48+
%{
49+
token: "admin_token",
50+
code: "admin_code",
51+
name: "Test Admin",
52+
username: "admin",
53+
role: :admin
54+
},
55+
%{
56+
token: "staff_token",
57+
code: "staff_code",
58+
name: "Test Staff",
59+
username: "staff",
60+
role: :staff
61+
},
62+
%{
63+
token: "student_token",
64+
code: "student_code",
65+
name: "Test Student",
66+
username: "student",
67+
role: :student
68+
}
69+
]}
70+
},
71+
# See https://hexdocs.pm/openid_connect/readme.html
72+
# openid_connect_providers: [
73+
# cognito: [
74+
# discovery_document_uri: "",
75+
# client_id: "",
76+
# client_secret: "",
77+
# response_type: "code",
78+
# scope: "openid profile"
79+
# ]
80+
# ],
81+
autograder: [
82+
lambda_name: "autograderLambdaName"
83+
],
84+
uploader: [
85+
assets_bucket: "source-academy-assets",
86+
sourcecasts_bucket: "env-cadet-sourcecasts"
87+
],
88+
# Configuration for Sling integration (executing on remote devices)
89+
remote_execution: [
90+
# Prefix for AWS IoT thing names
91+
thing_prefix: "env-sling",
92+
# AWS IoT thing group to put created things into (must be set-up beforehand)
93+
thing_group: "env-sling",
94+
# Role ARN to use when generating signed client MQTT-WS URLs (must be set-up beforehand)
95+
client_role_arn: "arn:aws:iam::12345678:role/env-cadet-frontend"
96+
]
97+
98+
config :sentry,
99+
dsn: "https://public_key/sentry.io/somethingsomething"

config/config.exs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,3 @@ config :guardian, Guardian.DB,
8989
token_types: ["refresh"],
9090
# default: 60 minute
9191
sweep_interval: 180
92-
93-
# Import secrets, such as the LumiNUS key, or guest account credentials
94-
# The secret.exs file holds secrets that are useful even in development, and
95-
# so is kept separate from the prod.secret.exs file, which holds secrets useful
96-
# only for configuring the production build.
97-
if Mix.env() != :test, do: import_config("secrets.exs")

config/dev.exs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,5 @@ config :git_hooks,
7272
]
7373
]
7474
]
75+
76+
import_config("dev.secrets.exs")
File renamed without changes.

config/prod.exs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,3 @@ config :logger, level: :info
4444
config :ex_aws,
4545
access_key_id: [:instance_role],
4646
secret_access_key: [:instance_role]
47-
48-
# Finally import the config/prod.secret.exs
49-
# which should be versioned separately.
50-
import_config "prod.secrets.exs"

config/prod.secrets.exs.example

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

config/releases.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"CONFIG" |> System.get_env("/etc/cadet.exs") |> Code.eval_file()

lib/cadet/jobs/autograder/lambda_worker.ex

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@ defmodule Cadet.Autograder.LambdaWorker do
1212
alias Cadet.Autograder.ResultStoreWorker
1313
alias Cadet.Assessments.{Answer, Question}
1414

15-
@lambda_name :cadet |> Application.compile_env!(:autograder) |> Keyword.get(:lambda_name)
16-
1715
@doc """
1816
This Que callback transforms an input of %{question: %Question{}, answer: %Answer{}} into
1917
the correct shape to dispatch to lambda, waits for the response, parses it, and enqueues a
@@ -28,7 +26,9 @@ defmodule Cadet.Autograder.LambdaWorker do
2826
Process.sleep(1000)
2927
else
3028
response =
31-
@lambda_name
29+
:cadet
30+
|> Application.fetch_env!(:autograder)
31+
|> Keyword.get(:lambda_name)
3232
|> ExAws.Lambda.invoke(lambda_params, %{})
3333
|> ExAws.request!()
3434

0 commit comments

Comments
 (0)