in cookbooks/aws-parallelcluster-platform/files/dcv/pcluster_dcv_authenticator.py [0:0]
def do_POST(self): # noqa N802 pylint: disable=C0103
"""
Handle POST requests, coming from Amazon DCV server.
The format of the request is the following:
curl -k http://localhost:<port> -d sessionId=<session-id> -d authenticationToken=<token>
"""
try:
length = int(self.headers["Content-Length"])
field_data = self.rfile.read(length).decode("utf-8")
parameters = dict(parse_qsl(field_data))
if len(parameters) != 3:
raise DCVAuthenticator.IncorrectRequestError(
f"Incorrect number of parameters passed.\nParameters: {parameters}"
)
session_token, session_id = self._extract_parameters_values(
parameters, ["authenticationToken", "sessionId"]
)
authorized_user = self._check_auth(session_id, session_token)
if authorized_user:
self._return_auth_ok(username=authorized_user)
else:
raise DCVAuthenticator.IncorrectRequestError("The session token is not valid")
except DCVAuthenticator.IncorrectRequestError as e:
logger.error(e)
self._return_auth_ko(e)