config: cleanup LISTEN_PORT

parent de55c5fc
......@@ -46,7 +46,7 @@ class BeiranContext:
"""Context object for Beiran Commands which keeps clients and other common objects"""
def __init__(self) -> None:
daemon_url = config.url if config.url else \
daemon_url = config.url if config.url != '' else \
"http+unix://" + config.socket_file
peer_address = PeerAddress(address=daemon_url)
......
......@@ -40,7 +40,7 @@ DEFAULTS = {
'CACHE_DIR': '/var/cache/beiran',
'RUN_DIR': '/var/run',
'DISCOVERY_METHOD': 'zeroconf',
'URL': None,
'URL': '',
'KNOWN_NODES': [],
}
......@@ -273,7 +273,7 @@ class Config(metaclass=ConfigMeta):
@property
def url(self):
"""
Beiran daemon's URL. The default value is ``None``
Beiran daemon's URL. The default value is ``''``
config.toml: section ``beiran``, key ``url``
......
......@@ -28,7 +28,7 @@ from beiran.models import Node, PeerAddress
from beiran.cmd_req_handler import RPCEndpoint, rpc
from beiran.daemon.common import Services
from beiran.daemon.lib import get_listen_address, get_listen_port
from beiran.daemon.lib import get_listen_address
define('listen_address',
......@@ -37,7 +37,7 @@ define('listen_address',
help='Listen address')
define('listen_port',
group='webserver',
default=get_listen_port(),
default=config.listen_port,
help='Listen port')
define('unix_socket',
group='webserver',
......
......@@ -115,19 +115,6 @@ def get_listen_address() -> str:
`{}` is not a valid one!""".format(env_addr))
def get_listen_port() -> int:
"""
Get listen port from env or default 8888
Returns:
int: listen port
"""
try:
return int(os.environ.get('LISTEN_PORT', config.listen_port))
except ValueError:
raise ValueError('LISTEN_PORT must be a valid port number!')
def get_listen_interface() -> str:
"""
Seek for listen interface in order described below and return it.
......@@ -246,14 +233,14 @@ def collect_node_info() -> dict:
peer_address = PeerAddress(
uuid=local_node_uuid().hex,
host=get_advertise_address(),
port=get_listen_port(),
port=config.listen_port,
)
return {
"uuid": local_node_uuid().hex,
"address": peer_address.address,
"hostname": get_hostname(),
"ip_address": get_advertise_address(),
"port": get_listen_port(),
"port": config.listen_port,
"ip_address_6": None,
"os_type": platform.system(),
"os_version": platform.version(),
......
......@@ -48,7 +48,7 @@ from beiran.daemon.nodes import Nodes
from beiran.daemon.peer import Peer
from beiran.daemon.lib import collect_node_info
from beiran.daemon.lib import get_listen_port, get_advertise_address
from beiran.daemon.lib import get_advertise_address
from beiran.daemon.lib import update_sync_version_file
from beiran.daemon.http_ws import ROUTES
......@@ -102,7 +102,7 @@ class BeiranDaemon(EventEmitter):
service_port (int): service port of new node
"""
service_port = service_port or get_listen_port()
service_port = service_port or config.listen_port
try:
node = await self.nodes.get_node_by_ip_and_port(ip_address, service_port)
except Node.DoesNotExist:
......@@ -277,7 +277,7 @@ class BeiranDaemon(EventEmitter):
if plugin['type'] == 'discovery':
type_specific_config = {
"address": get_advertise_address(),
"port": get_listen_port()
"port": config.listen_port
}
_plugin_obj = await self.get_plugin(plugin['type'], plugin['name'], {
**shared_config_for_plugins,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment