From 5aedfce0f030b6cdc8051d2615cc4a48706fddc2 Mon Sep 17 00:00:00 2001 From: Jake Morrison Date: Wed, 27 Dec 2023 15:20:14 -0600 Subject: [PATCH] Get rid of Ecto --- lib/acme_client/cert.ex | 62 ---------------------------------------- lib/acme_client/order.ex | 30 ------------------- 2 files changed, 92 deletions(-) delete mode 100644 lib/acme_client/cert.ex delete mode 100644 lib/acme_client/order.ex diff --git a/lib/acme_client/cert.ex b/lib/acme_client/cert.ex deleted file mode 100644 index 535daca..0000000 --- a/lib/acme_client/cert.ex +++ /dev/null @@ -1,62 +0,0 @@ -defmodule AcmeClient.Cert do - @moduledoc false - use Ecto.Schema - - require Logger - - @primary_key {:hash, :binary_id, autogenerate: false} - schema "certs" do - field(:content, :string) - end - - def changeset(cert, params \\ %{}) do - cert - |> Ecto.Changeset.cast(params, [ - :hash, - :content - ]) - |> Ecto.Changeset.validate_required([:hash, :cert]) - end - - @doc ~S""" - Create RSA private key. - - ## Examples - private_key = AcmeClient.Cert.new_private_key(2048) - """ - @spec new_private_key(non_neg_integer) :: X509.PrivateKey.t() - def new_private_key(size), do: X509.PrivateKey.new_rsa(size) - - @spec private_key_to_pem(X509.PrivateKey.t()) :: String.t() - def private_key_to_pem(private_key) do - private_key - |> X509.PrivateKey.to_pem() - |> normalize_pem() - end - - @doc ~S""" - Create Certificate Signing Request. - - ## Examples - private_key = AcmeClient.Cert.new_private_key(2048) - csr = AcmeClient.Cert.new_csr(["example.com", "*.example.com"], private_key) - """ - @spec new_csr([binary()], X509.PrivateKey.t()) :: X509.CSR.t() - def new_csr(domains, private_key, opts \\ []) do - subject = opts[:subject] || {:rdnSequence, []} - - X509.CSR.new(private_key, subject, - extension_request: [X509.Certificate.Extension.subject_alt_name(domains)] - ) - - # X509.CSR.to_der(csr) - end - - @spec normalize_pem(String.t()) :: String.t() - def normalize_pem(pem) do - case String.trim(pem) do - "" -> "" - pem -> pem <> "\n" - end - end -end diff --git a/lib/acme_client/order.ex b/lib/acme_client/order.ex deleted file mode 100644 index a769459..0000000 --- a/lib/acme_client/order.ex +++ /dev/null @@ -1,30 +0,0 @@ -defmodule AcmeClient.Order do - @moduledoc false - use Ecto.Schema - - schema "orders" do - field(:domain, :string) - field(:identifiers, :string) - field(:status, :string) - field(:url, :string) - field(:private_key, :string) - field(:cert, :string) - field(:csr, :string) - - timestamps() - end - - def changeset(order, params \\ %{}) do - order - |> Ecto.Changeset.cast(params, [ - :domain, - :identifiers, - :status, - :url, - :private_key, - :cert, - :csr - ]) - |> Ecto.Changeset.validate_required([:domain]) - end -end