# Path: f8a_worker/defaults.py
# class F8AConfiguration(object):
#     def _make_postgres_string(password):
#     def is_local_deployment(cls):
#     def _rate_limit_exceeded(cls, headers):
#     def _decide_token_usage(cls):
#     def select_random_github_token(cls):
#     def libraries_io_project_url(cls, ecosystem, name):
#     def dependency_check_script_path(self):
#     BIGQUERY_JSON_KEY = environ.get('GITHUB_CONSUMER_KEY', 'not-set')
#     BROKER_CONNECTION = "amqp://guest@{host}:{port}".format(
#         host=environ.get('RABBITMQ_SERVICE_SERVICE_HOST', 'coreapi-broker'),
#         port=environ.get('RABBITMQ_SERVICE_SERVICE_PORT', '5672'))
#     GIT_USER_NAME = environ.get('GIT_USER_NAME', 'f8a')
#     GIT_USER_EMAIL = environ.get('GIT_USER_EMAIL', 'f8a@f8a')
#     GITHUB_TOKEN = environ.get('GITHUB_TOKEN', 'not-set').split(',')
#     GITHUB_API = "https://api.github.com/"
#     LIBRARIES_IO_TOKEN = environ.get('LIBRARIES_IO_TOKEN', 'not-set')
#     LIBRARIES_IO_API = 'https://libraries.io/api'
#     NPMJS_CHANGES_URL = environ.get('NPMJS_CHANGES_URL',
#                                     "https://skimdb.npmjs.com/registry/"
#                                     "_changes?descending=true&include_docs=true&feed=continuous")
#     UNQUOTED_POSTGRES_CONNECTION = _make_postgres_string(environ.get('POSTGRESQL_PASSWORD', ''))
#     POSTGRES_CONNECTION = _make_postgres_string(
#         quote(environ.get('POSTGRESQL_PASSWORD', ''), safe=''))
#     WORKER_DATA_DIR = environ.get('WORKER_DATA_DIR', 'not-set')
#     NPM_DATA_DIR = path.join(environ.get('HOME', '.npm'))
#     SCANCODE_LICENSE_SCORE = environ.get('SCANCODE_LICENSE_SCORE', '20')  # scancode's default is 0
#     SCANCODE_TIMEOUT = environ.get('SCANCODE_TIMEOUT', '120')  # scancode's default is 120
#     SCANCODE_PROCESSES = environ.get('SCANCODE_PROCESSES', '1')  # scancode's default is 1
#     SCANCODE_PATH = environ.get('SCANCODE_PATH', '/opt/scancode-toolkit/')
#     SCANCODE_IGNORE = ['*.pyc', '*.so', '*.dll', '*.rar', '*.jar',
#                        '*.zip', '*.tar', '*.tar.gz', '*.tar.xz', '*.png']  # don't scan binaries
#     AWS_S3_REGION = environ.get('AWS_S3_REGION')
#     AWS_S3_ACCESS_KEY_ID = environ.get('AWS_S3_ACCESS_KEY_ID')
#     AWS_S3_SECRET_ACCESS_KEY = environ.get('AWS_S3_SECRET_ACCESS_KEY')
#     S3_ENDPOINT_URL = environ.get('S3_ENDPOINT_URL')
#     DEPLOYMENT_PREFIX = environ.get('DEPLOYMENT_PREFIX')
#     BAYESIAN_SYNC_S3 = int(environ.get('BAYESIAN_SYNC_S3', 0)) == 1
#     AWS_SQS_ACCESS_KEY_ID = environ.get('AWS_SQS_ACCESS_KEY_ID')
#     AWS_SQS_SECRET_ACCESS_KEY = environ.get('AWS_SQS_SECRET_ACCESS_KEY')
#     CELERY_RESULT_BACKEND = environ.get('CELERY_RESULT_BACKEND')
#     AWS_SQS_REGION = environ.get('AWS_SQS_REGION')
#     JAVANCSS_PATH = environ.get('JAVANCSS_PATH')
#     OWASP_DEP_CHECK_PATH = environ.get('OWASP_DEP_CHECK_PATH')
#         USAGE_THRESHOLD = int(environ.get("LOW_USAGE_THRESHOLD", "5000"))
#         USAGE_THRESHOLD = 5000
#         POPULARITY_THRESHOLD = int(environ.get("LOW_POPULARITY_THRESHOLD", "5000"))
#         POPULARITY_THRESHOLD = 5000
#     BAYESIAN_GREMLIN_HTTP_SERVICE_HOST = environ.get("BAYESIAN_GREMLIN_HTTP_SERVICE_HOST",
#                                                      "localhost")
#     BAYESIAN_GREMLIN_HTTP_SERVICE_PORT = environ.get("BAYESIAN_GREMLIN_HTTP_SERVICE_PORT", "8182")


import os
import json
import uuid
import boto3
import botocore
from selinon import DataStorage
from selinon import StoragePool
from f8a_worker.defaults import configuration
"""Basic interface to the Amazon S3 database."""



class AmazonS3(DataStorage):
    """Basic interface to the Amazon S3 database."""

    _DEFAULT_REGION_NAME = 'us-east-1'
    _DEFAULT_BUCKET_NAME = 'bayesian-core-unknown'
    _DEFAULT_LOCAL_ENDPOINT = 'http://coreapi-s3:33000'
    _DEFAULT_ENCRYPTION = 'aws:kms'
    _DEFAULT_VERSIONED = True

    def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, bucket_name=None,
                 region_name=None, endpoint_url=None, use_ssl=False, encryption=None,
                 versioned=None):
        """Initialize object, setup connection to the AWS S3."""
        # TODO: reduce cyclomatic complexity
        # Priority for configuration options:
        #   1. environment variables
        #   2. arguments passed to constructor
        #   3. defaults as listed in self._DEFAULT_*
        super().__init__()
        self._s3 = None

        self.region_name = configuration.AWS_S3_REGION or region_name or self._DEFAULT_REGION_NAME
        bucket_name = bucket_name or self._DEFAULT_BUCKET_NAME
        self.bucket_name = bucket_name.format(**os.environ)
        self._aws_access_key_id = configuration.AWS_S3_ACCESS_KEY_ID or aws_access_key_id
        self._aws_secret_access_key = \

# Path: f8a_worker/defaults.py
# class F8AConfiguration(object):
#     def _make_postgres_string(password):
#     def is_local_deployment(cls):
#     def _rate_limit_exceeded(cls, headers):
#     def _decide_token_usage(cls):
#     def select_random_github_token(cls):
#     def libraries_io_project_url(cls, ecosystem, name):
#     def dependency_check_script_path(self):
#     BIGQUERY_JSON_KEY = environ.get('GITHUB_CONSUMER_KEY', 'not-set')
#     BROKER_CONNECTION = "amqp://guest@{host}:{port}".format(
#         host=environ.get('RABBITMQ_SERVICE_SERVICE_HOST', 'coreapi-broker'),
#         port=environ.get('RABBITMQ_SERVICE_SERVICE_PORT', '5672'))
#     GIT_USER_NAME = environ.get('GIT_USER_NAME', 'f8a')
#     GIT_USER_EMAIL = environ.get('GIT_USER_EMAIL', 'f8a@f8a')
#     GITHUB_TOKEN = environ.get('GITHUB_TOKEN', 'not-set').split(',')
#     GITHUB_API = "https://api.github.com/"
#     LIBRARIES_IO_TOKEN = environ.get('LIBRARIES_IO_TOKEN', 'not-set')
#     LIBRARIES_IO_API = 'https://libraries.io/api'
#     NPMJS_CHANGES_URL = environ.get('NPMJS_CHANGES_URL',
#                                     "https://skimdb.npmjs.com/registry/"
#                                     "_changes?descending=true&include_docs=true&feed=continuous")
#     UNQUOTED_POSTGRES_CONNECTION = _make_postgres_string(environ.get('POSTGRESQL_PASSWORD', ''))
#     POSTGRES_CONNECTION = _make_postgres_string(
#         quote(environ.get('POSTGRESQL_PASSWORD', ''), safe=''))
#     WORKER_DATA_DIR = environ.get('WORKER_DATA_DIR', 'not-set')
#     NPM_DATA_DIR = path.join(environ.get('HOME', '.npm'))
#     SCANCODE_LICENSE_SCORE = environ.get('SCANCODE_LICENSE_SCORE', '20')  # scancode's default is 0
#     SCANCODE_TIMEOUT = environ.get('SCANCODE_TIMEOUT', '120')  # scancode's default is 120
#     SCANCODE_PROCESSES = environ.get('SCANCODE_PROCESSES', '1')  # scancode's default is 1
#     SCANCODE_PATH = environ.get('SCANCODE_PATH', '/opt/scancode-toolkit/')
#     SCANCODE_IGNORE = ['*.pyc', '*.so', '*.dll', '*.rar', '*.jar',
#                        '*.zip', '*.tar', '*.tar.gz', '*.tar.xz', '*.png']  # don't scan binaries
#     AWS_S3_REGION = environ.get('AWS_S3_REGION')
#     AWS_S3_ACCESS_KEY_ID = environ.get('AWS_S3_ACCESS_KEY_ID')
#     AWS_S3_SECRET_ACCESS_KEY = environ.get('AWS_S3_SECRET_ACCESS_KEY')
#     S3_ENDPOINT_URL = environ.get('S3_ENDPOINT_URL')
#     DEPLOYMENT_PREFIX = environ.get('DEPLOYMENT_PREFIX')
#     BAYESIAN_SYNC_S3 = int(environ.get('BAYESIAN_SYNC_S3', 0)) == 1
#     AWS_SQS_ACCESS_KEY_ID = environ.get('AWS_SQS_ACCESS_KEY_ID')
#     AWS_SQS_SECRET_ACCESS_KEY = environ.get('AWS_SQS_SECRET_ACCESS_KEY')
#     CELERY_RESULT_BACKEND = environ.get('CELERY_RESULT_BACKEND')
#     AWS_SQS_REGION = environ.get('AWS_SQS_REGION')
#     JAVANCSS_PATH = environ.get('JAVANCSS_PATH')
#     OWASP_DEP_CHECK_PATH = environ.get('OWASP_DEP_CHECK_PATH')
#         USAGE_THRESHOLD = int(environ.get("LOW_USAGE_THRESHOLD", "5000"))
#         USAGE_THRESHOLD = 5000
#         POPULARITY_THRESHOLD = int(environ.get("LOW_POPULARITY_THRESHOLD", "5000"))
#         POPULARITY_THRESHOLD = 5000
#     BAYESIAN_GREMLIN_HTTP_SERVICE_HOST = environ.get("BAYESIAN_GREMLIN_HTTP_SERVICE_HOST",
#                                                      "localhost")
#     BAYESIAN_GREMLIN_HTTP_SERVICE_PORT = environ.get("BAYESIAN_GREMLIN_HTTP_SERVICE_PORT", "8182")


# Path: f8a_worker/storages/s3.py
import os
import json
import uuid
import boto3
import botocore
from selinon import DataStorage
from selinon import StoragePool
from f8a_worker.defaults import configuration

"""Basic interface to the Amazon S3 database."""



class AmazonS3(DataStorage):
    """Basic interface to the Amazon S3 database."""

    _DEFAULT_REGION_NAME = 'us-east-1'
    _DEFAULT_BUCKET_NAME = 'bayesian-core-unknown'
    _DEFAULT_LOCAL_ENDPOINT = 'http://coreapi-s3:33000'
    _DEFAULT_ENCRYPTION = 'aws:kms'
    _DEFAULT_VERSIONED = True

    def __init__(self, aws_access_key_id=None, aws_secret_access_key=None, bucket_name=None,
                 region_name=None, endpoint_url=None, use_ssl=False, encryption=None,
                 versioned=None):
        """Initialize object, setup connection to the AWS S3."""
        # TODO: reduce cyclomatic complexity
        # Priority for configuration options:
        #   1. environment variables
        #   2. arguments passed to constructor
        #   3. defaults as listed in self._DEFAULT_*
        super().__init__()
        self._s3 = None

        self.region_name = configuration.AWS_S3_REGION or region_name or self._DEFAULT_REGION_NAME
        bucket_name = bucket_name or self._DEFAULT_BUCKET_NAME
        self.bucket_name = bucket_name.format(**os.environ)
        self._aws_access_key_id = configuration.AWS_S3_ACCESS_KEY_ID or aws_access_key_id
        self._aws_secret_access_key = \

            configuration.AWS_S3_SECRET_ACCESS_KEY or aws_secret_access_key