Beispiel #1
0
def config_fixture() -> Config:
    return Config(
        data_refresh_period=None,
        reverse_geocoding_path=TEST_DATA_PATH / "station_location.csv",
        port=0,
        user_content_storage=None,
        velib_data_base_path=TEST_DATA_PATH,
    )
Beispiel #2
0
    def uri(self, type):
        db_uri = None

        if type == DBType.sqlite:
            db_uri = "sqlite:///" + Config()["database"]["sqlite"]["path"]

        if type == DBType.mysql:
            config = Config()["database"]["mysql"]
            db_uri = "mysql+pymysql://{0}:{1}@{2}:3306/{3}".format(
                config["user"], config["password"], config["host"],
                config["db"])

        if type == DBType.postgres:
            config = Config()["database"]["postgres"]
            db_uri = "postgresql://{0}:{1}@{2}:{3}/{4}".format(
                config["user"], config["password"], config["host"],
                config["port"], config["db"])

        return db_uri
Beispiel #3
0
    def test_init_results(self):
        """Make sure _init_results does what is expected"""

        config = Config()
        config.monitors = {"http://test/": {}, "http://test2/": {}}

        result = App._init_results(config)

        assert result["http://test/"] is None
        assert result["http://test2/"] is None
Beispiel #4
0
    def test_expected_configs(self):
        expected_region = 'test-region'
        expected_sender_email = '*****@*****.**'

        os.environ['SES_AWS_REGION'] = expected_region
        os.environ['SES_SENDER_EMAIL'] = expected_sender_email

        expected = Config(
            ses_aws_region=expected_region,
            ses_sender_email=expected_sender_email,
        )

        actual = get_configs_by_env()
        self.assertEqual(expected, actual)
Beispiel #5
0
def api_config_post():
    args = request.form
    name = args["name"]
    api = args["api"]
    token = args["token"]
    config = Config.query.get(1)
    if not config:
        config = Config(name, api, token)
        db.session.add(config)
        db.session.commit()
    config.name = name
    config.api = api
    config.token = token
    db.session.commit()
    return jsonify({"message": "OK."}), 200
#!/usr/bin/env python3

import logging

from app import Config
from ldaploginprovider import LDAPLoginProvider

LOGFORMAT = "[%(asctime)s] [%(levelname)8s] --- %(message)s (%(filename)s:%(lineno)s)"
logging.basicConfig(level=logging.INFO, format=LOGFORMAT)

config = Config()
logging.info("Building ldap_provider")
ldap_provider = LDAPLoginProvider(config.ldap_server, config.ldap_base_dn, config.ldap_user_prefix)
ldap_provider.build_connection()

logging.info("Attempting to login")
user = ldap_provider.login(config.known_user, config.known_pass)
logging.info("Login: " + str(user.__dict__))
Beispiel #7
0
def api_config_get():
    config = Config.query.get(1)
    if not config:
        config = Config("", "", "")
        db.session.commit()
    return jsonify({"config": config.to_dict()}), 200
    def get_service(self, service):
        return self.c.catalog.service(service)

    def deregister_service(self, service_id):
        return self.c.agent.service.deregister(service_id)

    def register_service(self, service_name, vmid, port, address, tags):
        # register(name, service_id=None, address=None, port=None, tags=None, check=None, token=None, script=None, interval=None, ttl=None, http=None, timeout=None, enable_tag_override=False)
        self.c.agent.service.register(service_name,
                                      service_id=vmid,
                                      port=port,
                                      address=address,
                                      tags=[tags])


config = Config().read()
logging.basicConfig(filename=config['settings']['log_file'],
                    filemode='a',
                    format='%(asctime)s [ %(levelname)s ] - %(message)s',
                    datefmt='%m/%d/%Y  %H:%M:%S',
                    level=config['settings']['log_level'])


def register(service_name, data):
    new = []
    for x in data:
        new.append(x['vmid'])

    old = []
    for x in Consul().get_service(service_name)[1]:
        old.append(x['ServiceID'])
Beispiel #9
0
from sqlalchemy.exc import DatabaseError
from flask_sqlalchemy import Model
from sqlalchemy.orm import sessionmaker

from app import Config
from app.utils.traces import print_exception_traces


class DBType(Enum):
    sqlite = 1
    mysql = 2
    postgres = 3


db_type = DBType.sqlite  # Default
if "sqlite" == Config()["database"]["active"]:
    db_type = DBType.sqlite
if "mysql" == Config()["database"]["active"]:
    db_type = DBType.mysql
if "postgres" == Config()["database"]["active"]:
    db_type = DBType.postgres


## Init session
class DBSession():
    def uri(self, type):
        db_uri = None

        if type == DBType.sqlite:
            db_uri = "sqlite:///" + Config()["database"]["sqlite"]["path"]
Beispiel #10
0
def interface(ctx):
    """SetupEnv: A simple templating program"""
    ctx.obj = Config()
Beispiel #11
0
    def test_read_example(self):
        """Just try to read the example config and make sure we do it right"""

        config = Config()
        config.read_from_file('config.example.yaml')
Beispiel #12
0
 def setUpClass(cls):
     # create test database
     config = Config(RuntimeEnvironment.TEST)
     if not database_exists(config.db_uri):
         create_database(config.db_uri)
Beispiel #13
0
def print_exception_traces(e):
    config = Config()
    if config["stacktrace"]:
        print(traceback.format_exc())
    else:
        print(e)