# -*- coding: UTF-8 -*- from core import add_allowed_principals_args, validate_env, read_configuration, \ describe_endpoint_service_permissions, add_allowed_principals, list_endpoint_service def main(): args = add_allowed_principals_args() env = args['env'] validate_env(env) profile = args['profile'] arn = args['arn'] config = read_configuration(env) endpoint_services_conf = config["endpoint_services"] for region, endpoint_services in endpoint_services_conf.items(): for e in endpoint_services: service_name = e['service_name'] svcs = list_endpoint_service(region, profile, service_names=[service_name]) if len(svcs) != 1: print("failed to get svc") exit(1) svc = svcs[0] service_id = svc["ServiceId"] allowed_principals = describe_endpoint_service_permissions(region, profile, service_id) if len([ap for ap in allowed_principals if ap["Principal"] == arn]) != 0: print("service_name has been added allowed principal before, ignore") continue add_allowed_principals(region, profile, service_id, arn) if __name__ == '__main__': main()