mirror of
https://github.com/aljazceru/python-teos.git
synced 2025-12-17 14:14:22 +01:00
Adds API HOST and PORT as configurable parameters.
Uses API_BIND/API_PORT for the server and API_CONNECT/API_PORT for the user, for consistency.
This commit is contained in:
@@ -15,8 +15,8 @@ Refer to [INSTALL.md](INSTALL.md)
|
|||||||
|
|
||||||
#### Global options
|
#### Global options
|
||||||
|
|
||||||
- `-s, --server`: API server where to send the requests. Defaults to 'localhost' (modifiable in conf file).
|
- `--apiconnect`: API server where to send the requests. Defaults to 'localhost' (modifiable in conf file).
|
||||||
- `-p, --port` : API port where to send the requests. Defaults to '9814' (modifiable in conf file).
|
- `-apiport` : API port where to send the requests. Defaults to '9814' (modifiable in conf file).
|
||||||
- `-h --help`: shows a list of commands or help for a specific command.
|
- `-h --help`: shows a list of commands or help for a specific command.
|
||||||
|
|
||||||
#### Commands
|
#### Commands
|
||||||
@@ -191,10 +191,10 @@ By default, `teos_cli` will connect to your local instance (running on localhost
|
|||||||
- mainnet endpoint = `teosmainnet.pisa.watch`
|
- mainnet endpoint = `teosmainnet.pisa.watch`
|
||||||
|
|
||||||
### Connecting to the mainnet instance
|
### Connecting to the mainnet instance
|
||||||
Add `-s https://teosmainnet.pisa.watch` to your calls, for example:
|
Add `--apiconnect https://teosmainnet.pisa.watch` to your calls, for example:
|
||||||
|
|
||||||
```
|
```
|
||||||
python teos_cli.py -s https://teosmainnet.pisa.watch add_appointment -f dummy_appointment_data.json
|
python teos_cli.py --apiconnect https://teosmainnet.pisa.watch add_appointment -f dummy_appointment_data.json
|
||||||
```
|
```
|
||||||
|
|
||||||
You can also change the config file to avoid specifying the server every time:
|
You can also change the config file to avoid specifying the server every time:
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ LOG_PREFIX = "cli"
|
|||||||
|
|
||||||
# Load config fields
|
# Load config fields
|
||||||
DEFAULT_CONF = {
|
DEFAULT_CONF = {
|
||||||
"TEOS_SERVER": {"value": "localhost", "type": str},
|
"API_CONNECT": {"value": "localhost", "type": str},
|
||||||
"TEOS_PORT": {"value": 9814, "type": int},
|
"API_PORT": {"value": 9814, "type": int},
|
||||||
"LOG_FILE": {"value": "teos_cli.log", "type": str, "path": True},
|
"LOG_FILE": {"value": "teos_cli.log", "type": str, "path": True},
|
||||||
"APPOINTMENTS_FOLDER_NAME": {"value": "appointment_receipts", "type": str, "path": True},
|
"APPOINTMENTS_FOLDER_NAME": {"value": "appointment_receipts", "type": str, "path": True},
|
||||||
"CLI_PUBLIC_KEY": {"value": "cli_pk.der", "type": str, "path": True},
|
"CLI_PUBLIC_KEY": {"value": "cli_pk.der", "type": str, "path": True},
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ def show_usage():
|
|||||||
"\n\tget_all_appointments \tGets information about all appointments stored in the tower."
|
"\n\tget_all_appointments \tGets information about all appointments stored in the tower."
|
||||||
"\n\thelp \t\t\tShows a list of commands or help for a specific command."
|
"\n\thelp \t\t\tShows a list of commands or help for a specific command."
|
||||||
"\n\nGLOBAL OPTIONS:"
|
"\n\nGLOBAL OPTIONS:"
|
||||||
"\n\t-s, --server \tAPI server where to send the requests. Defaults to 'localhost' (modifiable in conf file)."
|
"\n\t--apiconnect \tAPI server where to send the requests. Defaults to 'localhost' (modifiable in conf file)."
|
||||||
"\n\t-p, --port \tAPI port where to send the requests. Defaults to '9814' (modifiable in conf file)."
|
"\n\t--apiport \tAPI port where to send the requests. Defaults to '9814' (modifiable in conf file)."
|
||||||
"\n\t-d, --debug \tshows debug information and stores it in teos_cli.log."
|
"\n\t-d, --debug \tshows debug information and stores it in teos_cli.log."
|
||||||
"\n\t-h --help \tshows this message."
|
"\n\t-h --help \tshows this message."
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
[teos]
|
[teos]
|
||||||
TEOS_SERVER = localhost
|
api_connect = localhost
|
||||||
TEOS_PORT = 9814
|
api_port = 9814
|
||||||
|
|
||||||
|
|||||||
@@ -406,7 +406,7 @@ def main(command, args, command_line_conf):
|
|||||||
setup_logging(config.get("LOG_FILE"), LOG_PREFIX)
|
setup_logging(config.get("LOG_FILE"), LOG_PREFIX)
|
||||||
|
|
||||||
# Set the teos url
|
# Set the teos url
|
||||||
teos_url = "{}:{}".format(config.get("TEOS_SERVER"), config.get("TEOS_PORT"))
|
teos_url = "{}:{}".format(config.get("API_CONNECT"), config.get("API_PORT"))
|
||||||
# If an http or https prefix if found, leaves the server as is. Otherwise defaults to http.
|
# If an http or https prefix if found, leaves the server as is. Otherwise defaults to http.
|
||||||
if not teos_url.startswith("http"):
|
if not teos_url.startswith("http"):
|
||||||
teos_url = "http://" + teos_url
|
teos_url = "http://" + teos_url
|
||||||
@@ -479,17 +479,17 @@ if __name__ == "__main__":
|
|||||||
commands = ["register", "add_appointment", "get_appointment", "get_all_appointments", "help"]
|
commands = ["register", "add_appointment", "get_appointment", "get_all_appointments", "help"]
|
||||||
|
|
||||||
try:
|
try:
|
||||||
opts, args = getopt(argv[1:], "s:p:h", ["server", "port", "help"])
|
opts, args = getopt(argv[1:], "h", ["apiconnect=", "apiport=", "help"])
|
||||||
|
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
if opt in ["-s", "--server"]:
|
if opt in ["--apiconnect"]:
|
||||||
if arg:
|
if arg:
|
||||||
command_line_conf["TEOS_SERVER"] = arg
|
command_line_conf["API_CONNECT"] = arg
|
||||||
|
|
||||||
if opt in ["-p", "--port"]:
|
if opt in ["--apiport"]:
|
||||||
if arg:
|
if arg:
|
||||||
try:
|
try:
|
||||||
command_line_conf["TEOS_PORT"] = int(arg)
|
command_line_conf["API_PORT"] = int(arg)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
sys.exit("port must be an integer")
|
sys.exit("port must be an integer")
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
HOST = "localhost"
|
|
||||||
PORT = 9814
|
|
||||||
DATA_DIR = os.path.expanduser("~/.teos/")
|
DATA_DIR = os.path.expanduser("~/.teos/")
|
||||||
CONF_FILE_NAME = "teos.conf"
|
CONF_FILE_NAME = "teos.conf"
|
||||||
LOG_PREFIX = "teos"
|
LOG_PREFIX = "teos"
|
||||||
|
|
||||||
# Default conf fields
|
# Default conf fields
|
||||||
DEFAULT_CONF = {
|
DEFAULT_CONF = {
|
||||||
|
"API_BIND": {"value": "localhost", "type": str},
|
||||||
|
"API_PORT": {"value": 9814, "type": int},
|
||||||
"BTC_RPC_USER": {"value": "user", "type": str},
|
"BTC_RPC_USER": {"value": "user", "type": str},
|
||||||
"BTC_RPC_PASSWORD": {"value": "passwd", "type": str},
|
"BTC_RPC_PASSWORD": {"value": "passwd", "type": str},
|
||||||
"BTC_RPC_CONNECT": {"value": "127.0.0.1", "type": str},
|
"BTC_RPC_CONNECT": {"value": "127.0.0.1", "type": str},
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import logging
|
|||||||
from math import ceil
|
from math import ceil
|
||||||
from flask import Flask, request, abort, jsonify
|
from flask import Flask, request, abort, jsonify
|
||||||
|
|
||||||
|
from teos import LOG_PREFIX
|
||||||
import teos.errors as errors
|
import teos.errors as errors
|
||||||
from teos import HOST, PORT, LOG_PREFIX
|
|
||||||
from teos.inspector import InspectionFailed
|
from teos.inspector import InspectionFailed
|
||||||
from teos.gatekeeper import NotEnoughSlots, IdentificationFailure
|
from teos.gatekeeper import NotEnoughSlots, IdentificationFailure
|
||||||
|
|
||||||
@@ -79,7 +79,9 @@ class API:
|
|||||||
access.
|
access.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, inspector, watcher, gatekeeper):
|
def __init__(self, host, port, inspector, watcher, gatekeeper):
|
||||||
|
self.host = host
|
||||||
|
self.port = port
|
||||||
self.inspector = inspector
|
self.inspector = inspector
|
||||||
self.watcher = watcher
|
self.watcher = watcher
|
||||||
self.gatekeeper = gatekeeper
|
self.gatekeeper = gatekeeper
|
||||||
@@ -341,4 +343,4 @@ class API:
|
|||||||
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
||||||
os.environ["WERKZEUG_RUN_MAIN"] = "true"
|
os.environ["WERKZEUG_RUN_MAIN"] = "true"
|
||||||
|
|
||||||
app.run(host=HOST, port=PORT)
|
app.run(host=self.host, port=self.port)
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ def show_usage():
|
|||||||
"USAGE: "
|
"USAGE: "
|
||||||
"\n\tpython teosd.py [global options]"
|
"\n\tpython teosd.py [global options]"
|
||||||
"\n\nGLOBAL OPTIONS:"
|
"\n\nGLOBAL OPTIONS:"
|
||||||
|
"\n\t--apibind \t\taddress that teos API will bind to. Defaults to 'localhost' (modifiable in conf file)."
|
||||||
|
"\n\t--apiport \t\tport that teos API will bind to. Defaults to '9814' (modifiable in conf file)."
|
||||||
"\n\t--btcnetwork \t\tNetwork bitcoind is connected to. Either mainnet, testnet or regtest. Defaults to "
|
"\n\t--btcnetwork \t\tNetwork bitcoind is connected to. Either mainnet, testnet or regtest. Defaults to "
|
||||||
"'mainnet' (modifiable in conf file)."
|
"'mainnet' (modifiable in conf file)."
|
||||||
"\n\t--btcrpcuser \t\tbitcoind rpcuser. Defaults to 'user' (modifiable in conf file)."
|
"\n\t--btcrpcuser \t\tbitcoind rpcuser. Defaults to 'user' (modifiable in conf file)."
|
||||||
|
|||||||
@@ -11,6 +11,8 @@ feed_connect = 127.0.0.1
|
|||||||
feed_port = 28332
|
feed_port = 28332
|
||||||
|
|
||||||
[teos]
|
[teos]
|
||||||
|
api_bind = localhost
|
||||||
|
api_port = 9814
|
||||||
subscription_slots = 100
|
subscription_slots = 100
|
||||||
max_appointments = 1000000
|
max_appointments = 1000000
|
||||||
expiry_delta = 6
|
expiry_delta = 6
|
||||||
|
|||||||
@@ -154,7 +154,8 @@ def main(command_line_conf):
|
|||||||
# FIXME: 92-block-data-during-bootstrap-db
|
# FIXME: 92-block-data-during-bootstrap-db
|
||||||
chain_monitor.monitor_chain()
|
chain_monitor.monitor_chain()
|
||||||
gatekeeper = Gatekeeper(UsersDBM(config.get("USERS_DB_PATH")), config.get("DEFAULT_SLOTS"))
|
gatekeeper = Gatekeeper(UsersDBM(config.get("USERS_DB_PATH")), config.get("DEFAULT_SLOTS"))
|
||||||
API(Inspector(block_processor, config.get("MIN_TO_SELF_DELAY")), watcher, gatekeeper).start()
|
inspector = Inspector(block_processor, config.get("MIN_TO_SELF_DELAY"))
|
||||||
|
API(config.get("API_BIND"), config.get("API_PORT"), inspector, watcher, gatekeeper).start()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error("An error occurred: {}. Shutting down".format(e))
|
logger.error("An error occurred: {}. Shutting down".format(e))
|
||||||
exit(1)
|
exit(1)
|
||||||
@@ -167,9 +168,23 @@ if __name__ == "__main__":
|
|||||||
opts, _ = getopt(
|
opts, _ = getopt(
|
||||||
argv[1:],
|
argv[1:],
|
||||||
"h",
|
"h",
|
||||||
["btcnetwork=", "btcrpcuser=", "btcrpcpassword=", "btcrpcconnect=", "btcrpcport=", "datadir=", "help"],
|
[
|
||||||
|
"apiconnect=",
|
||||||
|
"apiport=",
|
||||||
|
"btcnetwork=",
|
||||||
|
"btcrpcuser=",
|
||||||
|
"btcrpcpassword=",
|
||||||
|
"btcrpcconnect=",
|
||||||
|
"btcrpcport=",
|
||||||
|
"datadir=",
|
||||||
|
"help",
|
||||||
|
],
|
||||||
)
|
)
|
||||||
for opt, arg in opts:
|
for opt, arg in opts:
|
||||||
|
if opt in ["--apibind"]:
|
||||||
|
command_line_conf["API_BIND"] = arg
|
||||||
|
if opt in ["--apiport"]:
|
||||||
|
command_line_conf["API_PORT"] = arg
|
||||||
if opt in ["--btcnetwork"]:
|
if opt in ["--btcnetwork"]:
|
||||||
command_line_conf["BTC_NETWORK"] = arg
|
command_line_conf["BTC_NETWORK"] = arg
|
||||||
if opt in ["--btcrpcuser"]:
|
if opt in ["--btcrpcuser"]:
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ dummy_teos_sk = PrivateKey.from_int(2)
|
|||||||
dummy_teos_pk = dummy_teos_sk.public_key
|
dummy_teos_pk = dummy_teos_sk.public_key
|
||||||
another_sk = PrivateKey.from_int(3)
|
another_sk = PrivateKey.from_int(3)
|
||||||
|
|
||||||
teos_url = "http://{}:{}".format(config.get("TEOS_SERVER"), config.get("TEOS_PORT"))
|
teos_url = "http://{}:{}".format(config.get("API_CONNECT"), config.get("API_PORT"))
|
||||||
add_appointment_endpoint = "{}/add_appointment".format(teos_url)
|
add_appointment_endpoint = "{}/add_appointment".format(teos_url)
|
||||||
register_endpoint = "{}/register".format(teos_url)
|
register_endpoint = "{}/register".format(teos_url)
|
||||||
get_appointment_endpoint = "{}/get_appointment".format(teos_url)
|
get_appointment_endpoint = "{}/get_appointment".format(teos_url)
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ from test.teos.e2e.conftest import (
|
|||||||
cli_config = get_config(DATA_DIR, CONF_FILE_NAME, DEFAULT_CONF)
|
cli_config = get_config(DATA_DIR, CONF_FILE_NAME, DEFAULT_CONF)
|
||||||
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
|
common.cryptographer.logger = Logger(actor="Cryptographer", log_name_prefix="")
|
||||||
|
|
||||||
teos_base_endpoint = "http://{}:{}".format(cli_config.get("TEOS_SERVER"), cli_config.get("TEOS_PORT"))
|
teos_base_endpoint = "http://{}:{}".format(cli_config.get("API_CONNECT"), cli_config.get("API_PORT"))
|
||||||
teos_add_appointment_endpoint = "{}/add_appointment".format(teos_base_endpoint)
|
teos_add_appointment_endpoint = "{}/add_appointment".format(teos_base_endpoint)
|
||||||
teos_get_appointment_endpoint = "{}/get_appointment".format(teos_base_endpoint)
|
teos_get_appointment_endpoint = "{}/get_appointment".format(teos_base_endpoint)
|
||||||
teos_get_all_appointments_endpoint = "{}/get_all_appointments".format(teos_base_endpoint)
|
teos_get_all_appointments_endpoint = "{}/get_all_appointments".format(teos_base_endpoint)
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ from shutil import rmtree
|
|||||||
from binascii import hexlify
|
from binascii import hexlify
|
||||||
|
|
||||||
from teos.api import API
|
from teos.api import API
|
||||||
from teos import HOST, PORT
|
|
||||||
import teos.errors as errors
|
import teos.errors as errors
|
||||||
from teos.watcher import Watcher
|
from teos.watcher import Watcher
|
||||||
from teos.inspector import Inspector
|
from teos.inspector import Inspector
|
||||||
@@ -22,8 +21,9 @@ from common.constants import (
|
|||||||
ENCRYPTED_BLOB_MAX_SIZE_HEX,
|
ENCRYPTED_BLOB_MAX_SIZE_HEX,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
config = get_config()
|
||||||
|
|
||||||
TEOS_API = "http://{}:{}".format(HOST, PORT)
|
TEOS_API = "http://{}:{}".format(config.get("API_HOST"), config.get("API_PORT"))
|
||||||
register_endpoint = "{}/register".format(TEOS_API)
|
register_endpoint = "{}/register".format(TEOS_API)
|
||||||
add_appointment_endpoint = "{}/add_appointment".format(TEOS_API)
|
add_appointment_endpoint = "{}/add_appointment".format(TEOS_API)
|
||||||
get_appointment_endpoint = "{}/get_appointment".format(TEOS_API)
|
get_appointment_endpoint = "{}/get_appointment".format(TEOS_API)
|
||||||
@@ -38,8 +38,6 @@ TWO_SLOTS_BLOTS = "A" * ENCRYPTED_BLOB_MAX_SIZE_HEX + "AA"
|
|||||||
appointments = {}
|
appointments = {}
|
||||||
locator_dispute_tx_map = {}
|
locator_dispute_tx_map = {}
|
||||||
|
|
||||||
config = get_config()
|
|
||||||
|
|
||||||
|
|
||||||
client_sk, client_pk = generate_keypair()
|
client_sk, client_pk = generate_keypair()
|
||||||
compressed_client_pk = hexlify(client_pk.format(compressed=True)).decode("utf-8")
|
compressed_client_pk = hexlify(client_pk.format(compressed=True)).decode("utf-8")
|
||||||
@@ -62,8 +60,8 @@ def api(db_manager, carrier, block_processor, gatekeeper, run_bitcoind):
|
|||||||
|
|
||||||
responder = Responder(db_manager, carrier, block_processor)
|
responder = Responder(db_manager, carrier, block_processor)
|
||||||
watcher = Watcher(db_manager, block_processor, responder, sk.to_der(), MAX_APPOINTMENTS, config.get("EXPIRY_DELTA"))
|
watcher = Watcher(db_manager, block_processor, responder, sk.to_der(), MAX_APPOINTMENTS, config.get("EXPIRY_DELTA"))
|
||||||
|
inspector = Inspector(block_processor, config.get("MIN_TO_SELF_DELAY"))
|
||||||
api = API(Inspector(block_processor, config.get("MIN_TO_SELF_DELAY")), watcher, gatekeeper)
|
api = API(config.get("API_HOST"), config.get("API_PORT"), inspector, watcher, gatekeeper)
|
||||||
|
|
||||||
return api
|
return api
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user