Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
HAWKULAR-814 - Secret Store UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jpkrohling committed Dec 11, 2015
1 parent 329724b commit 0677cd0
Show file tree
Hide file tree
Showing 7 changed files with 252 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<div class="modal-header">
<button type="button" class="close" ng-click="removeModal.cancel()">
<span class="pficon pficon-close"></span>
</button>
<h4 class="modal-title">Revoke Token</h4>
</div>
<div class="modal-body">
<div class="form-group">
<p class="primary-message">
Are you sure you want to revoke the token <strong>{{removeModal.token.id}}</strong>?
</p>
<p>
All clients using this token will need to be configured with a new token, otherwise their requests will be
denied.
</p>
<p>This action can't be undone.</p>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" ng-click="removeModal.cancel()">Cancel</button>
<button type="button" class="btn btn-danger" ng-click="removeModal.revoke()">Revoke</button>
</div>
61 changes: 61 additions & 0 deletions console/src/main/scripts/plugins/accounts/html/tokens.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<div class="hk-organizations row" ng-controller="HawkularAccounts.TokensController as controller">
<div class="col-lg-8 col-lg-offset-2 col-md-10 col-md-offset-1">

<h1 class="text-center" ng-show="!controller.loading">Tokens</h1>

<div class="text-center hk-spinner-container-alone" ng-show="controller.loading">
<div class="spinner spinner-lg"></div>
<p class="hk-spinner-legend-below">Loading...</p>
</div>

<div class="blank-slate-pf" ng-show="!controller.tokens.length && !controller.loading">
<div class="blank-slate-pf-icon">
<i class="fa fa-shield"></i>
</div>
<h1>No tokens created.</h1>
<p>
You can create access tokens for usage in the Agent or in other applications to make REST calls.
</p>
<div class="blank-slate-pf-main-action">
<button class="btn btn-primary btn-lg" type="button" role="button" ng-click="controller.create()">
Create Token
</button>
</div>
</div>

<div class="text-right" ng-show="controller.tokens.length && !controller.loading">
<button class="btn btn-primary" type="button" role="button" ng-click="controller.create()">
Create Token
</button>
</div>
<div class="hk-table-container" ng-show="controller.tokens.length && !controller.loading">
<table class="table table-bordered hk-table-clean">
<thead>
<tr>
<th>Key</th>
<th>Secret</th>
<th>Persona</th>
<th></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="token in controller.tokens">
<td>{{token.id}}</td>
<td>{{token.secret}}</td>
<td>{{controller.personaForToken(token)}}</td>
<td class="hk-actions-one">
<button type="button"
class="btn btn-link"
tooltip-trigger
tooltip-placement="top"
tooltip="Revoke"
ng-click="controller.revoke(token)">
<i class="fa fa-trash-o"></i>
</button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
12 changes: 12 additions & 0 deletions console/src/main/scripts/plugins/accounts/ts/accountsGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,18 @@ module HawkularAccounts {
updatedAt: string;
}

export interface IToken {
id: string;
key: string;
secret: string;
createdAt: string;
updatedAt: string;
attributes: { [key:string]:string; };
$remove(options:{},
success?:(success:IOrganization) => void,
failure?:(error:IErrorPayload) => void);
}

export interface IOrganization extends IPersona {
owner: IPersona;
$update(options:{},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,14 @@ module HawkularAccounts {
'/hawkular-ui/invitation/accept/:token',
{templateUrl: builder.join(HawkularAccounts.templatePath, 'organization-accept-invitation.html')})

.when(
'/hawkular-ui/tokens',
{templateUrl: builder.join(HawkularAccounts.templatePath, 'tokens.html')})

.when(
'/hawkular-ui/tokens/:id',
{templateUrl: builder.join(HawkularAccounts.templatePath, 'tokens.html')})

.when(
'/hawkular-ui/settings',
{templateUrl: builder.join(HawkularAccounts.templatePath, 'user-settings.html')});
Expand Down
138 changes: 138 additions & 0 deletions console/src/main/scripts/plugins/accounts/ts/tokens.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
///
/// Copyright 2015 Red Hat, Inc. and/or its affiliates
/// and other contributors as indicated by the @author tags.
///
/// Licensed under the Apache License, Version 2.0 (the "License");
/// you may not use this file except in compliance with the License.
/// You may obtain a copy of the License at
///
/// http://www.apache.org/licenses/LICENSE-2.0
///
/// Unless required by applicable law or agreed to in writing, software
/// distributed under the License is distributed on an "AS IS" BASIS,
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
/// See the License for the specific language governing permissions and
/// limitations under the License.
///

/// <reference path='accountsPlugin.ts'/>
module HawkularAccounts {
export class TokensController {
public static $inject = [
'$window', '$rootScope', '$scope',
'$modal', '$log', 'HawkularAccount', 'NotificationsService'
];
public tokens:Array<IToken>;
public personas:Array<IPersona>;
public loading:boolean = true;

constructor(private $window:any,
private $rootScope:any,
private $scope:any,
private $modal:any,
private $log:ng.ILogService,
private HawkularAccount:any,
private NotificationsService:INotificationsService) {
this.prepareListeners();
this.loadData();
}

public prepareListeners() {
this.$rootScope.$on('SwitchedPersona', () => {
this.loadData();
});
}

public loadData():void {
this.loading = true;
this.tokens = this.HawkularAccount.Token.query({},
(response:Array<IToken>) => {
this.personas = this.HawkularAccount.Persona.query({},
(response:Array<IPersona>) => {
this.loading = false;
}, (error:IErrorPayload) => {
let message = `Failed to retrieve the list of possible personas: ${error.data.message}`;
this.NotificationsService.error(message);
this.$log.warn(message);
this.loading = false;
}
);
}, (error:IErrorPayload) => {
this.$log.warn(`List of tokens could NOT be retrieved: ${error.data.message}`);
this.NotificationsService.warning(`List of tokens could NOT be retrieved: ${error.data.message}`);
this.loading = false;
}
);
}

public create():void {
this.$window.location.href = '/hawkular/secret-store/v1/tokens/create?'
+ 'Hawkular-Persona=' + encodeURI(this.$rootScope.currentPersona.id);
}

public personaForToken(token:IToken):string {
if (this.loading) {
return token.id;
}

let id = token.attributes['Hawkular-Persona'];
if (id === null) {
id = token.id;
}

if (id === this.$rootScope.currentPersona.id) {
return this.$rootScope.currentPersona.name;
}

let personaName = id;
angular.forEach(this.personas, (persona:IPersona) => {
if (persona.id === id) {
personaName = persona.name;
}
});

return personaName;
}

public revoke(token:IToken):void {
this.$modal.open({
controller: 'HawkularAccounts.TokenRevokeController as removeModal',
templateUrl: 'plugins/accounts/html/token-revoke-modal.html',
resolve: {
token: () => token
}
})
.result
.then(() => {
token.$remove({}, () => {
this.NotificationsService.success('Token successfully revoked.');
this.tokens.splice(this.tokens.indexOf(token), 1);
}, (error:IErrorPayload) => {
let message = `Failed to revoke the token ${token.id}: ${error.data.message}`;
this.$log.warn(message);
this.NotificationsService.error(message);
});
});
}
}

export class TokenRevokeController {
public static $inject = ['$scope', '$modalInstance', 'token'];

constructor(private $scope:any,
private $modalInstance:any,
private token:IToken) {
}

public cancel():void {
this.$modalInstance.dismiss('cancel');
}

public revoke():void {
this.$modalInstance.close();
}
}

_module.controller('HawkularAccounts.TokensController', TokensController);
_module.controller('HawkularAccounts.TokenRevokeController', TokenRevokeController);
}
3 changes: 3 additions & 0 deletions console/src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<li>
<a id="userSettingsOption" href="/hawkular-ui/settings">User Settings</a>
</li>
<li>
<a id="tokensOption" href="/hawkular-ui/tokens">Tokens</a>
</li>
<li class="divider"></li>
<li>
<a id="logout" href="#" ng-click="userDetails.logout()">Log Out</a>
Expand Down
8 changes: 8 additions & 0 deletions dist/src/main/resources/wildfly/patches/standalone.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@
<xsl:attribute name="name">hawkular.metrics.waitForService</xsl:attribute>
<xsl:attribute name="value">&#36;{hawkular.metrics.waitForService:True}</xsl:attribute>
</property>
<property>
<xsl:attribute name="name">secretstore.redirectTo</xsl:attribute>
<xsl:attribute name="value">&#36;{secretstore.redirectTo:/hawkular-ui/tokens/{tokenId}}</xsl:attribute>
</property>
<property>
<xsl:attribute name="name">secretstore.parametersToPersist</xsl:attribute>
<xsl:attribute name="value">&#36;{secretstore.parametersToPersist:Hawkular-Persona}</xsl:attribute>
</property>
<xsl:choose>
<xsl:when test="$kettle.build.type='dev'">
<property>
Expand Down

0 comments on commit 0677cd0

Please sign in to comment.