Skip to content

Commit

Permalink
implemented realm creation
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriele Ghio <[email protected]>

to squash
  • Loading branch information
shinnokdisengir committed Sep 11, 2024
1 parent 3cdbdb5 commit 630344d
Show file tree
Hide file tree
Showing 14 changed files with 281 additions and 1,695 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
26 changes: 26 additions & 0 deletions tools/astarte_dev_tool/lib/commands/auth/keys.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#
# This file is part of Astarte.
#
# Copyright 2024 SECO Mind Srl
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

defmodule AstarteDevTool.Commands.Auth.Keys do
@moduledoc false
alias AstarteDevTool.Utilities.Auth, as: AuthUtilities

def exec(), do: AuthUtilities.pem_key()
def exec(nil), do: exec()
def exec(priv), do: AuthUtilities.pem_key(priv)
end
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 630344d

Please sign in to comment.