def decorated_view(*args, **kwargs): # if OctoPrint hasn't been set up yet, abort if settings().getBoolean([ "server", "firstRun" ]) and (octoprint.server.userManager is None or not octoprint.server.userManager.hasBeenCustomized()): return make_response("OctoPrint isn't setup yet", 403) # if API is globally enabled, enabled for this request and an api key is provided that is not the current UI API key, try to use that apikey = getApiKey(request) if settings().get( ["api", "enabled"] ) and apiEnabled and apikey is not None and apikey != octoprint.server.UI_API_KEY: if apikey == settings().get(["api", "key"]): # master key was used user = ApiUser() else: # user key might have been used user = octoprint.server.userManager.findUser(apikey=apikey) if user is None: return make_response("Invalid API key", 401) if login_user(user, remember=False): identity_changed.send(current_app._get_current_object(), identity=Identity(user.get_id())) return func(*args, **kwargs) # call regular login_required decorator #TODO: remove this temporary disablement of login requirement #return login_required(func)(*args, **kwargs) return func(*args, **kwargs)
def decorated_view(*args, **kwargs): # if OctoPrint hasn't been set up yet, abort if settings().getBoolean(["server", "firstRun"]) and (octoprint.server.userManager is None or not octoprint.server.userManager.hasBeenCustomized()): return make_response("OctoPrint isn't setup yet", 403) # if API is globally enabled, enabled for this request and an api key is provided that is not the current UI API key, try to use that apikey = getApiKey(request) if settings().get(["api", "enabled"]) and apiEnabled and apikey is not None and apikey != octoprint.server.UI_API_KEY: if apikey == settings().get(["api", "key"]): # master key was used user = ApiUser() else: # user key might have been used user = octoprint.server.userManager.findUser(apikey=apikey) if user is None: return make_response("Invalid API key", 401) if login_user(user, remember=False): identity_changed.send(current_app._get_current_object(), identity=Identity(user.get_id())) return func(*args, **kwargs) # call regular login_required decorator #TODO: remove this temporary disablement of login requirement #return login_required(func)(*args, **kwargs) return func(*args, **kwargs)
def getUserForApiKey(apikey): if settings().get(["api", "enabled"]) and apikey is not None: if apikey == settings().get(["api", "key"]): # master key was used return ApiUser() else: # user key might have been used return octoprint.server.userManager.findUser(apikey=apikey) else: return None