captive-cli 1.7.0 → 1.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/captive/cli/dependencies.rb +1 -0
- data/lib/captive/cli.rb +4 -0
- data/lib/captive/commands/env_set.rb +2 -11
- data/lib/captive/commands/functions_commands.rb +78 -0
- data/lib/captive/commands/supabase_commands.rb +16 -0
- data/lib/captive/dashboard/env_vars_resource.rb +2 -3
- data/lib/captive/dashboard/functions_resource.rb +26 -0
- data/lib/captive/loader.rb +2 -0
- data/lib/captive/presenter/edge_function.rb +45 -0
- data/lib/captive/shell_completions.rb +4 -1
- data/lib/captive/version.rb +1 -1
- metadata +5 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: e022def3e51501451ec37a1c8eb094447c85ca293b52cce2614a4172c7690215
|
|
4
|
+
data.tar.gz: 47b7dd39c7312f18608ae35d046c49646b7846c58517e945129511199160d484
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cc2c4a6ca16167135d7464a27bb847e26cba1bdcc45c174703ac11159ee49ca06d47ebc418854a9d0281bb0fb074f3222b0590d5bf3fa4070a8b8678c9f0dfd
|
|
7
|
+
data.tar.gz: bdcd2d55dec2beb74cbd0d4270f4fc007d9da8ec682fcfb17adf1558cb80c53d6bc111e579e5d7c258ffbfd7cf5d30d34f222baf55bc7c33f5e22df8cebfb799
|
|
@@ -26,6 +26,7 @@ module Captive
|
|
|
26
26
|
def crons_api = @crons_api ||= Dashboard::ScheduledTasksResource.new(api: dashboard)
|
|
27
27
|
def domains_api = @domains_api ||= Dashboard::DomainsResource.new(api: dashboard)
|
|
28
28
|
def addons_api = @addons_api ||= Dashboard::AddonsResource.new(api: dashboard)
|
|
29
|
+
def functions_api = @functions_api ||= Dashboard::FunctionsResource.new(api: dashboard)
|
|
29
30
|
|
|
30
31
|
def active_kubeconfig
|
|
31
32
|
env_kc = ENV["KUBECONFIG"]
|
data/lib/captive/cli.rb
CHANGED
|
@@ -8,6 +8,7 @@ require_relative "commands/env_commands"
|
|
|
8
8
|
require_relative "commands/crons_commands"
|
|
9
9
|
require_relative "commands/domains_commands"
|
|
10
10
|
require_relative "commands/addons_commands"
|
|
11
|
+
require_relative "commands/supabase_commands"
|
|
11
12
|
require_relative "commands/db_commands"
|
|
12
13
|
require_relative "commands/user_login"
|
|
13
14
|
require_relative "commands/auth_commands"
|
|
@@ -70,6 +71,9 @@ module Captive
|
|
|
70
71
|
desc "addons SUBCOMMAND", "Add-ons d'une app (bases, Supabase…)"
|
|
71
72
|
subcommand "addons", Commands::AddonsCommands
|
|
72
73
|
|
|
74
|
+
desc "supabase SUBCOMMAND", "Extension Supabase d'une app : Edge Functions"
|
|
75
|
+
subcommand "supabase", Commands::SupabaseCommands
|
|
76
|
+
|
|
73
77
|
desc "auth SUBCOMMAND", "Jeton pour kubectl", hide: true
|
|
74
78
|
subcommand "auth", Commands::AuthCommands
|
|
75
79
|
|
|
@@ -14,7 +14,8 @@ module Captive
|
|
|
14
14
|
def run(app, pairs)
|
|
15
15
|
parsed = pairs.map { |pair| parse(pair) }
|
|
16
16
|
existing = @env_vars.list(app).to_set { |var| var["key"] }
|
|
17
|
-
|
|
17
|
+
@env_vars.bulk_set(app, parsed)
|
|
18
|
+
parsed.map { |key, _| [ key, existing.include?(key) ? :updated : :created ] }
|
|
18
19
|
end
|
|
19
20
|
|
|
20
21
|
private
|
|
@@ -25,16 +26,6 @@ module Captive
|
|
|
25
26
|
|
|
26
27
|
[ key, value ]
|
|
27
28
|
end
|
|
28
|
-
|
|
29
|
-
def write(app, key, value, exists)
|
|
30
|
-
if exists
|
|
31
|
-
@env_vars.update(app, key, value)
|
|
32
|
-
[ key, :updated ]
|
|
33
|
-
else
|
|
34
|
-
@env_vars.create(app, key, value)
|
|
35
|
-
[ key, :created ]
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
29
|
end
|
|
39
30
|
end
|
|
40
31
|
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Commands
|
|
5
|
+
# Les Edge Functions d'une app via le dashboard (`captive supabase functions`) : la section
|
|
6
|
+
# Fonctions de l'extension Supabase, sans quitter le terminal.
|
|
7
|
+
class FunctionsCommands < Thor
|
|
8
|
+
include CLIDependencies
|
|
9
|
+
|
|
10
|
+
PLAGES = %w[30m 2h 24h 7d].freeze
|
|
11
|
+
INTERVAL = 2
|
|
12
|
+
|
|
13
|
+
def self.exit_on_failure? = true
|
|
14
|
+
|
|
15
|
+
desc "list APP", "Liste les fonctions de l'app, avec leurs appels et erreurs des dernières 24 h"
|
|
16
|
+
long_desc <<~DESC
|
|
17
|
+
\x05Exemple :
|
|
18
|
+
\x05 captive supabase functions list my-app-staging
|
|
19
|
+
DESC
|
|
20
|
+
def list(app)
|
|
21
|
+
fonctions = functions_api.list(app)
|
|
22
|
+
return puts(paint.dim("Aucune fonction dans supabase/functions/ au commit déployé.")) if fonctions.empty?
|
|
23
|
+
|
|
24
|
+
fonctions.each { |fonction| puts presenter.function(fonction) }
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
desc "invocations APP NAME", "Liste les appels reçus par une fonction, les plus récents d'abord"
|
|
28
|
+
long_desc <<~DESC
|
|
29
|
+
Chaque appel affiche son heure, sa méthode, son statut, sa durée et son exécution,
|
|
30
|
+
à passer à `captive supabase functions logs --exec` pour en lire les logs.
|
|
31
|
+
|
|
32
|
+
\x05Exemples :
|
|
33
|
+
\x05 captive supabase functions invocations my-app-staging stripe-webhook
|
|
34
|
+
\x05 captive supabase functions invocations my-app-staging stripe-webhook --range 7d
|
|
35
|
+
DESC
|
|
36
|
+
method_option :range, enum: PLAGES, default: "24h", desc: "Période"
|
|
37
|
+
def invocations(app, name)
|
|
38
|
+
appels = functions_api.invocations(app, name, range: options[:range])
|
|
39
|
+
return puts(paint.dim("Aucun appel sur la période.")) if appels.empty?
|
|
40
|
+
|
|
41
|
+
appels.each { |appel| puts presenter.invocation(appel) }
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
desc "logs APP NAME", "Affiche les logs d'une fonction"
|
|
45
|
+
long_desc <<~DESC
|
|
46
|
+
\x05Exemples :
|
|
47
|
+
\x05 captive supabase functions logs my-app-staging stripe-webhook
|
|
48
|
+
\x05 captive supabase functions logs my-app-staging stripe-webhook --range 24h
|
|
49
|
+
\x05 captive supabase functions logs my-app-staging stripe-webhook -f
|
|
50
|
+
\x05 captive supabase functions logs my-app-staging stripe-webhook --exec 1acfa451-66d9-4f9a-922a-038afc7e0701
|
|
51
|
+
DESC
|
|
52
|
+
method_option :range, enum: PLAGES, default: "2h", desc: "Période"
|
|
53
|
+
method_option :exec, type: :string, desc: "N'affiche que les logs de cette exécution"
|
|
54
|
+
method_option :follow, aliases: "-f", type: :boolean, default: false, desc: "Suit en continu (Ctrl+C)"
|
|
55
|
+
def logs(app, name)
|
|
56
|
+
dernier = afficher(functions_api.logs(app, name, range: options[:range], exec: options[:exec]))
|
|
57
|
+
return unless options[:follow]
|
|
58
|
+
|
|
59
|
+
loop do
|
|
60
|
+
sleep INTERVAL
|
|
61
|
+
dernier = afficher(functions_api.logs(app, name, range: options[:range], since: dernier)) || dernier
|
|
62
|
+
end
|
|
63
|
+
rescue Interrupt
|
|
64
|
+
puts
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
private
|
|
68
|
+
|
|
69
|
+
# Rend l'horodatage de la dernière ligne affichée, pour reprendre le direct après elle.
|
|
70
|
+
def afficher(lignes)
|
|
71
|
+
lignes.each { |ligne| puts presenter.log(ligne) }
|
|
72
|
+
lignes.last&.fetch("ts")
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def presenter = Presenter::EdgeFunction.new(paint: paint)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "functions_commands"
|
|
4
|
+
|
|
5
|
+
module Captive
|
|
6
|
+
module Commands
|
|
7
|
+
# Ce que l'extension Supabase d'une app offre au-delà de son ajout : ses Edge Functions,
|
|
8
|
+
# comme la section Fonctions de l'extension Supabase du dashboard.
|
|
9
|
+
class SupabaseCommands < Thor
|
|
10
|
+
def self.exit_on_failure? = true
|
|
11
|
+
|
|
12
|
+
desc "functions SUBCOMMAND", "Edge Functions de l'app : appels et logs"
|
|
13
|
+
subcommand "functions", FunctionsCommands
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -12,9 +12,8 @@ module Captive
|
|
|
12
12
|
|
|
13
13
|
def list(app) = @api.get(path(app))
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
def update(app, key, value) = @api.patch(path(app, key), { env_var: { value: value } })
|
|
15
|
+
# Un seul run set-env pour tout le lot ; le dashboard refuse le lot entier en 422.
|
|
16
|
+
def bulk_set(app, pairs) = @api.patch(path(app, "bulk"), { env_vars: pairs.map { |key, value| { key:, value: } } })
|
|
18
17
|
|
|
19
18
|
def delete(app, key) = @api.delete(path(app, key))
|
|
20
19
|
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Dashboard
|
|
5
|
+
# Les Edge Functions Supabase d'une app, leurs invocations et leurs logs : la même API que
|
|
6
|
+
# la section Fonctions de l'extension Supabase du dashboard (ADR 0037).
|
|
7
|
+
class FunctionsResource
|
|
8
|
+
PATH = AppPath.new("functions")
|
|
9
|
+
|
|
10
|
+
def initialize(api:)
|
|
11
|
+
@api = api
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def list(app) = @api.get(PATH.call(app))["functions"]
|
|
15
|
+
|
|
16
|
+
def invocations(app, name, range:)
|
|
17
|
+
@api.get("#{PATH.call(app, name)}/invocations?#{URI.encode_www_form(range:)}")["invocations"]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# `params` : range, since (suite du direct), exec (une seule exécution).
|
|
21
|
+
def logs(app, name, **params)
|
|
22
|
+
@api.get("#{PATH.call(app, name)}/logs?#{URI.encode_www_form(params.compact)}")["lines"]
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/lib/captive/loader.rb
CHANGED
|
@@ -19,11 +19,13 @@ require_relative "dashboard/env_vars_resource"
|
|
|
19
19
|
require_relative "dashboard/scheduled_tasks_resource"
|
|
20
20
|
require_relative "dashboard/domains_resource"
|
|
21
21
|
require_relative "dashboard/addons_resource"
|
|
22
|
+
require_relative "dashboard/functions_resource"
|
|
22
23
|
require_relative "presenter/app_info"
|
|
23
24
|
require_relative "presenter/scheduled_task"
|
|
24
25
|
require_relative "presenter/domain"
|
|
25
26
|
require_relative "presenter/addon"
|
|
26
27
|
require_relative "presenter/supabase_auth"
|
|
28
|
+
require_relative "presenter/edge_function"
|
|
27
29
|
require_relative "activity_trail"
|
|
28
30
|
require_relative "errors"
|
|
29
31
|
require_relative "ui/spinner"
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Presenter
|
|
5
|
+
# Une Edge Function, une invocation ou une ligne de log, chacune sur une ligne.
|
|
6
|
+
class EdgeFunction
|
|
7
|
+
ERREUR = 400
|
|
8
|
+
NIVEAUX = { "error" => "ERR ", "warning" => "WARN", "debug" => "DBG ", "info" => "INFO" }.freeze
|
|
9
|
+
|
|
10
|
+
def initialize(paint:)
|
|
11
|
+
@paint = paint
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def function(fonction)
|
|
15
|
+
erreurs = fonction["errors_24h"]
|
|
16
|
+
erreurs = erreurs.positive? ? @paint.red("#{erreurs} erreurs") : "0 erreur"
|
|
17
|
+
"#{@paint.bold(fonction["name"])} #{fonction["invocations_24h"]} appels #{erreurs} (24 h)"
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def invocation(appel)
|
|
21
|
+
"#{heure(appel["ts"])} #{appel["method"].ljust(6)} #{statut(appel["status"])} " \
|
|
22
|
+
"#{appel["duration_ms"]} ms #{@paint.dim(appel["exec"].to_s)}"
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def log(ligne)
|
|
26
|
+
"#{heure(ligne["ts"])} #{niveau(ligne["level"])} #{ligne["msg"]}"
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def heure(iso) = @paint.dim(Time.parse(iso).localtime.strftime("%d/%m %H:%M:%S"))
|
|
32
|
+
|
|
33
|
+
def statut(code) = code.to_i >= ERREUR ? @paint.red(code.to_s) : @paint.green(code.to_s)
|
|
34
|
+
|
|
35
|
+
def niveau(level)
|
|
36
|
+
libelle = NIVEAUX.fetch(level, level.to_s.upcase)
|
|
37
|
+
case level
|
|
38
|
+
when "error" then @paint.red(libelle)
|
|
39
|
+
when "warning" then @paint.yellow(libelle)
|
|
40
|
+
else libelle
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Captive
|
|
4
4
|
module ShellCompletions
|
|
5
|
-
ROOT_COMMANDS = %w[apps env crons domains addons db login whoami console run logs version completions].freeze
|
|
5
|
+
ROOT_COMMANDS = %w[apps env crons domains addons supabase db login whoami console run logs version completions].freeze
|
|
6
6
|
|
|
7
7
|
SUBCOMMANDS = {
|
|
8
8
|
"apps" => %w[list info restart rebuild],
|
|
@@ -10,6 +10,7 @@ module Captive
|
|
|
10
10
|
"crons" => %w[list add edit rm suspend resume trigger runs],
|
|
11
11
|
"domains" => %w[list add rm redirect serve],
|
|
12
12
|
"addons" => %w[list catalog add],
|
|
13
|
+
"supabase" => %w[functions],
|
|
13
14
|
"db" => %w[restore],
|
|
14
15
|
}.freeze
|
|
15
16
|
|
|
@@ -27,6 +28,8 @@ module Captive
|
|
|
27
28
|
crons) COMPREPLY=($(compgen -W "#{SUBCOMMANDS["crons"].join(" ")}" -- "$cur")); return ;;
|
|
28
29
|
domains) COMPREPLY=($(compgen -W "#{SUBCOMMANDS["domains"].join(" ")}" -- "$cur")); return ;;
|
|
29
30
|
addons) COMPREPLY=($(compgen -W "#{SUBCOMMANDS["addons"].join(" ")}" -- "$cur")); return ;;
|
|
31
|
+
supabase) COMPREPLY=($(compgen -W "#{SUBCOMMANDS["supabase"].join(" ")}" -- "$cur")); return ;;
|
|
32
|
+
functions) COMPREPLY=($(compgen -W "list invocations logs" -- "$cur")); return ;;
|
|
30
33
|
db) COMPREPLY=($(compgen -W "#{SUBCOMMANDS["db"].join(" ")}" -- "$cur")); return ;;
|
|
31
34
|
esac
|
|
32
35
|
|
data/lib/captive/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: captive-cli
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Captive Studio
|
|
@@ -126,10 +126,12 @@ files:
|
|
|
126
126
|
- lib/captive/commands/domains_commands.rb
|
|
127
127
|
- lib/captive/commands/env_commands.rb
|
|
128
128
|
- lib/captive/commands/env_set.rb
|
|
129
|
+
- lib/captive/commands/functions_commands.rb
|
|
129
130
|
- lib/captive/commands/logs.rb
|
|
130
131
|
- lib/captive/commands/one_off_session.rb
|
|
131
132
|
- lib/captive/commands/run.rb
|
|
132
133
|
- lib/captive/commands/supabase_auth_change.rb
|
|
134
|
+
- lib/captive/commands/supabase_commands.rb
|
|
133
135
|
- lib/captive/commands/user_login.rb
|
|
134
136
|
- lib/captive/credentials.rb
|
|
135
137
|
- lib/captive/credentials_store.rb
|
|
@@ -138,6 +140,7 @@ files:
|
|
|
138
140
|
- lib/captive/dashboard/apps_resource.rb
|
|
139
141
|
- lib/captive/dashboard/domains_resource.rb
|
|
140
142
|
- lib/captive/dashboard/env_vars_resource.rb
|
|
143
|
+
- lib/captive/dashboard/functions_resource.rb
|
|
141
144
|
- lib/captive/dashboard/scheduled_tasks_resource.rb
|
|
142
145
|
- lib/captive/dashboard_api.rb
|
|
143
146
|
- lib/captive/dashboard_client.rb
|
|
@@ -157,6 +160,7 @@ files:
|
|
|
157
160
|
- lib/captive/presenter/ansi_stripper.rb
|
|
158
161
|
- lib/captive/presenter/app_info.rb
|
|
159
162
|
- lib/captive/presenter/domain.rb
|
|
163
|
+
- lib/captive/presenter/edge_function.rb
|
|
160
164
|
- lib/captive/presenter/log_colorizer.rb
|
|
161
165
|
- lib/captive/presenter/scheduled_task.rb
|
|
162
166
|
- lib/captive/presenter/supabase_auth.rb
|