Skip to content
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

UI: Add IPv6 bracket-wrapping to network serializer #6007

Merged
merged 5 commits into from
Jul 30, 2019
Merged
Show file tree
Hide file tree
Changes from 3 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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ IMPROVEMENTS:
* metrics: Added namespace label as appropriate to metrics [[GH-5847](https://github.com/hashicorp/nomad/issues/5847)]
* ui: Added page titles [[GH-5924](https://github.com/hashicorp/nomad/pull/5924)]
backspace marked this conversation as resolved.
Show resolved Hide resolved
* ui: Added buttons to copy client and allocation UUIDs [[GH-5926](https://github.com/hashicorp/nomad/pull/5926)]
* ui: Fixed links containing IPv6 addresses to include required square brackets [[GH-6007](https://github.com/hashicorp/nomad/pull/6007)]
* ui: Moved client status, draining, and eligibility fields into single state column [[GH-5789](https://github.com/hashicorp/nomad/pull/5789)]

BUG FIXES:
Expand Down
11 changes: 11 additions & 0 deletions ui/app/serializers/network.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,20 @@
import ApplicationSerializer from './application';
import isIp from 'is-ip';

export default ApplicationSerializer.extend({
attrs: {
cidr: 'CIDR',
ip: 'IP',
mbits: 'MBits',
},

normalize(typeHash, hash) {
const ip = hash.IP;

if (isIp.v6(ip)) {
hash.IP = `[${ip}]`;
}

return this._super(...arguments);
},
});
1 change: 1 addition & 0 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@
"flat": "^4.0.0",
"fuse.js": "^3.4.4",
"husky": "^1.3.1",
"is-ip": "^3.1.0",
"ivy-codemirror": "^2.1.0",
"lint-staged": "^8.1.5",
"loader.js": "^4.7.0",
Expand Down
31 changes: 31 additions & 0 deletions ui/tests/unit/serializers/network-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
import NetworkModel from 'nomad-ui/models/network';

module('Unit | Serializer | Network', function(hooks) {
setupTest(hooks);
hooks.beforeEach(function() {
this.store = this.owner.lookup('service:store');
this.subject = () => this.store.serializerFor('network');
});

test('v4 IPs are passed through', async function(assert) {
const ip = '10.0.13.12';
const original = {
IP: ip,
};

const { data } = this.subject().normalize(NetworkModel, original);
assert.equal(data.attributes.ip, ip);
});

test('v6 IPs are wrapped in square brackets', async function(assert) {
const ip = '2001:0dac:aba3:0000:0000:8a2e:0370:7334';
const original = {
IP: ip,
};

const { data } = this.subject().normalize(NetworkModel, original);
assert.equal(data.attributes.ip, `[${ip}]`);
});
});
12 changes: 12 additions & 0 deletions ui/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6569,6 +6569,11 @@ invert-kv@^1.0.0:
resolved "https://registry.yarnpkg.com/invert-kv/-/invert-kv-1.0.0.tgz#104a8e4aaca6d3d8cd157a8ef8bfab2d7a3ffdb6"
integrity sha1-EEqOSqym09jNFXqO+L+rLXo//bY=

ip-regex@^4.0.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/ip-regex/-/ip-regex-4.1.0.tgz#5ad62f685a14edb421abebc2fff8db94df67b455"
integrity sha512-pKnZpbgCTfH/1NLIlOduP/V+WRXzC2MOz3Qo8xmxk8C5GudJLgK5QyLVXOSWy3ParAH7Eemurl3xjv/WXYFvMA==

ipaddr.js@1.8.0:
version "1.8.0"
resolved "https://registry.yarnpkg.com/ipaddr.js/-/ipaddr.js-1.8.0.tgz#eaa33d6ddd7ace8f7f6fe0c9ca0440e706738b1e"
Expand Down Expand Up @@ -6719,6 +6724,13 @@ is-glob@^4.0.0:
dependencies:
is-extglob "^2.1.1"

is-ip@^3.1.0:
version "3.1.0"
resolved "https://registry.yarnpkg.com/is-ip/-/is-ip-3.1.0.tgz#2ae5ddfafaf05cb8008a62093cf29734f657c5d8"
integrity sha512-35vd5necO7IitFPjd/YBeqwWnyDWbuLH9ZXQdMfDA8TEo7pv5X8yfrvVO3xbJbLUlERCMvf6X0hTUamQxCYJ9Q==
dependencies:
ip-regex "^4.0.0"

is-number@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/is-number/-/is-number-3.0.0.tgz#24fd6201a4782cf50561c810276afc7d12d71195"
Expand Down