From dd5850502d4793725c0384f839075d608f4e2a12 Mon Sep 17 00:00:00 2001 From: Alexandre de Souza Date: Tue, 6 Jun 2023 08:49:09 -0300 Subject: [PATCH] Update LivebookProto messages and minor fixes (#1962) --- lib/livebook/hubs.ex | 2 ++ lib/livebook/hubs/provider.ex | 9 +++------ lib/livebook/hubs/team_client.ex | 4 ++-- lib/livebook/teams/http.ex | 8 ++++---- proto/lib/livebook_proto/event.pb.ex | 6 +++--- proto/lib/livebook_proto/secret_deleted.pb.ex | 1 - .../{user_synchronized.pb.ex => user_connected.pb.ex} | 2 +- proto/messages.proto | 5 ++--- 8 files changed, 17 insertions(+), 20 deletions(-) rename proto/lib/livebook_proto/{user_synchronized.pb.ex => user_connected.pb.ex} (81%) diff --git a/lib/livebook/hubs.ex b/lib/livebook/hubs.ex index d448709b5..09bf5be5a 100644 --- a/lib/livebook/hubs.ex +++ b/lib/livebook/hubs.ex @@ -125,11 +125,13 @@ defmodule Livebook.Hubs do * `:hub_connected` * `:hub_disconnected` * `{:hub_connection_failed, reason}` + * `{:hub_server_error, reason}` Topic `hubs:secrets`: * `{:secret_created, %Secret{}}` * `{:secret_updated, %Secret{}}` + * `{:secret_deleted, %Secret{}}` """ @spec subscribe(atom() | list(atom())) :: :ok | {:error, term()} diff --git a/lib/livebook/hubs/provider.ex b/lib/livebook/hubs/provider.ex index bbdaef78a..4c7667720 100644 --- a/lib/livebook/hubs/provider.ex +++ b/lib/livebook/hubs/provider.ex @@ -4,11 +4,8 @@ defprotocol Livebook.Hubs.Provider do alias Livebook.Secrets.Secret @type capability :: :connect | :list_secrets | :create_secret - @type capabilities :: list(capability()) - @type changeset_errors :: %{required(:errors) => list({String.t(), {String.t(), list()}})} - @typedoc """ An provider-specific map stored as notebook stamp. @@ -71,19 +68,19 @@ defprotocol Livebook.Hubs.Provider do @doc """ Creates a secret of the given hub. """ - @spec create_secret(t(), Secret.t()) :: :ok | {:error, changeset_errors()} + @spec create_secret(t(), Secret.t()) :: :ok | {:error, Ecto.Changeset.t()} def create_secret(hub, secret) @doc """ Updates a secret of the given hub. """ - @spec update_secret(t(), Secret.t()) :: :ok | {:error, changeset_errors()} + @spec update_secret(t(), Secret.t()) :: :ok | {:error, Ecto.Changeset.t()} def update_secret(hub, secret) @doc """ Deletes a secret of the given hub. """ - @spec delete_secret(t(), Secret.t()) :: :ok | {:error, changeset_errors()} + @spec delete_secret(t(), Secret.t()) :: :ok | {:error, Ecto.Changeset.t()} def delete_secret(hub, secret) @doc """ diff --git a/lib/livebook/hubs/team_client.ex b/lib/livebook/hubs/team_client.ex index 4d19be2d4..44bff9561 100644 --- a/lib/livebook/hubs/team_client.ex +++ b/lib/livebook/hubs/team_client.ex @@ -58,14 +58,14 @@ defmodule Livebook.Hubs.TeamClient do @impl true def init(%Team{} = team) do - header = [ + headers = [ {"x-user", to_string(team.user_id)}, {"x-org", to_string(team.org_id)}, {"x-org-key", to_string(team.org_key_id)}, {"x-session-token", team.session_token} ] - {:ok, _pid} = Connection.start_link(self(), header) + {:ok, _pid} = Connection.start_link(self(), headers) {:ok, %__MODULE__{hub: team}} end diff --git a/lib/livebook/teams/http.ex b/lib/livebook/teams/http.ex index 20e74ba99..8a3a3014c 100644 --- a/lib/livebook/teams/http.ex +++ b/lib/livebook/teams/http.ex @@ -31,16 +31,16 @@ defmodule Livebook.Teams.HTTP do get("/api/org-request/#{id}?device_code=#{device_code}") end - defp post(path, json, header \\ []) do + defp post(path, json, headers \\ []) do body = {"application/json", Jason.encode!(json)} - request(:post, path, body: body, header: header) + request(:post, path, body: body, headers: headers) end - defp get(path, params \\ %{}, header \\ []) do + defp get(path, params \\ %{}, headers \\ []) do query_string = URI.encode_query(params) path = if query_string != "", do: "#{path}?#{query_string}", else: path - request(:get, path, header: header) + request(:get, path, headers: headers) end defp request(method, path, opts) do diff --git a/proto/lib/livebook_proto/event.pb.ex b/proto/lib/livebook_proto/event.pb.ex index 23efc2b6f..c69f57438 100644 --- a/proto/lib/livebook_proto/event.pb.ex +++ b/proto/lib/livebook_proto/event.pb.ex @@ -19,8 +19,8 @@ defmodule LivebookProto.Event do json_name: "secretDeleted", oneof: 0 - field :user_synchronized, 4, - type: LivebookProto.UserSynchronized, - json_name: "userSynchronized", + field :user_connected, 4, + type: LivebookProto.UserConnected, + json_name: "userConnected", oneof: 0 end diff --git a/proto/lib/livebook_proto/secret_deleted.pb.ex b/proto/lib/livebook_proto/secret_deleted.pb.ex index c2ea54acd..248264de5 100644 --- a/proto/lib/livebook_proto/secret_deleted.pb.ex +++ b/proto/lib/livebook_proto/secret_deleted.pb.ex @@ -3,5 +3,4 @@ defmodule LivebookProto.SecretDeleted do use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3 field :name, 1, type: :string - field :value, 2, type: :string end diff --git a/proto/lib/livebook_proto/user_synchronized.pb.ex b/proto/lib/livebook_proto/user_connected.pb.ex similarity index 81% rename from proto/lib/livebook_proto/user_synchronized.pb.ex rename to proto/lib/livebook_proto/user_connected.pb.ex index 5e8d3e3e0..88baaba03 100644 --- a/proto/lib/livebook_proto/user_synchronized.pb.ex +++ b/proto/lib/livebook_proto/user_connected.pb.ex @@ -1,4 +1,4 @@ -defmodule LivebookProto.UserSynchronized do +defmodule LivebookProto.UserConnected do @moduledoc false use Protobuf, protoc_gen_elixir_version: "0.11.0", syntax: :proto3 diff --git a/proto/messages.proto b/proto/messages.proto index 7a1f3c225..217f5fefe 100644 --- a/proto/messages.proto +++ b/proto/messages.proto @@ -21,10 +21,9 @@ message SecretUpdated { message SecretDeleted { string name = 1; - string value = 2; } -message UserSynchronized { +message UserConnected { string name = 1; repeated Secret secrets = 2; } @@ -34,6 +33,6 @@ message Event { SecretCreated secret_created = 1; SecretUpdated secret_updated = 2; SecretDeleted secret_deleted = 3; - UserSynchronized user_synchronized = 4; + UserConnected user_connected = 4; } }