Skip to content

Add canI checks for route custom hosts #1935

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
Aug 15, 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
1 change: 1 addition & 0 deletions app/scripts/directives/oscFileInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ angular.module('openshiftConsole')
model: "=",
required: "=",
disabled: "=ngDisabled",
readonly: "=ngReadonly",
showTextArea: '=',
// Hide the clear value link.
hideClear: '=?',
Expand Down
37 changes: 34 additions & 3 deletions app/scripts/directives/oscRouting.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ angular.module("openshiftConsole")
* An expression that will disable the form (default: false)
*/
.directive("oscRouting",
function(Constants,
function($filter,
Constants,
DNS1123_SUBDOMAIN_VALIDATION) {
return {
require: '^form',
Expand All @@ -40,7 +41,7 @@ angular.module("openshiftConsole")
services: "=",
showNameInput: "=",
routingDisabled: "=",
hostReadOnly: "="
existingRoute: "="
},
templateUrl: 'views/directives/osc-routing.html',
link: function(scope, element, attrs, formCtl) {
Expand All @@ -51,12 +52,42 @@ angular.module("openshiftConsole")
alternateServices: false
};

var customHostResource = {
group: 'route.openshift.io',
resource: 'routes/custom-host'
};
scope.canICreateCustomHosts = $filter('canI')(customHostResource, 'create');
scope.canIUpdateCustomHosts = $filter('canI')(customHostResource, 'update');

var canISetCustomHost = function() {
if (scope.existingRoute) {
return scope.canIUpdateCustomHosts;
}

return scope.canICreateCustomHosts;
};

scope.isHostnameReadOnly = function() {
return !canISetCustomHost();
};

scope.disableWildcards = Constants.DISABLE_WILDCARD_ROUTES;
scope.disableCertificateInputs = function() {

// Certificate updates also require custom host.
scope.areCertificateInputsReadOnly = function() {
return !canISetCustomHost();
};

scope.areCertificateInputsDisabled = function() {
var termination = _.get(scope, 'route.tls.termination');
return !termination || termination === 'passthrough';
};

scope.isDestinationCACertInputDisabled = function() {
// This input only applies to reencrypt routes.
return _.get(scope, 'route.tls.termination') !== 'reencrypt';
};

scope.insecureTrafficOptions = [
{value: '', label: 'None'},
{value: 'Allow', label: 'Allow'},
Expand Down
8 changes: 5 additions & 3 deletions app/views/directives/osc-file-input.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@
readonly
ng-show="supportsFileUpload"
ng-disabled="disabled"
ng-readonly="readonly"
ng-attr-aria-describedby="{{helpText ? helpID : undefined}}">
<span class="input-group-btn">
<span class="btn btn-default btn-file" ng-show="supportsFileUpload" ng-attr-disabled="{{ disabled || undefined }}">
<span class="btn btn-default btn-file" ng-show="supportsFileUpload" ng-attr-disabled="{{ (disabled || readonly) || undefined }}">
Browse&hellip;
<input type="file" ng-disabled="disabled" class="form-control">
<input type="file" ng-disabled="disabled || readonly" class="form-control">
</span>
</span>
</div>
Expand All @@ -30,11 +31,12 @@
ng-model="model"
ng-required="required"
ng-disabled="disabled"
ng-readonly="readonly"
autocorrect="off"
autocapitalize="none"
spellcheck="false"
ng-attr-aria-describedby="{{helpText ? helpID : undefined}}">
</textarea>

<a href="" ng-show="(model || fileName) && !disabled && !hideClear" ng-click="cleanInputValues()">Clear Value</a>
<a href="" ng-show="(model || fileName) && !disabled && !readonly && !hideClear" ng-click="cleanInputValues()">Clear Value</a>
</div>
16 changes: 10 additions & 6 deletions app/views/directives/osc-routing.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
ng-model="route.host"
ng-pattern="hostnamePattern"
ng-maxlength="hostnameMaxLength"
ng-readonly="hostReadOnly"
ng-readonly="isHostnameReadOnly()"
placeholder="www.example.com"
autocorrect="off"
autocapitalize="none"
Expand All @@ -66,7 +66,7 @@
You can use <var>*.example.com</var> with routers that support wildcard subdomains.
</span>
</p>
<p>The hostname can't be changed after the route is created.</p>
<p ng-if="(existingRoute || canICreateCustomHosts) && !canIUpdateCustomHosts">The hostname can't be changed after the route is created.</p>
</span>
</div>
<div class="has-error" ng-show="routeForm.host.$error.pattern && routeForm.host.$touched && !routingDisabled">
Expand Down Expand Up @@ -302,7 +302,8 @@ <h3>Certificates</h3>
drop-zone-id="certificate-file"
show-text-area="true"
help-text="The PEM format certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipbard."
ng-disabled="disableCertificateInputs()">
ng-readonly="areCertificateInputsReadOnly()"
ng-disabled="areCertificateInputsDisabled()">
</osc-file-input>
</div>
<div class="form-group" id="private-key-file">
Expand All @@ -312,7 +313,8 @@ <h3>Certificates</h3>
drop-zone-id="private-key-file"
show-text-area="true"
help-text="The PEM format key. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
ng-disabled="disableCertificateInputs()">
ng-readonly="areCertificateInputsReadOnly()"
ng-disabled="areCertificateInputsDisabled()">
</osc-file-input>
</div>
<div class="form-group" id="ca-certificate-file">
Expand All @@ -322,7 +324,8 @@ <h3>Certificates</h3>
drop-zone-id="ca-certificate-file"
show-text-area="true"
help-text="The PEM format CA certificate. Upload file by dragging & dropping, selecting it, or pasting from the clipboard."
ng-disabled="disableCertificateInputs()">
ng-readonly="areCertificateInputsReadOnly()"
ng-disabled="areCertificateInputsDisabled()">
</osc-file-input>
</div>
<div class="form-group" id="dest-ca-certificate-file">
Expand All @@ -332,7 +335,8 @@ <h3>Certificates</h3>
show-text-area="true"
drop-zone-id="dest-ca-certificate-file"
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."
ng-disabled="route.tls.termination !== 'reencrypt'">
ng-readonly="areCertificateInputsReadOnly()"
ng-disabled="isDestinationCACertInputDisabled()">
</osc-file-input>
<!-- Show a warning if the value won't be used, but only if we're
not already showing the generic certificate warning above. -->
Expand Down
2 changes: 1 addition & 1 deletion app/views/edit/route.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>Edit Route {{routeName}}</h1>
model="routing"
services="services"
show-name-input="false"
host-read-only="true">
existing-route="true">
</osc-routing>
<div class="button-group gutter-top gutter-bottom">
<button type="submit"
Expand Down
114 changes: 65 additions & 49 deletions dist/scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -9224,6 +9224,7 @@ scope: {
model: "=",
required: "=",
disabled: "=ngDisabled",
readonly: "=ngReadonly",
showTextArea: "=",
hideClear: "=?",
helpText: "@?",
Expand Down Expand Up @@ -9347,7 +9348,7 @@ tag: "="
},
templateUrl: "views/directives/osc-image-summary.html"
};
}), angular.module("openshiftConsole").directive("oscRouting", [ "Constants", "DNS1123_SUBDOMAIN_VALIDATION", function(e, t) {
}), angular.module("openshiftConsole").directive("oscRouting", [ "$filter", "Constants", "DNS1123_SUBDOMAIN_VALIDATION", function(e, t, n) {
return {
require: "^form",
restrict: "E",
Expand All @@ -9356,17 +9357,32 @@ route: "=model",
services: "=",
showNameInput: "=",
routingDisabled: "=",
hostReadOnly: "="
existingRoute: "="
},
templateUrl: "views/directives/osc-routing.html",
link: function(n, a, r, o) {
n.form = o, n.controls = {}, n.options = {
link: function(a, r, o, i) {
a.form = i, a.controls = {}, a.options = {
secureRoute: !1,
alternateServices: !1
}, n.disableWildcards = e.DISABLE_WILDCARD_ROUTES, n.disableCertificateInputs = function() {
var e = _.get(n, "route.tls.termination");
};
var s = {
group: "route.openshift.io",
resource: "routes/custom-host"
};
a.canICreateCustomHosts = e("canI")(s, "create"), a.canIUpdateCustomHosts = e("canI")(s, "update");
var c = function() {
return a.existingRoute ? a.canIUpdateCustomHosts : a.canICreateCustomHosts;
};
a.isHostnameReadOnly = function() {
return !c();
}, a.disableWildcards = t.DISABLE_WILDCARD_ROUTES, a.areCertificateInputsReadOnly = function() {
return !c();
}, a.areCertificateInputsDisabled = function() {
var e = _.get(a, "route.tls.termination");
return !e || "passthrough" === e;
}, n.insecureTrafficOptions = [ {
}, a.isDestinationCACertInputDisabled = function() {
return "reencrypt" !== _.get(a, "route.tls.termination");
}, a.insecureTrafficOptions = [ {
value: "",
label: "None"
}, {
Expand All @@ -9375,73 +9391,73 @@ label: "Allow"
}, {
value: "Redirect",
label: "Redirect"
} ], _.has(n, "route.tls.insecureEdgeTerminationPolicy") || _.set(n, "route.tls.insecureEdgeTerminationPolicy", "");
n.$watchGroup([ "route.tls.termination", "route.tls.insecureEdgeTerminationPolicy" ], function() {
var e = "passthrough" !== _.get(n, "route.tls.termination") || "Allow" !== _.get(n, "route.tls.insecureEdgeTerminationPolicy");
n.routeForm.insecureTraffic.$setValidity("passthrough", e);
}), 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;
var i = function(e) {
} ], _.has(a, "route.tls.insecureEdgeTerminationPolicy") || _.set(a, "route.tls.insecureEdgeTerminationPolicy", "");
a.$watchGroup([ "route.tls.termination", "route.tls.insecureEdgeTerminationPolicy" ], function() {
var e = "passthrough" !== _.get(a, "route.tls.termination") || "Allow" !== _.get(a, "route.tls.insecureEdgeTerminationPolicy");
a.routeForm.insecureTraffic.$setValidity("passthrough", e);
}), 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;
var l = function(e) {
if (e) {
var t = _.get(e, "spec.ports", []);
n.unnamedServicePort = 1 === t.length && !t[0].name, t.length && !n.unnamedServicePort ? n.route.portOptions = _.map(t, function(e) {
a.unnamedServicePort = 1 === t.length && !t[0].name, t.length && !a.unnamedServicePort ? a.route.portOptions = _.map(t, function(e) {
return {
port: e.name,
label: e.port + " → " + e.targetPort + " (" + e.protocol + ")"
};
}) : n.route.portOptions = [];
}) : a.route.portOptions = [];
}
};
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) {
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) {
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) {
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) {
return e === t.metadata.name;
}));
}), n.$watch("route.alternateServices", function(e) {
n.duplicateServices = _(e).map("name").filter(function(e, t, n) {
}), a.$watch("route.alternateServices", function(e) {
a.duplicateServices = _(e).map("name").filter(function(e, t, n) {
return _.includes(n, e, t + 1);
}).value(), o.$setValidity("duplicateServices", !n.duplicateServices.length), n.options.alternateServices = !_.isEmpty(e);
}).value(), i.$setValidity("duplicateServices", !a.duplicateServices.length), a.options.alternateServices = !_.isEmpty(e);
}, !0);
var s = function() {
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));
var u = function() {
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));
};
n.$watch("route.tls.termination", function() {
n.options.secureRoute = !!_.get(n, "route.tls.termination"), n.showCertificatesNotUsedWarning = s();
a.$watch("route.tls.termination", function() {
a.options.secureRoute = !!_.get(a, "route.tls.termination"), a.showCertificatesNotUsedWarning = u();
});
var c;
n.$watch("options.secureRoute", function(e, t) {
var d;
a.$watch("options.secureRoute", function(e, t) {
if (e !== t) {
var a = _.get(n, "route.tls.termination");
!n.securetRoute && a && (c = a, delete n.route.tls.termination), n.options.secureRoute && !a && _.set(n, "route.tls.termination", c || "edge");
}
}), n.$watch("options.alternateServices", function(e, t) {
e !== t && (e || (n.route.alternateServices = []), e && _.isEmpty(n.route.alternateServices) && n.addAlternateService());
}), n.addAlternateService = function() {
n.route.alternateServices = n.route.alternateServices || [];
var e = _.find(n.services, function(e) {
return e.metadata.name !== n.route.to.service && !_.some(n.route.alternateServices, {
var n = _.get(a, "route.tls.termination");
!a.securetRoute && n && (d = n, delete a.route.tls.termination), a.options.secureRoute && !n && _.set(a, "route.tls.termination", d || "edge");
}
}), a.$watch("options.alternateServices", function(e, t) {
e !== t && (e || (a.route.alternateServices = []), e && _.isEmpty(a.route.alternateServices) && a.addAlternateService());
}), a.addAlternateService = function() {
a.route.alternateServices = a.route.alternateServices || [];
var e = _.find(a.services, function(e) {
return e.metadata.name !== a.route.to.service && !_.some(a.route.alternateServices, {
service: e.metadata.name
});
});
_.has(n, "route.to.weight") || _.set(n, "route.to.weight", 1), n.route.alternateServices.push({
_.has(a, "route.to.weight") || _.set(a, "route.to.weight", 1), a.route.alternateServices.push({
service: e.metadata.name,
weight: 1
});
}, n.weightAsPercentage = function(e, t) {
}, a.weightAsPercentage = function(e, t) {
e = e || 0;
var a = _.get(n, "route.to.weight", 0);
if (_.each(n.route.alternateServices, function(e) {
a += _.get(e, "weight", 0);
}), !a) return "";
var r = e / a * 100;
var n = _.get(a, "route.to.weight", 0);
if (_.each(a.route.alternateServices, function(e) {
n += _.get(e, "weight", 0);
}), !n) return "";
var r = e / n * 100;
return t ? d3.round(r, 1) + "%" : r;
};
var l = !1;
n.$watch("route.alternateServices.length", function(e) {
if (0 === e && _.has(n, "route.to.weight") && delete n.route.to.weight, 1 === e) {
if (0 === n.route.to.weight && 0 === n.route.alternateServices[0].weight) return void (n.controls.hideSlider = !0);
l = !0, n.controls.rangeSlider = n.weightAsPercentage(n.route.to.weight);
var m = !1;
a.$watch("route.alternateServices.length", function(e) {
if (0 === e && _.has(a, "route.to.weight") && delete a.route.to.weight, 1 === e) {
if (0 === a.route.to.weight && 0 === a.route.alternateServices[0].weight) return void (a.controls.hideSlider = !0);
m = !0, a.controls.rangeSlider = a.weightAsPercentage(a.route.to.weight);
}
}), n.$watch("controls.rangeSlider", function(e, t) {
l ? l = !1 : e !== t && (e = parseInt(e, 10), _.set(n, "route.to.weight", e), _.set(n, "route.alternateServices[0].weight", 100 - e));
}), a.$watch("controls.rangeSlider", function(e, t) {
m ? m = !1 : e !== t && (e = parseInt(e, 10), _.set(a, "route.to.weight", e), _.set(a, "route.alternateServices[0].weight", 100 - e));
});
}
};
Expand Down
Loading