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

allow owners to view public networks #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
31 changes: 28 additions & 3 deletions lib/endpoints/networks.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ var ResourceNotFoundError = restify.ResourceNotFoundError;
var MissingParameterError = restify.MissingParameterError;

var FABRIC_VLAN_FIELDS = ['description', 'name', 'vlan_id'];
var NETWORK_FIELDS = ['description', 'gateway', 'name',
'provision_end_ip', 'provision_start_ip', 'resolvers',
'routes', 'subnet', 'uuid', 'vlan_id'];
var FABRIC_NETWORK_FIELDS = ['description', 'fabric', 'gateway',
'internet_nat', 'name', 'provision_end_ip', 'provision_start_ip',
'resolvers', 'routes', 'subnet', 'uuid', 'vlan_id'];
Expand Down Expand Up @@ -136,8 +139,9 @@ function translateErr(err) {


// Note here "net" can be a network, fabric network or network_pool from NAPI
function translateNetwork(net) {
function translateNetwork(net, account) {
assert.object(net, 'net');
assert.optionalUuid(account, 'account');

var obj = {
id: net.uuid,
Expand Down Expand Up @@ -165,6 +169,27 @@ function translateNetwork(net) {
return;
}

if (net.hasOwnProperty(p)) {
obj[p] = net[p];
}
});
} else {
NETWORK_FIELDS.forEach(function (p) {
if (p === 'uuid') {
return;
}

if (net.hasOwnProperty(p)) {
obj[p] = net[p];
}
});
}
if (account != null && net.owner_uuids != null && net.owner_uuids.indexOf(account) > -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to make check issues, this code doesn't work.

[2021-05-21T18:18:53.220Z] ERROR: cloudapi/80319 on 882de077-91f3-4f27-9a24-67d0efe0b8e5: unexpected error (req_id=41d2d897-ae7c-4227-bbcf-27b55247068c)
    TypeError: Cannot read property 'indexOf' of undefined
        at translateNetwork (/opt/smartdc/cloudapi/lib/endpoints/networks.js:188:24)
        at /opt/smartdc/cloudapi/lib/endpoints/networks.js:283:16
        at Array.map (native)
        at Server.listNetworks (/opt/smartdc/cloudapi/lib/endpoints/networks.js:282:8)
        at next (/opt/smartdc/cloudapi/node_modules/restify/lib/server.js:912:30)
        at f (/opt/smartdc/cloudapi/node_modules/once/once.js:25:25)
        at Server.rateLimit (/opt/smartdc/cloudapi/node_modules/restify/lib/plugins/throttle.js:294:17)
        at next (/opt/smartdc/cloudapi/node_modules/restify/lib/server.js:912:30)
        at f (/opt/smartdc/cloudapi/node_modules/once/once.js:25:25)
        at Server.saveContext (/opt/smartdc/cloudapi/lib/app.js:499:28)

NETWORK_FIELDS.forEach(function (p) {
if (p === 'uuid') {
return;
}

if (net.hasOwnProperty(p)) {
obj[p] = net[p];
}
Expand Down Expand Up @@ -254,7 +279,7 @@ function listNetworks(req, res, next) {
// assuming this list never gets too big
return skipNetworkUuids.indexOf(n.uuid) === -1;
}).map(function (pool) {
return translateNetwork(pool);
return translateNetwork(pool, req.account.uuid);
});

req.log.debug({
Expand Down Expand Up @@ -282,7 +307,7 @@ function getNetwork(req, res, next) {
resources.getRoleTags(req, res);
}

network = translateNetwork(net[0]);
network = translateNetwork(net[0], req.account.uuid);

req.log.debug({
network: network,
Expand Down