defmodule LivebookWeb.Hub.FileSystemFormComponent do
use LivebookWeb, :live_component
alias Livebook.FileSystem
alias Livebook.FileSystems
@impl true
def mount(socket) do
{:ok, assign(socket, error_message: nil)}
end
@impl true
def update(assigns, socket) do
{file_system, assigns} = Map.pop!(assigns, :file_system)
mode = mode(file_system)
title = title(file_system)
button = button_attrs(file_system)
file_system = file_system || %FileSystem.S3{hub_id: assigns.hub.id}
changeset = FileSystems.change_file_system(file_system)
{:ok,
socket
|> assign_new(:hub, fn -> assigns.hub end)
|> assign_new(:file_system, fn -> file_system end)
|> assign_new(:type, fn -> FileSystems.type(file_system) end)
|> assign_new(:mode, fn -> mode end)
|> assign_new(:title, fn -> title end)
|> assign_new(:button, fn -> button end)
|> assign_new(:return_to, fn -> assigns.return_to end)
|> assign_new(:disabled, fn -> assigns.disabled end)
|> assign_form(changeset)}
end
@impl true
def render(assigns) do
~H"""
{@title}
{@error_message}
<.radio_card_input
id="file_system_type-s3"
name="file_system[type]"
title="S3"
phx-click={JS.push("select_type", value: %{value: :s3})}
phx-target={@myself}
value={@type}
checked_value={:s3}
disabled={@mode == :edit}
>
Configure an AWS S3 bucket as a Livebook file storage. Many storage services offer an S3-compatible API and those work as well.
<.radio_card_input
id="file_system_type-git"
name="file_system[type]"
title="Git"
phx-click={JS.push("select_type", value: %{value: :git})}
phx-target={@myself}
value={@type}
checked_value={:git}
disabled={@mode == :edit}
>
Configure a Git repository as a read-only Livebook file storage. You will need a valid SSH key to access your Git repository.
You may leave Access Key fields empty. In such cases,
they will be automatically read from your environment variables,
AWS credentials, or Amazon EC2/ECS metadata.
Start Livebook with LIVEBOOK_AWS_CREDENTIALS environment
variable set if you want to automatically read credentials from
environment variables, AWS credentials, or Amazon EC2/ECS metadata.
<% end %>
"""
end
defp file_system_form_fields(%{file_system: %FileSystem.Git{}} = assigns) do
~H"""