-
Notifications
You must be signed in to change notification settings - Fork 6
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
8 changed files
with
64 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
defmodule CA.HTTP do | ||
use Plug.Router | ||
plug :match | ||
plug :dispatch | ||
plug Plug.Parsers, parsers: [:json], json_decoder: Jason | ||
|
||
# Authority PKI X.509 Enrollment Protocol over HTTP | ||
|
||
post "/authority" do CA.HTTP.Post.post(conn, [], "Authority", [], "enroll") end | ||
get "/authority/:id/validate" do CA.HTTP.Get.get(conn, [], "Authority", id, "validate") end | ||
put "/authority/:id/update" do CA.HTTP.Put.put(conn, [], "Authority", id, "update") end | ||
delete "/authority/:id" do CA.HTTP.Delete.delete(conn, [], "Authority", id, "delete") end | ||
|
||
match _ do send_resp(conn, 404, "Please refer to https://authority.erp.uno for more information.") end | ||
def encode(x) do | ||
case Jason.encode(x) do | ||
{:ok, bin} -> bin | ||
{:error, _} -> "" | ||
end |> Jason.Formatter.pretty_print | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule CA.HTTP.Delete do | ||
import Plug.Conn | ||
def delete(conn,_,type,id,spec) do | ||
# :io.format 'DELETE/3:#{type}#{id}/#{spec}', [] | ||
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec})) | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule CA.HTTP.Get do | ||
import Plug.Conn | ||
def get(conn,_,type,id,spec) do | ||
# :io.format 'GET/4:#{type}/#{id}/#{spec}', [] | ||
send_resp(conn, 200, CA.HTTP.encode([%{"type" => type, "id" => id, "spec" => spec}])) | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule CA.HTTP.Patch do | ||
import Plug.Conn | ||
def patch(conn,_,type,id,spec) do | ||
# :io.format 'PUT/4:#{type}#{id}/#{spec}', [] | ||
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec})) | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule CA.HTTP.Post do | ||
import Plug.Conn | ||
def post(conn,_,type,id,spec) do | ||
# :io.format 'PUT/4:#{type}#{id}/#{spec}', [] | ||
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec})) | ||
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
defmodule CA.HTTP.Put do | ||
import Plug.Conn | ||
def put(conn,_,type,id,spec) do | ||
# :io.format 'PUT/4:#{type}#{id}/#{spec}', [] | ||
send_resp(conn, 200, CA.HTTP.encode(%{"type" => type, "id" => id, "spec" => spec})) | ||
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