This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
329724b
commit 0677cd0
Showing
7 changed files
with
252 additions
and
0 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
console/src/main/scripts/plugins/accounts/html/token-revoke-modal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
console/src/main/scripts/plugins/accounts/html/tokens.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters