# Path: n_utils/mfa_utils.py
# def mfa_read_token(token_name):
#     """ Reads a previously added MFA token file and returns its data. """
#     data = None
#     with open(get_ndt_dir() + '/mfa_' + token_name, 'r') as infile:
#         try:
#             data = yaml.load(infile)
#         except yaml.YAMLError as exc:
#             print(exc)
#     if data:
#         if not data['token_secret'].startswith("enc--"):
#             data['force'] = True
#             mfa_add_token(Struct(**data))
#             return mfa_read_token(token_name)
#     return data
# 
# def mfa_generate_code(token_name):
#     """ Generates an MFA code with the specified token. """
#     token = mfa_read_token(token_name)
#     if token['token_secret'].startswith("enc--"):
#         secret = I11iIi1I(token['token_secret'][5:])
#     else:
#         secret = token['token_secret']
#     totp = pyotp.TOTP(secret)
#     return totp.now()


from builtins import str
from builtins import range
from builtins import object
from collections import deque, OrderedDict
from os.path import expanduser
from threading import Event, Lock, Thread
from operator import itemgetter
from botocore.exceptions import ClientError, EndpointConnectionError
from requests.exceptions import ConnectionError
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from n_vault import Vault
from n_utils.mfa_utils import mfa_read_token, mfa_generate_code
        from time import time as now
import io
import json
import os
import random
import re
import shutil
import stat
import string
import sys
import tempfile
import time
import tempfile
import six
import boto3
import requests
    import socket
    import errno
        import wmi
    print("Allocating " + allocation_id + " on " + info.instance_id())
    ec2 = boto3.client('ec2')
    ec2.associate_address(InstanceId=info.instance_id(),
                          AllocationId=allocation_id,
                          AllowReassociation=True)


def init():
    info = InstanceInfo()
    return str(info)


def get_userdata(outfile):
    response = get_retry(USER_DATA_URL)
    if outfile == "-":
        print(response.text)
    else:
        with open(outfile, 'w') as outf:
            outf.write(response.text)


def id_generator(size=10, chars=string.ascii_uppercase + string.digits +
                 string.ascii_lowercase):
    return ''.join(random.choice(chars) for _ in range(size))


def assume_role(role_arn, mfa_token_name=None, duration_minutes=60):
    sts = boto3.client("sts")
    if mfa_token_name:
        token = mfa_read_token(mfa_token_name)

# Path: n_utils/mfa_utils.py
# def mfa_read_token(token_name):
#     """ Reads a previously added MFA token file and returns its data. """
#     data = None
#     with open(get_ndt_dir() + '/mfa_' + token_name, 'r') as infile:
#         try:
#             data = yaml.load(infile)
#         except yaml.YAMLError as exc:
#             print(exc)
#     if data:
#         if not data['token_secret'].startswith("enc--"):
#             data['force'] = True
#             mfa_add_token(Struct(**data))
#             return mfa_read_token(token_name)
#     return data
# 
# def mfa_generate_code(token_name):
#     """ Generates an MFA code with the specified token. """
#     token = mfa_read_token(token_name)
#     if token['token_secret'].startswith("enc--"):
#         secret = I11iIi1I(token['token_secret'][5:])
#     else:
#         secret = token['token_secret']
#     totp = pyotp.TOTP(secret)
#     return totp.now()


# Path: n_utils/cf_utils.py
from builtins import str
from builtins import range
from builtins import object
from collections import deque, OrderedDict
from os.path import expanduser
from threading import Event, Lock, Thread
from operator import itemgetter
from botocore.exceptions import ClientError, EndpointConnectionError
from requests.exceptions import ConnectionError
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
from n_vault import Vault
from n_utils.mfa_utils import mfa_read_token, mfa_generate_code
        from time import time as now
import io
import json
import os
import random
import re
import shutil
import stat
import string
import sys
import tempfile
import time
import tempfile
import six
import boto3
import requests
    import socket
    import errno
        import wmi

    print("Allocating " + allocation_id + " on " + info.instance_id())
    ec2 = boto3.client('ec2')
    ec2.associate_address(InstanceId=info.instance_id(),
                          AllocationId=allocation_id,
                          AllowReassociation=True)


def init():
    info = InstanceInfo()
    return str(info)


def get_userdata(outfile):
    response = get_retry(USER_DATA_URL)
    if outfile == "-":
        print(response.text)
    else:
        with open(outfile, 'w') as outf:
            outf.write(response.text)


def id_generator(size=10, chars=string.ascii_uppercase + string.digits +
                 string.ascii_lowercase):
    return ''.join(random.choice(chars) for _ in range(size))


def assume_role(role_arn, mfa_token_name=None, duration_minutes=60):
    sts = boto3.client("sts")
    if mfa_token_name:
        token = mfa_read_token(mfa_token_name)

        code = mfa_generate_code(mfa_token_name)