mirror of
https://gitlab.sectorq.eu/jaydee/portainer.git
synced 2025-12-14 10:44:52 +01:00
build
This commit is contained in:
32
portainer.py
32
portainer.py
@@ -175,12 +175,6 @@ logging.info("script started")
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
if args.site == "portainer":
|
||||
base = os.getenv("PORTAINER_URL", "https://portainer.sectorq.eu/api")
|
||||
PORTAINER_API_KEY = "ptr_GCNUoFcTOaXm7k8ZxPdQGmrFIamxZPTydbserYofMHc="
|
||||
else:
|
||||
base = os.getenv("PORTAINER_URL", "https://port.sectorq.eu/api")
|
||||
PORTAINER_API_KEY = "ptr_/5RkMCT/j3BTaL32vMSDtXFi76yOXRKVFOrUtzMsl5Y="
|
||||
|
||||
|
||||
def wl(msg):
|
||||
@@ -192,8 +186,8 @@ def prompt_missing_args(args_in, defaults_in, fields):
|
||||
"""
|
||||
fields = [("arg_name", "Prompt text")]
|
||||
"""
|
||||
def input_with_default(prompt, default):
|
||||
full_prompt = f" >> {prompt:40}"
|
||||
def input_with_default(prompt, default, longest):
|
||||
full_prompt = f" >> {prompt:{longest}}"
|
||||
sys.stdout.write(full_prompt)
|
||||
sys.stdout.flush()
|
||||
checkmark = "\033[92m\u2714\033[0m"
|
||||
@@ -225,25 +219,32 @@ def prompt_missing_args(args_in, defaults_in, fields):
|
||||
# rewrite final line cleanly
|
||||
sys.stdout.write(f"\r{full_prompt}{user_input:10} {checkmark}\n")
|
||||
sys.stdout.flush()
|
||||
|
||||
|
||||
return user_input
|
||||
longest = 0
|
||||
for field, text in fields:
|
||||
a = text + " (default= " + cur_config["PORTAINER_" + field.upper()] + ")"
|
||||
if len(a) > longest:
|
||||
longest = len(a)
|
||||
|
||||
for field, text in fields:
|
||||
value_in = getattr(args_in, field)
|
||||
default = defaults_in.get(f"PORTAINER_{field}".upper())
|
||||
|
||||
cur_site = defaults_in.get("PORTAINER_SITE".upper())
|
||||
if value_in is None:
|
||||
if default is not None:
|
||||
prompt = f"{text} (default={default}) : "
|
||||
# value_in = input(prompt) or default
|
||||
value_in = input_with_default(prompt, default)
|
||||
value_in = input_with_default(prompt, default, longest+2)
|
||||
defaults_in[f"PORTAINER_{field}".upper()] = value_in
|
||||
else:
|
||||
#value_in = input(f"{text}: ")
|
||||
value_in = input_with_default(text, default)
|
||||
value_in = input_with_default(text, default, longest+2)
|
||||
defaults_in[f"PORTAINER_{field}".upper()] = value_in
|
||||
setattr(args, field, value_in)
|
||||
os.environ[field] = value_in
|
||||
|
||||
if field == "site" and value_in != cur_site:
|
||||
por.get_site(value_in)
|
||||
with open("/myapps/portainer.conf", "w") as f:
|
||||
for k in defaults_in.keys():
|
||||
f.write(f"{k}={defaults_in[k]}\n")
|
||||
@@ -288,8 +289,9 @@ if __name__ == "__main__":
|
||||
args.action = actions[int(ans) - 1]
|
||||
os.system("cls" if os.name == "nt" else "clear")
|
||||
# Example: list endpoints
|
||||
por = Portainer(base, PORTAINER_API_KEY, timeout=args.timeout)
|
||||
|
||||
por = Portainer(defaults['site'], timeout=args.timeout)
|
||||
if args.debug:
|
||||
por._debug = True
|
||||
if args.action == "secrets":
|
||||
if args.endpoint_id is None:
|
||||
args.endpoint_id = input("Endpoint ID is required for creating secrets : ")
|
||||
|
||||
Reference in New Issue
Block a user