captive-cli 1.7.0 → 1.9.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/activity_trail.rb +16 -2
- data/lib/captive/cli/dependencies.rb +1 -0
- data/lib/captive/cli.rb +4 -0
- data/lib/captive/commands/db_commands.rb +11 -3
- data/lib/captive/commands/db_exec.rb +3 -1
- data/lib/captive/commands/db_psql.rb +17 -2
- 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/dashboard_client.rb +2 -1
- data/lib/captive/kubectl.rb +10 -1
- 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: 6194e6a9c07f9da6c263e19ae462f65e543c2de410198eb72e3d99a02bd8633d
|
|
4
|
+
data.tar.gz: 558810ef6307fe5ba02f10052a6968127a55b7f13475746607cf27d27749aa96
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 14880605229de4aadf6a417bb670b07626c36a0988d2d82853549a8632cb559f89d8bc625158aa6d2dc895bc133b3927a8c25c844728eeb33645dfac556d956f
|
|
7
|
+
data.tar.gz: d7f976950c383a71db5fde0903e21ddf71826f258d7872a08c808d4055f697c80ee81ae3fc81a4336a5999a676b81c2583545e4da5f5ef3fe51ee9fe3c1bb12f
|
|
@@ -20,6 +20,15 @@ module Captive
|
|
|
20
20
|
def console_opened(app, session: nil) = signaler(app, "console", session: session)
|
|
21
21
|
def db_dumped(app) = signaler(app, "db_dump")
|
|
22
22
|
def db_restored(app) = signaler(app, "db_restore")
|
|
23
|
+
def db_psql_opened(app) = signaler(app, "db_psql")
|
|
24
|
+
|
|
25
|
+
def db_query_run(app, sql, read_only:)
|
|
26
|
+
signaler(app, "db_query", command: borne(sql), read_only: read_only)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def db_file_executed(app, file, content)
|
|
30
|
+
signaler(app, "db_exec", command: borne("-- #{file}\n#{content}"))
|
|
31
|
+
end
|
|
23
32
|
|
|
24
33
|
def command_run(app, command, session: nil)
|
|
25
34
|
signaler(app, "run", command: Array(command).join(" "), session: session)
|
|
@@ -27,10 +36,15 @@ module Captive
|
|
|
27
36
|
|
|
28
37
|
private
|
|
29
38
|
|
|
39
|
+
# Un dump joué par erreur avec exec ne doit pas partir en entier dans une requête HTTP.
|
|
40
|
+
SQL_MAX = 65_536
|
|
41
|
+
|
|
42
|
+
def borne(sql) = sql.byteslice(0, SQL_MAX).scrub("")
|
|
43
|
+
|
|
30
44
|
# Un dashboard indisponible ne doit jamais empêcher d'ouvrir une console : l'accès est ce
|
|
31
45
|
# que l'utilisateur a demandé, le signaler ne l'est pas.
|
|
32
|
-
def signaler(app, kind, command: nil, session: nil)
|
|
33
|
-
@dashboard.record_activity(app, kind: kind, command: command, session: session)
|
|
46
|
+
def signaler(app, kind, command: nil, session: nil, **details)
|
|
47
|
+
@dashboard.record_activity(app, kind: kind, command: command, session: session, **details)
|
|
34
48
|
rescue StandardError
|
|
35
49
|
nil
|
|
36
50
|
end
|
|
@@ -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
|
|
|
@@ -41,7 +41,7 @@ module Captive
|
|
|
41
41
|
desc: "Joue le fichier dans une transaction unique " \
|
|
42
42
|
"(--no-transaction pour CREATE INDEX CONCURRENTLY, pg_cron…)"
|
|
43
43
|
def exec(app, file)
|
|
44
|
-
result = DbExec.new(kubectl: kubectl).run(app, file, single_transaction: options[:transaction])
|
|
44
|
+
result = DbExec.new(kubectl: kubectl, trail: trail).run(app, file, single_transaction: options[:transaction])
|
|
45
45
|
puts paint.green(" ✓ #{result} appliqué.")
|
|
46
46
|
rescue Errno::ENOENT => e
|
|
47
47
|
abort paint.red("✗ Fichier introuvable : #{e.message}")
|
|
@@ -49,16 +49,24 @@ module Captive
|
|
|
49
49
|
abort paint.red("✗ #{e.message}")
|
|
50
50
|
end
|
|
51
51
|
|
|
52
|
-
desc "psql APP", "Ouvre une session psql
|
|
52
|
+
desc "psql APP", "Ouvre une session psql sur la base, ou joue une requête avec -c"
|
|
53
53
|
long_desc <<~DESC
|
|
54
54
|
Session psql interactive sur la base de l'app, sous un rôle admin
|
|
55
55
|
non-superuser. L'équivalent du SQL Editor de Supabase, en ligne de commande.
|
|
56
56
|
|
|
57
|
+
Avec -c, joue la requête sans session interactive : utilisable par un agent.
|
|
58
|
+
--read-only refuse toute écriture (garde-fou, contournable par un SET).
|
|
59
|
+
|
|
57
60
|
\x05Exemple :
|
|
58
61
|
\x05 captive db psql my-app-staging
|
|
62
|
+
\x05 captive db psql my-app-staging -c "SELECT count(*) FROM users" --read-only
|
|
59
63
|
DESC
|
|
64
|
+
method_option :command, aliases: "-c", type: :string, desc: "Requête SQL à jouer sans session interactive"
|
|
65
|
+
method_option :read_only, type: :boolean, default: false, desc: "Refuse toute écriture (avec -c)"
|
|
60
66
|
def psql(app)
|
|
61
|
-
DbPsql.new(kubectl: kubectl).run(app)
|
|
67
|
+
DbPsql.new(kubectl: kubectl, trail: trail).run(app, command: options[:command], read_only: options[:read_only] || false)
|
|
68
|
+
rescue Captive::ExecError => e
|
|
69
|
+
abort paint.red("✗ #{e.message}")
|
|
62
70
|
end
|
|
63
71
|
|
|
64
72
|
desc "restore APP DUMP_FILE", "Restaure la base depuis un dump local"
|
|
@@ -6,13 +6,15 @@ require_relative "db_target"
|
|
|
6
6
|
module Captive
|
|
7
7
|
module Commands
|
|
8
8
|
class DbExec
|
|
9
|
-
def initialize(kubectl:, target: DbTarget.new(kubectl: kubectl))
|
|
9
|
+
def initialize(kubectl:, trail:, target: DbTarget.new(kubectl: kubectl))
|
|
10
10
|
@kubectl = kubectl
|
|
11
|
+
@trail = trail
|
|
11
12
|
@target = target
|
|
12
13
|
end
|
|
13
14
|
|
|
14
15
|
def run(app, file, single_transaction: true)
|
|
15
16
|
pod, user, password = @target.resolve(app)
|
|
17
|
+
@trail.db_file_executed(app, file, File.read(file))
|
|
16
18
|
ok = @kubectl.psql_file(app, pod, file,
|
|
17
19
|
user: user, password: password, single_transaction: single_transaction)
|
|
18
20
|
raise ExecError, "L'exécution de #{file} a échoué" if ok == false
|
|
@@ -6,13 +6,28 @@ require_relative "db_target"
|
|
|
6
6
|
module Captive
|
|
7
7
|
module Commands
|
|
8
8
|
class DbPsql
|
|
9
|
-
def initialize(kubectl:, target: DbTarget.new(kubectl: kubectl))
|
|
9
|
+
def initialize(kubectl:, trail:, target: DbTarget.new(kubectl: kubectl))
|
|
10
10
|
@kubectl = kubectl
|
|
11
|
+
@trail = trail
|
|
11
12
|
@target = target
|
|
12
13
|
end
|
|
13
14
|
|
|
14
|
-
def run(app)
|
|
15
|
+
def run(app, command: nil, read_only: false)
|
|
16
|
+
return interactive(app, read_only) unless command
|
|
17
|
+
|
|
18
|
+
pod, user, password = @target.resolve(app)
|
|
19
|
+
@trail.db_query_run(app, command, read_only: read_only)
|
|
20
|
+
ok = @kubectl.psql_command(app, pod, command, user: user, password: password, read_only: read_only)
|
|
21
|
+
raise ExecError, "La requête a échoué" if ok == false
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
def interactive(app, read_only)
|
|
27
|
+
raise ExecError, "--read-only s'utilise avec -c" if read_only
|
|
28
|
+
|
|
15
29
|
pod, user, password = @target.resolve(app)
|
|
30
|
+
@trail.db_psql_opened(app)
|
|
16
31
|
@kubectl.psql_interactive(app, pod, user: user, password: password)
|
|
17
32
|
end
|
|
18
33
|
end
|
|
@@ -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
|
|
@@ -30,11 +30,12 @@ module Captive
|
|
|
30
30
|
|
|
31
31
|
# Signale au dashboard un accès ouvert sur l'app. L'acteur n'est pas transmis : le
|
|
32
32
|
# dashboard le dérive du token, ce qui le rend infalsifiable côté client.
|
|
33
|
-
def record_activity(app, kind:, command: nil, session: nil)
|
|
33
|
+
def record_activity(app, kind:, command: nil, session: nil, read_only: nil)
|
|
34
34
|
uri = URI.parse("#{DASHBOARD_URL}/api/apps/#{URI.encode_uri_component(app)}/activity")
|
|
35
35
|
body = { kind: kind }
|
|
36
36
|
body[:command] = command if command
|
|
37
37
|
body[:session] = session if session
|
|
38
|
+
body[:read_only] = read_only unless read_only.nil?
|
|
38
39
|
|
|
39
40
|
post(uri, body)
|
|
40
41
|
end
|
data/lib/captive/kubectl.rb
CHANGED
|
@@ -168,6 +168,12 @@ module Captive
|
|
|
168
168
|
run_interactive("exec", "-n", namespace, "-it", pod, "--", *psql_argv(user, password))
|
|
169
169
|
end
|
|
170
170
|
|
|
171
|
+
# Sans -t : pas de TTY, pour qu'un agent puisse lancer la requête et lire le résultat.
|
|
172
|
+
def psql_command(namespace, pod, sql, user:, password:, read_only: false)
|
|
173
|
+
run_interactive("exec", "-n", namespace, pod, "--",
|
|
174
|
+
*psql_argv(user, password, [ "-v", "ON_ERROR_STOP=1", "-c", sql ], read_only: read_only))
|
|
175
|
+
end
|
|
176
|
+
|
|
171
177
|
def exec_with_file(namespace, pod, file, *cmd)
|
|
172
178
|
system("kubectl", *kubeconfig_args, "exec", "-n", namespace, "-i", pod, "--", *cmd, in: File.open(file))
|
|
173
179
|
end
|
|
@@ -257,8 +263,11 @@ module Captive
|
|
|
257
263
|
|
|
258
264
|
private
|
|
259
265
|
|
|
260
|
-
|
|
266
|
+
# shortcut: default_transaction_read_only se contourne par un SET, garde-fou contre
|
|
267
|
+
# l'erreur et non barrière ; un rôle Postgres lecture seule le jour où il en faut une.
|
|
268
|
+
def psql_argv(user, password, flags = [], read_only: false)
|
|
261
269
|
[ "env", "PGPASSWORD=#{password}",
|
|
270
|
+
*("PGOPTIONS=-c default_transaction_read_only=on" if read_only),
|
|
262
271
|
"psql", *flags, "-h", "localhost", "-U", user, "-d", "app", ]
|
|
263
272
|
end
|
|
264
273
|
|
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.9.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
|