Esempio n. 1
0
def system_cfg_init(session, tid):
    for var_name, desc in ConfigDescriptor.items():
        if callable(desc.default):
            default = desc.default()
        else:
            default = desc.default

        session.add(Config(tid, var_name, default))
Esempio n. 2
0
    def update_defaults(self):
        actual = set([c[0] for c in self.session.query(Config.var_name).filter(Config.tid == self.tid)])
        allowed = set(ConfigDescriptor.keys())
        extra = list(actual - allowed)

        if extra:
            self.session.query(Config).filter(Config.tid == self.tid, Config.var_name.in_(extra)).delete(synchronize_session='fetch')

        missing = list(allowed - actual)
        for key in missing:
            self.session.add(Config({'tid': self.tid, 'var_name': key, 'value': get_default(ConfigDescriptor[key].default)}))
Esempio n. 3
0
def initialize_tenant_config(session, tid):
    variables = {}

    # Initialization valid for any tenant
    for name, desc in ConfigDescriptor.items():
        variables[name] = get_default(desc.default)

    if tid != 1:
        # Initialization valid for secondary tenants
        root_tenant_node = ConfigFactory(session, 1, 'node').serialize()
        for name in inherit_from_root_tenant:
            variables[name] = root_tenant_node[name]

    for name, value in variables.items():
        session.add(Config(tid, name, value))
Esempio n. 4
0
def fix_tenant_config(session, tid):
    '''
    The function add new defined variables and remove variables not anymore defined
    '''
    actual = set([c[0] for c in session.query(Config.var_name).filter(Config.tid == tid)])
    allowed = set(ConfigDescriptor.keys())
    extra = list(actual - allowed)

    if extra:
        session.query(Config).filter(Config.tid == tid, Config.var_name.in_(extra)).delete(synchronize_session='fetch')

    missing = list(allowed - actual)
    for key in missing:
        session.add(Config(tid, key, get_default(ConfigDescriptor[key].default)))

    return len(missing), len(extra)
Esempio n. 5
0
def initialize_config(session, tid, mode):
    variables = {}

    # Initialization valid for any tenant
    for name, desc in ConfigDescriptor.items():
        variables[name] = get_default(desc.default)

    if tid != 1:
        # Initialization valid for secondary tenants
        variables['mode'] = mode

        root_tenant_node = ConfigFactory(session, 1).serialize('node')
        for name in inherit_from_root_tenant:
            variables[name] = root_tenant_node[name]

    for name, value in variables.items():
        session.add(Config({'tid': tid, 'var_name': name, 'value': value}))
Esempio n. 6
0
    def clean_and_add(self):
        actual = set([
            c[0] for c in self.session.query(Config.var_name).filter(
                Config.tid == self.tid)
        ])
        allowed = set(ConfigDescriptor.keys())
        extra = list(actual - allowed)

        if extra:
            self.session.query(Config).filter(
                Config.tid == self.tid,
                Config.var_name.in_(extra)).delete(synchronize_session='fetch')

        missing = list(allowed - actual)
        for key in missing:
            self.session.add(
                Config(self.tid, key, ConfigDescriptor[key].default))

        return len(missing), len(extra)
Esempio n. 7
0
def initialize_config(session, tid, mode):
    variables = {}

    # Initialization valid for any tenant
    for name, desc in ConfigDescriptor.items():
        variables[name] = get_default(desc.default)

    if tid != 1:
        # Initialization valid for secondary tenants
        variables['mode'] = mode

    if mode == 'default':
        variables['onionservice'], variables[
            'tor_onion_key'] = generate_onion_service_v3()

    if mode == 'whistleblowing.it':
        root_tenant_node = ConfigFactory(session, 1).serialize('node')
        for name in inherit_from_root_tenant:
            variables[name] = root_tenant_node[name]

    for name, value in variables.items():
        session.add(Config({'tid': tid, 'var_name': name, 'value': value}))