Skip to content

Commit

Permalink
(#127) Add API token to DB
Browse files Browse the repository at this point in the history
  • Loading branch information
x-ji committed Sep 29, 2021
1 parent ea8fca4 commit 94f7f52
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/magpie/experiments/experiment.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ defmodule Magpie.Experiments.Experiment do
field :name, :string, null: false
field :author, :string, null: false

# A randomly generated API token which the frontend should provide when interacting with the backend
field :api_token, :string, null: false

# Note that the type :text is actually used for Postgres (specified in the migration file). It may not be valid for other databases. The description is potentially longer than varchar(255) limited by the default :string.
field :description, :string
field :active, :boolean, default: true, null: false
Expand Down
3 changes: 2 additions & 1 deletion lib/magpie_web/templates/experiment/edit.html.eex
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<h1>Edit Experiment</h1>

<p>
Please use the endpoints shown below when submitting/retrieving experiments:
Please refer to the following information when submitting/retrieving experiments:
</p>

<ul>
<li>API token: <code><%= @experiment.api_token %></code></li>
<li>Submission: <code><%= get_endpoint_url(:submit, @experiment.id) %></code></li>
<li>Dynamic retrieval: <code><%= get_endpoint_url(:retrieve_as_json, @experiment.id) %></code></li>
<li>Socket endpoint for interactive experiments: <code><%= get_socket_url() %></code></li>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Magpie.Repo.Migrations.AddApiTokenToExperiments do
use Ecto.Migration

def change do
execute(
"CREATE EXTENSION IF NOT EXISTS \"pgcrypto\"",
"DROP EXTENSION IF EXISTS \"pgcrypto\""
)

alter table(:experiments) do
add :api_token, :string, null: false, default: fragment("md5(random()::text)")
end
end
end

0 comments on commit 94f7f52

Please sign in to comment.