-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jake Laderman <jsladerman@gmail.com>
- Loading branch information
1 parent
fdb8814
commit 1a1a2f3
Showing
57 changed files
with
2,192 additions
and
148 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -67,4 +67,7 @@ yarn-error.log* | |
cert.pem | ||
key.pem | ||
|
||
|
||
/test-certs/ | ||
|
||
.vscode |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
erlang 24.3.4.14 | ||
elixir 1.12.3 | ||
erlang 24.3.4.17 | ||
elixir 1.13.4 |
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
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,96 @@ | ||
defmodule Core.Clients.Console do | ||
require Logger | ||
|
||
@clusters_q """ | ||
query { | ||
clusters(first: 100) { | ||
edges { node { name id distro metadata } } | ||
} | ||
} | ||
""" | ||
|
||
@create_svc_q """ | ||
mutation Create($clusterId: ID!, $attributes: ServiceDeploymentAttributes!) { | ||
createServiceDeployment(clusterId: $clusterId, attributes: $attributes) { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
@delete_svc_q """ | ||
mutation Delete($id: ID!) { | ||
deleteServiceDeployment(id: $id) { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
@update_svc_q """ | ||
mutation Update($id: ID!, $attributes: ServiceUpdateAttributes!) { | ||
updateServiceDeployment(id: $id) { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
@repo_q """ | ||
query Repo($url: String!) { | ||
gitRepository(url: $url) { | ||
id | ||
} | ||
} | ||
""" | ||
|
||
def new(url, token) do | ||
Req.new(base_url: url, auth: "Token #{token}") | ||
|> AbsintheClient.attach() | ||
end | ||
|
||
def clusters(client) do | ||
Req.post(client, graphql: @clusters_q) | ||
|> case do | ||
{:ok, %Req.Response{body: %{"clusters" => %{"edges" => edges}}}} -> {:ok, Enum.map(edges, & &1["node"])} | ||
res -> | ||
Logger.warn "Failed to fetch clusters: #{inspect(res)}" | ||
{:error, "could not fetch clusters"} | ||
end | ||
end | ||
|
||
def repo(client, url) do | ||
Req.post(client, graphql: {@repo_q, %{url: url}}) | ||
|> case do | ||
{:ok, %Req.Response{body: %{"gitRepository" => %{"id" => id}}}} -> {:ok, id} | ||
res -> | ||
Logger.warn "Failed to fetch clusters: #{inspect(res)}" | ||
{:error, "could not fetch repo"} | ||
end | ||
end | ||
|
||
def create_service(client, cluster_id, attrs) do | ||
Req.post(client, graphql: {@create_svc_q, %{clusterId: cluster_id, attributes: attrs}}) | ||
|> service_resp("createServiceDeployment") | ||
end | ||
|
||
def update_service(client, id, attrs) do | ||
Req.post(client, graphql: {@update_svc_q, %{id: id, attributes: attrs}}) | ||
|> service_resp("updateServiceDeployment") | ||
end | ||
|
||
def delete_service(client, id) do | ||
Req.post(client, graphql: {@delete_svc_q, %{id: id}}) | ||
|> service_resp("deleteServiceDeployment") | ||
end | ||
|
||
defp service_resp({:ok, %Req.Response{status: 200, body: body}}, field) do | ||
case body[field] do | ||
%{"id" => id} -> {:ok, id} | ||
err -> | ||
Logger.warn "invalid console gql response: #{inspect(err)}" | ||
end | ||
end | ||
|
||
defp service_resp(resp, _) do | ||
Logger.error "failed to fetch from console: #{inspect(resp)}" | ||
{:error, "console error"} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
defmodule Core.Policies.Cloud do | ||
use Piazza.Policy | ||
alias Core.Schema.{User, ConsoleInstance} | ||
alias Core.Services.Payments | ||
|
||
def can?(%User{} = user, %ConsoleInstance{}, :create) do | ||
case Payments.has_feature?(user, :cd) do | ||
true -> :pass | ||
_ -> {:error, "you must be on a paid plan to use Plural Cloud"} | ||
end | ||
end | ||
|
||
def can?(u, %Ecto.Changeset{} = cs, action), do: can?(u, apply_changes(cs), action) | ||
|
||
def can?(_, _, _), do: :pass | ||
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
Oops, something went wrong.