Autoformat
This commit is contained in:
@@ -2,34 +2,34 @@ import os
|
||||
|
||||
import click
|
||||
|
||||
from dragonion_server.utils.config import db
|
||||
from dragonion_server.common import console
|
||||
from dragonion_server.utils.config import db
|
||||
|
||||
|
||||
class ServiceRemoveCommand(click.Command):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
name='remove',
|
||||
name="remove",
|
||||
callback=self.callback,
|
||||
params=[
|
||||
click.Option(
|
||||
('--name', '-n'),
|
||||
("--name", "-n"),
|
||||
required=True,
|
||||
prompt=True,
|
||||
type=str,
|
||||
help='Name of service to write to'
|
||||
help="Name of service to write to",
|
||||
)
|
||||
]
|
||||
],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def callback(name: str):
|
||||
try:
|
||||
del db.services[name]
|
||||
if os.path.isfile(f'{name}.auth'):
|
||||
os.remove(f'{name}.auth')
|
||||
|
||||
print(f'Removed service {name}')
|
||||
if os.path.isfile(f"{name}.auth"):
|
||||
os.remove(f"{name}.auth")
|
||||
|
||||
print(f"Removed service {name}")
|
||||
except KeyError:
|
||||
print(f'Service "{name}" does not exist in this storage')
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,60 +1,63 @@
|
||||
import sys
|
||||
|
||||
import click
|
||||
|
||||
from dragonion_server.modules.server import run, run_without_onion, integrate_onion
|
||||
from dragonion_server.common import console
|
||||
from dragonion_server.modules.server import integrate_onion, run, run_without_onion
|
||||
|
||||
|
||||
class ServiceRunCommand(click.Command):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
name='run',
|
||||
name="run",
|
||||
callback=self.callback,
|
||||
params=[
|
||||
click.Option(
|
||||
('--name', '-n'),
|
||||
("--name", "-n"),
|
||||
required=True,
|
||||
prompt=True,
|
||||
type=str,
|
||||
help='Name of service to write to'
|
||||
help="Name of service to write to",
|
||||
),
|
||||
click.Option(
|
||||
('--port', '-p'),
|
||||
("--port", "-p"),
|
||||
required=False,
|
||||
prompt=True,
|
||||
prompt_required=False,
|
||||
type=int,
|
||||
help='Port to start service on'
|
||||
help="Port to start service on",
|
||||
),
|
||||
click.Option(
|
||||
('--without-tor', '-wt'),
|
||||
("--without-tor", "-wt"),
|
||||
is_flag=True,
|
||||
help='Run service without tor'
|
||||
help="Run service without tor",
|
||||
),
|
||||
click.Option(
|
||||
('--only-tor', '-ot'),
|
||||
("--only-tor", "-ot"),
|
||||
is_flag=True,
|
||||
help='Run only tor proxy to service'
|
||||
)
|
||||
]
|
||||
help="Run only tor proxy to service",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def callback(name: str, port: int | None, without_tor: bool, only_tor: bool):
|
||||
try:
|
||||
if without_tor and only_tor:
|
||||
print('Cannot run only tor without tor, exiting')
|
||||
print("Cannot run only tor without tor, exiting")
|
||||
sys.exit(1)
|
||||
elif without_tor:
|
||||
run_without_onion(name, port)
|
||||
elif only_tor:
|
||||
if port is None:
|
||||
print('For this mode, you need to specify port, '
|
||||
'to which requests will be redirected. Cannot start '
|
||||
'tor service, exiting')
|
||||
print(
|
||||
"For this mode, you need to specify port, "
|
||||
"to which requests will be redirected. Cannot start "
|
||||
"tor service, exiting"
|
||||
)
|
||||
sys.exit(1)
|
||||
onion = integrate_onion(port, name)
|
||||
input('Press Enter to stop onion and service...')
|
||||
input("Press Enter to stop onion and service...")
|
||||
onion.cleanup()
|
||||
else:
|
||||
run(name, port)
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
from ...utils import ModuleGroup
|
||||
from .write import ServiceWriteCommand
|
||||
from .run import ServiceRunCommand
|
||||
from .remove import ServiceRemoveCommand
|
||||
|
||||
from .run import ServiceRunCommand
|
||||
from .write import ServiceWriteCommand
|
||||
|
||||
service_group = ModuleGroup(
|
||||
name='service',
|
||||
name="service",
|
||||
commands={
|
||||
'write': ServiceWriteCommand(),
|
||||
'run': ServiceRunCommand(),
|
||||
'remove': ServiceRemoveCommand()
|
||||
}
|
||||
"write": ServiceWriteCommand(),
|
||||
"run": ServiceRunCommand(),
|
||||
"remove": ServiceRemoveCommand(),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -1,30 +1,30 @@
|
||||
import click
|
||||
|
||||
from dragonion_server.utils.onion import Onion
|
||||
from dragonion_server.common import console
|
||||
from dragonion_server.utils.onion import Onion
|
||||
|
||||
|
||||
class ServiceWriteCommand(click.Command):
|
||||
def __init__(self):
|
||||
super().__init__(
|
||||
name='write',
|
||||
name="write",
|
||||
callback=self.callback,
|
||||
params=[
|
||||
click.Option(
|
||||
('--name', '-n'),
|
||||
("--name", "-n"),
|
||||
required=True,
|
||||
prompt=True,
|
||||
type=str,
|
||||
help='Name of service to write to'
|
||||
help="Name of service to write to",
|
||||
),
|
||||
click.Option(
|
||||
('--port', '-p'),
|
||||
("--port", "-p"),
|
||||
required=True,
|
||||
prompt=True,
|
||||
type=int,
|
||||
help='Port to start service on'
|
||||
)
|
||||
]
|
||||
help="Port to start service on",
|
||||
),
|
||||
],
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
|
||||
Reference in New Issue
Block a user