Redo the tokens page to be a form that validates a token and lists policies

This commit is contained in:
Michael Lange 2017-10-13 15:18:05 -07:00
parent 040e3fec10
commit d177cf90c3
2 changed files with 109 additions and 17 deletions

View File

@ -1,20 +1,53 @@
import Ember from 'ember'; import Ember from 'ember';
const { Controller, inject } = Ember; const { Controller, inject, computed } = Ember;
export default Controller.extend({ export default Controller.extend({
token: inject.service(), token: inject.service(),
actions: { tokenRecord: null,
setTokenProperty(property, event) { secret: computed.reads('token.secret'),
this.get('token').set(property, event.currentTarget.value); accessor: computed.reads('token.accessor'),
},
tokenIsValid: false,
tokenIsInvalid: false,
actions: {
clearTokenProperties() { clearTokenProperties() {
this.get('token').setProperties({ this.get('token').setProperties({
secret: undefined, secret: undefined,
accessor: undefined, accessor: undefined,
}); });
this.setProperties({
tokenIsValid: false,
tokenIsInvalid: false,
});
},
verifyToken() {
const { secret, accessor } = this.getProperties('secret', 'accessor');
this.set('token.secret', secret);
this.get('store')
.findRecord('token', accessor)
.then(
token => {
this.set('token.accessor', accessor);
this.setProperties({
tokenIsValid: true,
tokenIsInvalid: false,
tokenRecord: token,
});
},
() => {
this.set('token.secret', null);
this.setProperties({
tokenIsInvalid: true,
tokenIsValid: false,
tokenRecord: null,
});
}
);
}, },
}, },
}); });

View File

@ -16,21 +16,80 @@
</div> </div>
</div> </div>
<div class="field"> {{#if (not tokenIsValid)}}
<label class="label">Secret ID</label> <div class="field">
<div class="control"> <label class="label">Secret ID</label>
<input class="input token-secret" type="text" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" value={{token.secret}} oninput={{action "setTokenProperty" "secret"}}> <div class="control">
<input class="input token-secret" type="text" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" value={{token.secret}} oninput={{action (mut secret) value="target.value"}}>
</div>
<p class="help">Sent with every request to determine authorization</p>
</div> </div>
<p class="help">Sent with every request to determine authorization</p>
</div>
<div class="field"> <div class="field">
<label class="label">Accessor ID</label> <label class="label">Accessor ID</label>
<div class="control"> <div class="control">
<input class="input token-accessor" type="text" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" value={{token.accessor}} oninput={{action "setTokenProperty" "accessor"}}> <input class="input token-accessor" type="text" placeholder="XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" value={{token.accessor}} oninput={{action (mut accessor) value="target.value"}}>
</div>
<p class="help">Used to look up authorized policies</p>
</div> </div>
<p class="help">Used to look up authorized policies</p> <p class="content"><button class="button is-primary" {{action "verifyToken"}}>Set Token</button></p>
</div> {{/if}}
{{#if tokenIsValid}}
<div class="notification is-success">
<div class="columns">
<div class="column">
<h3 class="title is-4">Token Authenticated!</h3>
<p>Your token is valid and authorized for the following policies.</p>
</div>
</div>
</div>
{{/if}}
{{#if tokenIsInvalid}}
<div class="notification is-danger">
<div class="columns">
<div class="column">
<h3 class="title is-4">Token Failed to Authenticate</h3>
<p>The token secret and accessor you have provided do not match.</p>
</div>
</div>
</div>
{{/if}}
{{#if tokenRecord}}
<h3 class="title is-4">Token: {{tokenRecord.name}}</h3>
<div class="content">
<div>AccessorID: <code>{{tokenRecord.accessor}}</code></div>
<div>SecretID: <code>{{tokenRecord.secret}}</code></div>
</div>
<h3 class="title is-4">Policies</h3>
{{#if (eq tokenRecord.type "management")}}
<div class="boxed-section">
<div class="boxed-section-body has-centered-text">
The management token has all permissions
</div>
</div>
{{else}}
{{#each tokenRecord.policies as |policy|}}
<div class="boxed-section">
<div class="boxed-section-head">
{{policy.name}}
</div>
<div class="boxed-section-body">
<p class="content">
{{#if policy.description}}
{{policy.description}}
{{else}}
<em>No description</em>
{{/if}}
</p>
<pre><code>{{policy.rules}}</code></pre>
</div>
</div>
{{/each}}
{{/if}}
{{/if}}
</div> </div>
</div> </div>
</section> </section>