Skip to content

Commit

Permalink
Handle displaying parameters when secrets are not available.
Browse files Browse the repository at this point in the history
Bump catalog version to 0.0.58
  • Loading branch information
jeff-phillips-18 committed Oct 24, 2017
1 parent 0f2d9ba commit 9f0c28b
Show file tree
Hide file tree
Showing 9 changed files with 295 additions and 221 deletions.
30 changes: 24 additions & 6 deletions app/scripts/controllers/serviceInstance.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading

0 comments on commit 9f0c28b

Please sign in to comment.