# Path: n_utils/profile_util.py
# def enable_profile(profile_type, profile):
#     profile = re.sub("[^a-zA-Z0-9_-]", "_", profile)
#     safe_profile = re.sub("[^A-Z0-9]", "_", profile.upper())
#     if profile_type == "iam":
#         _print_profile_switch(profile)
#     elif profile_type == "azure":
#         _print_profile_switch(profile)
#         if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#             expiry = int(os.environ["AWS_SESSION_EXPIRATION_EPOC_" + safe_profile])
#         else:
#             expiry = _epoc_secs(parse(read_profile_expiry(profile)).replace(tzinfo=tzutc()))
#         if expiry < _epoc_secs(datetime.now(tzutc())):
#             if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#                 print("unset AWS_SESSION_EXPIRATION_EPOC_" + safe_profile + ";")
#             print("aws-azure-login --profile " + profile + " --no-prompt")
#         elif "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile not in os.environ:
#             print_profile_expiry(profile)
#     elif profile_type == "ndt":
#         if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#             expiry = int(os.environ["AWS_SESSION_EXPIRATION_EPOC_" + safe_profile])
#         else:
#             expiry = _epoc_secs(parse(read_profile_expiry(profile)).replace(tzinfo=tzutc()))
#         if expiry < _epoc_secs(datetime.now(tzutc())):
#             if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#                 print("unset AWS_SESSION_EXPIRATION_EPOC_" + safe_profile + ";")
#             profile_data = get_profile(profile)
#             if "ndt_origin_profile" not in profile_data:
#                 return
#             origin_profile = profile_data["ndt_origin_profile"]
#             origin_profile_data = get_profile(origin_profile)
#             if "azure_tenant_id" in origin_profile_data:
#                 origin_type = "azure"
#             else:
#                 origin_type = "iam"
#             enable_profile(origin_type, origin_profile)
# 
#             command = ["ndt", "assume-role"]
#             if "ndt_mfa_token" in profile_data:
#                 command.append("-t")
#                 command.append(profile_data["ndt_mfa_token"])
#             if "ndt_default_duration_hours" in profile_data:
#                 command.append("-d")
#                 duration = str(int(profile_data["ndt_default_duration_hours"]) * 60)
#                 command.append(duration)
#             command.append("-p")
#             command.append(profile)
#             command.append(profile_data["ndt_role_arn"])
#             print(" ".join(command))
#         elif "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile not in os.environ:
#             print_profile_expiry(profile)
#         _print_profile_switch(profile)


from os import linesep
from os.path import expanduser, join, exists
from sys import argv
from n_utils.profile_util import enable_profile
import locale
import subprocess
from __future__ import print_function

def load_project_env():
    """ Print parameters set by git config variables to setup project environment with region and aws credentials
    """
    proc = subprocess.Popen(["git", "config", "--list", "--local"], stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    out = proc.communicate()
    if proc.returncode:
        return
    vars = {}
    for line in out[0].decode(locale.getpreferredencoding()).split("\n"):
        if line:
            next = line.split("=", 1)
            vars[next[0]] = next[1]
    do_print = False
    ret = ""
    if "ndt.profile.azure" in vars:
        enable_profile("azure", vars["ndt.profile.azure"])
    if "ndt.profile.iam" in vars:

# Path: n_utils/profile_util.py
# def enable_profile(profile_type, profile):
#     profile = re.sub("[^a-zA-Z0-9_-]", "_", profile)
#     safe_profile = re.sub("[^A-Z0-9]", "_", profile.upper())
#     if profile_type == "iam":
#         _print_profile_switch(profile)
#     elif profile_type == "azure":
#         _print_profile_switch(profile)
#         if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#             expiry = int(os.environ["AWS_SESSION_EXPIRATION_EPOC_" + safe_profile])
#         else:
#             expiry = _epoc_secs(parse(read_profile_expiry(profile)).replace(tzinfo=tzutc()))
#         if expiry < _epoc_secs(datetime.now(tzutc())):
#             if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#                 print("unset AWS_SESSION_EXPIRATION_EPOC_" + safe_profile + ";")
#             print("aws-azure-login --profile " + profile + " --no-prompt")
#         elif "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile not in os.environ:
#             print_profile_expiry(profile)
#     elif profile_type == "ndt":
#         if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#             expiry = int(os.environ["AWS_SESSION_EXPIRATION_EPOC_" + safe_profile])
#         else:
#             expiry = _epoc_secs(parse(read_profile_expiry(profile)).replace(tzinfo=tzutc()))
#         if expiry < _epoc_secs(datetime.now(tzutc())):
#             if "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile in os.environ:
#                 print("unset AWS_SESSION_EXPIRATION_EPOC_" + safe_profile + ";")
#             profile_data = get_profile(profile)
#             if "ndt_origin_profile" not in profile_data:
#                 return
#             origin_profile = profile_data["ndt_origin_profile"]
#             origin_profile_data = get_profile(origin_profile)
#             if "azure_tenant_id" in origin_profile_data:
#                 origin_type = "azure"
#             else:
#                 origin_type = "iam"
#             enable_profile(origin_type, origin_profile)
# 
#             command = ["ndt", "assume-role"]
#             if "ndt_mfa_token" in profile_data:
#                 command.append("-t")
#                 command.append(profile_data["ndt_mfa_token"])
#             if "ndt_default_duration_hours" in profile_data:
#                 command.append("-d")
#                 duration = str(int(profile_data["ndt_default_duration_hours"]) * 60)
#                 command.append(duration)
#             command.append("-p")
#             command.append(profile)
#             command.append(profile_data["ndt_role_arn"])
#             print(" ".join(command))
#         elif "AWS_SESSION_EXPIRATION_EPOC_" + safe_profile not in os.environ:
#             print_profile_expiry(profile)
#         _print_profile_switch(profile)


# Path: n_utils/project_util.py
from os import linesep
from os.path import expanduser, join, exists
from sys import argv
from n_utils.profile_util import enable_profile
import locale
import subprocess

from __future__ import print_function

def load_project_env():
    """ Print parameters set by git config variables to setup project environment with region and aws credentials
    """
    proc = subprocess.Popen(["git", "config", "--list", "--local"], stdout=subprocess.PIPE,
                            stderr=subprocess.PIPE)
    out = proc.communicate()
    if proc.returncode:
        return
    vars = {}
    for line in out[0].decode(locale.getpreferredencoding()).split("\n"):
        if line:
            next = line.split("=", 1)
            vars[next[0]] = next[1]
    do_print = False
    ret = ""
    if "ndt.profile.azure" in vars:
        enable_profile("azure", vars["ndt.profile.azure"])
    if "ndt.profile.iam" in vars:

        enable_profile("iam", vars["ndt.profile.iam"])