Skip to content

Commit

Permalink
fix: region parameters were not handled correctly
Browse files Browse the repository at this point in the history
Note: Look for camel case as well as _ separated param names. in case of nrmig the params come in as _ separated names.
  • Loading branch information
adiosspandit committed Jul 7, 2021
1 parent a2715e3 commit d491ad7
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
4 changes: 2 additions & 2 deletions library/clients/alertsclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,13 @@ def infra_conditions_by_name(api_key, policy_id, region):
return conditions_by_name


def get_alert_status_file_name(fromFile, fromFileEntities, src_account_id, tgt_account_id):
def get_alert_status_file_name(fromFile, fromFileEntities, src_account_id, tgt_account_id, suffix):
status_file_name = str(src_account_id) + '_'
if fromFile:
status_file_name += utils.file_name_from(fromFile) + '_'
if fromFileEntities:
status_file_name += utils.file_name_from(fromFileEntities) + '_'
return status_file_name + str(tgt_account_id) + '_conditions.csv'
return status_file_name + str(tgt_account_id) + suffix + '.csv'


def get_policy_entity_map(api_key, alert_policies, region=Endpoints.REGION_US):
Expand Down
8 changes: 6 additions & 2 deletions library/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,15 +134,19 @@ def ensure_region(args):

def ensure_source_region(args):
sourceRegion = 'us'
if args.sourceRegion and len(args.sourceRegion) > 0:
if 'sourceRegion' in args and len(args.sourceRegion) > 0:
sourceRegion = args.sourceRegion[0]
elif 'source_region' in args and args.source_region:
sourceRegion = args.source_region[0]
return sourceRegion


def ensure_target_region(args):
targetRegion = 'us'
if args.targetRegion and len(args.targetRegion) > 0:
if 'targetRegion' in args and len(args.targetRegion) > 0:
targetRegion = args.targetRegion[0]
elif 'target_region' in args and len(args.target_region) > 0:
targetRegion = args.target_region[0]
return targetRegion


Expand Down
3 changes: 2 additions & 1 deletion migrateconditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def migrate(
policy_file_path,
entity_file_path,
source_acct_id,
target_acct_id
target_acct_id,
'_conditions'
)
store.save_status_csv(status_file, status, cs)

Expand Down
19 changes: 8 additions & 11 deletions migratepolicies.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def configure_parser(
'--source_region',
nargs=1,
type=str,
required=is_standalone,
required=False,
help='Source Account Region us(default) or eu',
dest='source_region'
)
Expand Down Expand Up @@ -126,16 +126,10 @@ def print_args(args, src_api_key, src_region, tgt_api_key, tgt_region):
if (args.entity_file):
logger.info("Using fromFileEntities : " + args.entity_file[0])
logger.info("Using sourceAccount : " + str(args.source_account_id[0]))
if args.sourceRegion and len(args.sourceRegion) > 0:
logger.info("sourceRegion : " + args.sourceRegion[0])
else:
logger.info("sourceRegion not passed : Defaulting to " + src_region)
logger.info("sourceRegion : " + src_region)
logger.info("Using sourceApiKey : " + len(src_api_key[:-4])*"*"+src_api_key[-4:])
logger.info("Using targetAccount : " + str(args.target_account_id[0]))
if args.targetRegion and len(args.targetRegion) > 0:
logger.info("targetRegion : " + args.targetRegion[0])
else:
logger.info("targetRegion not passed : Defaulting to " + tgt_region)
logger.info("targetRegion : " + tgt_region)
logger.info("Using targetApiKey : " + len(tgt_api_key[:-4]) * "*" + tgt_api_key[-4:])
if args.use_local:
fetch_channels = False
Expand Down Expand Up @@ -286,7 +280,8 @@ def migrate(
policy_file_path,
entity_file_path,
source_acct_id,
target_acct_id
target_acct_id,
'_policies'
)
store.save_status_csv(status_file, status, askeys)

Expand Down Expand Up @@ -373,12 +368,14 @@ def main():
sys.exit()
sourceRegion = utils.ensure_source_region(args)
targetRegion = utils.ensure_target_region(args)
print_args(source_api_key, sourceRegion, target_api_key, targetRegion)
print_args(args, source_api_key, sourceRegion, target_api_key, targetRegion)
migrate(
policy_file,
entity_file,
args.source_account_id[0],
sourceRegion,
args.target_account_id[0],
targetRegion,
source_api_key,
target_api_key,
args.use_local
Expand Down

0 comments on commit d491ad7

Please sign in to comment.