Skip to content

Service instance details configuration and edit #2237

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

Merged
merged 1 commit into from
Oct 19, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 97 additions & 17 deletions app/scripts/controllers/serviceInstance.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,19 @@ angular.module('openshiftConsole')
$routeParams,
APIService,
BindingService,
AuthorizationService,
Catalog,
DataService,
Logger,
ProjectsService,
SecretsService,
ServiceInstancesService) {
$scope.alerts = {};
$scope.projectName = $routeParams.project;
$scope.serviceInstance = null;
$scope.serviceClass = null;
$scope.serviceClasses = null;
$scope.editDialogShown = false;

$scope.breadcrumbs = [
{
Expand All @@ -28,9 +34,26 @@ angular.module('openshiftConsole')
ServiceInstancesService.deprovision($scope.serviceInstance, $scope.bindings);
};

$scope.showEditDialog = function() {
$scope.editDialogShown = true;
};

$scope.showParameterValues = false;

$scope.toggleShowParameterValues = function() {
$scope.showParameterValues = !$scope.showParameterValues;
};

$scope.closeEditDialog = function() {
$scope.editDialogShown = false;
};

var watches = [];
var secretWatchers = [];
var serviceClassPromise;

var serviceInstanceDisplayName = $filter('serviceInstanceDisplayName');
var serviceInstanceReady = $filter('isServiceInstanceReady');

// API Versions
var serviceBindingsVersion = APIService.getPreferredVersion('servicebindings');
Expand All @@ -42,28 +65,76 @@ angular.module('openshiftConsole')
});
};

var serviceClassPromise;
var updateParameterData = function() {
if (!$scope.serviceInstance || !$scope.parameterSchema) {
return;
}

DataService.unwatchAll(secretWatchers);
secretWatchers = [];

$scope.parameterData = {};
_.each(_.keys(_.get($scope.parameterSchema, 'properties')), function(key) {
$scope.parameterData[key] = $scope.parameterSchema.properties[key].default;
});

$scope.parameterData = angular.extend($scope.parameterData, _.get($scope.serviceInstance, 'spec.parameters', {}));

if (AuthorizationService.canI('secrets', 'get', $scope.projectName)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This means that you will not be able to see that there's a parameter at all when it comes from a secret and you can't get the secret, correct?

We could possibly fill in the redacted values using status.externalProperties.parameters when users can't list secrets (without letting them reveal). I'm OK handling this as a follow on, however.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@spadgett What should we do when the user does reveal and we have redacted values for some of the parameters? Continue to show ***** for those parameters?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove the "reveal" action?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're close enough here it should be a follow-on anyway.

_.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]));
} catch (e) {
Logger.warn('Unable to load parameters from secret ' + _.get(parametersSource, 'secretKeyRef.name'), e);
}
}));
});
}
};

var updateEditable = function() {
if (!$scope.plan || !$scope.serviceClass || !$scope.serviceInstance) {
return;
}

var updateSchema = _.get($scope.plan, 'spec.instanceUpdateParameterSchema');
var planUpdatable = (_.size(_.get(updateSchema, 'properties')) > 0) || (_.get($scope.serviceClass, 'spec.planUpdatable') && (_.size($scope.servicePlans) > 1));

$scope.editAvailable = planUpdatable && serviceInstanceReady($scope.serviceInstance) && !_.get($scope.serviceInstance, 'metadata.deletionTimestamp');
};

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');
};

var updateServiceClass = function() {
// If we've previously loaded the service class or a request is in flight, don't do anything.
if ($scope.serviceClass || serviceClassPromise) {
if (!$scope.serviceInstance || $scope.serviceClass || serviceClassPromise) {
return;
}

serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function(serviceClass) {
serviceClassPromise = ServiceInstancesService.fetchServiceClassForInstance($scope.serviceInstance).then(function (serviceClass) {
$scope.serviceClass = serviceClass;
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, serviceClass);
$scope.displayName = serviceInstanceDisplayName($scope.serviceInstance, $scope.serviceClass);

updateBreadcrumbs();
serviceClassPromise = null;
});
};

var updatePlan = function() {
if (ServiceInstancesService.isCurrentPlan($scope.serviceInstance, $scope.plan)) {
return;
}
Catalog.getServicePlans().then(function (plans) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we fix the removed plans, let's use a field filter on list to get just the plans for this service class and filter removed plans client side (follow on)

plans = plans.by('metadata.name');

var plansByServiceClassName = Catalog.groupPlansByServiceClassName(plans);
$scope.servicePlans = plansByServiceClassName[$scope.serviceClass.metadata.name];

ServiceInstancesService.fetchServicePlanForInstance($scope.serviceInstance).then(function(plan) {
$scope.plan = plan;
var servicePlanName = _.get($scope.serviceInstance, 'spec.clusterServicePlanRef.name');
$scope.plan = plans[servicePlanName];

updateParameterSchema();
updateParameterData();
updateEditable();
});
});
};

Expand All @@ -79,7 +150,8 @@ angular.module('openshiftConsole')
}

updateServiceClass();
updatePlan();
updateParameterData();
updateEditable();
};

ProjectsService
Expand All @@ -106,9 +178,17 @@ angular.module('openshiftConsole')
details: $filter('getErrorDetails')(error)
};
});
}, function(error) {
$scope.loaded = true;
$scope.alerts["load"] = {
type: "error",
message: "The service details could not be loaded.",
details: $filter('getErrorDetails')(error)
};
}));

$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
});
}));
$scope.$on('$destroy', function(){
DataService.unwatchAll(watches);
DataService.unwatchAll(secretWatchers);
});
});
2 changes: 1 addition & 1 deletion app/scripts/controllers/serviceInstances.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ angular.module('openshiftConsole')
};

$scope.getServiceClass = function(serviceInstance) {
var serviceClassName = _.get(serviceInstance, 'spec.serviceClassRef.name');
var serviceClassName = _.get(serviceInstance, 'spec.clusterServiceClassRef.name');
return _.get($scope, ['serviceClasses', serviceClassName]);
};

Expand Down
2 changes: 1 addition & 1 deletion app/scripts/directives/bindService.js
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@
ctrl.serviceClass = ctrl.serviceClasses[serviceClassName];
var servicePlanName = ServiceInstancesService.getServicePlanNameForInstance(instance);
ctrl.plan = ctrl.servicePlans[servicePlanName];
ctrl.parameterSchema = _.get(ctrl.plan, 'spec.serviceInstanceCredentialCreateParameterSchema');
ctrl.parameterSchema = _.get(ctrl.plan, 'spec.serviceBindingCreateParameterSchema');
ctrl.parameterFormDefinition = _.get(ctrl.plan, 'spec.externalMetadata.schemas.service_binding.create.openshift_form_definition');
bindParametersStep.hidden = !_.has(ctrl.parameterSchema, 'properties');
ctrl.nextTitle = bindParametersStep.hidden ? 'Bind' : 'Next >';
Expand Down
55 changes: 50 additions & 5 deletions app/scripts/directives/serviceBinding.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
(function() {
angular.module('openshiftConsole').component('serviceBinding', {
controller: [
"APIService",
"ServiceInstancesService",
'APIService',
'AuthorizationService',
'DataService',
'Logger',
'SecretsService',
'ServiceInstancesService',
ServiceBinding
],
controllerAs: '$ctrl',
Expand All @@ -20,23 +24,64 @@
});

function ServiceBinding(APIService,
AuthorizationService,
DataService,
Logger,
SecretsService,
ServiceInstancesService) {
var ctrl = this;
ctrl.serviceBindingsVersion = APIService.getPreferredVersion('servicebindings');
ctrl.showParameterValues = false;

var context = {
namespace: ctrl.namespace
};

var updateParameterData = function() {
ctrl.parameterData = angular.copy(_.get(ctrl.binding, 'spec.parameters', {}));
if (AuthorizationService.canI('secrets', 'get', ctrl.namespace)) {
_.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]));
} catch (e) {
Logger.warn('Unable to load parameters from secret ' + _.get(parametersSource, 'secretKeyRef.name'), e);
}
});
});
}
};

var updateParameterSchema = function() {
var resource = APIService.getPreferredVersion('clusterserviceplans');
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');
});
};

var updateServiceClass = function() {
if (_.get(ctrl.refApiObject, 'kind') !== 'ServiceInstance') {
var instanceName = _.get(ctrl.binding, 'spec.instanceRef.name');
var instance = _.get(ctrl.serviceInstances, [instanceName]);
var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(instance);
ctrl.serviceClass = _.get(ctrl.serviceClasses, [serviceClassName]);
ctrl.serviceInstance = _.get(ctrl.serviceInstances, [instanceName]);
} else {
ctrl.serviceInstance = ctrl.refApiObject;
}

var serviceClassName = ServiceInstancesService.getServiceClassNameForInstance(ctrl.serviceInstance);
ctrl.serviceClass = _.get(ctrl.serviceClasses, [serviceClassName]);
};

this.$onChanges = function(changes) {
if (changes.binding || changes.serviceInstances || changes.serviceClasses) {
updateServiceClass();
updateParameterSchema();
updateParameterData();
}
};

ctrl.toggleShowParameterValues = function() {
ctrl.showParameterValues = !ctrl.showParameterValues;
};
}
})();
23 changes: 23 additions & 0 deletions app/styles/_components.less
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,29 @@ code.command {
}
}

.service-binding-message {
margin-left: 20px;
}
.service-binding-parameters {
margin-left: 20px;
> a {
border-left: 1px solid @color-pf-black-300;
padding: 0 10px;

&:first-of-type {
border-left: 0;
}
}
.parameters-heading {
color: @color-pf-black-500;
text-transform: uppercase;
}
.parameter-title {
font-weight: 700;
text-align: right;
}
}

.service-binding-actions {
font-size: 13px;
font-weight: 400;
Expand Down
26 changes: 26 additions & 0 deletions app/styles/_core.less
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,32 @@
}

.resource-details {
.config-parameters-form {
margin-top: 5px;

.control-label {
padding-right: 0;
word-break: break-word;
}

form {
margin-top: 10px;
}

.form-group {
margin-bottom: 0;
}

.hide-show-link {
font-size: @font-size-base;
margin-left: 5px;
}

@media (min-width: @screen-lg-min) {
margin-bottom: 10px;
}
}

h3 {
border-bottom: 1px solid #eee;
padding-bottom: 10px;
Expand Down
Loading