# Path: studio/credentials/credentials.py
# class Credentials:
#     def __init__(self, cred_dict):
#         self.logger = logs.get_logger(self.__class__.__name__)
#         self.logger.setLevel(storage_setup.get_storage_verbose_level())
# 
#         self.type = None
#         self.key = None
#         self.secret_key = None
#         self.session_token = None
#         self.region = None
#         self.profile = None
#         if cred_dict is None:
#             return
# 
#         if isinstance(cred_dict, str) and cred_dict == 'none':
#             return
# 
#         if not isinstance(cred_dict, dict):
#             msg: str =\
#                 "NOT SUPPORTED credentials format {0}".format(repr(cred_dict))
#             util.report_fatal(msg, self.logger)
# 
#         if len(cred_dict) == 0:
#             # Empty credentials dictionary is like None:
#             return
# 
#         if len(cred_dict) == 1 and AWS_TYPE in cred_dict.keys():
#             aws_creds = cred_dict[AWS_TYPE]
#             self.type = AWS_TYPE
#             self.key = aws_creds.get(AWS_KEY, None)
#             self.secret_key = aws_creds.get(AWS_SECRET_KEY, None)
#             self.session_token = aws_creds.get(AWS_SESSION_TOKEN, None)
#             self.region = self._get_named(AWS_REGION, aws_creds)
#             self.profile = self._get_named(AWS_PROFILE, aws_creds)
# 
#             if self.key is None or self.secret_key is None:
#                 msg: str = \
#                     "INVALID aws credentials format {0}".format(repr(cred_dict))
#                 util.report_fatal(msg, self.logger)
#         else:
#             msg: str =\
#                 "NOT SUPPORTED credentials format {0}".format(repr(cred_dict))
#             util.report_fatal(msg, self.logger)
# 
#     def get_type(self):
#         return self.type
# 
#     def get_key(self):
#         return self.key
# 
#     def get_secret_key(self):
#         return self.secret_key
# 
#     def get_session_token(self):
#         return self.session_token
# 
#     def get_region(self):
#         return self.region
# 
#     def get_profile(self):
#         return self.profile
# 
#     def _get_named(self, key: str, config: Dict):
#         value = config.get(key, None)
#         if value is None:
#             value = config.get(key+'_name', None)
#         return value
# 
#     def to_dict(self):
#         result: Dict = {
#             self.type: {
#                 AWS_KEY: self.key,
#                 AWS_SECRET_KEY: self.secret_key
#             }
#         }
#         if self.session_token is not None:
#             result[self.type][AWS_SESSION_TOKEN] = self.session_token
#         if self.region is not None:
#             result[self.type][AWS_REGION] = self.region
#         if self.profile is not None:
#             result[self.type][AWS_PROFILE] = self.profile
#         return result
# 
#     def get_fingerprint(self) -> str:
#         if self.type is None and self.key is None and\
#             self.secret_key is None:
#             return ''
#         id_str: str = "{0}::{1}::{2}::{3}::{4}::{5}"\
#             .format(self.type, self.key, self.secret_key,
#                     self.session_token,
#                     self.profile, self.region)
#         return hashlib.sha256(id_str.encode()).hexdigest()
# 
#     @classmethod
#     def get_credentials(cls, config):
#         if config is None:
#             return None
#         cred_dict = config.get(KEY_CREDENTIALS, None)
#         return Credentials(cred_dict) if cred_dict else None
# 
#     def to_string(self):
#         return "type: {0} key: {1} secret: <reducted> profile: {2} region: {3}"\
#             .format(self.type, self.key, self.profile, self.region)
# 
# KEY_CREDENTIALS = 'credentials'
# 
# Path: studio/storage/storage_setup.py
# def get_storage_verbose_level():
#     global _storage_verbose_level
#     return _storage_verbose_level
# 
# Path: studio/util/logs.py
# DEBUG = logging.DEBUG
# INFO = logging.INFO
# ERROR = logging.ERROR
# def get_logger(name):
# def debug(line):
# def error(line):
# def info(line):
# 
# Path: studio/util/util.py
# DAY = 86400
# HOUR = 3600
# MINUTE = 60
# def remove_backspaces(line):
# def report_fatal(msg: str, logger):
# def sha256_checksum(filename, block_size=65536):
# def filehash(filename, block_size=65536, hashobj=None):
# def rand_string(length):
# def _looks_like_url(name):
# def parse_s3_path(qualified: str):
# def retry(f,
#           no_retries=5, sleep_time=1,
#           exception_class=BaseException, logger=None):
# def compression_to_extension(compression):
# def compression_to_taropt(compression):
# def _compression_to_extension_taropt(compression):
# def timeit(method):
#     def timed(*args, **kw):
# def sixdecode(sval):
# def shquote(sval):
# def parse_duration(duration_str):
# def parse_verbosity(verbosity=None):
# def str2duration(sval):
# def get_temp_filename() -> str:
# def delete_local_path(local_path: str, root: str, shallow: bool):
# def delete_local_folders(local_folder_path: str, root: str):
# def rm_rf(path):
# def check_for_kb_interrupt():
# def add_packages(list1, list2):


import time
import boto3
from typing import Dict
from studio.credentials.credentials import Credentials, KEY_CREDENTIALS
from studio.storage.storage_setup import get_storage_verbose_level
from studio.util import logs, util


class SQSQueue:

    def __init__(self, name,
                 config=None, logger=None):

        if logger is not None:
            self.logger = logger
        else:
            self.logger = logs.get_logger('SQSQueue')

# Path: studio/credentials/credentials.py
# class Credentials:
#     def __init__(self, cred_dict):
#         self.logger = logs.get_logger(self.__class__.__name__)
#         self.logger.setLevel(storage_setup.get_storage_verbose_level())
# 
#         self.type = None
#         self.key = None
#         self.secret_key = None
#         self.session_token = None
#         self.region = None
#         self.profile = None
#         if cred_dict is None:
#             return
# 
#         if isinstance(cred_dict, str) and cred_dict == 'none':
#             return
# 
#         if not isinstance(cred_dict, dict):
#             msg: str =\
#                 "NOT SUPPORTED credentials format {0}".format(repr(cred_dict))
#             util.report_fatal(msg, self.logger)
# 
#         if len(cred_dict) == 0:
#             # Empty credentials dictionary is like None:
#             return
# 
#         if len(cred_dict) == 1 and AWS_TYPE in cred_dict.keys():
#             aws_creds = cred_dict[AWS_TYPE]
#             self.type = AWS_TYPE
#             self.key = aws_creds.get(AWS_KEY, None)
#             self.secret_key = aws_creds.get(AWS_SECRET_KEY, None)
#             self.session_token = aws_creds.get(AWS_SESSION_TOKEN, None)
#             self.region = self._get_named(AWS_REGION, aws_creds)
#             self.profile = self._get_named(AWS_PROFILE, aws_creds)
# 
#             if self.key is None or self.secret_key is None:
#                 msg: str = \
#                     "INVALID aws credentials format {0}".format(repr(cred_dict))
#                 util.report_fatal(msg, self.logger)
#         else:
#             msg: str =\
#                 "NOT SUPPORTED credentials format {0}".format(repr(cred_dict))
#             util.report_fatal(msg, self.logger)
# 
#     def get_type(self):
#         return self.type
# 
#     def get_key(self):
#         return self.key
# 
#     def get_secret_key(self):
#         return self.secret_key
# 
#     def get_session_token(self):
#         return self.session_token
# 
#     def get_region(self):
#         return self.region
# 
#     def get_profile(self):
#         return self.profile
# 
#     def _get_named(self, key: str, config: Dict):
#         value = config.get(key, None)
#         if value is None:
#             value = config.get(key+'_name', None)
#         return value
# 
#     def to_dict(self):
#         result: Dict = {
#             self.type: {
#                 AWS_KEY: self.key,
#                 AWS_SECRET_KEY: self.secret_key
#             }
#         }
#         if self.session_token is not None:
#             result[self.type][AWS_SESSION_TOKEN] = self.session_token
#         if self.region is not None:
#             result[self.type][AWS_REGION] = self.region
#         if self.profile is not None:
#             result[self.type][AWS_PROFILE] = self.profile
#         return result
# 
#     def get_fingerprint(self) -> str:
#         if self.type is None and self.key is None and\
#             self.secret_key is None:
#             return ''
#         id_str: str = "{0}::{1}::{2}::{3}::{4}::{5}"\
#             .format(self.type, self.key, self.secret_key,
#                     self.session_token,
#                     self.profile, self.region)
#         return hashlib.sha256(id_str.encode()).hexdigest()
# 
#     @classmethod
#     def get_credentials(cls, config):
#         if config is None:
#             return None
#         cred_dict = config.get(KEY_CREDENTIALS, None)
#         return Credentials(cred_dict) if cred_dict else None
# 
#     def to_string(self):
#         return "type: {0} key: {1} secret: <reducted> profile: {2} region: {3}"\
#             .format(self.type, self.key, self.profile, self.region)
# 
# KEY_CREDENTIALS = 'credentials'
# 
# Path: studio/storage/storage_setup.py
# def get_storage_verbose_level():
#     global _storage_verbose_level
#     return _storage_verbose_level
# 
# Path: studio/util/logs.py
# DEBUG = logging.DEBUG
# INFO = logging.INFO
# ERROR = logging.ERROR
# def get_logger(name):
# def debug(line):
# def error(line):
# def info(line):
# 
# Path: studio/util/util.py
# DAY = 86400
# HOUR = 3600
# MINUTE = 60
# def remove_backspaces(line):
# def report_fatal(msg: str, logger):
# def sha256_checksum(filename, block_size=65536):
# def filehash(filename, block_size=65536, hashobj=None):
# def rand_string(length):
# def _looks_like_url(name):
# def parse_s3_path(qualified: str):
# def retry(f,
#           no_retries=5, sleep_time=1,
#           exception_class=BaseException, logger=None):
# def compression_to_extension(compression):
# def compression_to_taropt(compression):
# def _compression_to_extension_taropt(compression):
# def timeit(method):
#     def timed(*args, **kw):
# def sixdecode(sval):
# def shquote(sval):
# def parse_duration(duration_str):
# def parse_verbosity(verbosity=None):
# def str2duration(sval):
# def get_temp_filename() -> str:
# def delete_local_path(local_path: str, root: str, shallow: bool):
# def delete_local_folders(local_folder_path: str, root: str):
# def rm_rf(path):
# def check_for_kb_interrupt():
# def add_packages(list1, list2):


# Path: studio/queues/sqs_queue.py
import time
import boto3
from typing import Dict
from studio.credentials.credentials import Credentials, KEY_CREDENTIALS
from studio.storage.storage_setup import get_storage_verbose_level
from studio.util import logs, util



class SQSQueue:

    def __init__(self, name,
                 config=None, logger=None):

        if logger is not None:
            self.logger = logger
        else:
            self.logger = logs.get_logger('SQSQueue')

            self.logger.setLevel(get_storage_verbose_level())