diff options
Diffstat (limited to 'lib/policy.js')
-rw-r--r-- | lib/policy.js | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/lib/policy.js b/lib/policy.js index 89e5b6a..87280e6 100644 --- a/lib/policy.js +++ b/lib/policy.js @@ -43,6 +43,8 @@ function policyUpdate(req, res, next) { latest_policies : JSON.stringify((req.body && req.body.latest_policies) || {}), removed_policies : JSON.stringify((req.body && req.body.removed_policies) || {}), errored_policies : JSON.stringify((req.body && req.body.errored_policies) || {}), + errored_scopes : JSON.stringify((req.body && req.body.errored_scopes) || []), + scope_prefixes : JSON.stringify((req.body && req.body.scope_prefixes) || []), policy_deployments : {}, updated_policy_ids : {}, added_policy_ids : {}, @@ -55,6 +57,8 @@ function policyUpdate(req, res, next) { + " latest_policies: " + policy_update.latest_policies + " removed_policies: " + policy_update.removed_policies + " errored_policies: " + policy_update.errored_policies + + " errored_scopes: " + policy_update.errored_scopes + + " scope_prefixes: " + policy_update.scope_prefixes ); /** * reply to and free up the policy_handler @@ -64,11 +68,23 @@ function policyUpdate(req, res, next) { policy_update.latest_policies = JSON.parse(policy_update.latest_policies); policy_update.removed_policies = JSON.parse(policy_update.removed_policies); policy_update.errored_policies = JSON.parse(policy_update.errored_policies); + policy_update.errored_scopes = JSON.parse(policy_update.errored_scopes); + policy_update.scope_prefixes = JSON.parse(policy_update.scope_prefixes); + const is_policy_in_scopes = function(policy_id) { + return policy_update.scope_prefixes.some(scope_prefix => { + return policy_id.startsWith(scope_prefix); + }); + }; + + const is_policy_in_errored_scopes = function(policy_id) { + return policy_update.errored_scopes.some(errored_scope => { + return policy_id.startsWith(errored_scope); + }); + }; /** * filter out the policies to what is deployed in components and needs updating (new policyVersion) */ - const collect_policy_deployments = function(node_instances) { node_instances.forEach(node_instance => { if (!node_instance.runtime_properties @@ -90,10 +106,15 @@ function policyUpdate(req, res, next) { const deployed_policies = node_instance.runtime_properties.policies || {}; Object.keys(deployed_policies).forEach(policy_id => { + const deployed_policy = deployed_policies[policy_id]; const latest_policy = policy_update.latest_policies[policy_id]; if (policy_update.removed_policies[policy_id] - || (policy_update.catch_up && !latest_policy - && !policy_update.errored_policies[policy_id])) { + || (policy_update.catch_up + && deployed_policy.policy_body + && !latest_policy + && !policy_update.errored_policies[policy_id]) + && !is_policy_in_errored_scopes(policy_id) + && is_policy_in_scopes(policy_id)) { have_policies = true; deployment.removed_policy_ids[policy_id] = true; policy_update.removed_policy_ids[policy_id] = true; @@ -101,7 +122,6 @@ function policyUpdate(req, res, next) { return; } - const deployed_policy = deployed_policies[policy_id]; if (!latest_policy || !latest_policy.policy_body || isNaN(latest_policy.policy_body.policyVersion) || latest_policy.policy_body.policyVersion |