dalben-cli 0.1.0 → 0.2.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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/dalben_cli/main.rb +46 -7
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b49acbca6214da48adb5ab49ce8083089d6849ca24a5da113ce58d55f8d02fc9
4
- data.tar.gz: 011df112624218005c09657975bcd429ff1a6f27b71404eee936fd628dd599e6
3
+ metadata.gz: d966122a0c39dc90ba4bae7f30ae5d6888b464a003dc6b8c98e32faa99640b43
4
+ data.tar.gz: 448b3ddc7dace45e1e741130372ec0fbed72b9227deb2111096a6d5294ee497d
5
5
  SHA512:
6
- metadata.gz: ec3a89f0b4a35692e7f2bf6497c68806a95b93bd0535eaf06d63601375fe43254abf908225b4585df382debc235d00f14506ab57dd68ce887c64e467cde28750
7
- data.tar.gz: 704415149c85d063404ed9285d3472d59b89037c247933e8ab8f0fe11cdb561150c7766f5de6413f3e39c31d2669941ec405581876e8e40cf8ee30d2074f488c
6
+ metadata.gz: edfcb8dc6d4820cf2b39ec6a8a2b41952d24c7b8a5b3c2aa97d1aaf556316af00091da53b822e42a1158060a0dd4923293c2fb4405c324b2570a67fb92b49aa2
7
+ data.tar.gz: e070ab68e00014e7404151ba008918de93584318f4fd0f1f62649f0afd966b0ca6e045f6d9dc35d147aa03d5927365c9a56b4a6774a8dea758e6a1799ad201b3
@@ -99,14 +99,18 @@ module DalbenCli
99
99
 
100
100
  Dokku settings
101
101
  settings -a APP
102
- settings:set KEY=VALUE ... -a APP keys: ports, tls, checks, builder, buildpacks, deploy_branch,
102
+ settings:set KEY=VALUE ... -a APP keys: port, tls, checks, builder, buildpacks, deploy_branch,
103
103
  nginx.client-max-body-size, nginx.proxy-read-timeout,
104
104
  limits.TYPE.memory, limits.TYPE.cpu (lists comma-separated)
105
105
 
106
106
  Domains
107
107
  domains -a APP
108
- domains:add HOST -a APP [--no-tls]
108
+ domains:add HOST -a APP [--no-tls] --no-tls: no certificate, even with HTTPS on
109
109
  domains:remove HOST -a APP
110
+ ports -a APP what nginx forwards to the app, as of the last deploy
111
+ certs:auto -a APP whether HTTPS with Let's Encrypt is on
112
+ certs:auto:enable -a APP turn HTTPS on: certificates for every domain, renewed automatically
113
+ certs:auto:disable -a APP turn HTTPS off: the app answers on http only
110
114
  certs:retry -a APP ask Let's Encrypt again for domains still waiting
111
115
 
112
116
  Log drains (one per app; logs also stay on the server for 14 days)
@@ -162,6 +166,10 @@ module DalbenCli
162
166
  pg:upgrade:switch ADDON --confirm ADDON make a copy (upgrade, fork, restore) the app's DATABASE_URL;
163
167
  the old add-on stays as NAME_OLD_URL until you destroy it
164
168
 
169
+ MySQL access (developers; over SSH with your key, no public database port)
170
+ mysql:cli ADDON open the mysql client on the add-on, for at most four hours
171
+ mysql:tunnel ADDON [--port 3306] a local port for GUI tools for eight hours; prints the URL to connect to
172
+
165
173
  Imports (copy an app from Heroku; nothing changes on Heroku)
166
174
  import heroku HEROKU_APP --server SERVER --project PROJECT [-a NAME] [--token-stdin]
167
175
  create the app with its tier, add-ons, config vars, domains and
@@ -181,7 +189,7 @@ module DalbenCli
181
189
 
182
190
  def initialize(argv)
183
191
  @argv = argv.dup
184
- @opts = { wait: true, restart: true, tls: true }
192
+ @opts = { wait: true, restart: true }
185
193
  @config = Config.new
186
194
  end
187
195
 
@@ -782,10 +790,28 @@ module DalbenCli
782
790
  end
783
791
  end
784
792
 
785
- def cmd_domains_add = follow(api.post("apps/#{app!}/domains", hostname: arg!("HOST"), tls: @opts[:tls]))
793
+ # Without --[no-]tls the domain follows the app's HTTPS setting.
794
+ def cmd_domains_add = follow(api.post("apps/#{app!}/domains", { hostname: arg!("HOST"), tls: @opts[:tls] }.compact))
786
795
  def cmd_domains_remove = follow(api.delete("apps/#{app!}/domains/#{arg!('HOST')}"))
787
796
  def cmd_certs_retry = follow(api.post("apps/#{app!}/certificate"))
788
797
 
798
+ # Like Heroku's Automated Certificate Management: one switch per app.
799
+ def cmd_certs_auto
800
+ output(api.get("apps/#{app!}/settings").slice("tls")) do |settings|
801
+ puts settings["tls"] ? "HTTPS is on: Let's Encrypt certificates, renewed automatically. See domains for each one." : "HTTPS is off."
802
+ end
803
+ end
804
+
805
+ def cmd_certs_auto_enable = follow(api.patch("apps/#{app!}/settings", settings: { "tls" => true }))
806
+ def cmd_certs_auto_disable = follow(api.patch("apps/#{app!}/settings", settings: { "tls" => false }))
807
+
808
+ # The port map Dokku reported after the last deploy or port change.
809
+ def cmd_ports
810
+ output(api.get("apps/#{app!}").fetch("port_map")) do |map|
811
+ rows(map.map { %w[scheme port container_port].zip(_1.split(":")).to_h }, :scheme, :port, :container_port)
812
+ end
813
+ end
814
+
789
815
  # --- log drains -----------------------------------------------------
790
816
  def cmd_drains = output(api.get("apps/#{app!}/log_drains")) { rows(_1, :id, :kind, :url) }
791
817
  def cmd_drains_add = follow(api.post("apps/#{app!}/log_drains", url: arg!("URL")))
@@ -943,18 +969,31 @@ module DalbenCli
943
969
  exec_ssh("ssh", "-t", "-p", ssh["port"].to_s, "#{ssh['user']}@#{ssh['host']}", *ssh["command"].split)
944
970
  end
945
971
 
972
+ def cmd_pg_tunnel = db_tunnel("postgres", 5432)
973
+
974
+ # --- MySQL access ------------------------------------------------------
975
+ # The mysql client and tunnels work as for Postgres: the same tickets,
976
+ # over SSH with the user's own key.
977
+ def cmd_mysql_cli
978
+ ssh = api.post("addons/#{scoped(arg!('ADDON'))}/console").fetch("ssh")
979
+ raise Error, "unexpected mysql command from the manager" unless ssh["command"].to_s.match?(DB_CONNECT)
980
+ exec_ssh("ssh", "-t", "-p", ssh["port"].to_s, "#{ssh['user']}@#{ssh['host']}", *ssh["command"].split)
981
+ end
982
+
983
+ def cmd_mysql_tunnel = db_tunnel("mysql", 3306)
984
+
946
985
  # A local port for GUI tools. Dokku refuses SSH port forwarding for user
947
986
  # keys, so every connection to the port gets its own SSH session, which
948
987
  # the node joins to the database. Runs until Ctrl-C.
949
- def cmd_pg_tunnel
950
- port = @opts[:port] || 5432
988
+ def db_tunnel(scheme, default_port)
989
+ port = @opts[:port] || default_port
951
990
  grant = api.post("addons/#{scoped(arg!('ADDON'))}/tunnel")
952
991
  ssh = grant.fetch("ssh")
953
992
  raise Error, "unexpected tunnel command from the manager" unless ssh["command"].to_s.match?(DB_TUNNEL)
954
993
  server = listen(port)
955
994
  db = grant.fetch("connection")
956
995
  puts "Tunnel open until #{grant['expires_at']}. Connect to:",
957
- " postgres://#{db['user']}:#{db['password']}@127.0.0.1:#{port}/#{db['database']}",
996
+ " #{scheme}://#{db['user']}:#{db['password']}@127.0.0.1:#{port}/#{db['database']}",
958
997
  "Press Ctrl-C to close it."
959
998
  session = [ "ssh", "-T", "-p", ssh["port"].to_s, "#{ssh['user']}@#{ssh['host']}", *ssh["command"].split ]
960
999
  loop { relay(server.accept, session) }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dalben-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gerrit Heiko Schimpf