-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from infn-datacloud/3-use-socketio
3 use socketio
- Loading branch information
Showing
18 changed files
with
667 additions
and
163 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import argparse | ||
import os | ||
|
||
import socketio | ||
from socketio import ClientNamespace | ||
|
||
parser = argparse.ArgumentParser(description="Pass token.") | ||
parser.add_argument( | ||
"--token", | ||
"-t", | ||
type=str, | ||
default=os.environ.get("SOCKETIO_CLIENT_TOKEN", None), | ||
help="Access token to use. If not set use the value in the SOCKETIO_CLIENT_TOKEN", | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
|
||
class SiteAdminNameSpace(ClientNamespace): | ||
def on_connect(self): | ||
print(f"Connection to namespace {self.namespace} established") | ||
self.emit("list_provider_federation_requests", {"username": ""}) | ||
|
||
def on_connect_error(self, data): | ||
print(f"Failed to connect to namespace {self.namespace}", data) | ||
|
||
def on_list_provider_federation_requests(self, data): | ||
print(f"Message received with {data}") | ||
self.disconnect() | ||
|
||
def on_disconnect(self): | ||
print(f"Disconnected from namespace {self.namespace}") | ||
|
||
|
||
sio = socketio.Client() | ||
sio.register_namespace(SiteAdminNameSpace("/site_admin")) | ||
|
||
|
||
sio.connect( | ||
"http://localhost:8000", | ||
transports=["websocket", "polling"], | ||
auth={"token": args.token}, | ||
) | ||
sio.wait() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from typing import Any, Literal | ||
|
||
from socketio import AsyncNamespace | ||
|
||
from fed_mng.socketio.utils import validate_auth_on_connect | ||
|
||
|
||
class AdminNamespace(AsyncNamespace): | ||
async def on_connect( | ||
self, sid: str, environ: dict[str, Any], auth: dict[Literal["token"], str] | ||
): | ||
"""When connecting evaluate user authentication.""" | ||
print(f"Connecting to namespace: {self.namespace}") | ||
print(f"SID: {sid}") | ||
print(f"Environment variables: {environ}") | ||
print(f"Auth data: {auth}") | ||
validate_auth_on_connect(auth=auth, target_role=self.namespace[1:]) | ||
print(f"Connected to namespace '{self.namespace}' with sid '{sid}'") | ||
|
||
async def on_disconnect(self, sid): | ||
"""Close connection | ||
Args: | ||
sid (_type_): _description_ | ||
""" | ||
print("disconnect from namespace:", self.namespace, sid) |
Oops, something went wrong.