-
Notifications
You must be signed in to change notification settings - Fork 2
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
3 changed files
with
52 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Polar.Machines.Cluster.Connect do | ||
use Oban.Worker, queue: :default | ||
|
||
alias Polar.Repo | ||
alias Polar.Accounts.User | ||
alias Polar.Machines.Cluster | ||
|
||
@lexdee Application.compile_env(:instellar, :lexdee) || Lexdee | ||
|
||
def perform(%Job{args: %{"user_id" => user_id, "cluster_id" => cluster_id}}) do | ||
user = Repo.get(User, user_id) | ||
%{credential: credential} = cluster = Repo.get(Cluster, cluster_id) | ||
|
||
client = | ||
Lexdee.create_client( | ||
credential["endpoint"], | ||
credential["certificiate"], | ||
credential["private_key"] | ||
) | ||
|
||
params = %{ | ||
"password" => credential["password"], | ||
"certificate" => credential["certificate"] | ||
} | ||
|
||
case @lexdee.create_certificate(client, params) do | ||
{:ok, _response} -> | ||
Eventful.Transit.perform(cluster, user, "healthy") | ||
|
||
{:error, %{"error" => "Certificate already in trust store"}} -> | ||
Eventful.Transit.perform(cluster, user, "healthy") | ||
|
||
{:error, %{"error" => reason, "error_code" => 403}} -> | ||
Eventful.Transit.perform(cluster, user, "revert", comment: reason) | ||
|
||
_ -> | ||
Eventful.Transit.perform(cluster, user, "revert", | ||
comment: "Create certificate failed, make sure port is open." | ||
) | ||
end | ||
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
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