env_bro 0.1.2 → 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.
@@ -1,109 +1,97 @@
1
- <% content_for :title, "Review · #{@environment.name}" %>
1
+ <% env_bro_styles %>
2
2
  <% can_reveal = env_bro_can?(:reveal) %>
3
3
  <% meta = @differ.proposed_metadata %>
4
4
  <% changes = @differ.changes %>
5
5
  <% unchanged = @differ.entries.reject(&:changed?) %>
6
+ <% bro_hub_crumb @environment.name, "Review" %>
7
+ <% content_for :bro_hub_crumb_actions do %><%= bro_hub_crumb_link "Review another file", new_review_path %><% end %>
6
8
 
7
- <div class="page-head">
8
- <div>
9
- <h1>Proposed changes to <%= @environment.name %></h1>
10
- <p class="muted">Compared against the <%= @base_enc ? "uploaded base file" : "file deployed on this server" %>
11
- (<code><%= env_bro_short_digest(@base_digest) %></code>).</p>
12
- </div>
13
- <%= link_to "Review another file", new_review_path, class: "btn" %>
14
- </div>
9
+ <%= bro_hub_hero eyebrow: "#{@environment.name} · #{@environment.filename}", title: changes.size.to_s,
10
+ subtitle: "changed #{changes.size == 1 ? 'key' : 'keys'}", tone: (changes.any? ? :amber : :green),
11
+ lead: safe_join([ "Proposed changes to #{@environment.name}, compared against the #{@base_enc ? 'uploaded base file' : 'file deployed on this server'} (",
12
+ tag.code(env_bro_short_digest(@base_digest)), ")." ]),
13
+ stats: [ [ @differ.counts[:added] || 0, "added", :green ], [ @differ.counts[:changed] || 0, "changed", :amber ],
14
+ [ @differ.counts[:removed] || 0, "removed", :red ] ] %>
15
15
 
16
16
  <% case @base_status %>
17
17
  <% when :current %>
18
- <div class="alert alert-ok">Built on the same version it is compared against. The diff below is exactly what this PR changes.</div>
18
+ <div class="eb-banner is-ok">Built on the same version it is compared against. The diff below is exactly what this PR changes.</div>
19
19
  <% when :stale %>
20
- <div class="alert alert-warn">
20
+ <div class="eb-banner is-warn">
21
21
  <strong>Outdated base.</strong> This file was built on version <code><%= env_bro_short_digest(meta["base_digest"]) %></code>,
22
22
  not <code><%= env_bro_short_digest(@base_digest) %></code>. Changes made since then may be reverted by this PR. Look for unexpected removals or changes,
23
23
  and ask the author to rebuild the file if in doubt.
24
24
  </div>
25
25
  <% else %>
26
- <div class="alert alert-warn">
26
+ <div class="eb-banner is-warn">
27
27
  <strong>Not built with EnvBro.</strong> The file has no EnvBro metadata, so it may have been edited by hand or be an older copy of the file.
28
28
  Check every change below carefully.
29
29
  </div>
30
30
  <% end %>
31
31
 
32
- <div class="split">
33
- <div>
32
+ <div class="bh-split">
33
+ <div class="bh-split-main">
34
34
  <%= form_with url: reveal_review_path, method: :post, local: true, data: { turbo: false } do %>
35
35
  <%= hidden_field_tag :proposed_enc, @proposed_enc %>
36
36
  <%= hidden_field_tag :base_enc, @base_enc %>
37
37
 
38
- <div class="panel">
39
- <div class="toolbar">
40
- <h2>Changed keys</h2>
41
- <% if can_reveal && changes.any? %>
42
- <button type="submit" name="reveal_key" value="*" class="btn btn-small">Reveal all values</button>
43
- <% end %>
44
- </div>
38
+ <div class="bh-block-head">
39
+ <h2 class="bh-h2">Changed keys</h2>
40
+ <% if can_reveal && changes.any? %>
41
+ <button type="submit" name="reveal_key" value="*" class="eb-add">Reveal all values</button>
42
+ <% end %>
43
+ </div>
45
44
 
46
- <div class="summary">
47
- <% %i[added changed removed].each do |status| %>
48
- <span class="badge badge-<%= status %>"><%= @differ.counts[status] || 0 %> <%= status %></span>
49
- <% end %>
50
- <span class="badge badge-unchanged"><%= unchanged.size %> unchanged</span>
51
- </div>
45
+ <div class="eb-summary-tags">
46
+ <% %i[added changed removed].each do |status| %>
47
+ <%= content_tag :span, "#{@differ.counts[status] || 0} #{status}", class: "bh-tag #{EnvBro::ApplicationHelper::STATUS_TAGS[status.to_s]}" %>
48
+ <% end %>
49
+ <span class="bh-tag"><%= unchanged.size %> unchanged</span>
50
+ </div>
52
51
 
53
- <% if changes.empty? %>
54
- <p class="empty">No key or value differs from the base file.</p>
55
- <% else %>
56
- <table>
57
- <thead>
58
- <tr><th>Key</th><th>Status</th><th>Before</th><th>After</th><% if can_reveal %><th></th><% end %></tr>
59
- </thead>
60
- <tbody>
61
- <% changes.each do |entry| %>
62
- <% revealed = @revealed.include?(entry.key) %>
63
- <tr class="row-<%= entry.status %>">
64
- <td class="key"><%= entry.key %></td>
65
- <td class="nowrap"><%= env_bro_status_badge(entry.status) %></td>
66
- <td><%= revealed ? env_bro_value(entry.old_value) : env_bro_masked(entry.old_value) %></td>
67
- <td><%= revealed ? env_bro_value(entry.new_value) : env_bro_masked(entry.new_value) %></td>
68
- <% if can_reveal %>
69
- <td class="nowrap">
70
- <% unless revealed %>
71
- <button type="submit" name="reveal_key" value="<%= entry.key %>" class="btn-link">reveal</button>
72
- <% end %>
73
- </td>
52
+ <% if changes.empty? %>
53
+ <p class="bh-hint">No key or value differs from the base file.</p>
54
+ <% else %>
55
+ <div class="bh-table eb-cols-diff<%= ' no-reveal' unless can_reveal %>" style="--min: 0">
56
+ <div class="bh-row is-head"><span>Key</span><span>Status</span><span>Before</span><span>After</span><% if can_reveal %><span></span><% end %></div>
57
+ <% changes.each do |entry| %>
58
+ <% revealed = @revealed.include?(entry.key) %>
59
+ <div class="bh-row row-<%= entry.status %> <%= { 'added' => 'bh-edge-violet', 'changed' => 'bh-edge-amber', 'removed' => 'bh-edge-red' }[entry.status.to_s] %>">
60
+ <span class="bh-cell-strong" style="font-family:var(--bh-mono);font-weight:500;font-size:14px;overflow-wrap:anywhere"><%= entry.key %></span>
61
+ <span><%= env_bro_status_badge(entry.status) %></span>
62
+ <span><%= revealed ? env_bro_value(entry.old_value) : env_bro_masked(entry.old_value) %></span>
63
+ <span><%= revealed ? env_bro_value(entry.new_value) : env_bro_masked(entry.new_value) %></span>
64
+ <% if can_reveal %>
65
+ <span>
66
+ <% unless revealed %>
67
+ <button type="submit" name="reveal_key" value="<%= entry.key %>" class="btn-link">reveal</button>
74
68
  <% end %>
75
- </tr>
69
+ </span>
76
70
  <% end %>
77
- </tbody>
78
- </table>
79
- <% if can_reveal %>
80
- <p class="hint mt-12">Revealing values is recorded in the audit log.</p>
71
+ </div>
81
72
  <% end %>
73
+ </div>
74
+ <% if can_reveal %>
75
+ <p class="eb-note">Revealing values is recorded in the audit log.</p>
82
76
  <% end %>
83
- </div>
77
+ <% end %>
84
78
 
85
79
  <% if unchanged.any? %>
86
- <div class="panel">
87
- <details>
88
- <summary><%= unchanged.size %> unchanged keys</summary>
89
- <table class="mt-12">
90
- <tbody>
91
- <% unchanged.each do |entry| %>
92
- <tr class="row-unchanged"><td class="key"><%= entry.key %></td></tr>
93
- <% end %>
94
- </tbody>
95
- </table>
96
- </details>
97
- </div>
80
+ <details class="eb-details" style="margin-top:32px">
81
+ <summary><%= unchanged.size %> unchanged keys</summary>
82
+ <% unchanged.each do |entry| %>
83
+ <div class="eb-unchanged-key row-unchanged"><%= entry.key %></div>
84
+ <% end %>
85
+ </details>
98
86
  <% end %>
99
87
  <% end %>
100
88
  </div>
101
89
 
102
- <div>
103
- <div class="panel">
104
- <h2>Proposal</h2>
90
+ <div class="bh-split-aside">
91
+ <section class="bh-block">
92
+ <h2 class="bh-h2">Proposal</h2>
105
93
  <% if meta %>
106
- <dl class="meta">
94
+ <dl class="bh-dl">
107
95
  <dt>Author</dt><dd><%= meta["proposed_by"].presence || "unknown" %></dd>
108
96
  <dt>Built at</dt><dd><%= meta["proposed_at"] %></dd>
109
97
  <dt>Built on</dt><dd><code><%= env_bro_short_digest(meta["base_digest"]) %></code></dd>
@@ -112,23 +100,23 @@
112
100
  <% end %>
113
101
  </dl>
114
102
  <% if Array(meta["changes"]).any? %>
115
- <p class="muted small mt-12">Changes declared by the author:</p>
116
- <ul class="steps">
103
+ <p class="eb-note">Changes declared by the author:</p>
104
+ <ul class="eb-steps">
117
105
  <% Array(meta["changes"]).each do |c| %><li><code><%= c %></code></li><% end %>
118
106
  </ul>
119
107
  <% end %>
120
108
  <% else %>
121
- <p class="muted">No EnvBro metadata in this file.</p>
109
+ <p class="bh-hint">No EnvBro metadata in this file.</p>
122
110
  <% end %>
123
- </div>
111
+ </section>
124
112
 
125
- <div class="panel">
126
- <h2>Before merging</h2>
127
- <ol class="steps">
113
+ <section class="bh-block">
114
+ <h2 class="bh-h2">Before merging</h2>
115
+ <ol class="eb-steps">
128
116
  <li>Every changed key is expected and matches the PR description.</li>
129
117
  <li>No unexpected removals (a sign of an outdated or replaced file).</li>
130
118
  <li>The PR changes only <code><%= @environment.filename %></code>, nothing else.</li>
131
119
  </ol>
132
- </div>
120
+ </section>
133
121
  </div>
134
122
  </div>
@@ -0,0 +1,57 @@
1
+ <%# What EnvBro's pages need on top of BroHub's shared styles. %>
2
+ <style<%= %( nonce="#{content_security_policy_nonce}").html_safe if content_security_policy_nonce %>>
3
+ .bh-main code { font: 500 .92em var(--bh-mono); color: var(--bh-text); overflow-wrap: anywhere; }
4
+ .hidden { display: none !important; }
5
+ .eb-cols-envs { --cols: minmax(200px, 1fr) 80px 80px 190px 130px; --min: 700px; }
6
+ .eb-cols-diff { --cols: minmax(150px, 1.2fr) 100px minmax(110px, 1fr) minmax(110px, 1fr) 80px; --min: 640px; }
7
+ .eb-cols-diff.no-reveal { --cols: minmax(150px, 1.2fr) 100px minmax(110px, 1fr) minmax(110px, 1fr); }
8
+ .eb-cols-audit { --cols: 170px 130px 150px minmax(180px, 1fr) minmax(170px, 1fr); --min: 840px; }
9
+ .eb-env-name { font: 700 20px var(--bh-sans); font-stretch: 85%; color: var(--bh-text); }
10
+ .eb-env-name small { font: 400 13px var(--bh-mono); color: var(--bh-muted); }
11
+ a.bh-row.eb-env-row:hover { border-left-color: var(--bh-green); }
12
+ .eb-keys { margin-top: 0; }
13
+ .eb-banner { padding: 14px var(--bh-pad); border-bottom: 1px solid var(--bh-line); border-left: 4px solid var(--bh-muted); font: 500 13px/1.5 var(--bh-mono); text-wrap: pretty; }
14
+ .eb-banner[hidden] { display: none; }
15
+ .eb-banner.is-ok { border-left-color: var(--bh-green); background: rgba(46, 204, 122, .08); }
16
+ .eb-banner.is-warn { border-left-color: var(--bh-amber); background: rgba(245, 184, 74, .1); }
17
+ .eb-banner.is-error { border-left-color: var(--bh-red); background: rgba(240, 79, 84, .12); }
18
+ .eb-banner strong { color: var(--bh-text); }
19
+ .eb-steps { margin: 12px 0 0; padding-left: 20px; line-height: 1.7; }
20
+ .eb-note { margin: 12px 0 0; font: 400 12px var(--bh-mono); color: var(--bh-muted); text-wrap: pretty; }
21
+
22
+ /* Propose a change */
23
+ .newkey-row { display: flex; flex-wrap: wrap; gap: 10px 20px; align-items: center; margin-bottom: 10px; }
24
+ .newkey-row input, .newkey-row textarea { background: transparent; border: 0; border-bottom: 2px solid var(--bh-text); color: var(--bh-text); font: 500 14px var(--bh-mono); padding: 10px 0; outline: none; min-width: 0; resize: none; overflow: hidden; }
25
+ .newkey-row input { flex: 1 1 220px; }
26
+ .newkey-row textarea { flex: 2 1 280px; }
27
+ .newkey-row input:focus, .newkey-row textarea:focus { border-bottom-color: var(--bh-green); }
28
+ .icon-btn { background: none; border: 0; cursor: pointer; font: 600 16px var(--bh-mono); color: var(--bh-muted); padding: 6px 8px; }
29
+ .icon-btn:hover { color: var(--bh-red); }
30
+ .eb-add { cursor: pointer; padding: 6px 10px; font: 600 12px var(--bh-mono); border: 1px solid var(--bh-green); background: transparent; color: var(--bh-green); }
31
+ .eb-add:hover { background: var(--bh-green); color: var(--bh-bg); }
32
+ .yaml-line.yaml-group { padding: 16px 0 6px 14px; font: 600 14px var(--bh-mono); color: var(--bh-violet-l); }
33
+ .yaml-line.yaml-leaf { display: grid; grid-template-columns: minmax(150px, 1fr) minmax(160px, 1.5fr) auto; gap: 16px; align-items: center; padding: 8px 0 8px 10px; border-bottom: 1px solid var(--bh-line); border-left: 4px solid transparent; }
34
+ .yaml-line.is-changed { border-left-color: var(--bh-violet); background: rgba(124, 109, 250, .12); }
35
+ .yaml-line.is-removed { border-left-color: var(--bh-red); background: rgba(240, 79, 84, .12); }
36
+ .yaml-key { font: 500 15px var(--bh-mono); overflow-wrap: anywhere; }
37
+ .yaml-key.depth-1 { padding-left: 24px; } .yaml-key.depth-2 { padding-left: 48px; } .yaml-key.depth-3 { padding-left: 72px; }
38
+ .yaml-key.depth-4 { padding-left: 96px; } .yaml-key.depth-5 { padding-left: 120px; } .yaml-key.depth-6 { padding-left: 144px; }
39
+ .is-removed .yaml-key { color: var(--bh-red); text-decoration: line-through; }
40
+ .yaml-leaf textarea { min-width: 0; background: transparent; border: 0; border-bottom: 1px solid var(--bh-line-2); color: var(--bh-text); font: 500 14px var(--bh-mono); padding: 8px 0; outline: none; resize: none; overflow: hidden; }
41
+ .yaml-leaf textarea:focus { border-bottom-color: var(--bh-violet); }
42
+ .yaml-leaf textarea:disabled { color: var(--bh-muted); }
43
+ .remove-toggle { display: inline-flex; gap: 6px; align-items: center; cursor: pointer; padding: 6px 10px; font: 600 12px var(--bh-mono); border: 1px solid var(--bh-line-2); color: var(--bh-text); }
44
+ .remove-toggle input { accent-color: var(--bh-red); margin: 0; }
45
+ .is-removed .remove-toggle { border-color: var(--bh-red); background: var(--bh-red); color: var(--bh-bg); }
46
+ .eb-summary { font: 500 13px var(--bh-mono); color: var(--bh-muted); }
47
+ .eb-summary.has-changes { color: var(--bh-text); }
48
+
49
+ /* Review */
50
+ .mask { letter-spacing: .1em; }
51
+ .btn-link { background: none; border: 0; padding: 0; cursor: pointer; font: 600 12px var(--bh-mono); color: var(--bh-violet-l); text-decoration: underline; }
52
+ .eb-details summary { cursor: pointer; font: 600 13px var(--bh-mono); color: var(--bh-muted); }
53
+ .eb-details[open] summary { margin-bottom: 12px; }
54
+ .eb-file input[type="file"] { padding: 12px 0; font: 500 13px var(--bh-mono); color: var(--bh-text); border-bottom: 2px solid var(--bh-line-2); }
55
+ .eb-summary-tags { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 14px; }
56
+ .eb-unchanged-key { padding: 6px 0 6px 10px; border-bottom: 1px solid var(--bh-line); font: 500 13px var(--bh-mono); color: var(--bh-muted); }
57
+ </style>
@@ -17,9 +17,9 @@
17
17
  each("[data-leaf]", function (line) {
18
18
  var value = line.querySelector("textarea");
19
19
  var remove = line.querySelector("[data-remove-toggle]");
20
- var isRemoved = remove.checked;
21
- var isChanged = !isRemoved && value.value.trim() !== "";
22
- value.disabled = isRemoved;
20
+ var isRemoved = !!remove && remove.checked;
21
+ var isChanged = !isRemoved && !!value && value.value.trim() !== "";
22
+ if (value) value.disabled = isRemoved;
23
23
  line.classList.toggle("is-removed", isRemoved);
24
24
  line.classList.toggle("is-changed", isChanged);
25
25
  if (isRemoved) removed++;
@@ -97,7 +97,8 @@
97
97
  document.addEventListener("change", function (event) {
98
98
  if (!event.target.matches("[data-remove-toggle]")) return;
99
99
  refresh();
100
- if (!event.target.checked) event.target.closest("[data-leaf]").querySelector("textarea").focus();
100
+ var textarea = event.target.closest("[data-leaf]").querySelector("textarea");
101
+ if (!event.target.checked && textarea) textarea.focus();
101
102
  });
102
103
 
103
104
  // The proposal form answers with a file download, so the page itself does not change.
@@ -1,5 +1,3 @@
1
- <% content_for :title, "Not allowed" %>
2
- <div class="panel empty">
3
- <h1>Not allowed</h1>
4
- <p>You don't have permission to use this part of EnvBro. Ask an admin if you need access.</p>
5
- </div>
1
+ <% bro_hub_crumb "Not allowed" %>
2
+ <%= bro_hub_hero eyebrow: "Access", title: "Not allowed", tone: :red,
3
+ lead: "You don't have permission to use this part of EnvBro. Ask an admin if you need access." %>
@@ -1,13 +1,17 @@
1
- <% content_for :title, "Not available" %>
2
1
  <% status = @environment.status %>
3
- <div class="panel">
4
- <h1><%= @environment.name %> credentials <%= env_bro_environment_badge(status) %></h1>
5
- <% case status
6
- when :missing_file %>
7
- <p>There is no credentials file at <code><%= env_bro_display_path(@environment.content_path) %></code> on this server.</p>
8
- <% when :missing_key %>
9
- <p>This server has no key for <code><%= @environment.filename %></code>. Set <code><%= @environment.env_key %></code> or add <code><%= env_bro_display_path(@environment.key_path) %></code>.</p>
10
- <% else %>
11
- <p>The key on this server (<code><%= @environment.env_key %></code> or <code><%= env_bro_display_path(@environment.key_path) %></code>) cannot decrypt <code><%= @environment.filename %></code>.</p>
12
- <% end %>
13
- </div>
2
+ <% bro_hub_crumb @environment.name, "Not available" %>
3
+ <%= bro_hub_hero eyebrow: "#{@environment.name} credentials", title: "Not available", tone: :red,
4
+ lead: begin
5
+ case status
6
+ when :missing_file
7
+ safe_join([ "There is no credentials file at ", tag.code(env_bro_display_path(@environment.content_path)), " on this server." ])
8
+ when :missing_key
9
+ safe_join([ "This server has no key for ", tag.code(@environment.filename), ". Set ", tag.code(@environment.env_key),
10
+ " or add ", tag.code(env_bro_display_path(@environment.key_path)), "." ])
11
+ else
12
+ safe_join([ "The key on this server (", tag.code(@environment.env_key), " or ", tag.code(env_bro_display_path(@environment.key_path)),
13
+ ") cannot decrypt ", tag.code(@environment.filename), "." ])
14
+ end
15
+ end do %>
16
+ <p style="margin-top:16px"><%= env_bro_environment_badge(status) %></p>
17
+ <% end %>
@@ -4,17 +4,39 @@ module EnvBro
4
4
  # ApplicationController gives access to its authentication (current_user etc).
5
5
  attr_accessor :parent_controller
6
6
 
7
- # ->(controller) { ... } returning the signed in user, or nil.
7
+ # ->(controller) { ... } returning the signed in user, or nil. Defaults to BroHub.config.current_user.
8
8
  attr_accessor :current_user
9
9
 
10
10
  # ->(user) { ... } returning a short label for the audit log and file metadata.
11
11
  attr_accessor :user_label
12
12
 
13
13
  # Permission checks, each ->(user) { true/false }.
14
- # can_propose - see key names, build a new encrypted file with changes
14
+ # can_create - propose new keys
15
+ # can_update - propose new values for existing keys
16
+ # can_destroy - propose removing keys
15
17
  # can_review - upload a proposed file and see which keys changed (values masked)
16
18
  # can_reveal - reveal the actual values in a review diff (every reveal is audited)
17
- attr_accessor :can_propose, :can_review, :can_reveal
19
+ #
20
+ # Any of them gets a user into the propose page (which only offers what they may do).
21
+ # Higher permissions include the lower ones, so you don't have to repeat yourself:
22
+ # review includes create, update and destroy; reveal includes everything.
23
+ attr_accessor :can_create, :can_update, :can_destroy, :can_review, :can_reveal
24
+
25
+ PERMISSIONS = %i[create update destroy review reveal].freeze
26
+
27
+ # Permissions that also grant the key.
28
+ IMPLIED_BY = {
29
+ create: %i[review reveal],
30
+ update: %i[review reveal],
31
+ destroy: %i[review reveal],
32
+ review: %i[reveal],
33
+ reveal: []
34
+ }.freeze
35
+
36
+ # Shorthand: grant create, update and destroy with one check.
37
+ def can_propose=(check)
38
+ @can_create = @can_update = @can_destroy = check
39
+ end
18
40
 
19
41
  # Reject plain HTTP requests (secret values travel through the browser).
20
42
  attr_accessor :require_ssl
@@ -30,9 +52,12 @@ module EnvBro
30
52
 
31
53
  def initialize
32
54
  @parent_controller = "::ApplicationController"
33
- @current_user = ->(controller) { controller.respond_to?(:current_user, true) ? controller.send(:current_user) : nil }
55
+ # Configured once for all Bro gems in BroHub.config.current_user, unless EnvBro needs its own.
56
+ @current_user = ->(controller) { BroHub.config.current_user.call(controller) }
34
57
  @user_label = ->(user) { user.respond_to?(:email) ? user.email : user.to_s }
35
- @can_propose = ->(_user) { false }
58
+ @can_create = ->(_user) { false }
59
+ @can_update = ->(_user) { false }
60
+ @can_destroy = ->(_user) { false }
36
61
  @can_review = ->(_user) { false }
37
62
  @can_reveal = ->(_user) { false }
38
63
  @require_ssl = defined?(Rails) && Rails.env.production?
@@ -40,5 +65,15 @@ module EnvBro
40
65
  @max_upload_bytes = 1024 * 1024
41
66
  @track_deployments = true
42
67
  end
68
+
69
+ # Does the user hold this permission, directly or through a higher one?
70
+ # :propose means any of create, update or destroy.
71
+ def allows?(user, permission)
72
+ return false if user.nil?
73
+ return %i[create update destroy].any? { |p| allows?(user, p) } if permission == :propose
74
+ raise ArgumentError, "Unknown permission #{permission.inspect}" unless PERMISSIONS.include?(permission)
75
+
76
+ [ permission, *IMPLIED_BY.fetch(permission) ].any? { |p| !!public_send(:"can_#{p}").call(user) }
77
+ end
43
78
  end
44
79
  end
@@ -1,4 +1,12 @@
1
1
  module EnvBro
2
+ # Items in the BroHub sidebar. Paths are relative to the engine.
3
+ BRO_HUB_ITEMS = [
4
+ { label: "Environments", path: "/" },
5
+ { label: "Propose a change", path: "/proposal/new" },
6
+ { label: "Review", path: "/review/new", match: %r{\A/review} },
7
+ { label: "Audit log", path: "/audit" }
8
+ ].freeze
9
+
2
10
  class Engine < ::Rails::Engine
3
11
  isolate_namespace EnvBro
4
12
 
@@ -13,3 +21,9 @@ module EnvBro
13
21
  end
14
22
  end
15
23
  end
24
+
25
+ # Registered when the gem loads, so it is in place before routes are drawn and BroHub can mount the engine.
26
+ # Showing a section is navigation only: every EnvBro controller still authorizes each request.
27
+ BroHub.register :env_bro, name: "EnvBro", label: "EnvBro · config", accent: :green,
28
+ engine: "EnvBro::Engine", order: 20, items: EnvBro::BRO_HUB_ITEMS,
29
+ visible_to: ->(user) { EnvBro.config.allows?(user, :propose) || EnvBro.config.allows?(user, :review) }
@@ -1,3 +1,3 @@
1
1
  module EnvBro
2
- VERSION = "0.1.2"
2
+ VERSION = "0.2.0"
3
3
  end
data/lib/env_bro.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "bro_hub"
1
2
  require "env_bro/version"
2
3
  require "env_bro/configuration"
3
4
  require "env_bro/environment"
@@ -1,31 +1,21 @@
1
1
  require "rails/generators"
2
+ require "generators/bro_hub/installable"
2
3
 
3
4
  module EnvBro
4
5
  module Generators
5
6
  # bin/rails generate env_bro:install
6
7
  class InstallGenerator < Rails::Generators::Base
7
- source_root File.expand_path("templates", __dir__)
8
-
9
- desc "Adds the EnvBro initializer, mounts the engine and copies its migrations."
8
+ # BroHub first (one mount for all the Bro gems), then EnvBro itself.
9
+ include BroHub::Generators::Installable
10
10
 
11
- DEFAULT_MOUNT_PATH = "/admin/env"
11
+ source_root File.expand_path("templates", __dir__)
12
12
 
13
- class_option :mount_path, type: :string,
14
- desc: "Where to mount EnvBro (asked interactively when omitted, default #{DEFAULT_MOUNT_PATH})"
13
+ desc "Sets up the BroHub dashboard, adds the EnvBro initializer and copies EnvBro's migrations."
15
14
 
16
15
  def copy_initializer
17
16
  copy_file "env_bro.rb", "config/initializers/env_bro.rb"
18
17
  end
19
18
 
20
- def mount_engine
21
- routes = File.join(destination_root, "config/routes.rb")
22
- if File.exist?(routes) && File.read(routes).include?("EnvBro::Engine")
23
- say_status :skip, "EnvBro::Engine is already mounted", :yellow
24
- else
25
- route %(mount EnvBro::Engine => "#{mount_path}")
26
- end
27
- end
28
-
29
19
  def copy_migrations
30
20
  rails_command "env_bro:install:migrations", inline: true
31
21
  end
@@ -36,20 +26,11 @@ module EnvBro
36
26
  EnvBro is installed. Next:
37
27
  1. bin/rails db:migrate
38
28
  2. Set who may propose, review and reveal in config/initializers/env_bro.rb
39
- 3. Visit #{mount_path}
29
+ 3. Visit #{bro_hub_path}/env_bro (BroHub mounts EnvBro under its own path)
30
+ 4. Upgrading from EnvBro 0.1.x? Run `bin/rails g bro_hub:install --remove-direct-mounts`, or remove the old
31
+ `mount EnvBro::Engine` line from config/routes.rb yourself. It keeps working until you do.
40
32
  TEXT
41
33
  end
42
-
43
- private
44
- # --mount-path wins; otherwise ask when someone is at the terminal.
45
- def mount_path
46
- @mount_path ||= begin
47
- path = options[:mount_path].presence
48
- path ||= ask("Where should EnvBro be mounted?", default: DEFAULT_MOUNT_PATH) if $stdin.tty?
49
- path = path.to_s.strip.presence || DEFAULT_MOUNT_PATH
50
- "/" + path.delete_prefix("/").delete_suffix("/")
51
- end
52
- end
53
34
  end
54
35
  end
55
36
  end
@@ -3,9 +3,13 @@
3
3
  EnvBro.configure do |config|
4
4
  # Who may do what. Each lambda gets the signed in user (nil when signed out).
5
5
  # Everything is denied until you change these.
6
- config.can_propose = ->(user) { false } # e.g. user&.developer?
7
- config.can_review = ->(user) { false } # e.g. user&.admin?
8
- config.can_reveal = ->(user) { false } # see actual values in a review (audited)
6
+ config.can_create = ->(user) { false } # propose new keys, e.g. user&.developer?
7
+ config.can_update = ->(user) { false } # propose new values for existing keys
8
+ config.can_destroy = ->(user) { false } # propose removing keys
9
+ config.can_review = ->(user) { false } # upload a proposal and see what changed, e.g. user&.lead?
10
+ config.can_reveal = ->(user) { false } # see actual values in a review (audited), e.g. user&.admin?
11
+ # Higher includes lower: review includes create/update/destroy, reveal includes everything.
12
+ # config.can_propose = ->(user) { ... } sets create, update and destroy in one go.
9
13
 
10
14
  # How EnvBro finds the signed in user. Engine controllers inherit from
11
15
  # parent_controller, so its authentication (before_actions) applies too.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env_bro
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruby Dev SRL
@@ -23,6 +23,20 @@ dependencies:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
25
  version: '7.1'
26
+ - !ruby/object:Gem::Dependency
27
+ name: bro_hub
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0.1'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0.1'
26
40
  description: 'A mountable Rails engine: team members with permission build a re-encrypted
27
41
  credentials file with their changes and open a PR; reviewers upload the file and
28
42
  see a masked diff.'
@@ -44,15 +58,15 @@ files:
44
58
  - app/models/env_bro/application_record.rb
45
59
  - app/models/env_bro/audit_event.rb
46
60
  - app/views/env_bro/audit/index.html.erb
61
+ - app/views/env_bro/home/index.html.erb
47
62
  - app/views/env_bro/proposals/_new_key_row.html.erb
48
63
  - app/views/env_bro/proposals/new.html.erb
49
64
  - app/views/env_bro/reviews/new.html.erb
50
65
  - app/views/env_bro/reviews/show.html.erb
66
+ - app/views/env_bro/shared/_page_styles.html.erb
51
67
  - app/views/env_bro/shared/_script.html.erb
52
- - app/views/env_bro/shared/_styles.html.erb
53
68
  - app/views/env_bro/shared/forbidden.html.erb
54
69
  - app/views/env_bro/shared/not_ready.html.erb
55
- - app/views/layouts/env_bro/application.html.erb
56
70
  - config/routes.rb
57
71
  - db/migrate/20261029000000_create_env_bro_audit_events.rb
58
72
  - lib/env_bro.rb