align Py SDK with permission model

This commit is contained in:
Kenneth Bingham
2024-03-11 15:36:24 -04:00
parent de1ebdc333
commit e6fc45b2ce
4 changed files with 33 additions and 33 deletions

View File

@ -16,7 +16,7 @@ The zrok SDK requires Python 3.10 or later.
If you haven't already installed them, you'll need the dependent libraries used in the examples.
```bash
pip install -r ./sdk/python/examples/requirements.txt
pip install -r ./sdk/python/examples/pastebin/requirements.txt
```
## Running the Example :arrow_forward:
@ -25,7 +25,7 @@ This example contains a `copyto` server portion and `pastefrom` client portion.
### copyto
The server portion expects to get data you want to send via stdin. It can be evoked by:
The server portion expects to get the data you want to send via stdin. It can be invoked by:
```bash
echo "this is a cool test" | python pastebin.py copyto

View File

@ -12,14 +12,16 @@ import threading
exit_signal = threading.Event()
def signal_handler(signum, frame):
print("\nCtrl-C detected. Next connection will close server")
exit_signal.set()
class copyto:
def handle(self, *args, **kwargs):
root = zrok.environment.root.Load()
try:
shr = zrok.share.CreateShare(root=root, request=ShareRequest(
BackendMode=zrok.model.TCP_TUNNEL_BACKEND_MODE,
@ -48,7 +50,6 @@ class copyto:
conn.sendall(data.encode('utf-8'))
print("Server stopped.")
def loadData(self):
if not os.isatty(sys.stdin.fileno()):
@ -56,6 +57,7 @@ class copyto:
else:
raise Exception("'copyto' requires input from stdin; direct your paste buffer into stdin")
def pastefrom(options):
root = zrok.environment.root.Load()
@ -66,7 +68,7 @@ def pastefrom(options):
except Exception as e:
print("unable to create access", e)
sys.exit(1)
def removeAccess():
try:
zrok.access.DeleteAccess(root, acc)
@ -79,6 +81,7 @@ def pastefrom(options):
data = client.recv(1024)
print(data.decode('utf-8'))
if __name__ == "__main__":
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers()