From 3aa08ad522bc0be68192aa1c9dec001e239f05ac Mon Sep 17 00:00:00 2001 From: 5HT Date: Fri, 25 Oct 2024 00:02:08 +0300 Subject: [PATCH] EST 8047 --- lib/application.ex | 2 +- lib/services/ca.ex | 21 --------------------- lib/services/http/delete.ex | 4 ++-- lib/services/http/get.ex | 4 ++-- lib/services/http/patch.ex | 4 ++-- lib/services/http/post.ex | 4 ++-- lib/services/http/put.ex | 4 ++-- 7 files changed, 11 insertions(+), 32 deletions(-) delete mode 100644 lib/services/ca.ex diff --git a/lib/application.ex b/lib/application.ex index f8794f3..ce7ee37 100644 --- a/lib/application.ex +++ b/lib/application.ex @@ -15,7 +15,7 @@ defmodule CA do def start(_type, _args) do :logger.add_handlers(:ca) - children = [ { Bandit, scheme: :http, port: 8047, plug: CA.HTTP } ] + children = [ { Bandit, scheme: :http, port: 8047, plug: CA.EST } ] CA.CMP.start ; CA.CMC.start ; CA.TSP.start ; CA.OCSP.start Supervisor.start_link(children, strategy: :one_for_one, name: CA.Supervisor) end diff --git a/lib/services/ca.ex b/lib/services/ca.ex deleted file mode 100644 index 5b30757..0000000 --- a/lib/services/ca.ex +++ /dev/null @@ -1,21 +0,0 @@ -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 diff --git a/lib/services/http/delete.ex b/lib/services/http/delete.ex index f78d820..e7f137f 100644 --- a/lib/services/http/delete.ex +++ b/lib/services/http/delete.ex @@ -1,7 +1,7 @@ -defmodule CA.HTTP.Delete do +defmodule CA.EST.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})) + send_resp(conn, 200, CA.EST.encode(%{"type" => type, "id" => id, "spec" => spec})) end end \ No newline at end of file diff --git a/lib/services/http/get.ex b/lib/services/http/get.ex index 21e3319..c068daa 100644 --- a/lib/services/http/get.ex +++ b/lib/services/http/get.ex @@ -1,7 +1,7 @@ -defmodule CA.HTTP.Get do +defmodule CA.EST.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}])) + send_resp(conn, 200, CA.EST.encode([%{"type" => type, "id" => id, "spec" => spec}])) end end \ No newline at end of file diff --git a/lib/services/http/patch.ex b/lib/services/http/patch.ex index bd3f335..068c7d4 100644 --- a/lib/services/http/patch.ex +++ b/lib/services/http/patch.ex @@ -1,7 +1,7 @@ -defmodule CA.HTTP.Patch do +defmodule CA.EST.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})) + send_resp(conn, 200, CA.EST.encode(%{"type" => type, "id" => id, "spec" => spec})) end end diff --git a/lib/services/http/post.ex b/lib/services/http/post.ex index 25d86dd..ddd6e2f 100644 --- a/lib/services/http/post.ex +++ b/lib/services/http/post.ex @@ -1,7 +1,7 @@ -defmodule CA.HTTP.Post do +defmodule CA.EST.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})) + send_resp(conn, 200, CA.EST.encode(%{"type" => type, "id" => id, "spec" => spec})) end end diff --git a/lib/services/http/put.ex b/lib/services/http/put.ex index 83b6a70..ae0a005 100644 --- a/lib/services/http/put.ex +++ b/lib/services/http/put.ex @@ -1,7 +1,7 @@ -defmodule CA.HTTP.Put do +defmodule CA.EST.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})) + send_resp(conn, 200, CA.EST.encode(%{"type" => type, "id" => id, "spec" => spec})) end end