Exemplo n.º 1
0
def _unregister(config_file_path):
    channel = grpc.insecure_channel(
        '%s:%s' %
        (get_config("system", "experiment_manager_ip", config_file_path),
         get_config("system", "experiment_manager_port", config_file_path)))
    stub = messages_pb2_grpc.RegistrationServiceStub(channel)
    response = stub.unregister(
        messages_pb2.UnregisterMessage(
            name=get_config("system", "name", config_file_path),
            endpoint="%s:%s" %
            (get_config("system", "ip", config_file_path),
             get_config("messaging", "bind_port", config_file_path))))
    logging.debug("Manager received unregistration response: %s" %
                  response.result)
Exemplo n.º 2
0
def start():
    bottle.debug(True)

    #TODO forward change to .ini file
    port = get_config(config_file_path=config_path,
                      section='api',
                      key='port',
                      default=8080)
    app = bottle.app()
    # bottle.install(error_translation)

    session_opts = {
        'session.cookie_expires': True,
        # 'session.encrypt_key': get_config('api', 'encrypt_key', 'softfire'),
        'session.httponly': True,
        'session.timeout': 3600 * 24,  # 1 day
        'session.type': 'cookie',
        'session.validate_key': True,
    }
    app = SessionMiddleware(app, session_opts)
    # quiet_bottle = logger.getEffectiveLevel() < logging.DEBUG
    # logger.debug("Bootlepy quiet mode: %s" % quiet_bottle)

    logger.info("Starting want-agent REST server. listening on %s:%s" %
                (REST_HOST, PORT))
    bottle.run(app=app, port=PORT, host=REST_HOST)
Exemplo n.º 3
0
 def get_config_value(self,
                      section,
                      key,
                      default=None,
                      config_file_path="/etc/softfire/sdn-manager.ini"):
     return get_config(section=section,
                       key=key,
                       default=default,
                       config_file_path=config_file_path)
Exemplo n.º 4
0
def check_if_authorized(username):
    authorized_experimenter_file = get_config(
        'api', 'authorized-experimenters',
        '/etc/softfire/authorized-experimenters.json')
    if os.path.exists(authorized_experimenter_file) and os.path.isfile(
            authorized_experimenter_file):
        with open(authorized_experimenter_file, "r") as f:
            authorized_exp = json.loads(f.read().encode("utf-8"))
            return authorized_exp.get(username) and bool(
                authorized_exp[username])
    else:
        return False
Exemplo n.º 5
0
def download_scripts(id, resource):
    file_path = get_config(section="local-files",
                           key="path",
                           config_file_path=config_path)

    logger.info("incoming request")
    # username = aaa.current_user.username
    '''
    resources_db = '%s/security-manager.db' % local_files_path
    conn = sqlite3.connect(resources_db)
    cur = conn.cursor()
    res = cur.execute('SELECT * FROM resources WHERE  username = "******" AND random_id = "%s"' % (username, id))

    if len(res.fetchall()) == 0 :
        conn.close()
        return bottle.HTTPResponse(status=403)
    conn.close()
    '''

    if resource == "dashboard":
        ext = ".html"
        download = False
    else:
        ext = ".tar"
        download = True

    tmp_file_path = "%s/tmp" % file_path
    if resource == "dashboard":
        filename = "%s/%s%s" % (id, resource, ext)
    else:
        filename = "%s/%s-%s%s" % (id, resource, id, ext)

    logger.debug("%s-%s" % (tmp_file_path, filename))

    try:
        f = static_file(filename, tmp_file_path, download=download)
    except Exception:
        f = "ERROR"
    return f
Exemplo n.º 6
0
 def get_config_value(self, section, key, default=None):
     return get_config(section=section,
                       key=key,
                       default=default,
                       config_file_path=self.config_file_path)