Skip to content

Commit

Permalink
implemented realm creation
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriele Ghio <gabriele.ghio@secomind.com>
  • Loading branch information
shinnokdisengir committed Oct 2, 2024
1 parent d99cccf commit 534c156
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 1,690 deletions.
21 changes: 0 additions & 21 deletions tools/astarte_dev_tool/config/config.ex

This file was deleted.

14 changes: 14 additions & 0 deletions tools/astarte_dev_tool/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Config

config :logger, :console,
format: {PrettyLog.LogfmtFormatter, :format},
metadata: [:realm, :datacenter, :replication_factor, :module, :function, :tag]

config :astarte_dev_tool, :xandra,
nodes: [
"#{System.get_env("CASSANDRA_DB_HOST") || "localhost"}:#{System.get_env("CASSANDRA_DB_PORT") || 9042}"
],
sync_connect: 5000,
log: :info,
stacktrace: true,
pool_size: 10
41 changes: 30 additions & 11 deletions tools/astarte_dev_tool/lib/commands/realm/create.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,37 @@

defmodule AstarteDevTool.Commands.Realm.Create do
@moduledoc false
alias AstarteDevTool.Constants.System, as: Constants
alias Astarte.DataAccess.Database
alias Astarte.DataAccess.Realm, as: RealmDataAccess

def exec(path, volumes \\ false) do
args =
if volumes,
do: Constants.command_down_args() ++ ["-v"],
else: Constants.command_down_args()

case System.cmd(Constants.command(), args, Constants.base_opts() ++ [cd: path]) do
{_result, 0} -> :ok
{:error, reason} -> {:error, "System is not up and running: #{reason}"}
{result, exit_code} -> {:error, "Cannot exec system.down: #{result}, #{exit_code}"}
@start_apps [
:logger,
:crypto,
:ssl,
:xandra,
:astarte_data_access
]
def exec(
[{_, _} | _] = nodes,
realm_name,
replication \\ 1,
max_retention \\ 1,
public_key_pem \\ "@@@@",
device_registration_limit \\ nil,
realm_schema_version \\ 10
) do
with :ok <- Enum.each(@start_apps, &Application.ensure_all_started/1),
{:ok, _client} <- Database.connect(cassandra_nodes: nodes),
:ok <-
RealmDataAccess.create_realm(
realm_name,
replication,
max_retention,
public_key_pem,
device_registration_limit,
realm_schema_version
) do
:ok
end
end
end
Loading

0 comments on commit 534c156

Please sign in to comment.