sorted stable fields for 'triton rbac role ROLE' output; use 'add' for added fields in 'triton rbac apply' resource updates
This commit is contained in:
parent
432c962f82
commit
5ea3b1862a
@ -3,7 +3,8 @@
|
|||||||
## 3.4.1 (not yet released)
|
## 3.4.1 (not yet released)
|
||||||
|
|
||||||
- Add `-d,--data <data>` option to `triton cloudapi`.
|
- Add `-d,--data <data>` option to `triton cloudapi`.
|
||||||
- Fix `triton rbac role ROLE`.
|
- Fix `triton rbac role ROLE`. Also get that command to have a stable order for the
|
||||||
|
displayed fields.
|
||||||
|
|
||||||
|
|
||||||
## 3.4.0
|
## 3.4.0
|
||||||
|
@ -34,6 +34,10 @@ var CREATE_ROLE_FIELDS = [
|
|||||||
{key: 'policies', array: true}
|
{key: 'policies', array: true}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
var SHOW_ORDER_FIELDS = [
|
||||||
|
'id', 'name', 'default_members', 'members', 'policies'
|
||||||
|
];
|
||||||
|
|
||||||
var _isArrayFromKey = {};
|
var _isArrayFromKey = {};
|
||||||
UPDATABLE_ROLE_FIELDS.forEach(function (field) {
|
UPDATABLE_ROLE_FIELDS.forEach(function (field) {
|
||||||
_isArrayFromKey[field.key] = Boolean(field.array);
|
_isArrayFromKey[field.key] = Boolean(field.array);
|
||||||
@ -61,7 +65,24 @@ function _showRole(opts, cb) {
|
|||||||
if (opts.json) {
|
if (opts.json) {
|
||||||
console.log(JSON.stringify(role));
|
console.log(JSON.stringify(role));
|
||||||
} else {
|
} else {
|
||||||
Object.keys(role).forEach(function (key) {
|
var keys = Object.keys(role);
|
||||||
|
keys.sort(function cmpKeys(a, b) {
|
||||||
|
var idxA = SHOW_ORDER_FIELDS.indexOf(a);
|
||||||
|
var idxB = SHOW_ORDER_FIELDS.indexOf(b);
|
||||||
|
if (idxA === -1 && idxB === -1) {
|
||||||
|
return 0;
|
||||||
|
} else if (idxA === -1) {
|
||||||
|
return -1;
|
||||||
|
} else if (idxB === -1) {
|
||||||
|
return 1;
|
||||||
|
} else if (idxA < idxB) {
|
||||||
|
return -1;
|
||||||
|
} else if (idxA > idxB) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
keys.forEach(function (key) {
|
||||||
var val = role[key];
|
var val = role[key];
|
||||||
if (Array.isArray(val)) {
|
if (Array.isArray(val)) {
|
||||||
val = val.join(', ');
|
val = val.join(', ');
|
||||||
|
10
lib/rbac.js
10
lib/rbac.js
@ -149,7 +149,7 @@ function crudChangesForThings(opts) {
|
|||||||
});
|
});
|
||||||
Object.keys(wantThing_).forEach(function (field) {
|
Object.keys(wantThing_).forEach(function (field) {
|
||||||
if (! haveThing_.hasOwnProperty(field)) {
|
if (! haveThing_.hasOwnProperty(field)) {
|
||||||
diff[field] = 'create';
|
diff[field] = 'add';
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if (opts.compareFields) {
|
if (opts.compareFields) {
|
||||||
@ -370,7 +370,7 @@ function loadRbacState(ctx, cb) {
|
|||||||
next();
|
next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// XXX Q! or concurrency forEachParallel
|
// XXX Limit concurrency here!
|
||||||
// TODO: Optimization: could avoid getting keys for users that are
|
// TODO: Optimization: could avoid getting keys for users that are
|
||||||
// going to be deleted, for the `triton rbac apply` use case.
|
// going to be deleted, for the `triton rbac apply` use case.
|
||||||
vasync.forEachParallel({
|
vasync.forEachParallel({
|
||||||
@ -540,7 +540,11 @@ function createRbacUpdatePlan(ctx, cb) {
|
|||||||
idField: 'name',
|
idField: 'name',
|
||||||
have: ctx.rbacState.roles || [],
|
have: ctx.rbacState.roles || [],
|
||||||
want: ctx.rbacConfig.roles || [],
|
want: ctx.rbacConfig.roles || [],
|
||||||
compareFields: ['members', 'default_members', 'policies'],
|
compareFields: [
|
||||||
|
'members',
|
||||||
|
'default_members',
|
||||||
|
'policies'
|
||||||
|
],
|
||||||
normThing: function normRole(role) {
|
normThing: function normRole(role) {
|
||||||
role.members.sort();
|
role.members.sort();
|
||||||
role.default_members.sort();
|
role.default_members.sort();
|
||||||
|
Reference in New Issue
Block a user