cycls 0.0.2.17__py3-none-any.whl → 0.0.2.19__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
cycls/cycls.py
CHANGED
|
@@ -20,6 +20,7 @@ class Message(BaseModel):
|
|
|
20
20
|
id: str
|
|
21
21
|
history: Optional[List[Dict[str, str]]] = None
|
|
22
22
|
|
|
23
|
+
# too dirty
|
|
23
24
|
def find_available_port(start_port):
|
|
24
25
|
port = start_port
|
|
25
26
|
while True:
|
|
@@ -29,12 +30,11 @@ def find_available_port(start_port):
|
|
|
29
30
|
port += 1
|
|
30
31
|
|
|
31
32
|
import asyncssh, asyncio
|
|
32
|
-
|
|
33
33
|
async def create_ssh_tunnel(x,y,z='tuns.sh'):
|
|
34
34
|
try:
|
|
35
35
|
async with asyncssh.connect(z,client_keys=[key_path],known_hosts=None) as conn:
|
|
36
36
|
listener = await conn.forward_remote_port(x, 80, 'localhost', y)
|
|
37
|
-
print("✦/✧","tunnel\n")
|
|
37
|
+
print("✦/✧","tunnel | open\n")
|
|
38
38
|
await listener.wait_closed()
|
|
39
39
|
except (OSError, asyncssh.Error) as e:
|
|
40
40
|
print("✦/✧",f"tunnel disconnected: {e}")
|
|
@@ -45,17 +45,16 @@ def register(handles, network, url, mode):
|
|
|
45
45
|
response = client.post(f"{network}/register", json={"handles":handles, "url":url, "mode":mode})
|
|
46
46
|
if response.status_code==200:
|
|
47
47
|
data = (response.json()).get("content")
|
|
48
|
-
for i in data:
|
|
48
|
+
for i in data:
|
|
49
|
+
if i[0]=="new":
|
|
50
|
+
print(f"✦/✧ {i[0]} | {network}/{i[1]}")
|
|
51
|
+
else:
|
|
52
|
+
print(f"✦/✧ {i[0]} | {network}/{i[1]}")
|
|
49
53
|
else:
|
|
50
54
|
print("✦/✧ failed to register ⚠️")
|
|
51
55
|
except Exception as e:
|
|
52
56
|
print(f"An error occurred: {e}")
|
|
53
57
|
|
|
54
|
-
async def run_server(x,y):
|
|
55
|
-
config = uvicorn.Config(x, host="127.0.0.1", port=y, log_level="error")
|
|
56
|
-
server = uvicorn.Server(config)
|
|
57
|
-
await server.serve()
|
|
58
|
-
|
|
59
58
|
class Cycls:
|
|
60
59
|
def __init__(self, url="", network="https://cycls.com", port=find_available_port(8001)):
|
|
61
60
|
import uuid
|
|
@@ -75,7 +74,7 @@ class Cycls:
|
|
|
75
74
|
def sync_wrapper(*args, **kwargs):
|
|
76
75
|
return StreamingResponse(func(*args, **kwargs))
|
|
77
76
|
wrapper = async_wrapper if inspect.iscoroutinefunction(func) else sync_wrapper
|
|
78
|
-
self.apps[
|
|
77
|
+
self.apps[handle] = wrapper
|
|
79
78
|
return wrapper
|
|
80
79
|
return decorator
|
|
81
80
|
|
|
@@ -90,26 +89,30 @@ class Cycls:
|
|
|
90
89
|
|
|
91
90
|
def push(self):
|
|
92
91
|
self.server.post("/gateway")(self.gateway)
|
|
93
|
-
|
|
92
|
+
@self.server.on_event("startup")
|
|
93
|
+
def startup_event():
|
|
94
|
+
asyncio.create_task(create_ssh_tunnel(f"{self.subdomain}-cycls", self.port))
|
|
95
|
+
|
|
96
|
+
self.publish()
|
|
94
97
|
|
|
95
|
-
|
|
98
|
+
try:
|
|
99
|
+
uvicorn.run(self.server, host="127.0.0.1", port=self.port, log_level="error")
|
|
100
|
+
except KeyboardInterrupt:
|
|
101
|
+
print(f"\n✦/✧ exit | done")
|
|
102
|
+
|
|
103
|
+
def publish(self):
|
|
104
|
+
# prod catch is too dirty
|
|
96
105
|
prod=False
|
|
97
106
|
if self.url != "":
|
|
98
107
|
prod=True
|
|
99
108
|
|
|
100
|
-
print(f"✦/✧
|
|
109
|
+
print(f"✦/✧ port | {self.port}")
|
|
101
110
|
if prod:
|
|
102
111
|
print("✦/✧",f"production mode | url: {self.url}")
|
|
103
112
|
register(list(self.apps.keys()), self.network, self.url+"/gateway", "prod")
|
|
104
113
|
else:
|
|
105
114
|
self.url = f"http://{self.subdomain}-cycls.tuns.sh"
|
|
106
|
-
print("✦/✧","development
|
|
107
|
-
# print("✦/✧",f"url {self.url}")
|
|
115
|
+
print("✦/✧","mode | development")
|
|
108
116
|
register(list(self.apps.keys()), self.network, self.url+"/gateway", "dev")
|
|
109
|
-
t1 = asyncio.create_task(create_ssh_tunnel(f"{self.subdomain}-cycls", self.port))
|
|
110
|
-
|
|
111
|
-
t2 = asyncio.create_task(run_server(self.server,self.port))
|
|
112
117
|
|
|
113
|
-
await asyncio.gather(t1, t2) if not prod else await asyncio.gather(t2)
|
|
114
|
-
|
|
115
118
|
# poetry publish --build
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
cycls/__init__.py,sha256=HPPQikt_Trbc4s8XyEOeOjB_JRWXlXIkJuh762nUM_g,24
|
|
2
|
+
cycls/cycls.py,sha256=Y_6IiHAPgnZI9xZEzR4mzCwjVd6awFrbY5USUjX6jW4,4138
|
|
3
|
+
cycls/tuns,sha256=CT8olxDKOM0cY6r_bbSGtnWyEmEYFVDVHj9ug3gbYHk,1843
|
|
4
|
+
cycls-0.0.2.19.dist-info/METADATA,sha256=BmoAPVK4piZoaWvDo7YB-cpddkvpiJzdslWCiK-6QVE,2018
|
|
5
|
+
cycls-0.0.2.19.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
6
|
+
cycls-0.0.2.19.dist-info/RECORD,,
|
cycls-0.0.2.17.dist-info/RECORD
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
cycls/__init__.py,sha256=HPPQikt_Trbc4s8XyEOeOjB_JRWXlXIkJuh762nUM_g,24
|
|
2
|
-
cycls/cycls.py,sha256=t1-4vkJ-hltM-vKAnye0IauGk35WffOm7-4JbL1721Q,4063
|
|
3
|
-
cycls/tuns,sha256=CT8olxDKOM0cY6r_bbSGtnWyEmEYFVDVHj9ug3gbYHk,1843
|
|
4
|
-
cycls-0.0.2.17.dist-info/METADATA,sha256=Si9de9uRafOo5zo3ueXulHlzzaMyR5mO-Da-rXRMR4U,2018
|
|
5
|
-
cycls-0.0.2.17.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
|
|
6
|
-
cycls-0.0.2.17.dist-info/RECORD,,
|
|
File without changes
|