Skip to content

Commit bf64524

Browse files
authored
Features/grader (#57)
1 parent 22be577 commit bf64524

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+1349
-226
lines changed

grader.exs

-82
This file was deleted.

grading_server/.formatter.exs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[
2+
import_deps: [:phoenix],
3+
inputs: ["*.{ex,exs}", "{config,lib,test}/**/*.{ex,exs}"],
4+
subdirectories: []
5+
]

grading_server/.gitignore

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where 3rd-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
testy-*.tar
24+
25+
# Ignore assets that are produced by build tools.
26+
/priv/static/assets/
27+
28+
# Ignore digested assets cache.
29+
/priv/static/cache_manifest.json
30+
31+
# In case you use Node.js/npm, you want to ignore these.
32+
npm-debug.log
33+
/assets/node_modules/
34+
35+
!.gitignore
36+
!.sobelow-conf

grading_server/.sobelow-conf

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
verbose: true,
3+
private: false,
4+
skip: false,
5+
router: "",
6+
exit: "false",
7+
format: "txt",
8+
out: "",
9+
threshold: "medium",
10+
ignore: ["Config.HTTPS"],
11+
ignore_files: [""]
12+
]

grading_server/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# ESCT - Grading Server
2+
3+
To start your Phoenix server:
4+
5+
* Install dependencies with `mix deps.get`
6+
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
7+
8+
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
9+
10+
Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
11+
12+
## Deploying your own version
13+
14+
This only applies if you've created your own Grading Server and wish to lock down the API to your internal users.
15+
16+
1. Uncomment the `plug SimpleTokenAuthentication` line in the `router.ex` file
17+
2. Change the value of the config for `:simple_token_authentication` in `config/config.exs`
18+
3. Update the `priv/answers.yml` to reference actual answers.

grading_server/config/config.exs

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This file is responsible for configuring your application
2+
# and its dependencies with the aid of the Config module.
3+
#
4+
# This configuration file is loaded before any dependency and
5+
# is restricted to this project.
6+
7+
# General application configuration
8+
import Config
9+
10+
config :grading_server,
11+
answer_store_file: "answers.yml"
12+
13+
# Configures the endpoint
14+
config :grading_server, GradingServerWeb.Endpoint,
15+
url: [host: "localhost"],
16+
render_errors: [view: GradingServerWeb.ErrorView, accepts: ~w(json), layout: false],
17+
pubsub_server: GradingServer.PubSub,
18+
live_view: [signing_salt: "HVVkYc2t"]
19+
20+
# Configures Elixir's Logger
21+
config :logger, :console,
22+
format: "$time $metadata[$level] $message\n",
23+
metadata: [:request_id]
24+
25+
# Use Jason for JSON parsing in Phoenix
26+
config :phoenix, :json_library, Jason
27+
28+
config :simple_token_authentication,
29+
# CHANGE ME IF IN USE
30+
token: "my-token"
31+
32+
# Import environment specific config. This must remain at the bottom
33+
# of this file so it overrides the configuration defined above.
34+
import_config "#{config_env()}.exs"

grading_server/config/dev.exs

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import Config
2+
3+
# For development, we disable any cache and enable
4+
# debugging and code reloading.
5+
#
6+
# The watchers configuration can be used to run external
7+
# watchers to your application. For example, we use it
8+
# with esbuild to bundle .js and .css sources.
9+
config :grading_server, GradingServerWeb.Endpoint,
10+
# Binding to loopback ipv4 address prevents access from other machines.
11+
# Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
12+
http: [ip: {127, 0, 0, 1}, port: 4000],
13+
check_origin: false,
14+
code_reloader: true,
15+
debug_errors: true,
16+
secret_key_base: "3v9wINF+nNWThqV/ypHIqzb73TzIRmimofVeKeNcbKqM9WWV5qNC5h4ofMLuQxu2",
17+
watchers: []
18+
19+
# ## SSL Support
20+
#
21+
# In order to use HTTPS in development, a self-signed
22+
# certificate can be generated by running the following
23+
# Mix task:
24+
#
25+
# mix phx.gen.cert
26+
#
27+
# Note that this task requires Erlang/OTP 20 or later.
28+
# Run `mix help phx.gen.cert` for more information.
29+
#
30+
# The `http:` config above can be replaced with:
31+
#
32+
# https: [
33+
# port: 4001,
34+
# cipher_suite: :strong,
35+
# keyfile: "priv/cert/selfsigned_key.pem",
36+
# certfile: "priv/cert/selfsigned.pem"
37+
# ],
38+
#
39+
# If desired, both `http:` and `https:` keys can be
40+
# configured to run both http and https servers on
41+
# different ports.
42+
43+
# Do not include metadata nor timestamps in development logs
44+
config :logger, :console, format: "[$level] $message\n"
45+
46+
# Set a higher stacktrace during development. Avoid configuring such
47+
# in production as building large stacktraces may be expensive.
48+
config :phoenix, :stacktrace_depth, 20
49+
50+
# Initialize plugs at runtime for faster development compilation
51+
config :phoenix, :plug_init_mode, :runtime

grading_server/config/prod.exs

+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import Config
2+
3+
# For production, don't forget to configure the url host
4+
# to something meaningful, Phoenix uses this information
5+
# when generating URLs.
6+
#
7+
# Note we also include the path to a cache manifest
8+
# containing the digested version of static files. This
9+
# manifest is generated by the `mix phx.digest` task,
10+
# which you should run after static files are built and
11+
# before starting your production server.
12+
config :grading_server, GradingServerWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
13+
14+
# Do not print debug messages in production
15+
config :logger, level: :info
16+
17+
# ## SSL Support
18+
#
19+
# To get SSL working, you will need to add the `https` key
20+
# to the previous section and set your `:url` port to 443:
21+
#
22+
# config :grading_server, GradingServerWeb.Endpoint,
23+
# ...,
24+
# url: [host: "example.com", port: 443],
25+
# https: [
26+
# ...,
27+
# port: 443,
28+
# cipher_suite: :strong,
29+
# keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"),
30+
# certfile: System.get_env("SOME_APP_SSL_CERT_PATH")
31+
# ]
32+
#
33+
# The `cipher_suite` is set to `:strong` to support only the
34+
# latest and more secure SSL ciphers. This means old browsers
35+
# and clients may not be supported. You can set it to
36+
# `:compatible` for wider support.
37+
#
38+
# `:keyfile` and `:certfile` expect an absolute path to the key
39+
# and cert in disk or a relative path inside priv, for example
40+
# "priv/ssl/server.key". For all supported SSL configuration
41+
# options, see https://hexdocs.pm/plug/Plug.SSL.html#configure/1
42+
#
43+
# We also recommend setting `force_ssl` in your endpoint, ensuring
44+
# no data is ever sent via http, always redirecting to https:
45+
#
46+
# config :grading_server, GradingServerWeb.Endpoint,
47+
# force_ssl: [hsts: true]
48+
#
49+
# Check `Plug.SSL` for all available options in `force_ssl`.

grading_server/config/runtime.exs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import Config
2+
3+
# config/runtime.exs is executed for all environments, including
4+
# during releases. It is executed after compilation and before the
5+
# system starts, so it is typically used to load production configuration
6+
# and secrets from environment variables or elsewhere. Do not define
7+
# any compile-time configuration in here, as it won't be applied.
8+
# The block below contains prod specific runtime configuration.
9+
10+
# ## Using releases
11+
#
12+
# If you use `mix release`, you need to explicitly enable the server
13+
# by passing the PHX_SERVER=true when you start it:
14+
#
15+
# PHX_SERVER=true bin/grading_server start
16+
#
17+
# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server`
18+
# script that automatically sets the env var above.
19+
if System.get_env("PHX_SERVER") do
20+
config :grading_server, GradingServerWeb.Endpoint, server: true
21+
end
22+
23+
if config_env() == :prod do
24+
# The secret key base is used to sign/encrypt cookies and other secrets.
25+
# A default value is used in config/dev.exs and config/test.exs but you
26+
# want to use a different value for prod and you most likely don't want
27+
# to check this value into version control, so we use an environment
28+
# variable instead.
29+
secret_key_base =
30+
System.get_env("SECRET_KEY_BASE") ||
31+
raise """
32+
environment variable SECRET_KEY_BASE is missing.
33+
You can generate one by calling: mix phx.gen.secret
34+
"""
35+
36+
host = System.get_env("PHX_HOST") || "example.com"
37+
port = String.to_integer(System.get_env("PORT") || "4000")
38+
39+
config :grading_server, GradingServerWeb.Endpoint,
40+
url: [host: host, port: 443, scheme: "https"],
41+
http: [
42+
# Enable IPv6 and bind on all interfaces.
43+
# Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access.
44+
# See the documentation on https://hexdocs.pm/plug_cowboy/Plug.Cowboy.html
45+
# for details about using IPv6 vs IPv4 and loopback vs public addresses.
46+
ip: {0, 0, 0, 0, 0, 0, 0, 0},
47+
port: port
48+
],
49+
secret_key_base: secret_key_base
50+
end

grading_server/config/test.exs

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import Config
2+
3+
# We don't run a server during test. If one is required,
4+
# you can enable the server option below.
5+
config :grading_server, GradingServerWeb.Endpoint,
6+
http: [ip: {127, 0, 0, 1}, port: 4002],
7+
secret_key_base: "d//8uGEq9XnUKtzlFN5q5ia38hfd3HI38K6wWjXBEDsIJCaZMTPfX0z3biIX2qVQ",
8+
server: false
9+
10+
# Print only warnings and errors during test
11+
config :logger, level: :warn
12+
13+
# Initialize plugs at runtime for faster test compilation
14+
config :phoenix, :plug_init_mode, :runtime

grading_server/docker-compose.yaml

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
version: "3.8"
2+
services:
3+
db:
4+
image: postgres:14.4
5+
restart: always
6+
environment:
7+
- POSTGRES_PASSWORD=postgres
8+
- POSTGRES_USER=postgres
9+
ports:
10+
- 5432:5432
11+
volumes:
12+
- db:/var/lib/postgresql/data
13+
volumes:
14+
db:
15+
driver: local

grading_server/lib/grading_server.ex

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
defmodule GradingServer do
2+
@moduledoc """
3+
GradingServer keeps the contexts that define your domain
4+
and business logic.
5+
6+
Contexts are also responsible for managing your data, regardless
7+
if it comes from the database, an external API or others.
8+
"""
9+
end

0 commit comments

Comments
 (0)