Unverified Commit f1b62f55 authored by Phil Renaud's avatar Phil Renaud Committed by GitHub
Browse files

Merge pull request #14383 from hashicorp/variables-rename-ui

[ui] Variables Rename
parents 17cc73d6 70bfcbb3
Showing with 50 additions and 52 deletions
+50 -52
......@@ -48,7 +48,7 @@ export default class Variable extends AbstractAbility {
@computed('token.selfTokenPolicies')
get policiesSupportVariableList() {
return this.policyNamespacesIncludeSecureVariablesCapabilities(
return this.policyNamespacesIncludeVariablesCapabilities(
this.token.selfTokenPolicies,
['list', 'read', 'write', 'destroy']
);
......@@ -65,7 +65,7 @@ export default class Variable extends AbstractAbility {
/**
*
* Map to your policy's namespaces,
* and each of their SecureVariables blocks' paths,
* and each of their Variables blocks' paths,
* and each of their capabilities.
* Then, check to see if any of the permissions you're looking for
* are contained within at least one of them.
......@@ -74,36 +74,36 @@ export default class Variable extends AbstractAbility {
* @param {string[]} capabilities
* @returns {boolean}
*/
policyNamespacesIncludeSecureVariablesCapabilities(
policyNamespacesIncludeVariablesCapabilities(
policies = [],
capabilities = [],
path
) {
const namespacesWithSecureVariableCapabilities = policies
const namespacesWithVariableCapabilities = policies
.toArray()
.filter((policy) => get(policy, 'rulesJSON.Namespaces'))
.map((policy) => get(policy, 'rulesJSON.Namespaces'))
.flat()
.map((namespace = {}) => {
return namespace.SecureVariables?.Paths;
return namespace.Variables?.Paths;
})
.flat()
.compact()
.filter((secVarsBlock = {}) => {
.filter((varsBlock = {}) => {
if (!path || path === WILDCARD_GLOB) {
return true;
} else {
return secVarsBlock.PathSpec === path;
return varsBlock.PathSpec === path;
}
})
.map((secVarsBlock = {}) => {
return secVarsBlock.Capabilities;
.map((varsBlock = {}) => {
return varsBlock.Capabilities;
})
.flat()
.compact();
// Check for requested permissions
return namespacesWithSecureVariableCapabilities.some((abilityList) => {
return namespacesWithVariableCapabilities.some((abilityList) => {
return capabilities.includes(abilityList);
});
}
......@@ -113,7 +113,7 @@ export default class Variable extends AbstractAbility {
if (this.namespace === WILDCARD_GLOB && this.path === WILDCARD_GLOB) {
// If you're checking if you can write from root, and you don't specify a namespace,
// Then if you can write in ANY path in ANY namespace, you can get to /new.
return this.policyNamespacesIncludeSecureVariablesCapabilities(
return this.policyNamespacesIncludeVariablesCapabilities(
this.token.selfTokenPolicies,
['write'],
this._nearestMatchingPath(this.path)
......@@ -150,7 +150,7 @@ export default class Variable extends AbstractAbility {
const variables = (namespaces || []).find(
(namespace) => namespace.Name === matchingNamespace
)?.SecureVariables;
)?.Variables;
const pathNames = variables?.Paths?.map((path) => ({
name: path.PathSpec,
......
{{did-update this.onViewChange @view}}
{{did-insert this.establishKeyValues}}
<form class="new-secure-variables" autocomplete="off" {{on "submit" this.save}}>
<form class="new-variables" autocomplete="off" {{on "submit" this.save}}>
{{#if @model.isNew}}
<div class="related-entities related-entities-hint">
<p>Prefix your path with <code>nomad/jobs/</code> to automatically make your secure variable accessible to a specified job, task group, or task.<br />
<p>Prefix your path with <code>nomad/jobs/</code> to automatically make your variable accessible to a specified job, task group, or task.<br />
Format: <code>nomad/jobs/&lt;jobname&gt;</code>, <code>nomad/jobs/&lt;jobname&gt;/&lt;groupname&gt;</code>, <code>nomad/jobs/&lt;jobname&gt;/&lt;groupname&gt;/&lt;taskname&gt;</code></p>
</div>
{{/if}}
{{#if this.hasConflict}}
<div class="notification conflict is-danger">
<h3 class="title is-4">Heads up! Your Secure Variable has a conflict.</h3>
<h3 class="title is-4">Heads up! Your variable has a conflict.</h3>
<p>This might be because someone else tried saving in the time since you've had it open.</p>
{{#if this.conflictingVariable.modifyTime}}
<span class="tooltip" aria-label="{{format-ts this.conflictingVariable.modifyTime}}">
......@@ -46,7 +46,7 @@
/>
{{#if this.duplicatePathWarning}}
<p class="duplicate-path-error help is-danger">
There is already a Secure Variable located at
There is already a variable located at
{{this.path}}
.
<br />
......@@ -55,13 +55,13 @@
@route="variables.variable.edit"
@model={{this.duplicatePathWarning.path}}
>
edit the existing Secure Variable
edit the existing variable
</LinkTo>
.
</p>
{{/if}}
</label>
<SecureVariableForm::NamespaceFilter
<VariableForm::NamespaceFilter
@data={{hash
disabled=(not @model.isNew)
selection=this.variableNamespace
......@@ -108,7 +108,7 @@
{{on "input" (fn this.validateKey entry)}}
/>
</label>
<SecureVariableForm::InputGroup @entry={{entry}} />
<VariableForm::InputGroup @entry={{entry}} />
{{#if (eq entry this.keyValues.lastObject)}}
<button
class="add-more button is-info is-inverted"
......@@ -137,7 +137,7 @@
{{/if}}
{{#if (and this.shouldShowLinkedEntities @model.isNew)}}
<SecureVariableForm::RelatedEntities
<VariableForm::RelatedEntities
@new={{true}}
@job={{@model.pathLinkedEntities.job}}
@group={{@model.pathLinkedEntities.group}}
......
......@@ -19,7 +19,7 @@ const EMPTY_KV = {
warnings: EmberObject.create(),
};
export default class SecureVariableFormComponent extends Component {
export default class VariableFormComponent extends Component {
@service flashMessages;
@service router;
@service store;
......@@ -200,7 +200,7 @@ export default class SecureVariableFormComponent extends Component {
await this.args.model.save({ adapterOptions: { overwrite } });
this.flashMessages.add({
title: 'Secure Variable saved',
title: 'Variable saved',
message: `${this.path} successfully saved`,
type: 'success',
destroyOnClick: false,
......@@ -302,15 +302,13 @@ export default class SecureVariableFormComponent extends Component {
throw new Error('Invalid JSON');
}
// "myString" is valid JSON, but it's not a valid Secure Variable.
// Ditto for an array of objects. We expect a single object to be a Secure Variable.
// "myString" is valid JSON, but it's not a valid Variable.
// Ditto for an array of objects. We expect a single object to be a Variable.
const hasFormatErrors =
JSON.parse(value) instanceof Array ||
typeof JSON.parse(value) !== 'object';
if (hasFormatErrors) {
throw new Error(
'A Secure Variable must be formatted as a single JSON object'
);
throw new Error('A Variable must be formatted as a single JSON object');
}
set(this, 'JSONError', null);
......
<p class="related-entities notification">
<FlightIcon @name="info-fill" @color="var(--blue)" />
<span>
This secure variable {{#if @new}}will be{{else}}is{{/if}} accessible by
This variable {{#if @new}}will be{{else}}is{{/if}} accessible by
{{#if @task}}
task <strong>{{@task}}</strong> in group <LinkTo @route="jobs.job.task-group" @models={{array (concat @job "@" @namespace) @group}}>{{@group}} <FlightIcon @name="external-link" /></LinkTo>
{{else if @group}}
......
......@@ -40,7 +40,7 @@ export default class VariablesVariableIndexController extends Controller {
this.router.transitionTo('variables');
}
this.flashMessages.add({
title: 'Secure Variable deleted',
title: 'Variable deleted',
message: `${this.model.path} successfully deleted`,
type: 'success',
destroyOnClick: false,
......
......@@ -15,12 +15,12 @@ import { attr } from '@ember-data/model';
*/
/**
* @typedef SecureVariable
* @typedef Variable
* @type {object}
*/
/**
* A Secure Variable has a path, namespace, and an array of key-value pairs within the client.
* A Variable has a path, namespace, and an array of key-value pairs within the client.
* On the server, these key-value pairs are serialized into object structure.
* @class
* @extends Model
......
......@@ -46,5 +46,5 @@
@import './components/tooltip';
@import './components/two-step-button';
@import './components/evaluations';
@import './components/secure-variables';
@import './components/variables';
@import './components/keyboard-shortcuts-modal';
......@@ -21,7 +21,7 @@
}
}
.new-secure-variables {
.new-variables {
& > div {
margin-bottom: 1rem;
}
......
<Breadcrumb @crumb={{hash label="Secure Variables" args=(array "variables.index")}} />
<Breadcrumb @crumb={{hash label="Variables" args=(array "variables.index")}} />
<PageLayout>
{{outlet}}
</PageLayout>
\ No newline at end of file
{{page-title "Secure Variables"}}
{{page-title "Variables"}}
<section class="section">
<div class="toolbar">
<div class="toolbar-item is-right-aligned is-mobile-full-width">
......@@ -18,7 +18,7 @@
class="button is-primary"
data-test-create-var
>
Create Secure Variable
Create Variable
</LinkTo>
{{else}}
<button
......@@ -28,7 +28,7 @@
type="button"
data-test-disabled-create-var
>
Create Secure Variable
Create Variable
</button>
{{/if}}
......@@ -46,11 +46,11 @@
<div class="empty-message">
{{#if (eq this.namespaceSelection "*")}}
<h3 data-test-empty-variables-list-headline class="empty-message-headline">
No Secure Variables
No Variables
</h3>
{{#if (can "write variable" path="*" namespace=this.namespaceSelection)}}
<p class="empty-message-body">
Get started by <LinkTo @route="variables.new">creating a new secure variable</LinkTo>
Get started by <LinkTo @route="variables.new">creating a new variable</LinkTo>
</p>
{{/if}}
{{else}}
......
{{page-title "New Secure Variable"}}
{{page-title "New Variable"}}
<Breadcrumb @crumb={{hash label="New" args=(array "variables.new")}} />
<section class="section">
<h1 class="title variable-title">
Create a Secure Variable
Create a Variable
<Toggle
data-test-memory-toggle
@isActive={{eq this.view "json"}}
......@@ -12,7 +12,7 @@
>JSON</Toggle>
</h1>
<SecureVariableForm
<VariableForm
@model={{this.model}}
@path={{this.path}}
@existingVariables={{this.existingVariables}}
......
{{page-title "Secure Variables: " this.absolutePath}}
{{page-title "Variables: " this.absolutePath}}
{{#each this.breadcrumbs as |crumb|}}
<Breadcrumb @crumb={{crumb}} />
{{/each}}
......@@ -21,7 +21,7 @@
@query={{hash path=(concat this.absolutePath "/")}}
class="button is-primary"
>
Create Secure Variable
Create Variable
</LinkTo>
{{else}}
<button
......@@ -30,7 +30,7 @@
disabled
type="button"
>
Create Secure Variable
Create Variable
</button>
{{/if}}
</div>
......@@ -50,7 +50,7 @@
Path /{{this.absolutePath}} contains no variables
</h3>
<p class="empty-message-body">
To get started, <LinkTo @route="variables.new" @query={{hash path=(concat this.absolutePath "/")}}>create a new secure variable here</LinkTo>, or <LinkTo @route="variables">go back to the Secure Variables root directory</LinkTo>.
To get started, <LinkTo @route="variables.new" @query={{hash path=(concat this.absolutePath "/")}}>create a new variable here</LinkTo>, or <LinkTo @route="variables">go back to the Variables root directory</LinkTo>.
</p>
{{else}}
<h3 data-test-no-matching-variables-list-headline class="empty-message-headline">
......
{{page-title "Secure Variables: " this.model.path}}
{{page-title "Variables: " this.model.path}}
{{#each this.breadcrumbs as |crumb|}}
<Breadcrumb @crumb={{crumb}} />
{{/each}}
......
{{page-title "Edit Secure Variable"}}
{{page-title "Edit Variable"}}
<h1 class="title variable-title">
<LinkTo class="back-link" @route="variables.variable.index">
......@@ -19,7 +19,7 @@
</h1>
<SecureVariableForm
<VariableForm
@model={{this.model}}
@existingVariables={{this.existingVariables}}
@view={{this.view}}
......
......@@ -49,7 +49,7 @@
</h1>
{{#if this.shouldShowLinkedEntities}}
<SecureVariableForm::RelatedEntities
<VariableForm::RelatedEntities
@job={{this.model.pathLinkedEntities.job}}
@group={{this.model.pathLinkedEntities.group}}
@task={{this.model.pathLinkedEntities.task}}
......
......@@ -10,9 +10,9 @@ import { trimPath } from '../helpers/trim-path';
/**
* @typedef {Object} VariableFile
* @property {string} path - the folder path containing our "file", relative to parent
* @property {string} name - the secure variable "file" name
* @property {string} name - the variable "file" name
* @property {string} absoluteFilePath - the folder path containing our "file", absolute
* @property {VariableModel} variable - the secure variable itself
* @property {VariableModel} variable - the variable itself
*/
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment