Skip to content

Commit e89bb67

Browse files
author
OpenShift Bot
authored
Merge pull request #1935 from spadgett/canI-custom-hosts
Merged by openshift-bot
2 parents 6cd2686 + 6cc4254 commit e89bb67

File tree

7 files changed

+128
-74
lines changed

7 files changed

+128
-74
lines changed

app/scripts/directives/oscFileInput.js

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ angular.module('openshiftConsole')
88
model: "=",
99
required: "=",
1010
disabled: "=ngDisabled",
11+
readonly: "=ngReadonly",
1112
showTextArea: '=',
1213
// Hide the clear value link.
1314
hideClear: '=?',

app/scripts/directives/oscRouting.js

+34-3
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ angular.module("openshiftConsole")
3030
* An expression that will disable the form (default: false)
3131
*/
3232
.directive("oscRouting",
33-
function(Constants,
33+
function($filter,
34+
Constants,
3435
DNS1123_SUBDOMAIN_VALIDATION) {
3536
return {
3637
require: '^form',
@@ -40,7 +41,7 @@ angular.module("openshiftConsole")
4041
services: "=",
4142
showNameInput: "=",
4243
routingDisabled: "=",
43-
hostReadOnly: "="
44+
existingRoute: "="
4445
},
4546
templateUrl: 'views/directives/osc-routing.html',
4647
link: function(scope, element, attrs, formCtl) {
@@ -51,12 +52,42 @@ angular.module("openshiftConsole")
5152
alternateServices: false
5253
};
5354

55+
var customHostResource = {
56+
group: 'route.openshift.io',
57+
resource: 'routes/custom-host'
58+
};
59+
scope.canICreateCustomHosts = $filter('canI')(customHostResource, 'create');
60+
scope.canIUpdateCustomHosts = $filter('canI')(customHostResource, 'update');
61+
62+
var canISetCustomHost = function() {
63+
if (scope.existingRoute) {
64+
return scope.canIUpdateCustomHosts;
65+
}
66+
67+
return scope.canICreateCustomHosts;
68+
};
69+
70+
scope.isHostnameReadOnly = function() {
71+
return !canISetCustomHost();
72+
};
73+
5474
scope.disableWildcards = Constants.DISABLE_WILDCARD_ROUTES;
55-
scope.disableCertificateInputs = function() {
75+
76+
// Certificate updates also require custom host.
77+
scope.areCertificateInputsReadOnly = function() {
78+
return !canISetCustomHost();
79+
};
80+
81+
scope.areCertificateInputsDisabled = function() {
5682
var termination = _.get(scope, 'route.tls.termination');
5783
return !termination || termination === 'passthrough';
5884
};
5985

86+
scope.isDestinationCACertInputDisabled = function() {
87+
// This input only applies to reencrypt routes.
88+
return _.get(scope, 'route.tls.termination') !== 'reencrypt';
89+
};
90+
6091
scope.insecureTrafficOptions = [
6192
{value: '', label: 'None'},
6293
{value: 'Allow', label: 'Allow'},

app/views/directives/osc-file-input.html

+5-3
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010
readonly
1111
ng-show="supportsFileUpload"
1212
ng-disabled="disabled"
13+
ng-readonly="readonly"
1314
ng-attr-aria-describedby="{{helpText ? helpID : undefined}}">
1415
<span class="input-group-btn">
15-
<span class="btn btn-default btn-file" ng-show="supportsFileUpload" ng-attr-disabled="{{ disabled || undefined }}">
16+
<span class="btn btn-default btn-file" ng-show="supportsFileUpload" ng-attr-disabled="{{ (disabled || readonly) || undefined }}">
1617
Browse&hellip;
17-
<input type="file" ng-disabled="disabled" class="form-control">
18+
<input type="file" ng-disabled="disabled || readonly" class="form-control">
1819
</span>
1920
</span>
2021
</div>
@@ -30,11 +31,12 @@
3031
ng-model="model"
3132
ng-required="required"
3233
ng-disabled="disabled"
34+
ng-readonly="readonly"
3335
autocorrect="off"
3436
autocapitalize="none"
3537
spellcheck="false"
3638
ng-attr-aria-describedby="{{helpText ? helpID : undefined}}">
3739
</textarea>
3840

39-
<a href="" ng-show="(model || fileName) && !disabled && !hideClear" ng-click="cleanInputValues()">Clear Value</a>
41+
<a href="" ng-show="(model || fileName) && !disabled && !readonly && !hideClear" ng-click="cleanInputValues()">Clear Value</a>
4042
</div>

app/views/directives/osc-routing.html

+10-6
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
ng-model="route.host"
4949
ng-pattern="hostnamePattern"
5050
ng-maxlength="hostnameMaxLength"
51-
ng-readonly="hostReadOnly"
51+
ng-readonly="isHostnameReadOnly()"
5252
placeholder="www.example.com"
5353
autocorrect="off"
5454
autocapitalize="none"
@@ -66,7 +66,7 @@
6666
You can use <var>*.example.com</var> with routers that support wildcard subdomains.
6767
</span>
6868
</p>
69-
<p>The hostname can't be changed after the route is created.</p>
69+
<p ng-if="(existingRoute || canICreateCustomHosts) && !canIUpdateCustomHosts">The hostname can't be changed after the route is created.</p>
7070
</span>
7171
</div>
7272
<div class="has-error" ng-show="routeForm.host.$error.pattern && routeForm.host.$touched && !routingDisabled">
@@ -302,7 +302,8 @@ <h3>Certificates</h3>
302302
drop-zone-id="certificate-file"
303303
show-text-area="true"
304304
help-text="The PEM format certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipbard."
305-
ng-disabled="disableCertificateInputs()">
305+
ng-readonly="areCertificateInputsReadOnly()"
306+
ng-disabled="areCertificateInputsDisabled()">
306307
</osc-file-input>
307308
</div>
308309
<div class="form-group" id="private-key-file">
@@ -312,7 +313,8 @@ <h3>Certificates</h3>
312313
drop-zone-id="private-key-file"
313314
show-text-area="true"
314315
help-text="The PEM format key. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
315-
ng-disabled="disableCertificateInputs()">
316+
ng-readonly="areCertificateInputsReadOnly()"
317+
ng-disabled="areCertificateInputsDisabled()">
316318
</osc-file-input>
317319
</div>
318320
<div class="form-group" id="ca-certificate-file">
@@ -322,7 +324,8 @@ <h3>Certificates</h3>
322324
drop-zone-id="ca-certificate-file"
323325
show-text-area="true"
324326
help-text="The PEM format CA certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
325-
ng-disabled="disableCertificateInputs()">
327+
ng-readonly="areCertificateInputsReadOnly()"
328+
ng-disabled="areCertificateInputsDisabled()">
326329
</osc-file-input>
327330
</div>
328331
<div class="form-group" id="dest-ca-certificate-file">
@@ -332,7 +335,8 @@ <h3>Certificates</h3>
332335
show-text-area="true"
333336
drop-zone-id="dest-ca-certificate-file"
334337
help-text="The PEM format CA certificate to validate the endpoint certificate for re-encrypt termination. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
335-
ng-disabled="route.tls.termination !== 'reencrypt'">
338+
ng-readonly="areCertificateInputsReadOnly()"
339+
ng-disabled="isDestinationCACertInputDisabled()">
336340
</osc-file-input>
337341
<!-- Show a warning if the value won't be used, but only if we're
338342
not already showing the generic certificate warning above. -->

app/views/edit/route.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ <h1>Edit Route {{routeName}}</h1>
2222
model="routing"
2323
services="services"
2424
show-name-input="false"
25-
host-read-only="true">
25+
existing-route="true">
2626
</osc-routing>
2727
<div class="button-group gutter-top gutter-bottom">
2828
<button type="submit"

dist/scripts/scripts.js

+65-49
Original file line numberDiff line numberDiff line change
@@ -9224,6 +9224,7 @@ scope: {
92249224
model: "=",
92259225
required: "=",
92269226
disabled: "=ngDisabled",
9227+
readonly: "=ngReadonly",
92279228
showTextArea: "=",
92289229
hideClear: "=?",
92299230
helpText: "@?",
@@ -9347,7 +9348,7 @@ tag: "="
93479348
},
93489349
templateUrl: "views/directives/osc-image-summary.html"
93499350
};
9350-
}), angular.module("openshiftConsole").directive("oscRouting", [ "Constants", "DNS1123_SUBDOMAIN_VALIDATION", function(e, t) {
9351+
}), angular.module("openshiftConsole").directive("oscRouting", [ "$filter", "Constants", "DNS1123_SUBDOMAIN_VALIDATION", function(e, t, n) {
93519352
return {
93529353
require: "^form",
93539354
restrict: "E",
@@ -9356,17 +9357,32 @@ route: "=model",
93569357
services: "=",
93579358
showNameInput: "=",
93589359
routingDisabled: "=",
9359-
hostReadOnly: "="
9360+
existingRoute: "="
93609361
},
93619362
templateUrl: "views/directives/osc-routing.html",
9362-
link: function(n, a, r, o) {
9363-
n.form = o, n.controls = {}, n.options = {
9363+
link: function(a, r, o, i) {
9364+
a.form = i, a.controls = {}, a.options = {
93649365
secureRoute: !1,
93659366
alternateServices: !1
9366-
}, n.disableWildcards = e.DISABLE_WILDCARD_ROUTES, n.disableCertificateInputs = function() {
9367-
var e = _.get(n, "route.tls.termination");
9367+
};
9368+
var s = {
9369+
group: "route.openshift.io",
9370+
resource: "routes/custom-host"
9371+
};
9372+
a.canICreateCustomHosts = e("canI")(s, "create"), a.canIUpdateCustomHosts = e("canI")(s, "update");
9373+
var c = function() {
9374+
return a.existingRoute ? a.canIUpdateCustomHosts : a.canICreateCustomHosts;
9375+
};
9376+
a.isHostnameReadOnly = function() {
9377+
return !c();
9378+
}, a.disableWildcards = t.DISABLE_WILDCARD_ROUTES, a.areCertificateInputsReadOnly = function() {
9379+
return !c();
9380+
}, a.areCertificateInputsDisabled = function() {
9381+
var e = _.get(a, "route.tls.termination");
93689382
return !e || "passthrough" === e;
9369-
}, n.insecureTrafficOptions = [ {
9383+
}, a.isDestinationCACertInputDisabled = function() {
9384+
return "reencrypt" !== _.get(a, "route.tls.termination");
9385+
}, a.insecureTrafficOptions = [ {
93709386
value: "",
93719387
label: "None"
93729388
}, {
@@ -9375,73 +9391,73 @@ label: "Allow"
93759391
}, {
93769392
value: "Redirect",
93779393
label: "Redirect"
9378-
} ], _.has(n, "route.tls.insecureEdgeTerminationPolicy") || _.set(n, "route.tls.insecureEdgeTerminationPolicy", "");
9379-
n.$watchGroup([ "route.tls.termination", "route.tls.insecureEdgeTerminationPolicy" ], function() {
9380-
var e = "passthrough" !== _.get(n, "route.tls.termination") || "Allow" !== _.get(n, "route.tls.insecureEdgeTerminationPolicy");
9381-
n.routeForm.insecureTraffic.$setValidity("passthrough", e);
9382-
}), n.nameValidation = t, n.disableWildcards ? n.hostnamePattern = t.pattern : n.hostnamePattern = /^(\*(\.[a-z0-9]([-a-z0-9]*[a-z0-9]))+|[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)$/, n.hostnameMaxLength = t.maxlength;
9383-
var i = function(e) {
9394+
} ], _.has(a, "route.tls.insecureEdgeTerminationPolicy") || _.set(a, "route.tls.insecureEdgeTerminationPolicy", "");
9395+
a.$watchGroup([ "route.tls.termination", "route.tls.insecureEdgeTerminationPolicy" ], function() {
9396+
var e = "passthrough" !== _.get(a, "route.tls.termination") || "Allow" !== _.get(a, "route.tls.insecureEdgeTerminationPolicy");
9397+
a.routeForm.insecureTraffic.$setValidity("passthrough", e);
9398+
}), a.nameValidation = n, a.disableWildcards ? a.hostnamePattern = n.pattern : a.hostnamePattern = /^(\*(\.[a-z0-9]([-a-z0-9]*[a-z0-9]))+|[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*)$/, a.hostnameMaxLength = n.maxlength;
9399+
var l = function(e) {
93849400
if (e) {
93859401
var t = _.get(e, "spec.ports", []);
9386-
n.unnamedServicePort = 1 === t.length && !t[0].name, t.length && !n.unnamedServicePort ? n.route.portOptions = _.map(t, function(e) {
9402+
a.unnamedServicePort = 1 === t.length && !t[0].name, t.length && !a.unnamedServicePort ? a.route.portOptions = _.map(t, function(e) {
93879403
return {
93889404
port: e.name,
93899405
label: e.port + " → " + e.targetPort + " (" + e.protocol + ")"
93909406
};
9391-
}) : n.route.portOptions = [];
9407+
}) : a.route.portOptions = [];
93929408
}
93939409
};
9394-
n.services && !n.route.service && (n.route.service = _.find(n.services)), n.servicesByName, n.services ? n.servicesByName = _.keyBy(n.services, "metadata.name") : n.servicesByName = {}, n.$watch("route.to.name", function(e, t) {
9395-
i(n.servicesByName[e]), e === t && n.route.targetPort || (n.route.targetPort = _.get(n, "route.portOptions[0].port")), n.services && (n.alternateServiceOptions = _.reject(n.services, function(t) {
9410+
a.services && !a.route.service && (a.route.service = _.find(a.services)), a.servicesByName, a.services ? a.servicesByName = _.keyBy(a.services, "metadata.name") : a.servicesByName = {}, a.$watch("route.to.name", function(e, t) {
9411+
l(a.servicesByName[e]), e === t && a.route.targetPort || (a.route.targetPort = _.get(a, "route.portOptions[0].port")), a.services && (a.alternateServiceOptions = _.reject(a.services, function(t) {
93969412
return e === t.metadata.name;
93979413
}));
9398-
}), n.$watch("route.alternateServices", function(e) {
9399-
n.duplicateServices = _(e).map("name").filter(function(e, t, n) {
9414+
}), a.$watch("route.alternateServices", function(e) {
9415+
a.duplicateServices = _(e).map("name").filter(function(e, t, n) {
94009416
return _.includes(n, e, t + 1);
9401-
}).value(), o.$setValidity("duplicateServices", !n.duplicateServices.length), n.options.alternateServices = !_.isEmpty(e);
9417+
}).value(), i.$setValidity("duplicateServices", !a.duplicateServices.length), a.options.alternateServices = !_.isEmpty(e);
94029418
}, !0);
9403-
var s = function() {
9404-
return !!n.route.tls && ((!n.route.tls.termination || "passthrough" === n.route.tls.termination) && (n.route.tls.certificate || n.route.tls.key || n.route.tls.caCertificate || n.route.tls.destinationCACertificate));
9419+
var u = function() {
9420+
return !!a.route.tls && ((!a.route.tls.termination || "passthrough" === a.route.tls.termination) && (a.route.tls.certificate || a.route.tls.key || a.route.tls.caCertificate || a.route.tls.destinationCACertificate));
94059421
};
9406-
n.$watch("route.tls.termination", function() {
9407-
n.options.secureRoute = !!_.get(n, "route.tls.termination"), n.showCertificatesNotUsedWarning = s();
9422+
a.$watch("route.tls.termination", function() {
9423+
a.options.secureRoute = !!_.get(a, "route.tls.termination"), a.showCertificatesNotUsedWarning = u();
94089424
});
9409-
var c;
9410-
n.$watch("options.secureRoute", function(e, t) {
9425+
var d;
9426+
a.$watch("options.secureRoute", function(e, t) {
94119427
if (e !== t) {
9412-
var a = _.get(n, "route.tls.termination");
9413-
!n.securetRoute && a && (c = a, delete n.route.tls.termination), n.options.secureRoute && !a && _.set(n, "route.tls.termination", c || "edge");
9414-
}
9415-
}), n.$watch("options.alternateServices", function(e, t) {
9416-
e !== t && (e || (n.route.alternateServices = []), e && _.isEmpty(n.route.alternateServices) && n.addAlternateService());
9417-
}), n.addAlternateService = function() {
9418-
n.route.alternateServices = n.route.alternateServices || [];
9419-
var e = _.find(n.services, function(e) {
9420-
return e.metadata.name !== n.route.to.service && !_.some(n.route.alternateServices, {
9428+
var n = _.get(a, "route.tls.termination");
9429+
!a.securetRoute && n && (d = n, delete a.route.tls.termination), a.options.secureRoute && !n && _.set(a, "route.tls.termination", d || "edge");
9430+
}
9431+
}), a.$watch("options.alternateServices", function(e, t) {
9432+
e !== t && (e || (a.route.alternateServices = []), e && _.isEmpty(a.route.alternateServices) && a.addAlternateService());
9433+
}), a.addAlternateService = function() {
9434+
a.route.alternateServices = a.route.alternateServices || [];
9435+
var e = _.find(a.services, function(e) {
9436+
return e.metadata.name !== a.route.to.service && !_.some(a.route.alternateServices, {
94219437
service: e.metadata.name
94229438
});
94239439
});
9424-
_.has(n, "route.to.weight") || _.set(n, "route.to.weight", 1), n.route.alternateServices.push({
9440+
_.has(a, "route.to.weight") || _.set(a, "route.to.weight", 1), a.route.alternateServices.push({
94259441
service: e.metadata.name,
94269442
weight: 1
94279443
});
9428-
}, n.weightAsPercentage = function(e, t) {
9444+
}, a.weightAsPercentage = function(e, t) {
94299445
e = e || 0;
9430-
var a = _.get(n, "route.to.weight", 0);
9431-
if (_.each(n.route.alternateServices, function(e) {
9432-
a += _.get(e, "weight", 0);
9433-
}), !a) return "";
9434-
var r = e / a * 100;
9446+
var n = _.get(a, "route.to.weight", 0);
9447+
if (_.each(a.route.alternateServices, function(e) {
9448+
n += _.get(e, "weight", 0);
9449+
}), !n) return "";
9450+
var r = e / n * 100;
94359451
return t ? d3.round(r, 1) + "%" : r;
94369452
};
9437-
var l = !1;
9438-
n.$watch("route.alternateServices.length", function(e) {
9439-
if (0 === e && _.has(n, "route.to.weight") && delete n.route.to.weight, 1 === e) {
9440-
if (0 === n.route.to.weight && 0 === n.route.alternateServices[0].weight) return void (n.controls.hideSlider = !0);
9441-
l = !0, n.controls.rangeSlider = n.weightAsPercentage(n.route.to.weight);
9453+
var m = !1;
9454+
a.$watch("route.alternateServices.length", function(e) {
9455+
if (0 === e && _.has(a, "route.to.weight") && delete a.route.to.weight, 1 === e) {
9456+
if (0 === a.route.to.weight && 0 === a.route.alternateServices[0].weight) return void (a.controls.hideSlider = !0);
9457+
m = !0, a.controls.rangeSlider = a.weightAsPercentage(a.route.to.weight);
94429458
}
9443-
}), n.$watch("controls.rangeSlider", function(e, t) {
9444-
l ? l = !1 : e !== t && (e = parseInt(e, 10), _.set(n, "route.to.weight", e), _.set(n, "route.alternateServices[0].weight", 100 - e));
9459+
}), a.$watch("controls.rangeSlider", function(e, t) {
9460+
m ? m = !1 : e !== t && (e = parseInt(e, 10), _.set(a, "route.to.weight", e), _.set(a, "route.alternateServices[0].weight", 100 - e));
94459461
});
94469462
}
94479463
};

0 commit comments

Comments
 (0)