MCPcopy Create free account
hub / github.com/AstroPrint/AstroBox / getAccessKeys

Function getAccessKeys

src/octoprint/server/__init__.py:309–353  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

307
308@app.route("/accessKeys", methods=["POST"])
309def getAccessKeys():
310 from astroprint.cloud import astroprintCloud
311
312 publicKey = None
313 email = request.values.get('email', None)
314 accessKey = request.values.get('accessKey', None)
315
316 userLogged = settings().get(["cloudSlicer", "loggedUser"])
317 ####
318 # - nobody logged: None
319 # - any log: email
320
321 if email and accessKey:#somebody is logged in the remote client
322 if userLogged:#Somebody logged in Astrobox
323 if userLogged == email:#I am the user logged
324 online = networkManager().isOnline()
325
326 if online:
327 publicKey = astroprintCloud().get_public_key(email, accessKey)
328
329 if not publicKey:
330 abort(403)
331
332 else:
333 user = userManager.findUser(email)
334 if user.get_private_key() != accessKey:
335 abort(403)
336
337 else:#I am NOT the logged user
338 abort(403)
339
340 else:#nodody is logged in the remote client
341 if userLogged:
342 abort(401)
343
344 return Response(
345 json.dumps({
346 'api_key': UI_API_KEY,
347 'ws_token': create_ws_token(publicKey)
348 }),
349 mimetype= 'application/json',
350 headers= {
351 'Access-Control-Allow-Origin': '*'
352 } if settings().getBoolean(['api', 'allowCrossOrigin']) else None
353 )
354
355
356@identity_loaded.connect_via(app)

Callers

nothing calls this directly

Calls 10

settingsFunction · 0.90
networkManagerFunction · 0.90
astroprintCloudFunction · 0.90
create_ws_tokenFunction · 0.85
get_public_keyMethod · 0.80
getBooleanMethod · 0.80
getMethod · 0.45
isOnlineMethod · 0.45
findUserMethod · 0.45
get_private_keyMethod · 0.45

Tested by

no test coverage detected