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:
Sergi Delgado Segura
2020-04-07 12:10:49 +02:00
parent 2be433d589
commit bed21e9625
13 changed files with 50 additions and 31 deletions

View File

@@ -15,8 +15,8 @@ Refer to [INSTALL.md](INSTALL.md)
#### Global options
- `-s, --server`: 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).
- `--apiconnect`: API server where to send the requests. Defaults to 'localhost' (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.
#### Commands
@@ -191,10 +191,10 @@ By default, `teos_cli` will connect to your local instance (running on localhost
- mainnet endpoint = `teosmainnet.pisa.watch`
### 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:

View File

@@ -6,8 +6,8 @@ LOG_PREFIX = "cli"
# Load config fields
DEFAULT_CONF = {
"TEOS_SERVER": {"value": "localhost", "type": str},
"TEOS_PORT": {"value": 9814, "type": int},
"API_CONNECT": {"value": "localhost", "type": str},
"API_PORT": {"value": 9814, "type": int},
"LOG_FILE": {"value": "teos_cli.log", "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},

View File

@@ -9,8 +9,8 @@ def show_usage():
"\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\nGLOBAL OPTIONS:"
"\n\t-s, --server \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--apiconnect \tAPI server where to send the requests. Defaults to 'localhost' (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-h --help \tshows this message."
)

View File

@@ -1,4 +1,4 @@
[teos]
TEOS_SERVER = localhost
TEOS_PORT = 9814
api_connect = localhost
api_port = 9814

View File

@@ -406,7 +406,7 @@ def main(command, args, command_line_conf):
setup_logging(config.get("LOG_FILE"), LOG_PREFIX)
# 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 not teos_url.startswith("http"):
teos_url = "http://" + teos_url
@@ -479,17 +479,17 @@ if __name__ == "__main__":
commands = ["register", "add_appointment", "get_appointment", "get_all_appointments", "help"]
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:
if opt in ["-s", "--server"]:
if opt in ["--apiconnect"]:
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:
try:
command_line_conf["TEOS_PORT"] = int(arg)
command_line_conf["API_PORT"] = int(arg)
except ValueError:
sys.exit("port must be an integer")