workspaces 0.1.17 → 0.1.19
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/DESIGN.md +23 -21
- data/README.md +103 -8
- data/lib/workspaces/child_env.rb +6 -2
- data/lib/workspaces/cli.rb +18 -4
- data/lib/workspaces/config.rb +4 -0
- data/lib/workspaces/coordinator.rb +28 -0
- data/lib/workspaces/dashboard/app.js +21 -5
- data/lib/workspaces/dashboard/card.html.erb +42 -0
- data/lib/workspaces/dashboard/environment.js +196 -54
- data/lib/workspaces/dashboard/styles.css +172 -85
- data/lib/workspaces/dashboard/template.html.erb +17 -5
- data/lib/workspaces/dashboard_view.rb +165 -27
- data/lib/workspaces/environment_overrides.rb +103 -4
- data/lib/workspaces/front_door.rb +130 -9
- data/lib/workspaces/presentation.rb +1 -1
- data/lib/workspaces/registry.rb +26 -0
- data/lib/workspaces/vault/file_vault.rb +174 -0
- data/lib/workspaces/vault.rb +137 -0
- data/lib/workspaces/version.rb +1 -1
- metadata +5 -2
|
@@ -5,14 +5,17 @@
|
|
|
5
5
|
const status = document.getElementById('environment-status');
|
|
6
6
|
const fieldset = form.querySelector('[data-environment-fieldset]');
|
|
7
7
|
const submit = form.querySelector('[data-env-submit]');
|
|
8
|
-
const
|
|
8
|
+
const rowsContainer = document.getElementById('env-rows');
|
|
9
|
+
const rowTemplate = document.getElementById('env-row-template');
|
|
10
|
+
const addButton = form.querySelector('[data-env-add-row]');
|
|
9
11
|
const presetButtons = Array.from(form.querySelectorAll('[data-environment-preset]'));
|
|
10
12
|
const presetGroup = form.querySelector('[data-preset-controls]');
|
|
11
|
-
const initialDraft = editor ? editor.value : '';
|
|
12
13
|
let lastAnnounced = '';
|
|
13
14
|
let activeBusy = document.getElementById('workspace').dataset.busy === 'true';
|
|
14
15
|
let presets = {};
|
|
15
16
|
let selectedPreset = null;
|
|
17
|
+
let nextIndex = 0;
|
|
18
|
+
let initialSignature = '';
|
|
16
19
|
|
|
17
20
|
try {
|
|
18
21
|
presets = JSON.parse(form.dataset.environmentPresets || '{}');
|
|
@@ -22,17 +25,60 @@
|
|
|
22
25
|
const hasPresets = Object.keys(presets).length > 0;
|
|
23
26
|
if (presetGroup && hasPresets) presetGroup.hidden = false;
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
28
|
+
// A preset is a list of { name, value }. A row's state is what the person typed. Secret rows are
|
|
29
|
+
// never part of any comparison, so a preset can match while secrets are present.
|
|
30
|
+
function rowElements() {
|
|
31
|
+
return rowsContainer ? Array.from(rowsContainer.querySelectorAll('[data-env-row]')) : [];
|
|
29
32
|
}
|
|
30
33
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
// The value input is missing on a stored secret until Replace is clicked, so it can be null.
|
|
35
|
+
function fieldsOf(row) {
|
|
36
|
+
return {
|
|
37
|
+
name: row.querySelector('.env-row__name'),
|
|
38
|
+
value: row.querySelector('[data-env-value]'),
|
|
39
|
+
secret: row.querySelector('[data-env-secret]'),
|
|
40
|
+
remove: row.querySelector('[data-env-remove-row]'),
|
|
41
|
+
stored: row.querySelector('[data-env-stored]'),
|
|
42
|
+
replace: row.querySelector('[data-env-replace]')
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const valueOf = (fields) => (fields.value ? fields.value.value || '' : '');
|
|
47
|
+
|
|
48
|
+
// Keeps password managers out of every input this script creates: autocomplete is ignored on
|
|
49
|
+
// password fields, so each manager's own opt-out goes with it.
|
|
50
|
+
function noAutofill(input) {
|
|
51
|
+
input.autocomplete = 'off';
|
|
52
|
+
input.setAttribute('autocomplete', 'off');
|
|
53
|
+
input.setAttribute('data-1p-ignore', '');
|
|
54
|
+
input.setAttribute('data-lpignore', 'true');
|
|
55
|
+
input.setAttribute('data-bwignore', '');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function visibleEntries() {
|
|
59
|
+
return rowElements()
|
|
60
|
+
.map((row) => {
|
|
61
|
+
const fields = fieldsOf(row);
|
|
62
|
+
return {
|
|
63
|
+
name: (fields.name.value || '').trim(),
|
|
64
|
+
value: valueOf(fields),
|
|
65
|
+
secret: !!(fields.secret && fields.secret.checked)
|
|
66
|
+
};
|
|
67
|
+
})
|
|
68
|
+
.filter((entry) => !entry.secret && (entry.name || entry.value));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function signatureOf(entries) {
|
|
72
|
+
return JSON.stringify(
|
|
73
|
+
entries
|
|
74
|
+
.map((entry) => [entry.name, entry.value])
|
|
75
|
+
.sort((a, b) => (a[0] < b[0] ? -1 : a[0] > b[0] ? 1 : 0))
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function matchingPresetName() {
|
|
80
|
+
const current = signatureOf(visibleEntries());
|
|
81
|
+
return Object.keys(presets).find((name) => signatureOf(presets[name]) === current) || null;
|
|
36
82
|
}
|
|
37
83
|
|
|
38
84
|
function updatePresetButtons(nextSelected) {
|
|
@@ -69,15 +115,13 @@
|
|
|
69
115
|
if (fieldset) fieldset.disabled = activeBusy;
|
|
70
116
|
if (submit) submit.disabled = activeBusy;
|
|
71
117
|
presetButtons.forEach((button) => {
|
|
72
|
-
button.disabled = activeBusy;
|
|
118
|
+
button.disabled = activeBusy || !hasPresets;
|
|
73
119
|
});
|
|
74
120
|
}
|
|
75
121
|
|
|
76
122
|
function updateStatus(busy) {
|
|
77
123
|
if (busy)
|
|
78
|
-
setStatus(
|
|
79
|
-
'Workspace is busy. Environment updates are temporarily disabled.'
|
|
80
|
-
);
|
|
124
|
+
setStatus('Workspace is busy. Environment updates are temporarily disabled.');
|
|
81
125
|
else if (status.textContent === 'Workspace is busy. Environment updates are temporarily disabled.') {
|
|
82
126
|
status.textContent = '';
|
|
83
127
|
lastAnnounced = '';
|
|
@@ -86,75 +130,173 @@
|
|
|
86
130
|
|
|
87
131
|
function announceUnsaved(message) {
|
|
88
132
|
if (activeBusy) return;
|
|
89
|
-
const nextMessage =
|
|
133
|
+
const nextMessage =
|
|
134
|
+
message || 'Draft updated locally and not saved yet. Use ' + submitLabel() + ' to apply changes.';
|
|
90
135
|
status.textContent = nextMessage;
|
|
91
136
|
lastAnnounced = nextMessage;
|
|
92
137
|
}
|
|
93
138
|
|
|
94
|
-
function replaceDraft(value, message) {
|
|
95
|
-
if (!editor) return;
|
|
96
|
-
editor.value = value || '';
|
|
97
|
-
updatePresetButtons(matchingPresetNameForDraft(editor.value));
|
|
98
|
-
announceUnsaved(message);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
139
|
function clearStatus() {
|
|
102
140
|
if (activeBusy) return;
|
|
103
141
|
status.textContent = '';
|
|
104
142
|
lastAnnounced = '';
|
|
105
143
|
}
|
|
106
144
|
|
|
145
|
+
// The checkbox of a secret that is already stored is disabled (and a hidden field carries it), so a
|
|
146
|
+
// saved secret cannot be turned back into a visible variable. Ticking Secret on a new row switches
|
|
147
|
+
// its value to a password field; the value is write-only from then on.
|
|
148
|
+
function syncRow(row) {
|
|
149
|
+
const fields = fieldsOf(row);
|
|
150
|
+
const secret = !!(fields.secret && fields.secret.checked);
|
|
151
|
+
if (secret) row.setAttribute('data-secret', 'true');
|
|
152
|
+
else row.removeAttribute('data-secret');
|
|
153
|
+
if (!fields.value) return;
|
|
154
|
+
fields.value.type = secret ? 'password' : 'text';
|
|
155
|
+
noAutofill(fields.value);
|
|
156
|
+
if (row.hasAttribute('data-stored')) fields.value.placeholder = 'New value (leave blank to keep)';
|
|
157
|
+
else fields.value.placeholder = secret ? 'Value' : 'value';
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Replace adds the value input to a stored secret. Until then the page has no password field for
|
|
161
|
+
// it at all.
|
|
162
|
+
function revealReplaceInput(row) {
|
|
163
|
+
const fields = fieldsOf(row);
|
|
164
|
+
if (fields.value || !fields.stored) return;
|
|
165
|
+
const input = document.createElement('input');
|
|
166
|
+
input.className = 'env-row__value';
|
|
167
|
+
input.name = (fields.name.name || '').replace(/\[name\]$/, '[value]');
|
|
168
|
+
input.type = 'password';
|
|
169
|
+
input.value = '';
|
|
170
|
+
input.placeholder = 'New value (leave blank to keep)';
|
|
171
|
+
input.setAttribute('aria-label', 'New value');
|
|
172
|
+
input.setAttribute('spellcheck', 'false');
|
|
173
|
+
input.setAttribute('autocapitalize', 'off');
|
|
174
|
+
input.setAttribute('data-env-value', '');
|
|
175
|
+
noAutofill(input);
|
|
176
|
+
fields.stored.parentNode.insertBefore(input, fields.stored);
|
|
177
|
+
fields.stored.parentNode.removeChild(fields.stored);
|
|
178
|
+
input.focus();
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
function bindRow(row) {
|
|
182
|
+
const fields = fieldsOf(row);
|
|
183
|
+
if (fields.remove) {
|
|
184
|
+
fields.remove.hidden = false;
|
|
185
|
+
fields.remove.addEventListener('click', () => {
|
|
186
|
+
if (activeBusy) return;
|
|
187
|
+
row.parentNode.removeChild(row);
|
|
188
|
+
draftChanged();
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
if (fields.replace) {
|
|
192
|
+
fields.replace.hidden = false;
|
|
193
|
+
fields.replace.addEventListener('click', () => {
|
|
194
|
+
if (activeBusy) return;
|
|
195
|
+
revealReplaceInput(row);
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
['input', 'change'].forEach((type) => {
|
|
199
|
+
row.addEventListener(type, (event) => {
|
|
200
|
+
if (event && event.target && event.target.matches && event.target.matches('[data-env-secret]'))
|
|
201
|
+
syncRow(row);
|
|
202
|
+
draftChanged();
|
|
203
|
+
});
|
|
204
|
+
});
|
|
205
|
+
syncRow(row);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function addRow(entry) {
|
|
209
|
+
if (!rowTemplate || !rowsContainer) return null;
|
|
210
|
+
const holder = document.createElement('div');
|
|
211
|
+
holder.innerHTML = rowTemplate.innerHTML.split('__INDEX__').join(String(nextIndex++));
|
|
212
|
+
const row = holder.querySelector('[data-env-row]');
|
|
213
|
+
if (!row) return null;
|
|
214
|
+
rowsContainer.append(row);
|
|
215
|
+
const fields = fieldsOf(row);
|
|
216
|
+
if (entry) {
|
|
217
|
+
fields.name.value = entry.name || '';
|
|
218
|
+
if (fields.value) fields.value.value = entry.value || '';
|
|
219
|
+
}
|
|
220
|
+
bindRow(row);
|
|
221
|
+
return row;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function draftChanged() {
|
|
225
|
+
updatePresetButtons(matchingPresetName());
|
|
226
|
+
const unchanged = rowElements().length === 0 ? false : currentSignature() === initialSignature;
|
|
227
|
+
if (unchanged) clearStatus();
|
|
228
|
+
else announceUnsaved();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
function currentSignature() {
|
|
232
|
+
return JSON.stringify(
|
|
233
|
+
rowElements().map((row) => {
|
|
234
|
+
const fields = fieldsOf(row);
|
|
235
|
+
const secret = !!(fields.secret && fields.secret.checked);
|
|
236
|
+
// A secret's value is kept out of the signature, but whether one has been typed is not: a
|
|
237
|
+
// pending replacement is an unsaved change.
|
|
238
|
+
return [fields.name.value, secret ? '' : valueOf(fields), secret, secret && valueOf(fields) !== ''];
|
|
239
|
+
})
|
|
240
|
+
);
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// Loading a preset replaces the visible variables only. Secrets are never touched by a preset.
|
|
244
|
+
function loadPreset(name) {
|
|
245
|
+
const entries = presets[name] || [];
|
|
246
|
+
rowElements().forEach((row) => {
|
|
247
|
+
const fields = fieldsOf(row);
|
|
248
|
+
const isSecret = !!(fields.secret && fields.secret.checked);
|
|
249
|
+
if (!isSecret) row.parentNode.removeChild(row);
|
|
250
|
+
});
|
|
251
|
+
entries.forEach((entry) => addRow(entry));
|
|
252
|
+
updatePresetButtons(name);
|
|
253
|
+
announceUnsaved('Preset loaded into draft only. Use ' + submitLabel() + ' to apply changes.');
|
|
254
|
+
}
|
|
255
|
+
|
|
107
256
|
form.addEventListener('submit', () => {
|
|
108
257
|
setStatus('Submitting environment settings…');
|
|
109
258
|
});
|
|
110
259
|
|
|
111
|
-
if (editor)
|
|
112
|
-
editor.addEventListener('input', () => {
|
|
113
|
-
if (editor.value === initialDraft) {
|
|
114
|
-
updatePresetButtons(matchingPresetNameForDraft(initialDraft));
|
|
115
|
-
clearStatus();
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
updatePresetButtons(matchingPresetNameForDraft(editor.value));
|
|
119
|
-
announceUnsaved();
|
|
120
|
-
});
|
|
121
|
-
|
|
122
260
|
presetButtons.forEach((button) => {
|
|
123
261
|
button.addEventListener('click', () => {
|
|
124
262
|
if (activeBusy) return;
|
|
125
263
|
const nextValue = button.dataset.environmentPreset;
|
|
126
264
|
if (!nextValue) return;
|
|
127
265
|
if (!Object.prototype.hasOwnProperty.call(presets, nextValue)) return;
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
266
|
+
loadPreset(nextValue);
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
if (addButton) {
|
|
271
|
+
addButton.hidden = false;
|
|
272
|
+
addButton.addEventListener('click', () => {
|
|
273
|
+
if (activeBusy) return;
|
|
274
|
+
const row = addRow(null);
|
|
275
|
+
if (row) fieldsOf(row).name.focus();
|
|
132
276
|
});
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// Rows the server rendered already carry numbered names; new rows continue after the highest.
|
|
280
|
+
rowElements().forEach((row) => {
|
|
281
|
+
const match = /env\[(\d+)\]/.exec(fieldsOf(row).name.name || '');
|
|
282
|
+
if (match) nextIndex = Math.max(nextIndex, Number(match[1]) + 1);
|
|
283
|
+
bindRow(row);
|
|
133
284
|
});
|
|
285
|
+
initialSignature = currentSignature();
|
|
134
286
|
|
|
135
287
|
window.WorkspaceEnvironment = {
|
|
136
288
|
toggleBusy,
|
|
137
289
|
updateStatus,
|
|
138
290
|
setStatus,
|
|
139
291
|
setSubmitLabel,
|
|
292
|
+
// The rows are server-rendered and the person may be editing them, so a poll never rewrites
|
|
293
|
+
// them; it only keeps the selected preset in step when nothing has been touched.
|
|
140
294
|
syncFromSnapshot(snapshot) {
|
|
141
|
-
if (!snapshot || presetButtons.length === 0
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const expected = Object.keys(rendered)
|
|
145
|
-
.sort()
|
|
146
|
-
.map((name) => name + '=' + rendered[name])
|
|
147
|
-
.join('\n');
|
|
148
|
-
if (editor === document.activeElement) return;
|
|
149
|
-
if (editor.value !== expected) return;
|
|
150
|
-
updatePresetButtons(matchingPresetNameForDraft(expected));
|
|
295
|
+
if (!snapshot || presetButtons.length === 0) return;
|
|
296
|
+
if (rowsContainer && rowsContainer.contains(document.activeElement)) return;
|
|
297
|
+
updatePresetButtons(matchingPresetName());
|
|
151
298
|
}
|
|
152
299
|
};
|
|
153
|
-
updatePresetButtons(
|
|
154
|
-
if (!hasPresets) {
|
|
155
|
-
presetButtons.forEach((button) => {
|
|
156
|
-
button.disabled = true;
|
|
157
|
-
});
|
|
158
|
-
}
|
|
300
|
+
updatePresetButtons(matchingPresetName());
|
|
159
301
|
toggleBusy(activeBusy);
|
|
160
302
|
})();
|