Commit 1b2cf097 authored by Pawel Wodkowski's avatar Pawel Wodkowski Committed by Daniel Verkamp
Browse files

scripts/rpc: filter methods in load_config by allowed methods

parent 8021da8b
Loading
Loading
Loading
Loading
+30 −11
Original line number Diff line number Diff line
@@ -57,17 +57,36 @@ def save_config(client, args):

def load_config(client, args):
    if not args.filename or args.filename == '-':
        config = json.load(sys.stdin)
        json_config = json.load(sys.stdin)
    else:
        with open(args.filename, 'r') as file:
            config = json.load(file)
            json_config = json.load(file)

    for subsystem in config['subsystems']:
        name = subsystem['subsystem']
        config = subsystem['config']
        if not config:
    subsystems = json_config['subsystems']
    while subsystems:
        allowed_methods = client.call('get_rpc_methods', {'current': True})
        allowed_found = False

        for subsystem in list(subsystems):
            if not subsystem['config']:
                subsystems.remove(subsystem)
                continue
        for elem in subsystem['config']:
            if not elem or 'method' not in elem:

            config = subsystem['config']
            for elem in list(config):
                if not elem or 'method' not in elem or elem['method'] not in allowed_methods:
                    continue

                client.call(elem['method'], elem['params'])
                config.remove(elem)
                allowed_found = True

            if not config:
                subsystems.remove(subsystem)

        if 'start_subsystem_init' in allowed_methods:
            client.call('start_subsystem_init')
            allowed_found = True

        if subsystems and not allowed_found:
            raise JSONRPCException("Some config left but did not found any allowed method to execute")