mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-12 14:36:20 +08:00
Secret improvements (#2051)
Co-authored-by: José Valim <jose.valim@dashbit.co>
This commit is contained in:
parent
12385f2a82
commit
433cd43894
5 changed files with 67 additions and 28 deletions
|
@ -43,7 +43,9 @@ export function registerGlobalEventHandlers() {
|
||||||
|
|
||||||
window.addEventListener("lb:clipcopy", (event) => {
|
window.addEventListener("lb:clipcopy", (event) => {
|
||||||
if ("clipboard" in navigator) {
|
if ("clipboard" in navigator) {
|
||||||
if (event.target.tagName === "INPUT") {
|
if (event.detail.content) {
|
||||||
|
navigator.clipboard.writeText(event.detail.content);
|
||||||
|
} else if (event.target.tagName === "INPUT") {
|
||||||
navigator.clipboard.writeText(event.target.value);
|
navigator.clipboard.writeText(event.target.value);
|
||||||
} else {
|
} else {
|
||||||
navigator.clipboard.writeText(event.target.textContent);
|
navigator.clipboard.writeText(event.target.textContent);
|
||||||
|
|
|
@ -232,6 +232,7 @@ defmodule LivebookWeb.SessionLive do
|
||||||
settings={@data_view.app_settings}
|
settings={@data_view.app_settings}
|
||||||
app={@app}
|
app={@app}
|
||||||
deployed_app_slug={@data_view.deployed_app_slug}
|
deployed_app_slug={@data_view.deployed_app_slug}
|
||||||
|
any_session_secrets?={@data_view.any_session_secrets?}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div data-el-runtime-info>
|
<div data-el-runtime-info>
|
||||||
|
@ -2275,6 +2276,8 @@ defmodule LivebookWeb.SessionLive do
|
||||||
secrets: data.secrets,
|
secrets: data.secrets,
|
||||||
hub: Livebook.Hubs.fetch_hub!(data.notebook.hub_id),
|
hub: Livebook.Hubs.fetch_hub!(data.notebook.hub_id),
|
||||||
hub_secrets: data.hub_secrets,
|
hub_secrets: data.hub_secrets,
|
||||||
|
any_session_secrets?:
|
||||||
|
Session.Data.session_secrets(data.secrets, data.notebook.hub_id) != [],
|
||||||
file_entries: Enum.sort_by(data.notebook.file_entries, & &1.name),
|
file_entries: Enum.sort_by(data.notebook.file_entries, & &1.name),
|
||||||
app_settings: data.notebook.app_settings,
|
app_settings: data.notebook.app_settings,
|
||||||
deployed_app_slug: data.deployed_app_slug
|
deployed_app_slug: data.deployed_app_slug
|
||||||
|
|
|
@ -27,21 +27,28 @@ defmodule LivebookWeb.SessionLive.AppInfoComponent do
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<% else %>
|
<% else %>
|
||||||
<div class="mt-5 flex space-x-2">
|
<div class="mt-5 flex flex-col gap-6">
|
||||||
<button
|
<.message_box
|
||||||
class="button-base button-blue"
|
:if={@any_session_secrets?}
|
||||||
phx-click="deploy_app"
|
kind={:warning}
|
||||||
disabled={not Livebook.Notebook.AppSettings.valid?(@settings)}
|
message="You defined session secrets, but those are not available to the deployed app, only Hub secrets are."
|
||||||
>
|
/>
|
||||||
<.remix_icon icon="rocket-line" class="align-middle mr-1" />
|
<div class="flex space-x-2">
|
||||||
<span>Deploy</span>
|
<button
|
||||||
</button>
|
class="button-base button-blue"
|
||||||
<.link
|
phx-click="deploy_app"
|
||||||
patch={~p"/sessions/#{@session.id}/settings/app"}
|
disabled={not Livebook.Notebook.AppSettings.valid?(@settings)}
|
||||||
class="button-base button-outlined-gray bg-transparent"
|
>
|
||||||
>
|
<.remix_icon icon="rocket-line" class="align-middle mr-1" />
|
||||||
Configure
|
<span>Deploy</span>
|
||||||
</.link>
|
</button>
|
||||||
|
<.link
|
||||||
|
patch={~p"/sessions/#{@session.id}/settings/app"}
|
||||||
|
class="button-base button-outlined-gray bg-transparent"
|
||||||
|
>
|
||||||
|
Configure
|
||||||
|
</.link>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<%= if @app do %>
|
<%= if @app do %>
|
||||||
<h3 class="mt-10 uppercase text-sm font-semibold text-gray-500">
|
<h3 class="mt-10 uppercase text-sm font-semibold text-gray-500">
|
||||||
|
|
|
@ -77,12 +77,22 @@ defmodule LivebookWeb.SessionLive.SecretsListComponent do
|
||||||
<%= @secret.name %>
|
<%= @secret.name %>
|
||||||
</span>
|
</span>
|
||||||
<div
|
<div
|
||||||
class="flex-row justify-between items-center my-1 hidden"
|
class="flex justify-between items-center my-1 hidden"
|
||||||
id={"session-secret-#{@secret.name}-detail"}
|
id={"session-secret-#{@secret.name}-detail"}
|
||||||
>
|
>
|
||||||
<span class="text-sm font-mono break-all flex-row tooltip right" data-tooltip={@secret.value}>
|
<div class="flex items-center gap-1">
|
||||||
*****
|
<span class="text-sm font-mono break-all">
|
||||||
</span>
|
*****
|
||||||
|
</span>
|
||||||
|
<button
|
||||||
|
id={"session-secret-#{@secret.name}-delete"}
|
||||||
|
type="button"
|
||||||
|
phx-click={JS.dispatch("lb:clipcopy", detail: %{content: @secret.value})}
|
||||||
|
class="icon-button"
|
||||||
|
>
|
||||||
|
<.remix_icon icon="clipboard-line" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<button
|
<button
|
||||||
id={"session-secret-#{@secret.name}-delete"}
|
id={"session-secret-#{@secret.name}-delete"}
|
||||||
type="button"
|
type="button"
|
||||||
|
@ -92,7 +102,7 @@ defmodule LivebookWeb.SessionLive.SecretsListComponent do
|
||||||
target: @myself
|
target: @myself
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
class="hover:text-gray-900"
|
class="icon-button"
|
||||||
>
|
>
|
||||||
<.remix_icon icon="delete-bin-line" />
|
<.remix_icon icon="delete-bin-line" />
|
||||||
</button>
|
</button>
|
||||||
|
@ -149,16 +159,23 @@ defmodule LivebookWeb.SessionLive.SecretsListComponent do
|
||||||
</.form>
|
</.form>
|
||||||
</div>
|
</div>
|
||||||
<div class="flex-row justify-between items-center my-1 hidden" id={"#{@id}-detail"}>
|
<div class="flex-row justify-between items-center my-1 hidden" id={"#{@id}-detail"}>
|
||||||
<span
|
<div class="flex items-center gap-1">
|
||||||
class="text-sm font-mono break-all flex-row tooltip right"
|
<span class="text-sm font-mono break-all">
|
||||||
data-tooltip={@secret.value}
|
*****
|
||||||
>
|
</span>
|
||||||
*****
|
<button
|
||||||
</span>
|
id={"session-secret-#{@secret.name}-delete"}
|
||||||
|
type="button"
|
||||||
|
phx-click={JS.dispatch("lb:clipcopy", detail: %{content: @secret.value})}
|
||||||
|
class="icon-button"
|
||||||
|
>
|
||||||
|
<.remix_icon icon="clipboard-line" />
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<.link
|
<.link
|
||||||
id={"#{@id}-edit-button"}
|
id={"#{@id}-edit-button"}
|
||||||
navigate={~p"/hub/#{@secret.hub_id}/secrets/edit/#{@secret.name}"}
|
navigate={~p"/hub/#{@secret.hub_id}/secrets/edit/#{@secret.name}"}
|
||||||
class="hover:text-gray-900"
|
class="icon-button"
|
||||||
role="button"
|
role="button"
|
||||||
>
|
>
|
||||||
<.remix_icon icon="pencil-line" />
|
<.remix_icon icon="pencil-line" />
|
||||||
|
|
|
@ -1821,5 +1821,15 @@ defmodule LivebookWeb.SessionLiveTest do
|
||||||
|
|
||||||
Livebook.App.close(app.pid)
|
Livebook.App.close(app.pid)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "shows a warning when any session secrets are defined", %{conn: conn, session: session} do
|
||||||
|
secret = build(:secret, name: "FOO", value: "456", hub_id: nil)
|
||||||
|
Session.set_secret(session.pid, secret)
|
||||||
|
|
||||||
|
{:ok, view, _} = live(conn, ~p"/sessions/#{session.id}")
|
||||||
|
|
||||||
|
assert render(view) =~
|
||||||
|
"You defined session secrets, but those are not available to the deployed app, only Hub secrets are."
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue