Module: Portless::State
- Defined in:
- lib/portless/state.rb
Overview
The on-disk state directory (~/.rb-portless): the single source of coordination — routes, CA, and pid/port/marker files. No daemon IPC; the proxy watches routes.json and everything else is plain files. Mirrors portless's state-dir model.
Class Method Summary collapse
- .ca_cert ⇒ Object
- .ca_key ⇒ Object
- .ca_trusted_marker ⇒ Object
-
.dir ⇒ Object
Read the env at call time so an override (tests, or the PORTLESS_STATE_DIR we pass to the sudo'd daemon) is always respected.
- .ensure_dir! ⇒ Object
-
.fix_ownership(target = dir) ⇒ Object
When we wrote files while elevated (root), hand them back to the invoking user so the unprivileged CLI can still read/write routes.json.
- .host_certs_dir ⇒ Object
- .path(name) ⇒ Object
- .proxy_log ⇒ Object
- .proxy_pid_file ⇒ Object
- .proxy_port_file ⇒ Object
-
.routes_file ⇒ Object
File locations (1:1 with portless's state files).
- .routes_lock ⇒ Object
Class Method Details
.ca_cert ⇒ Object
30 |
# File 'lib/portless/state.rb', line 30 def ca_cert = path("ca.pem") |
.ca_key ⇒ Object
31 |
# File 'lib/portless/state.rb', line 31 def ca_key = path("ca-key.pem") |
.ca_trusted_marker ⇒ Object
32 |
# File 'lib/portless/state.rb', line 32 def ca_trusted_marker = path("ca.trusted") |
.dir ⇒ Object
Read the env at call time so an override (tests, or the PORTLESS_STATE_DIR we pass to the sudo'd daemon) is always respected.
15 |
# File 'lib/portless/state.rb', line 15 def dir = File.(ENV["PORTLESS_STATE_DIR"] || Constants::DEFAULT_STATE_DIR) |
.ensure_dir! ⇒ Object
19 20 21 22 |
# File 'lib/portless/state.rb', line 19 def ensure_dir! FileUtils.mkdir_p(dir, mode: 0o755) dir end |
.fix_ownership(target = dir) ⇒ Object
When we wrote files while elevated (root), hand them back to the invoking user so the unprivileged CLI can still read/write routes.json. Keyed on the SUDO_UID/SUDO_GID sudo exposes. No-op when not running as root.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/portless/state.rb', line 38 def fix_ownership(target = dir) return unless Process.respond_to?(:uid) && Process.uid.zero? uid = Integer(ENV["SUDO_UID"], exception: false) gid = Integer(ENV["SUDO_GID"], exception: false) return unless uid FileUtils.chown_R(uid, gid, target, force: true) rescue StandardError # Best-effort; never fail a command over ownership fix-ups. nil end |
.host_certs_dir ⇒ Object
33 |
# File 'lib/portless/state.rb', line 33 def host_certs_dir = path("host-certs") |
.path(name) ⇒ Object
17 |
# File 'lib/portless/state.rb', line 17 def path(name) = File.join(dir, name) |
.proxy_log ⇒ Object
29 |
# File 'lib/portless/state.rb', line 29 def proxy_log = path("proxy.log") |
.proxy_pid_file ⇒ Object
27 |
# File 'lib/portless/state.rb', line 27 def proxy_pid_file = path("proxy.pid") |
.proxy_port_file ⇒ Object
28 |
# File 'lib/portless/state.rb', line 28 def proxy_port_file = path("proxy.port") |
.routes_file ⇒ Object
File locations (1:1 with portless's state files).
25 |
# File 'lib/portless/state.rb', line 25 def routes_file = path("routes.json") |
.routes_lock ⇒ Object
26 |
# File 'lib/portless/state.rb', line 26 def routes_lock = path("routes.lock") |