Skip to content

Commit

Permalink
Fixed adding provider from file bug (#641)
Browse files Browse the repository at this point in the history
* Fixed adding provider from file bug

Signed-off-by: aish-where-ya <[email protected]>

* Minor fix

Signed-off-by: aish-where-ya <[email protected]>

---------

Signed-off-by: aish-where-ya <[email protected]>
  • Loading branch information
aish-where-ya committed Jul 10, 2023
1 parent 1f276d0 commit 4feeb1f
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 50 deletions.
4 changes: 2 additions & 2 deletions host_core/lib/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ defmodule HostCore.Application do
strategy: :one_for_one,
allow_latest: config.allow_latest,
allowed_insecure: config.allowed_insecure,
enable_actor_from_fs: config.enable_actor_from_fs},
enable_start_from_fs: config.enable_start_from_fs},
{HostCore.Actors.CallCounter, nil},
{HostCore.Lattice.LatticeRoot, nil},
{HostCore.Vhost.VirtualHost, config}
Expand Down Expand Up @@ -265,7 +265,7 @@ defmodule HostCore.Application do
end

defp ensure_booleans(config) do
bool_keys = [:config_service_enabled, :ctl_tls, :rpc_tls, :enable_ipv6, :enable_actor_from_fs]
bool_keys = [:config_service_enabled, :ctl_tls, :rpc_tls, :enable_ipv6, :enable_start_from_fs]

Enum.reduce(bool_keys, config, fn key, config ->
old = Map.get(config, key, nil)
Expand Down
4 changes: 2 additions & 2 deletions host_core/lib/host_core/actors/actor_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ defmodule HostCore.Actors.ActorSupervisor do
def start_actor_from_file(host_id, fileref, count \\ 1, annotations \\ %{}) do
config = VirtualHost.config(host_id)

if config.enable_actor_from_fs do
if config.enable_start_from_fs do
Tracer.with_span "Starting Actor from file", kind: :server do
case File.read(String.trim_leading(fileref, "file://")) do
{:error, err} ->
Expand Down Expand Up @@ -319,7 +319,7 @@ defmodule HostCore.Actors.ActorSupervisor do
config = VirtualHost.config(pid)

if String.starts_with?(ref, "file://") do
if not config.enable_actor_from_fs do
if not config.enable_start_from_fs do
{:error, "actor from local filesystem is disabled"}
else
with {:ok, binary} <- File.read(String.trim_leading(ref, "file://")),
Expand Down
24 changes: 7 additions & 17 deletions host_core/lib/host_core/control_interface/host_server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,13 @@ defmodule HostCore.ControlInterface.HostServer do
annotations = Map.get(start_provider_command, "annotations") || %{}

res =
if String.starts_with?(start_provider_command["provider_ref"], "bindle://") do
ProviderSupervisor.start_provider_from_bindle(
host_id,
start_provider_command["provider_ref"],
start_provider_command["link_name"],
Map.get(start_provider_command, "configuration", ""),
annotations
)
else
ProviderSupervisor.start_provider_from_oci(
host_id,
start_provider_command["provider_ref"],
start_provider_command["link_name"],
Map.get(start_provider_command, "configuration", ""),
annotations
)
end
ProviderSupervisor.start_provider_from_ref(
host_id,
start_provider_command["provider_ref"],
start_provider_command["link_name"],
Map.get(start_provider_command, "configuration", ""),
annotations
)

case res do
{:ok, _pid} ->
Expand Down
54 changes: 30 additions & 24 deletions host_core/lib/host_core/providers/provider_supervisor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -195,31 +195,37 @@ defmodule HostCore.Providers.ProviderSupervisor do
provider_configuration \\ ""
) do
Tracer.with_span "Start Provider from File" do
case Native.par_from_path(path, link_name) do
{:ok, par} ->
start_executable_provider(
host_id,
Native.par_cache_path(
par.claims.public_key,
par.claims.revision,
par.contract_id,
link_name
),
Map.put(par.claims, :contract_id, par.contract_id),
link_name,
par.contract_id,
"",
provider_configuration,
annotations
)

{:error, err} ->
Logger.error("Error starting provider from file: #{err}", link_name: link_name)
{:error, err}
config = VirtualHost.config(host_id)

err ->
Logger.error("Error starting provider from file: #{err}", link_name: link_name)
{:error, err}
if config.enable_start_from_fs do
case Native.par_from_path(String.trim_leading(path, "file://"), link_name) do
{:ok, par} ->
start_executable_provider(
host_id,
Native.par_cache_path(
par.claims.public_key,
par.claims.revision,
par.contract_id,
link_name
),
Map.put(par.claims, :contract_id, par.contract_id),
link_name,
par.contract_id,
path,
provider_configuration,
annotations
)

{:error, err} ->
Logger.error("Error starting provider from file: #{err}", link_name: link_name)
{:error, err}

err ->
Logger.error("Error starting provider from file: #{err}", link_name: link_name)
{:error, err}
end
else
{:error, "provider file loading is disabled"}
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions host_core/lib/host_core/vhost/config_plan.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule HostCore.Vhost.ConfigPlan do
{:structured_log_level, "WASMCLOUD_STRUCTURED_LOG_LEVEL",
required: false, map: &string_to_loglevel/1},
{:enable_ipv6, "WASMCLOUD_ENABLE_IPV6", required: false, map: &string_to_bool/1},
{:enable_actor_from_fs, "WASMCLOUD_ALLOW_FILE_LOAD",
{:enable_start_from_fs, "WASMCLOUD_ALLOW_FILE_LOAD",
required: false, map: &string_to_bool/1},
{:policy_topic, "WASMCLOUD_POLICY_TOPIC", required: false},
{:policy_changes_topic, "WASMCLOUD_POLICY_CHANGES_TOPIC", required: false},
Expand Down Expand Up @@ -111,7 +111,7 @@ defmodule HostCore.Vhost.ConfigPlan do
# DEPRECATED
{:structured_log_level, "structured_log_level", required: false, default: nil},
{:enable_ipv6, "enable_ipv6", required: false, default: false},
{:enable_actor_from_fs, "enable_actor_from_fs", required: false, default: false},
{:enable_start_from_fs, "enable_start_from_fs", required: false, default: false},
{:policy_topic, "policy_topic", required: false},
{:policy_changes_topic, "policy_changes_topic", required: false},
{:policy_timeout_ms, "policy_timeout_ms", required: false, default: 1_000}
Expand Down
4 changes: 2 additions & 2 deletions host_core/lib/host_core/vhost/configuration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule HostCore.Vhost.Configuration do
rpc_tls: boolean(),
config_service_enabled: boolean(),
enable_ipv6: boolean(),
enable_actor_from_fs: boolean(),
enable_start_from_fs: boolean(),
cluster_issuers: [String.t()],
log_level: atom(),
prov_rpc_tls: boolean(),
Expand Down Expand Up @@ -73,7 +73,7 @@ defmodule HostCore.Vhost.Configuration do
:rpc_tls,
:config_service_enabled,
:enable_ipv6,
:enable_actor_from_fs,
:enable_start_from_fs,
:cluster_issuers,
:log_level,
:prov_rpc_tls,
Expand Down
2 changes: 1 addition & 1 deletion host_core/test/support/common.exs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ defmodule HostCoreTest.Common do
enable_structured_logging: false,
log_level: :info,
enable_ipv6: false,
enable_actor_from_fs: true,
enable_start_from_fs: true,
policy_topic: nil,
policy_changes_topic: nil,
policy_timeout_ms: 1_000
Expand Down

0 comments on commit 4feeb1f

Please sign in to comment.