Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle displaying parameters when secrets are not available. #2355

Merged
merged 1 commit into from Oct 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 24 additions & 6 deletions app/scripts/controllers/serviceInstance.js
Expand Up @@ -73,18 +73,36 @@ angular.module('openshiftConsole')
DataService.unwatchAll(secretWatchers);
secretWatchers = [];

$scope.allowParametersReveal = AuthorizationService.canI('secrets', 'get', $scope.projectName);
$scope.parameterData = {};
_.each(_.keys(_.get($scope.parameterSchema, 'properties')), function(key) {
$scope.parameterData[key] = $scope.parameterSchema.properties[key].default;
$scope.opaqueParameterKeys = [];

// Set defaults for schema values
var defaultValue = $scope.allowParametersReveal ? '' : '*****';
_.each(_.keys(_.get($scope.parameterSchema, 'properties')), function (key) {
$scope.parameterData[key] = defaultValue;
});

$scope.parameterData = angular.extend($scope.parameterData, _.get($scope.serviceInstance, 'spec.parameters', {}));
// Get the current status's parameter values
var statusParameters = _.get($scope.serviceInstance, 'status.externalProperties.parameters', {});
_.each(_.keys(statusParameters), function(key) {
if (statusParameters[key] === '<redacted>') {
$scope.parameterData[key] = '*****';
} else {
$scope.parameterData[key] = statusParameters[key];
$scope.opaqueParameterKeys.push(key);
}
});

if (AuthorizationService.canI('secrets', 'get', $scope.projectName)) {
// Fill in the secret values if they are available to the user
if ($scope.allowParametersReveal) {
// Get the data from each secret
_.each(_.get($scope.serviceInstance, 'spec.parametersFrom'), function (parametersSource) {
secretWatchers.push(DataService.watchObject("secrets", _.get(parametersSource, 'secretKeyRef.name'), $scope.projectContext, function (secret) {
try {
_.extend($scope.parameterData, JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.secretKeyRef.key]));
var secretData = JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.secretKeyRef.key]);
// TODO: Only include fields from the secret that are part of the schema
_.extend($scope.parameterData, secretData);
} catch (e) {
Logger.warn('Unable to load parameters from secret ' + _.get(parametersSource, 'secretKeyRef.name'), e);
}
Expand All @@ -107,6 +125,7 @@ angular.module('openshiftConsole')
var updateParameterSchema = function() {
$scope.parameterFormDefinition = angular.copy(_.get($scope.plan, 'spec.externalMetadata.schemas.service_instance.update.openshift_form_definition'));
$scope.parameterSchema = _.get($scope.plan, 'spec.instanceCreateParameterSchema');
updateParameterData();
};

var updateServiceClass = function() {
Expand All @@ -132,7 +151,6 @@ angular.module('openshiftConsole')
$scope.plan = plans[servicePlanName];

updateParameterSchema();
updateParameterData();
updateEditable();
});
});
Expand Down
32 changes: 28 additions & 4 deletions app/scripts/directives/serviceBinding.js
Expand Up @@ -38,12 +38,36 @@
};

var updateParameterData = function() {
ctrl.parameterData = angular.copy(_.get(ctrl.binding, 'spec.parameters', {}));
if (AuthorizationService.canI('secrets', 'get', ctrl.namespace)) {

ctrl.allowParametersReveal = AuthorizationService.canI('secrets', 'get', ctrl.namespace);
ctrl.parameterData = {};
ctrl.opaqueParameterKeys = [];

// Set defaults for schema values
var defaultValue = ctrl.allowParametersReveal ? '' : '*****';
_.each(_.keys(_.get(ctrl.bindParameterSchema, 'properties')), function (key) {
ctrl.parameterData[key] = defaultValue;
});

// Get the current status's parameter values
var statusParameters = _.get(ctrl.binding, 'status.externalProperties.parameters', {});
_.each(_.keys(statusParameters), function(key) {
if (statusParameters[key] === '<redacted>') {
ctrl.parameterData[key] = '*****';
} else {
ctrl.parameterData[key] = statusParameters[key];
ctrl.opaqueParameterKeys.push(key);
}
});

// Fill in the secret values if they are available to the user
if (ctrl.allowParametersReveal) {
_.each(_.get(ctrl.binding, 'spec.parametersFrom'), function (parametersSource) {
DataService.get('secrets', _.get(parametersSource, 'secretKeyRef.name'), context).then(function (secret) {
try {
_.extend(ctrl.parameterData, JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.secretKeyRef.key]));
var secretData = JSON.parse(SecretsService.decodeSecretData(secret.data)[parametersSource.secretKeyRef.key]);
// TODO: Only include fields from the secret that are part of the schema
_.extend(ctrl.parameterData, secretData);
} catch (e) {
Logger.warn('Unable to load parameters from secret ' + _.get(parametersSource, 'secretKeyRef.name'), e);
}
Expand All @@ -57,6 +81,7 @@
DataService.get(resource, _.get(ctrl.serviceInstance, 'spec.clusterServicePlanRef.name'), context).then(function(servicePlan) {
ctrl.bindParameterFormDefinition = angular.copy(_.get(servicePlan, 'spec.externalMetadata.schemas.service_binding.create.openshift_form_definition'));
ctrl.bindParameterSchema = _.get(servicePlan, 'spec.serviceBindingCreateParameterSchema');
updateParameterData();
});
};

Expand All @@ -76,7 +101,6 @@
if (changes.binding || changes.serviceInstances || changes.serviceClasses) {
updateServiceClass();
updateParameterSchema();
updateParameterData();
}
};

Expand Down
3 changes: 2 additions & 1 deletion app/views/browse/service-instance.html
Expand Up @@ -104,13 +104,14 @@ <h3>Plan</h3>
<div ng-if="parameterSchema.properties" class="config-parameters-form">
<h3>
<span>Configuration</span>
<a href="" class="hide-show-link" ng-click="toggleShowParameterValues()" role="button">
<a ng-if="allowParametersReveal" href="" class="hide-show-link" ng-click="toggleShowParameterValues()" role="button">
{{showParameterValues ? 'Hide Values' : 'Reveal Values'}}
</a>
</h3>
<form name="forms.orderConfigureForm" >
<catalog-parameters
hide-values="!showParameterValues"
opaque-keys="opaqueParameterKeys"
model="parameterData"
parameter-schema="parameterSchema"
parameter-form-definition="parameterFormDefinition"
Expand Down
3 changes: 2 additions & 1 deletion app/views/directives/_service-binding.html
Expand Up @@ -50,12 +50,13 @@ <h3>
</div>
<div class="service-binding-parameters" ng-if="!$ctrl.isOverview && $ctrl.bindParameterSchema.properties">
<span class="component-label">Parameters</span>
<a href="" class="hide-show-link" ng-click="$ctrl.toggleShowParameterValues()" role="button">
<a ng-if="$ctrl.allowParametersReveal" href="" class="hide-show-link" ng-click="$ctrl.toggleShowParameterValues()" role="button">
{{$ctrl.showParameterValues ? 'Hide Values' : 'Reveal Values'}}
</a>
<form name="ctrl.parametersForm">
<catalog-parameters
hide-values="!$ctrl.showParameterValues"
opaque-keys="$ctrl.opaqueParameterKeys"
model="$ctrl.parameterData"
parameter-form-definition="$ctrl.bindParameterFormDefinition"
parameter-schema="$ctrl.bindParameterSchema"
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Expand Up @@ -47,7 +47,7 @@
"angular-utf8-base64": "0.0.5",
"file-saver": "1.3.3",
"origin-web-common": "0.0.68",
"origin-web-catalog": "0.0.57"
"origin-web-catalog": "0.0.58"
},
"devDependencies": {
"angular-mocks": "1.5.11",
Expand Down