captive-cli 1.11.0 → 1.12.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.rb +4 -0
- data/lib/captive/commands/addons_commands.rb +20 -2
- data/lib/captive/commands/database_option_change.rb +30 -0
- data/lib/captive/commands/vault_commands.rb +59 -0
- data/lib/captive/dashboard/addons_resource.rb +2 -3
- data/lib/captive/dashboard/database_option.rb +14 -0
- data/lib/captive/dashboard/vault_resource.rb +22 -0
- data/lib/captive/loader.rb +3 -1
- data/lib/captive/presenter/{pg_cron.rb → database_option.rb} +7 -6
- data/lib/captive/version.rb +1 -1
- metadata +6 -3
- data/lib/captive/commands/pg_cron_change.rb +0 -24
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3b199e8b6db6cba9030774543de150f46d4954acac5030f83624ac5c458fff8a
|
|
4
|
+
data.tar.gz: b3e10499cd8575b232953818cd33255cb690ee86b7a3d01d74b7410a0ba2e595
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bacf56a333aa58ecf7c5437d74dbe0505da9fa5dd6001e6310867a9687d2066561455fd434721f39697eb3e0bc34856c82c0f1a1c5c361118f1cb684c2a2ee8c
|
|
7
|
+
data.tar.gz: 4157193a980ffa0a3a0dd40228d19e41daf1ffb24126ef18282a2362d68390823404d9d185d6db0abc4328f56fa7278fe933bca652d3193b765800422cbdda31
|
data/lib/captive/cli.rb
CHANGED
|
@@ -5,6 +5,7 @@ require_relative "loader"
|
|
|
5
5
|
require_relative "cli/dependencies"
|
|
6
6
|
require_relative "commands/apps_commands"
|
|
7
7
|
require_relative "commands/env_commands"
|
|
8
|
+
require_relative "commands/vault_commands"
|
|
8
9
|
require_relative "commands/crons_commands"
|
|
9
10
|
require_relative "commands/domains_commands"
|
|
10
11
|
require_relative "commands/addons_commands"
|
|
@@ -74,6 +75,9 @@ module Captive
|
|
|
74
75
|
desc "supabase SUBCOMMAND", "Extension Supabase d'une app : Edge Functions"
|
|
75
76
|
subcommand "supabase", Commands::SupabaseCommands
|
|
76
77
|
|
|
78
|
+
desc "vault SUBCOMMAND", "Secrets Vault de la base d'une app"
|
|
79
|
+
subcommand "vault", Commands::VaultCommands
|
|
80
|
+
|
|
77
81
|
desc "auth SUBCOMMAND", "Jeton pour kubectl", hide: true
|
|
78
82
|
subcommand "auth", Commands::AuthCommands
|
|
79
83
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require_relative "supabase_auth_change"
|
|
4
4
|
require_relative "supabase_realtime_change"
|
|
5
|
-
require_relative "
|
|
5
|
+
require_relative "database_option_change"
|
|
6
6
|
|
|
7
7
|
module Captive
|
|
8
8
|
module Commands
|
|
@@ -97,12 +97,30 @@ module Captive
|
|
|
97
97
|
method_option :enabled, enum: %w[true false], desc: "Option pg_cron et pg_net"
|
|
98
98
|
map "pg-cron" => :pg_cron
|
|
99
99
|
def pg_cron(app)
|
|
100
|
-
puts
|
|
100
|
+
puts option_change(Dashboard::DatabaseOption::PG_CRON).run(app, options)
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
desc "vault APP", "Affiche ou modifie l'Option Vault de la base"
|
|
104
|
+
long_desc <<~DESC
|
|
105
|
+
Sans option : affiche si Supabase Vault est activé sur la base.
|
|
106
|
+
Avec --enabled : l'active ou le désactive. La base redémarre.
|
|
107
|
+
Exige PostgreSQL 18. Réservé aux admins de l'Organization.
|
|
108
|
+
Les secrets se gèrent ensuite avec captive vault.
|
|
109
|
+
|
|
110
|
+
\x05Exemples :
|
|
111
|
+
\x05 captive addons vault my-app-staging
|
|
112
|
+
\x05 captive addons vault my-app-staging --enabled=true
|
|
113
|
+
DESC
|
|
114
|
+
method_option :enabled, enum: %w[true false], desc: "Option Vault"
|
|
115
|
+
def vault(app)
|
|
116
|
+
puts option_change(Dashboard::DatabaseOption::VAULT).run(app, options)
|
|
101
117
|
end
|
|
102
118
|
|
|
103
119
|
private
|
|
104
120
|
|
|
105
121
|
def presenter = Presenter::Addon.new(paint: paint)
|
|
122
|
+
|
|
123
|
+
def option_change(option) = DatabaseOptionChange.new(addons: addons_api, paint: paint, option: option)
|
|
106
124
|
end
|
|
107
125
|
end
|
|
108
126
|
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Commands
|
|
5
|
+
# `addons pg-cron` et `addons vault` : sans réglage, les lignes qui décrivent l'option ; avec
|
|
6
|
+
# --enabled, l'état voulu envoyé au dashboard, que captive-platform applique plus tard en
|
|
7
|
+
# redémarrant la base (ADR 0041, 0046).
|
|
8
|
+
class DatabaseOptionChange
|
|
9
|
+
def initialize(addons:, paint:, option:)
|
|
10
|
+
@addons = addons
|
|
11
|
+
@paint = paint
|
|
12
|
+
@option = option
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# `options` : les options Thor de la commande, `enabled` ("true"/"false").
|
|
16
|
+
def run(app, options)
|
|
17
|
+
enabled = options["enabled"]
|
|
18
|
+
unless enabled
|
|
19
|
+
return Presenter::DatabaseOption.new(paint: @paint, option: @option)
|
|
20
|
+
.lines(@addons.database_option(app, @option), app: app)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
@addons.set_database_option(app, @option, enabled: enabled == "true")
|
|
24
|
+
[ @paint.green(" ✓ Option #{@option.label} en cours de modification, la base redémarre : " \
|
|
25
|
+
"#{CLIDependencies::ASYNC_NOTICE}"),
|
|
26
|
+
@paint.dim(" Suivre : captive addons #{@option.command} #{app}"), ]
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "io/console"
|
|
4
|
+
|
|
5
|
+
module Captive
|
|
6
|
+
module Commands
|
|
7
|
+
# `captive vault` : les Secrets Vault de la base (BRIO-287). La valeur se lit sur stdin, jamais
|
|
8
|
+
# en argument : elle finirait dans l'historique du shell et la liste des processus.
|
|
9
|
+
class VaultCommands < Thor
|
|
10
|
+
include CLIDependencies
|
|
11
|
+
|
|
12
|
+
def self.exit_on_failure? = true
|
|
13
|
+
|
|
14
|
+
desc "list APP", "Liste les Secrets Vault de la base, sans leur valeur"
|
|
15
|
+
long_desc <<~DESC
|
|
16
|
+
\x05Exemple :
|
|
17
|
+
\x05 captive vault list my-app-staging
|
|
18
|
+
DESC
|
|
19
|
+
def list(app)
|
|
20
|
+
vault_api.list(app).each do |secret|
|
|
21
|
+
puts [ secret["name"], paint.dim(secret["description"].to_s), paint.dim(secret["updated_at"].to_s) ]
|
|
22
|
+
.reject(&:empty?).join(" ")
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
desc "set APP NAME", "Crée un Secret Vault, ou remplace sa valeur (lue sur stdin)"
|
|
27
|
+
long_desc <<~DESC
|
|
28
|
+
La valeur est lue sur stdin, ou demandée sans écho dans un terminal.
|
|
29
|
+
|
|
30
|
+
\x05Exemple :
|
|
31
|
+
\x05 printf %s "$SECRET" | captive vault set my-app-staging perf_robot_secret
|
|
32
|
+
DESC
|
|
33
|
+
method_option :description, desc: "Description du secret ; absente, l'ancienne est gardée"
|
|
34
|
+
def set(app, name)
|
|
35
|
+
value = read_value
|
|
36
|
+
abort "La valeur est vide." if value.empty?
|
|
37
|
+
|
|
38
|
+
change = vault_api.set(app, name, value:, description: options[:description])
|
|
39
|
+
puts paint.green(" ✓ #{name} #{change == "created" ? "créé" : "remplacé"}")
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
desc "rm APP NAME", "Supprime un Secret Vault"
|
|
43
|
+
def rm(app, name)
|
|
44
|
+
vault_api.delete(app, name)
|
|
45
|
+
puts paint.green(" ✓ #{name} supprimé")
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
private
|
|
49
|
+
|
|
50
|
+
def vault_api = @vault_api ||= Dashboard::VaultResource.new(api: dashboard)
|
|
51
|
+
|
|
52
|
+
def read_value
|
|
53
|
+
return $stdin.read.to_s.chomp unless $stdin.tty?
|
|
54
|
+
|
|
55
|
+
IO.console.getpass("Valeur : ").to_s
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -8,7 +8,6 @@ module Captive
|
|
|
8
8
|
PATH = AppPath.new("addons")
|
|
9
9
|
SUPABASE_AUTH_PATH = AppPath.new("addons/supabase/auth")
|
|
10
10
|
SUPABASE_REALTIME_PATH = AppPath.new("addons/supabase/realtime")
|
|
11
|
-
PG_CRON_PATH = AppPath.new("addons/supabase/pg-cron")
|
|
12
11
|
|
|
13
12
|
def initialize(api:)
|
|
14
13
|
@api = api
|
|
@@ -30,8 +29,8 @@ module Captive
|
|
|
30
29
|
@api.put(SUPABASE_REALTIME_PATH.call(app), { enabled: enabled, postgres_changes: postgres_changes })
|
|
31
30
|
end
|
|
32
31
|
|
|
33
|
-
def
|
|
34
|
-
def
|
|
32
|
+
def database_option(app, option) = @api.get(option.path.call(app))
|
|
33
|
+
def set_database_option(app, option, enabled:) = @api.put(option.path.call(app), { enabled: enabled })
|
|
35
34
|
end
|
|
36
35
|
end
|
|
37
36
|
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Dashboard
|
|
5
|
+
# Une option de la base d'une app, réglage de l'add-on Supabase : pg_cron et pg_net (ADR 0041),
|
|
6
|
+
# Vault (ADR 0046). Activée, elle redémarre la base ; elle exige PostgreSQL 18.
|
|
7
|
+
DatabaseOption = Data.define(:command, :label) do
|
|
8
|
+
def path = AppPath.new("addons/supabase/#{command}")
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
DatabaseOption::PG_CRON = DatabaseOption.new(command: "pg-cron", label: "pg_cron et pg_net")
|
|
12
|
+
DatabaseOption::VAULT = DatabaseOption.new(command: "vault", label: "Vault")
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Captive
|
|
4
|
+
module Dashboard
|
|
5
|
+
# Les Secrets Vault de la base d'une app (BRIO-287), écrits tout de suite par le dashboard.
|
|
6
|
+
class VaultResource
|
|
7
|
+
PATH = AppPath.new("vault/secrets")
|
|
8
|
+
|
|
9
|
+
def initialize(api:)
|
|
10
|
+
@api = api
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def list(app) = @api.get(PATH.call(app))["secrets"]
|
|
14
|
+
|
|
15
|
+
def set(app, name, value:, description: nil)
|
|
16
|
+
@api.put(PATH.call(app, name), { value:, description: }.compact)["change"]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def delete(app, name) = @api.delete(PATH.call(app, name))
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
data/lib/captive/loader.rb
CHANGED
|
@@ -16,8 +16,10 @@ require_relative "dashboard_api"
|
|
|
16
16
|
require_relative "dashboard/app_path"
|
|
17
17
|
require_relative "dashboard/apps_resource"
|
|
18
18
|
require_relative "dashboard/env_vars_resource"
|
|
19
|
+
require_relative "dashboard/vault_resource"
|
|
19
20
|
require_relative "dashboard/scheduled_tasks_resource"
|
|
20
21
|
require_relative "dashboard/domains_resource"
|
|
22
|
+
require_relative "dashboard/database_option"
|
|
21
23
|
require_relative "dashboard/addons_resource"
|
|
22
24
|
require_relative "dashboard/functions_resource"
|
|
23
25
|
require_relative "presenter/app_info"
|
|
@@ -26,7 +28,7 @@ require_relative "presenter/domain"
|
|
|
26
28
|
require_relative "presenter/addon"
|
|
27
29
|
require_relative "presenter/supabase_auth"
|
|
28
30
|
require_relative "presenter/supabase_realtime"
|
|
29
|
-
require_relative "presenter/
|
|
31
|
+
require_relative "presenter/database_option"
|
|
30
32
|
require_relative "presenter/edge_function"
|
|
31
33
|
require_relative "activity_trail"
|
|
32
34
|
require_relative "errors"
|
|
@@ -2,17 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
module Captive
|
|
4
4
|
module Presenter
|
|
5
|
-
#
|
|
6
|
-
class
|
|
5
|
+
# Une option de la base (pg_cron, Vault), comme sur sa page du dashboard (ADR 0041, 0046).
|
|
6
|
+
class DatabaseOption
|
|
7
7
|
VALEURS = { true => "oui", false => "non" }.freeze
|
|
8
8
|
|
|
9
|
-
def initialize(paint:)
|
|
10
|
-
@paint
|
|
9
|
+
def initialize(paint:, option:)
|
|
10
|
+
@paint = paint
|
|
11
|
+
@option = option
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
def lines(settings, app:)
|
|
14
15
|
[
|
|
15
|
-
[ "
|
|
16
|
+
[ "#{@option.label} #{VALEURS.fetch(settings["enabled"], "inconnu")}", indisponible(settings) ].compact.join(" "),
|
|
16
17
|
(@paint.yellow("Changement en cours…") if settings["pending"]),
|
|
17
18
|
@paint.dim(modification(settings, app)),
|
|
18
19
|
].compact
|
|
@@ -23,7 +24,7 @@ module Captive
|
|
|
23
24
|
def modification(settings, app)
|
|
24
25
|
return "Modifiable par un admin de l'Organization" unless settings["can_edit"]
|
|
25
26
|
|
|
26
|
-
"Modifier : captive addons
|
|
27
|
+
"Modifier : captive addons #{@option.command} #{app} --enabled=true|false (redémarre la base)"
|
|
27
28
|
end
|
|
28
29
|
|
|
29
30
|
def indisponible(settings)
|
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.12.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Captive Studio
|
|
@@ -115,6 +115,7 @@ files:
|
|
|
115
115
|
- lib/captive/commands/console.rb
|
|
116
116
|
- lib/captive/commands/cron_declaration.rb
|
|
117
117
|
- lib/captive/commands/crons_commands.rb
|
|
118
|
+
- lib/captive/commands/database_option_change.rb
|
|
118
119
|
- lib/captive/commands/db_commands.rb
|
|
119
120
|
- lib/captive/commands/db_dump.rb
|
|
120
121
|
- lib/captive/commands/db_exec.rb
|
|
@@ -129,21 +130,23 @@ files:
|
|
|
129
130
|
- lib/captive/commands/functions_commands.rb
|
|
130
131
|
- lib/captive/commands/logs.rb
|
|
131
132
|
- lib/captive/commands/one_off_session.rb
|
|
132
|
-
- lib/captive/commands/pg_cron_change.rb
|
|
133
133
|
- lib/captive/commands/run.rb
|
|
134
134
|
- lib/captive/commands/supabase_auth_change.rb
|
|
135
135
|
- lib/captive/commands/supabase_commands.rb
|
|
136
136
|
- lib/captive/commands/supabase_realtime_change.rb
|
|
137
137
|
- lib/captive/commands/user_login.rb
|
|
138
|
+
- lib/captive/commands/vault_commands.rb
|
|
138
139
|
- lib/captive/credentials.rb
|
|
139
140
|
- lib/captive/credentials_store.rb
|
|
140
141
|
- lib/captive/dashboard/addons_resource.rb
|
|
141
142
|
- lib/captive/dashboard/app_path.rb
|
|
142
143
|
- lib/captive/dashboard/apps_resource.rb
|
|
144
|
+
- lib/captive/dashboard/database_option.rb
|
|
143
145
|
- lib/captive/dashboard/domains_resource.rb
|
|
144
146
|
- lib/captive/dashboard/env_vars_resource.rb
|
|
145
147
|
- lib/captive/dashboard/functions_resource.rb
|
|
146
148
|
- lib/captive/dashboard/scheduled_tasks_resource.rb
|
|
149
|
+
- lib/captive/dashboard/vault_resource.rb
|
|
147
150
|
- lib/captive/dashboard_api.rb
|
|
148
151
|
- lib/captive/dashboard_client.rb
|
|
149
152
|
- lib/captive/dashboard_response.rb
|
|
@@ -160,10 +163,10 @@ files:
|
|
|
160
163
|
- lib/captive/presenter/addon.rb
|
|
161
164
|
- lib/captive/presenter/ansi_stripper.rb
|
|
162
165
|
- lib/captive/presenter/app_info.rb
|
|
166
|
+
- lib/captive/presenter/database_option.rb
|
|
163
167
|
- lib/captive/presenter/domain.rb
|
|
164
168
|
- lib/captive/presenter/edge_function.rb
|
|
165
169
|
- lib/captive/presenter/log_colorizer.rb
|
|
166
|
-
- lib/captive/presenter/pg_cron.rb
|
|
167
170
|
- lib/captive/presenter/scheduled_task.rb
|
|
168
171
|
- lib/captive/presenter/supabase_auth.rb
|
|
169
172
|
- lib/captive/presenter/supabase_realtime.rb
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Captive
|
|
4
|
-
module Commands
|
|
5
|
-
# `addons pg-cron` : sans réglage, les lignes qui décrivent l'option ; avec --enabled, l'état
|
|
6
|
-
# voulu envoyé au dashboard, que captive-platform applique plus tard en redémarrant la base (ADR 0041).
|
|
7
|
-
class PgCronChange
|
|
8
|
-
def initialize(addons:, paint:)
|
|
9
|
-
@addons = addons
|
|
10
|
-
@paint = paint
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
# `options` : les options Thor de la commande, `enabled` ("true"/"false").
|
|
14
|
-
def run(app, options)
|
|
15
|
-
enabled = options["enabled"]
|
|
16
|
-
return Presenter::PgCron.new(paint: @paint).lines(@addons.pg_cron(app), app: app) unless enabled
|
|
17
|
-
|
|
18
|
-
@addons.set_pg_cron(app, enabled: enabled == "true")
|
|
19
|
-
[ @paint.green(" ✓ Option pg_cron en cours de modification, la base redémarre : #{CLIDependencies::ASYNC_NOTICE}"),
|
|
20
|
-
@paint.dim(" Suivre : captive addons pg-cron #{app}"), ]
|
|
21
|
-
end
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|