Skip to content

Commit

Permalink
Merge pull request #14383 from hashicorp/variables-rename-ui
Browse files Browse the repository at this point in the history
[ui] Variables Rename
  • Loading branch information
philrenaud committed Aug 29, 2022
2 parents 17cc73d + 70bfcbb commit f1b62f5
Show file tree
Hide file tree
Showing 28 changed files with 174 additions and 178 deletions.
24 changes: 12 additions & 12 deletions ui/app/abilities/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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']
);
Expand All @@ -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.
Expand All @@ -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);
});
}
Expand All @@ -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)
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{{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}}">
Expand Down Expand Up @@ -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 />
Expand All @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<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}}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/controllers/variables/variable/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions ui/app/models/variable.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion ui/app/styles/components.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
}
}

.new-secure-variables {
.new-variables {
& > div {
margin-bottom: 1rem;
}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/variables.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Breadcrumb @crumb={{hash label="Secure Variables" args=(array "variables.index")}} />
<Breadcrumb @crumb={{hash label="Variables" args=(array "variables.index")}} />
<PageLayout>
{{outlet}}
</PageLayout>
10 changes: 5 additions & 5 deletions ui/app/templates/variables/index.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{page-title "Secure Variables"}}
{{page-title "Variables"}}
<section class="section">
<div class="toolbar">
<div class="toolbar-item is-right-aligned is-mobile-full-width">
Expand All @@ -18,7 +18,7 @@
class="button is-primary"
data-test-create-var
>
Create Secure Variable
Create Variable
</LinkTo>
{{else}}
<button
Expand All @@ -28,7 +28,7 @@
type="button"
data-test-disabled-create-var
>
Create Secure Variable
Create Variable
</button>
{{/if}}

Expand All @@ -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}}
Expand Down
6 changes: 3 additions & 3 deletions ui/app/templates/variables/new.hbs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{{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"}}
Expand All @@ -12,7 +12,7 @@
>JSON</Toggle>
</h1>

<SecureVariableForm
<VariableForm
@model={{this.model}}
@path={{this.path}}
@existingVariables={{this.existingVariables}}
Expand Down
8 changes: 4 additions & 4 deletions ui/app/templates/variables/path.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{page-title "Secure Variables: " this.absolutePath}}
{{page-title "Variables: " this.absolutePath}}
{{#each this.breadcrumbs as |crumb|}}
<Breadcrumb @crumb={{crumb}} />
{{/each}}
Expand All @@ -21,7 +21,7 @@
@query={{hash path=(concat this.absolutePath "/")}}
class="button is-primary"
>
Create Secure Variable
Create Variable
</LinkTo>
{{else}}
<button
Expand All @@ -30,7 +30,7 @@
disabled
type="button"
>
Create Secure Variable
Create Variable
</button>
{{/if}}
</div>
Expand All @@ -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">
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/variables/variable.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{page-title "Secure Variables: " this.model.path}}
{{page-title "Variables: " this.model.path}}
{{#each this.breadcrumbs as |crumb|}}
<Breadcrumb @crumb={{crumb}} />
{{/each}}
Expand Down
4 changes: 2 additions & 2 deletions ui/app/templates/variables/variable/edit.hbs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{page-title "Edit Secure Variable"}}
{{page-title "Edit Variable"}}

<h1 class="title variable-title">
<LinkTo class="back-link" @route="variables.variable.index">
Expand All @@ -19,7 +19,7 @@

</h1>

<SecureVariableForm
<VariableForm
@model={{this.model}}
@existingVariables={{this.existingVariables}}
@view={{this.view}}
Expand Down
2 changes: 1 addition & 1 deletion ui/app/templates/variables/variable/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
Expand Down
4 changes: 2 additions & 2 deletions ui/app/utils/path-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/

/**
Expand Down
4 changes: 2 additions & 2 deletions ui/mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -837,7 +837,7 @@ export default function () {
}
);

//#region Secure Variables
//#region Variables

this.get('/vars', function (schema, { queryParams: { namespace } }) {
if (namespace && namespace !== '*') {
Expand Down Expand Up @@ -883,7 +883,7 @@ export default function () {
return '';
});

//#endregion Secure Variables
//#endregion Variables
}

function filterKeys(object, ...keys) {
Expand Down
Loading

0 comments on commit f1b62f5

Please sign in to comment.