diff options
author | MS <ms@taler.net> | 2021-05-17 16:33:11 +0200 |
---|---|---|
committer | MS <ms@taler.net> | 2021-05-17 16:33:11 +0200 |
commit | b0ff994f0303709320d8c210ec64b984f21ac092 (patch) | |
tree | ad80949cda527b1de65961a99ca920cf4a42a57e | |
parent | 5e5b0d13163c62b80e32f4dda1a551bb2982fd2f (diff) | |
download | deployment-b0ff994f0303709320d8c210ec64b984f21ac092.tar.gz deployment-b0ff994f0303709320d8c210ec64b984f21ac092.tar.bz2 deployment-b0ff994f0303709320d8c210ec64b984f21ac092.zip |
preferring loading API token from file
-rwxr-xr-x | bin/taler-deployment | 17 | ||||
-rw-r--r-- | bin/taler-deployment-auth-token | 31 |
2 files changed, 42 insertions, 6 deletions
diff --git a/bin/taler-deployment b/bin/taler-deployment index 62924cb..398a2b8 100755 --- a/bin/taler-deployment +++ b/bin/taler-deployment @@ -28,7 +28,6 @@ from typing import List, Callable from shutil import copy from taler_urls import get_urls from string import ascii_letters, ascii_uppercase -import random activate_template = """\ #!/bin/bash @@ -571,6 +570,12 @@ allowed_envs = ( "tanker" ) +def load_apitoken(): + apitoken_path = Path.home() / "envcfg.py" + if not os.path.isfile(apitoken_path): + return None + with open(apitoken_path, "r") as f: + return f.readline() def load_envcfg(): cfg = types.ModuleType("taler_deployment_cfg") @@ -657,9 +662,6 @@ def sync_repos() -> None: r_dir = home / "sources" / r.name subprocess.run(["git", "-C", str(r_dir), "clean", "-fdx"], check=True) -def generate_apitoken(): - return "secret-token:" + ''.join(random.choices(ascii_letters + ascii_uppercase, k=10)) - @cli.command() def bootstrap() -> None: """Bootstrap a GNU Taler deployment.""" @@ -681,7 +683,10 @@ def bootstrap() -> None: path_list.insert(0, local_path) if deployment_path not in path_list: path_list.insert(0, deployment_path) - + apitoken = load_apitoken() + if not apitoken: + print("Please create ~/merchant_auth_token (taler-deployment-auth-token can help).") + return 1 with (home / "activate").open("w") as f: f.write( activate_template.format( @@ -690,7 +695,7 @@ def bootstrap() -> None: currency=currmap[envname], curr_path=":".join(path_list), coverage=1 if envname == "coverage" else 0, - frontends_apitoken="{}".format(generate_apitoken()), + frontends_apitoken="{}".format(apitoken), **get_urls(envname) ) ) diff --git a/bin/taler-deployment-auth-token b/bin/taler-deployment-auth-token new file mode 100644 index 0000000..bd638fd --- /dev/null +++ b/bin/taler-deployment-auth-token @@ -0,0 +1,31 @@ +#!/usr/bin/env python3 + +# This file is part of GNU Taler. +# +# GNU Taler is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# GNU Taler is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Taler. If not, see <https://www.gnu.org/licenses/>. + +import random +import os + +TOKEN_FILE = "~/merchant_auth_token" + +def generate_apitoken(): + return "secret-token:" + ''.join(random.choices(ascii_letters + ascii_uppercase, k=10)) + +if os.path.isfile(TOKEN_FILE): + print("~/merchant_auth_token exists already. Not overwriting it!") + return 0 + +with open(TOKEN_FILE) as f: + f.write(generate_apitoken()) |