Skip to content

Commit 7c25d66

Browse files
author
OpenShift Bot
authored
Merge pull request #2107 from spadgett/disable-copy-login-command
Merged by openshift-bot
2 parents 6f40623 + 6fb94d8 commit 7c25d66

File tree

7 files changed

+129
-95
lines changed

7 files changed

+129
-95
lines changed

app/scripts/constants.js

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ angular.extend(window.OPENSHIFT_CONSTANTS, {
9393
// Currently disables watch on events used by the drawer.
9494
DISABLE_GLOBAL_EVENT_WATCH: false,
9595

96+
// Disables the copy login command option from the user menu and CLI page.
97+
DISABLE_COPY_LOGIN_COMMAND: false,
98+
9699
ENABLE_TECH_PREVIEW_FEATURE: {
97100
// Set to true when the template service broker is enabled for the cluster in master-config.yaml.
98101
template_service_broker: false,

app/scripts/controllers/commandLine.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ angular.module('openshiftConsole')
1313
$scope.cliDownloadURL = Constants.CLI;
1414
$scope.cliDownloadURLPresent = $scope.cliDownloadURL && !_.isEmpty($scope.cliDownloadURL);
1515
$scope.loginBaseURL = DataService.openshiftAPIBaseUrl();
16-
$scope.sessionToken = AuthService.UserStore().getToken();
17-
$scope.showSessionToken = false;
18-
19-
$scope.toggleShowSessionToken = function() {
20-
$scope.showSessionToken = !$scope.showSessionToken;
21-
};
16+
if (!Constants.DISABLE_COPY_LOGIN_COMMAND) {
17+
$scope.sessionToken = AuthService.UserStore().getToken();
18+
}
2219
});

app/scripts/directives/util.js

+24-6
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ angular.module('openshiftConsole')
103103
}
104104
};
105105
})
106-
.directive('copyLoginToClipboard', function(NotificationsService) {
106+
.directive('copyLoginToClipboard', function(AlertMessageService, NotificationsService) {
107107
return {
108108
restrict: 'E',
109109
replace: true,
@@ -115,16 +115,34 @@ angular.module('openshiftConsole')
115115
var clipboard = new Clipboard( element.get(0) );
116116
clipboard.on('success', function () {
117117
NotificationsService.addNotification({
118-
id: 'copied_to_clipboard_toast_success',
119-
type: 'warning',
120-
message: 'Do not share the API token in your clipboard. A token is a form of a password.'
118+
id: 'copy-login-command-success',
119+
type: 'success',
120+
message: 'Login command copied.'
121121
});
122+
123+
var tokenWarningAlertID = 'openshift/token-warning';
124+
if (!AlertMessageService.isAlertPermanentlyHidden(tokenWarningAlertID)) {
125+
NotificationsService.addNotification({
126+
id: tokenWarningAlertID,
127+
type: 'warning',
128+
message: 'A token is a form of a password. Do not share your API token.',
129+
links: [{
130+
href: "",
131+
label: "Don't Show Me Again",
132+
onClick: function() {
133+
AlertMessageService.permanentlyHideAlert(tokenWarningAlertID);
134+
// Return true close the existing alert.
135+
return true;
136+
}
137+
}]
138+
});
139+
}
122140
});
123141
clipboard.on('error', function () {
124142
NotificationsService.addNotification({
125-
id: 'copied_to_clipboard_toast_error',
143+
id: 'copy-login-command-error',
126144
type: 'error',
127-
message: 'Unable to copy.'
145+
message: 'Unable to copy the login command.'
128146
});
129147
});
130148
element.on('$destroy', function() {

app/scripts/extensions/nav/userDropdown.js

+13-6
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@ angular.module('openshiftConsole')
44
.run(function(extensionRegistry, $rootScope, DataService, AuthService) {
55
extensionRegistry
66
.add('nav-user-dropdown', function() {
7-
var msg = 'Log out';
7+
var items = [];
8+
if (!_.get(window, 'OPENSHIFT_CONSTANTS.DISABLE_COPY_LOGIN_COMMAND')) {
9+
items.push({
10+
type: 'dom',
11+
node: '<li><copy-login-to-clipboard clipboard-text="\'oc login ' + DataService.openshiftAPIBaseUrl() + ' --token=' + AuthService.UserStore().getToken() + '\'"></copy-login-to-clipboard></li>'
12+
});
13+
}
14+
15+
var msg = 'Log Out';
816
if ($rootScope.user.fullName && $rootScope.user.fullName !== $rootScope.user.metadata.name) {
917
msg += ' (' + $rootScope.user.metadata.name + ')';
1018
}
11-
return [{
12-
type: 'dom',
13-
node: '<li><copy-login-to-clipboard clipboard-text="\'oc login ' + DataService.openshiftAPIBaseUrl() + ' --token=' + AuthService.UserStore().getToken() + '\'"></copy-login-to-clipboard></li>'
14-
},{
19+
items.push({
1520
type: 'dom',
1621
node: '<li><a href="logout">' + _.escape(msg) + '</a></li>'
17-
}];
22+
});
23+
24+
return items;
1825
});
1926
});

app/views/command-line.html

+3-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ <h1 id="cli">Command Line Tools</h1>
2929
</p>
3030
<p>
3131
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:
32-
<copy-to-clipboard display-wide="true" clipboard-text="'oc login ' + loginBaseURL + ' --token=' + sessionToken" input-text="'oc login ' + loginBaseURL + ' --token=<hidden>'"></copy-to-clipboard>
33-
<pre class="code prettyprint ng-binding" ng-if="!sessionToken">
34-
oc login {{loginBaseURL}}
35-
</pre>
32+
<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>
33+
<copy-to-clipboard ng-if="!sessionToken" display-wide="true" clipboard-text="'oc login ' + loginBaseURL"></copy-to-clipboard>
3634
</p>
3735

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

0 commit comments

Comments
 (0)