Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
6690e6db
Commit
6690e6db
authored
3 years ago
by
Mario Raciti
Browse files
Options
Downloads
Patches
Plain Diff
TMSS-556
: Add first skeleton of WebSocket class to handle auth
parent
08ce9ea9
No related branches found
No related tags found
1 merge request
!822
Resolve TMSS-556
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
SAS/TMSS/backend/services/websocket/lib/websocket_service.py
+19
-1
19 additions, 1 deletion
SAS/TMSS/backend/services/websocket/lib/websocket_service.py
with
19 additions
and
1 deletion
SAS/TMSS/backend/services/websocket/lib/websocket_service.py
+
19
−
1
View file @
6690e6db
...
@@ -44,6 +44,23 @@ HTTP Headers are not supported inside the WebSocket protocol (see https://tools.
...
@@ -44,6 +44,23 @@ HTTP Headers are not supported inside the WebSocket protocol (see https://tools.
WS traffic is either UTC-8 text or binary data (see https://tools.ietf.org/html/rfc6455#page-39).
WS traffic is either UTC-8 text or binary data (see https://tools.ietf.org/html/rfc6455#page-39).
'''
'''
class
TMSSWebSocket
(
WebSocket
):
authenticated
=
False
# TODO: Handle list of connected clients.
def
handleMessage
(
self
):
if
not
self
.
authenticated
:
# Not (yet) authenticated
token
=
json
.
loads
(
self
.
data
).
get
(
'
token
'
,
''
)
self
.
authenticated
=
True
# TODO: Check if token is valid.
if
not
self
.
authenticated
:
logging
.
info
(
'
> Client unauthenticated %s
'
%
self
.
address
[
0
])
self
.
close
(
1011
,
u
'
unauthenticated
'
)
else
:
logging
.
info
(
'
> Client authenticated %s
'
%
self
.
address
[
0
])
self
.
sendMessage
(
'
Successfully authenticated.
'
)
class
TMSSEventMessageHandlerForWebsocket
(
TMSSEventMessageHandler
):
class
TMSSEventMessageHandlerForWebsocket
(
TMSSEventMessageHandler
):
'''
'''
'''
'''
...
@@ -71,7 +88,7 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
...
@@ -71,7 +88,7 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
# Create and run a simple ws server
# Create and run a simple ws server
def
start_ws_server
():
def
start_ws_server
():
logger
.
debug
(
"
starting websocket server on port %s
"
,
self
.
websocket_port
)
logger
.
debug
(
"
starting websocket server on port %s
"
,
self
.
websocket_port
)
self
.
_ws_server
=
SimpleWebSocketServer
(
''
,
self
.
websocket_port
,
WebSocket
)
self
.
_ws_server
=
SimpleWebSocketServer
(
''
,
self
.
websocket_port
,
TMSS
WebSocket
)
socket_started_event
.
set
()
socket_started_event
.
set
()
logger
.
info
(
"
started websocket server on port %s
"
,
self
.
websocket_port
)
logger
.
info
(
"
started websocket server on port %s
"
,
self
.
websocket_port
)
while
self
.
_run_ws
:
# Run the server till the stop_handling
while
self
.
_run_ws
:
# Run the server till the stop_handling
...
@@ -100,6 +117,7 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
...
@@ -100,6 +117,7 @@ class TMSSEventMessageHandlerForWebsocket(TMSSEventMessageHandler):
try
:
try
:
model_class
=
apps
.
get_model
(
"
tmssapp
"
,
object_type
.
value
.
replace
(
'
_
'
,
''
))
model_class
=
apps
.
get_model
(
"
tmssapp
"
,
object_type
.
value
.
replace
(
'
_
'
,
''
))
model_instance
=
model_class
.
objects
.
get
(
id
=
id
)
model_instance
=
model_class
.
objects
.
get
(
id
=
id
)
# TODO: Check user permissions for the model_instance.
if
hasattr
(
model_instance
,
'
process_start_time
'
)
and
model_instance
.
process_start_time
is
not
None
:
if
hasattr
(
model_instance
,
'
process_start_time
'
)
and
model_instance
.
process_start_time
is
not
None
:
json_blob
[
'
object_details
'
][
'
process_start_time
'
]
=
model_instance
.
process_start_time
.
isoformat
()
json_blob
[
'
object_details
'
][
'
process_start_time
'
]
=
model_instance
.
process_start_time
.
isoformat
()
if
hasattr
(
model_instance
,
'
process_stop_time
'
)
and
model_instance
.
process_stop_time
is
not
None
:
if
hasattr
(
model_instance
,
'
process_stop_time
'
)
and
model_instance
.
process_stop_time
is
not
None
:
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment