Exemplo n.º 1
0
def create_db(c):
    """Integration testing: Initialize the policy_sentry database"""
    try:
        initialize.initialize('')
    except UnexpectedExit as u_e:
        logger.critical(f"FAIL! UnexpectedExit: {u_e}")
        sys.exit(1)
    except Failure as f_e:
        logger.critical(f"FAIL: Failure: {f_e}")
        sys.exit(1)
Exemplo n.º 2
0
def create_db(c):
    sentry.initialize('')
Exemplo n.º 3
0
def create_db(c):
    """Integration testing: Initialize the policy_sentry database"""
    initialize.initialize('')
Exemplo n.º 4
0
from policy_sentry.shared import constants

constants.CONFIG_DIRECTORY = "/tmp/.policy_sentry"
constants.LOCAL_DATASTORE_FILE_PATH = "/tmp/.policy_sentry/iam-definition.json"
constants.LOCAL_ACCESS_OVERRIDES_FILE = "/tmp/.policy_sentry/access-level-overrides.yml"
constants.LOCAL_HTML_DIRECTORY_PATH = "/tmp/.policy_sentry/data/docs"

from policy_sentry.command.initialize import initialize

if __name__ == '__main__':
    initialize(None, True, True)
from os.path import isfile, isdir
from pathlib import Path
from policy_sentry.util.actions import get_service_from_action
from policy_sentry.analysis.analyze import analyze_by_access_level
from policy_sentry.shared.constants import DATABASE_FILE_PATH
from policy_sentry.shared.database import connect_db
from policy_sentry.util.file import list_files_in_directory
from policy_sentry.command.initialize import initialize
from common.awsinfo import is_aws_managed_policy

HOME = str(Path.home())
if isfile(HOME + '/.policy_sentry/aws.sqlite3'):
    print("Policy Sentry database found. Continuing...")
else:
    print("NOTE: Policy Sentry database not found. Initializing...")
    initialize()
db_session = connect_db(DATABASE_FILE_PATH)


@click.command(
    short_help=
    'analyze the JSON formatted results of the find_public_instances_with_roles script.'
)
@click.option(
    '--input-file',
    type=click.Path(exists=True),
    help=
    'Path to the JSON file you want to analyze, or a directory of those files. '
    'Defaults to the directory "./reports/accounts/"',
    default=os.getcwd() + '/reports/accounts/')
@click.option(