Skip to content

Commit

Permalink
Merge pull request #2107 from spadgett/disable-copy-login-command
Browse files Browse the repository at this point in the history
Merged by openshift-bot
  • Loading branch information
OpenShift Bot committed Sep 19, 2017
2 parents 6f40623 + 6fb94d8 commit 7c25d66
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 95 deletions.
3 changes: 3 additions & 0 deletions app/scripts/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
// Currently disables watch on events used by the drawer.
DISABLE_GLOBAL_EVENT_WATCH: false,

// Disables the copy login command option from the user menu and CLI page.
DISABLE_COPY_LOGIN_COMMAND: false,

ENABLE_TECH_PREVIEW_FEATURE: {
// Set to true when the template service broker is enabled for the cluster in master-config.yaml.
template_service_broker: false,
Expand Down
9 changes: 3 additions & 6 deletions app/scripts/controllers/commandLine.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ angular.module('openshiftConsole')
$scope.cliDownloadURL = Constants.CLI;
$scope.cliDownloadURLPresent = $scope.cliDownloadURL && !_.isEmpty($scope.cliDownloadURL);
$scope.loginBaseURL = DataService.openshiftAPIBaseUrl();
$scope.sessionToken = AuthService.UserStore().getToken();
$scope.showSessionToken = false;

$scope.toggleShowSessionToken = function() {
$scope.showSessionToken = !$scope.showSessionToken;
};
if (!Constants.DISABLE_COPY_LOGIN_COMMAND) {
$scope.sessionToken = AuthService.UserStore().getToken();
}
});
30 changes: 24 additions & 6 deletions app/scripts/directives/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ angular.module('openshiftConsole')
}
};
})
.directive('copyLoginToClipboard', function(NotificationsService) {
.directive('copyLoginToClipboard', function(AlertMessageService, NotificationsService) {
return {
restrict: 'E',
replace: true,
Expand All @@ -115,16 +115,34 @@ angular.module('openshiftConsole')
var clipboard = new Clipboard( element.get(0) );
clipboard.on('success', function () {
NotificationsService.addNotification({
id: 'copied_to_clipboard_toast_success',
type: 'warning',
message: 'Do not share the API token in your clipboard. A token is a form of a password.'
id: 'copy-login-command-success',
type: 'success',
message: 'Login command copied.'
});

var tokenWarningAlertID = 'openshift/token-warning';
if (!AlertMessageService.isAlertPermanentlyHidden(tokenWarningAlertID)) {
NotificationsService.addNotification({
id: tokenWarningAlertID,
type: 'warning',
message: 'A token is a form of a password. Do not share your API token.',
links: [{
href: "",
label: "Don't Show Me Again",
onClick: function() {
AlertMessageService.permanentlyHideAlert(tokenWarningAlertID);
// Return true close the existing alert.
return true;
}
}]
});
}
});
clipboard.on('error', function () {
NotificationsService.addNotification({
id: 'copied_to_clipboard_toast_error',
id: 'copy-login-command-error',
type: 'error',
message: 'Unable to copy.'
message: 'Unable to copy the login command.'
});
});
element.on('$destroy', function() {
Expand Down
19 changes: 13 additions & 6 deletions app/scripts/extensions/nav/userDropdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,23 @@ angular.module('openshiftConsole')
.run(function(extensionRegistry, $rootScope, DataService, AuthService) {
extensionRegistry
.add('nav-user-dropdown', function() {
var msg = 'Log out';
var items = [];
if (!_.get(window, 'OPENSHIFT_CONSTANTS.DISABLE_COPY_LOGIN_COMMAND')) {
items.push({
type: 'dom',
node: '<li><copy-login-to-clipboard clipboard-text="\'oc login ' + DataService.openshiftAPIBaseUrl() + ' --token=' + AuthService.UserStore().getToken() + '\'"></copy-login-to-clipboard></li>'
});
}

var msg = 'Log Out';
if ($rootScope.user.fullName && $rootScope.user.fullName !== $rootScope.user.metadata.name) {
msg += ' (' + $rootScope.user.metadata.name + ')';
}
return [{
type: 'dom',
node: '<li><copy-login-to-clipboard clipboard-text="\'oc login ' + DataService.openshiftAPIBaseUrl() + ' --token=' + AuthService.UserStore().getToken() + '\'"></copy-login-to-clipboard></li>'
},{
items.push({
type: 'dom',
node: '<li><a href="logout">' + _.escape(msg) + '</a></li>'
}];
});

return items;
});
});
8 changes: 3 additions & 5 deletions app/views/command-line.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ <h1 id="cli">Command Line Tools</h1>
</p>
<p>
After downloading and installing it, you can start by logging in. You are currently logged into this console as <strong>{{user.metadata.name}}</strong>. If you want to log into the CLI using the same session token:
<copy-to-clipboard display-wide="true" clipboard-text="'oc login ' + loginBaseURL + ' --token=' + sessionToken" input-text="'oc login ' + loginBaseURL + ' --token=<hidden>'"></copy-to-clipboard>
<pre class="code prettyprint ng-binding" ng-if="!sessionToken">
oc login {{loginBaseURL}}
</pre>
<copy-to-clipboard ng-if="sessionToken" display-wide="true" clipboard-text="'oc login ' + loginBaseURL + ' --token=' + sessionToken" input-text="'oc login ' + loginBaseURL + ' --token=<hidden>'"></copy-to-clipboard>
<copy-to-clipboard ng-if="!sessionToken" display-wide="true" clipboard-text="'oc login ' + loginBaseURL"></copy-to-clipboard>
</p>

<div class="alert alert-warning">
<div ng-if="sessionToken" class="alert alert-warning">
<span class="pficon pficon-warning-triangle-o" aria-hidden="true"></span>
<strong>A token is a form of a password.</strong>
Do not share your API token. To reveal your token, press the copy to clipboard button and then paste the clipboard contents.
Expand Down

0 comments on commit 7c25d66

Please sign in to comment.