Skip to content

Commit

Permalink
Ignore non-labels.policyIds predicate attributes when migrating workf…
Browse files Browse the repository at this point in the history
…lows
  • Loading branch information
crshanks committed Feb 6, 2023
1 parent 942fce8 commit 7e55096
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 18 deletions.
File renamed without changes.
15 changes: 9 additions & 6 deletions library/clients/workflowsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,15 @@ def create_workflow(workflow, user_api_key, account_id, region):
logger.info(f"Update policy id values in issuesFilter")
predicates = []
for predicate in workflow['issuesFilter']['predicates']:
target_predicate = {
'attribute': predicate['attribute'], # String!
'operator': predicate['operator'], # iWorkflowsOperator!
'values': predicate['targetValues'] # [String!]!
}
predicates.append(target_predicate)
if predicate['attribute'] == 'labels.policyIds':
target_predicate = {
'attribute': predicate['attribute'], # String!
'operator': predicate['operator'], # iWorkflowsOperator!
'values': predicate['targetValues'] # [String!]!
}
predicates.append(target_predicate)
else:
logger.debug(f"Ignoring predicate {predicate}")
if 'issuesFilter' in workflow:
workflowData['issuesFilter'] = {
'name': workflow['issuesFilter']['name'], # String: this is a guid, which is unexpected
Expand Down
27 changes: 15 additions & 12 deletions migrate_workflows.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,21 +70,24 @@ def migrate_workflows(src_acct, src_api_key, src_region, tgt_acct, tgt_api_key,
if "issuesFilter" in workflow:
workflow['issuesFilter']['targetAccountId'] = int(tgt_acct)
for predicate in workflow['issuesFilter']['predicates']:
targetValues = []
for source_policy_id in predicate['values']:
if int(source_policy_id) in policies_by_source_id:
policy = policies_by_source_id.get(int(source_policy_id))
if 'targetPolicyId' in policy:
targetValues.append(str(policy['targetPolicyId']))
log.info(f"Target policy id: {str(policy['targetPolicyId'])} found for source policy id: {source_policy_id} ")
if predicate['attribute'] == 'labels.policyIds':
targetValues = []
for source_policy_id in predicate['values']:
if int(source_policy_id) in policies_by_source_id:
policy = policies_by_source_id.get(int(source_policy_id))
if 'targetPolicyId' in policy:
targetValues.append(str(policy['targetPolicyId']))
log.info(f"Target policy id: {str(policy['targetPolicyId'])} found for source policy id: {source_policy_id} ")
else:
hasError = True
log.error(f"Unable to create workflow name: {workflow['name']}. Target policy id unavailable for source policy id: {source_policy_id}")
else:
hasError = True
log.error(f"Unable to create workflow name: {workflow['name']}. Target policy id unavailable for source policy id: {source_policy_id}")
else:
hasError = True
log.error(f"Unable to create workflow name: {workflow['name']}. Target policy id unavailable for source policy id: {source_policy_id}")
if len(targetValues) > 0:
predicate['targetValues'] = targetValues
if len(targetValues) > 0:
predicate['targetValues'] = targetValues
else:
log.debug(f"Ignoring predicate {predicate}")
else:
hasError = True
log.info(f"Workflow name: {workflow['name']} with id: {workflow['id']} has no issuesFilter: {workflow}")
Expand Down

0 comments on commit 7e55096

Please sign in to comment.