forked from openshift/origin-web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoscRouting.js
117 lines (107 loc) · 4.05 KB
/
oscRouting.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
"use strict";
angular.module("openshiftConsole")
/**
* Widget for entering route information
*
* model:
* The model for the input. The model will either use or add the following keys:
* {
* name: "",
* host: "",
* path: "",
* service: {}, // selected service object if services passed to directive
* tls.termination: "",
* tls.insecureEdgeTerminationPolicy: "",
* tls.certificate: "",
* tls.key: "",
* tls.caCertificate: "",
* tls.destinationCACertificate: ""
* }
*
* services:
* Collection of services to choose from for the route (optional)
*
* showNameInput:
* Whether to prompt the user for a route name (default: false)
*
* routingDisabled:
* An expression that will disable the form (default: false)
*/
.directive("oscRouting", function(){
return {
require: '^form',
restrict: 'E',
scope: {
route: "=model",
services: "=",
showNameInput: "=",
routingDisabled: "="
},
templateUrl: 'views/directives/osc-routing.html',
controller: function($scope) {
$scope.disableCertificateInputs = function() {
var termination = _.get($scope, 'route.tls.termination');
return !termination || termination === 'passthrough';
};
},
link: function(scope, element, attrs, formCtl){
scope.form = formCtl;
var updatePortOptions = function(service) {
if (!service) {
return;
}
scope.unnamedServicePort = service.spec.ports.length === 1 && !service.spec.ports[0].name;
// Only show port options when there is more than one port or when a
// single service port has a name. We want to use the service port
// name when creating a route. (Port name is required for services
// with more than one port.)
if (service.spec.ports.length && !scope.unnamedServicePort) {
scope.route.portOptions = _.map(service.spec.ports, function(portMapping) {
return {
port: portMapping.name,
// \u2192 is a Unicode right arrow.
label: portMapping.port + " \u2192 " +
portMapping.targetPort + " (" + portMapping.protocol + ")"
};
});
} else {
scope.route.portOptions = [];
}
};
if (scope.services && !scope.route.service) {
// Use _.find to get the first item.
scope.route.service = _.find(scope.services);
}
scope.$watch('route.service', function(newValue, oldValue) {
updatePortOptions(scope.route.service);
// Don't overwrite the target port when editing an existing route unless the user picked a
// different service.
if (newValue !== oldValue || !scope.route.targetPort) {
scope.route.targetPort = _.get(scope, 'route.portOptions[0].port');
}
});
var showCertificateWarning = function() {
if (!scope.route.tls) {
return false;
}
if (scope.route.tls.termination && scope.route.tls.termination !== 'passthrough') {
return false;
}
// Check if any certificate or key is set with an incompatible termination.
return scope.route.tls.certificate ||
scope.route.tls.key ||
scope.route.tls.caCertificate ||
scope.route.tls.destinationCACertificate;
};
// Show a warning if previously-set certificates won't be used because
// the TLS termination is now incompatible.
scope.$watch('route.tls.termination', function() {
if (_.get(scope, 'route.tls.termination')) {
// If editing a route with TLS termination already set, expand the secure route options.
scope.showSecureRouteOptions = true;
}
scope.showCertificatesNotUsedWarning = showCertificateWarning();
});
}
};
});