This repository has been archived by the owner on Dec 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use MARATHON_SCHEME_PORT label to define scheme of a given port
The links in the tasks view use the same scheme as the Marathon UI web application but in some cases users expose a service with a different scheme on a given port. In order to correctly redirect the user clicking on the link of a given port, one can use MARATHON_SCHEME_PORT and MARATHON_SCHEME_PORT<N> labels to define the scheme of the all the ports and/or the scheme of port with index N. The available values for those labels are 'http' and 'https'. If no label is provided, the scheme is the same as Marathon UI scheme to avoid breaking compatibility.
- Loading branch information
1 parent
cee3b3d
commit b51c1d2
Showing
7 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
const BASE_SCHEME_LABEL = "MARATHON_SCHEME_PORT"; | ||
|
||
var ServiceSchemeUtil = { | ||
/* | ||
* Returns service scheme of the n-th port. | ||
* | ||
* Given N a port index, if `MARATHON_SCHEME_PORT<N>` is | ||
* in the set of labels, then the function returns the value | ||
* of this label. | ||
* | ||
* Given N a port index, if `MARATHON_SCHEME_PORT0<N>` is | ||
* not in the set of labels, then the value associated with | ||
* `MARATHON_SCHEME_PORT` is returned. | ||
* | ||
* Given N a port index, if `MARATHON_SCHEME_PORT0<N>` and | ||
* `MARATHON_SCHEME_PORT` are not in the set of labels, the | ||
* function returns the `http` as the default scheme. | ||
*/ | ||
getServiceSchemeFromLabels(labels, n) { | ||
function getScheme(labelValue) { | ||
return (labelValue === "http" || labelValue === "https") | ||
? labelValue | ||
: ''; | ||
} | ||
|
||
const labelKey = ("" + BASE_SCHEME_LABEL + n); | ||
if (labels && labelKey in labels) | ||
return getScheme(labels[labelKey]); | ||
else if (labels && BASE_SCHEME_LABEL in labels) | ||
return getScheme(labels[BASE_SCHEME_LABEL]); | ||
|
||
return ''; | ||
} | ||
}; | ||
|
||
export default ServiceSchemeUtil; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import {expect} from "chai"; | ||
import ServiceSchemeUtil from "../../js/helpers/ServiceSchemeUtil"; | ||
|
||
function verifyPortSchemeWithDefault(serviceScheme, serviceScheme0, | ||
expectedSchemePort0, expectedSchemePort1) { | ||
describe("MARATHON_SCHEME_PORT is set to " + serviceScheme, function() { | ||
describe("MARATHON_SCHEME_PORT0 is set to " + serviceScheme0, function() { | ||
it("detect scheme of port 0", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT": serviceScheme, | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 0)).to.eq(expectedSchemePort0); | ||
}); | ||
|
||
it("detect scheme of port 1", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT": serviceScheme, | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 1)).to.eq(expectedSchemePort1); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
function verifyPortSchemeWithoutDefault(serviceScheme0, | ||
expectedSchemePort0, expectedSchemePort1) { | ||
describe("MARATHON_SCHEME_PORT is not set", function() { | ||
describe("MARATHON_SCHEME_PORT0 is set to " + serviceScheme0, function() { | ||
it("detect scheme of port 0", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 0)).to.eq(expectedSchemePort0); | ||
}); | ||
|
||
it("detect scheme of port 1", function() { | ||
expect(ServiceSchemeUtil.getServiceSchemeFromLabels({ | ||
"MARATHON_SCHEME_PORT0": serviceScheme0, | ||
}, 1)).to.eq(expectedSchemePort1); | ||
}); | ||
}); | ||
}); | ||
} | ||
|
||
describe("ServiceSchemeUtil", function () { | ||
// default scheme scheme port 0 expected port 0 expected port 1 | ||
verifyPortSchemeWithDefault("http", "http", "http", "http"); | ||
verifyPortSchemeWithDefault("http", "https", "https", "http"); | ||
verifyPortSchemeWithDefault("https", "http", "http", "https"); | ||
verifyPortSchemeWithDefault("https", "https", "https", "https"); | ||
|
||
// scheme port 0 expected port 0 expected port 1 | ||
verifyPortSchemeWithoutDefault("http", "http", ""); | ||
verifyPortSchemeWithoutDefault("https", "https", ""); | ||
verifyPortSchemeWithoutDefault("http", "http", ""); | ||
verifyPortSchemeWithoutDefault("https", "https", ""); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters