Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Jans linux setup require python3-distutils for deb clones #967

Merged
merged 9 commits into from
Mar 4, 2022
4 changes: 2 additions & 2 deletions jans-cli/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.DEFAULT_GOAL := develop

develop:
/usr/bin/env python3 setup.py develop
pip3 install -e .

install:
pip3 install .
Expand All @@ -10,4 +10,4 @@ uninstall:
pip3 uninstall jans-cli -y

zipapp:
shiv --compressed -o jans-cli.pyz -p '/usr/bin/env python3' -e cli.config_cli:main . --no-cache
shiv --compressed -o config-cli.pyz -p '/usr/bin/env python3' -e cli.config_cli:main . --no-cache
2 changes: 1 addition & 1 deletion jans-cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ If you would like to build `jans-cli` manually, you can go through the following
You can verify with the following command line if everything is done successfully.

```
python3 jans-cli.pyz -h
python3 config-cli.pyz -h
```


Expand Down
32 changes: 26 additions & 6 deletions jans-cli/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
from pathlib import Path
from urllib.parse import urlencode
from collections import OrderedDict

from prompt_toolkit import prompt, HTML
from prompt_toolkit.completion import WordCompleter

home_dir = Path.home()
config_dir = home_dir.joinpath('.config')
Expand All @@ -47,6 +48,7 @@
swagger_client.models = importlib.import_module(my_op_mode + '.swagger_client.models')
swagger_client.api = importlib.import_module(my_op_mode + '.swagger_client.api')
swagger_client.rest = importlib.import_module(my_op_mode + '.swagger_client.rest')
plugins = []

warning_color = 214
error_color = 196
Expand Down Expand Up @@ -100,6 +102,7 @@ def join(self):
parser.add_argument("--host", help="Hostname of server")
parser.add_argument("--client-id", help="Jans Config Api Client ID")
parser.add_argument("--client_secret", help="Jans Config Api Client ID secret")
parser.add_argument("--plugins", help="Available plugins separated by comma")
parser.add_argument("-debug", help="Run in debug mode", action='store_true')
parser.add_argument("--debug-log-file", default='swagger.log', help="Log file name when run in debug mode")
parser.add_argument("--operation-id", help="Operation ID to be done")
Expand All @@ -126,6 +129,9 @@ def join(self):

################## end of arguments #################

if args.plugins:
for plugin in args.plugins.split(','):
plugins.append(plugin.strip())

def write_config():
with open(config_ini_fn, 'w') as w:
Expand Down Expand Up @@ -247,6 +253,12 @@ def __init__(self, host, client_id, client_secret):
self.swagger_configuration = swagger_client.Configuration()
self.swagger_configuration.host = 'https://{}'.format(self.host)
self.access_token = config['DEFAULT'].get('access_token')

for plugin_s in config['DEFAULT'].get(my_op_mode + '_plugins', '').split(','):
plugin = plugin_s.strip()
if plugin:
plugins.append(plugin)

if not self.access_token and config['DEFAULT'].get('access_token_enc'):
self.access_token = encode_decode(config['DEFAULT']['access_token_enc'], decode=True)

Expand Down Expand Up @@ -352,11 +364,16 @@ def make_menu(self):
menu.add_child(m)
for path in self.cfg_yml['paths']:
for method in self.cfg_yml['paths'][path]:

if 'tags' in self.cfg_yml['paths'][path][method] and m.name in \
self.cfg_yml['paths'][path][method]['tags'] and 'operationId' in \
self.cfg_yml['paths'][path][method]:
# if isinstance(self.cfg_yml['paths'][path][method], dict) and self.cfg_yml['paths'][path][method].get('x-cli-ignore'):
# continue

if isinstance(self.cfg_yml['paths'][path][method], dict) and self.cfg_yml['paths'][path][method].get('x-cli-plugin') and not self.cfg_yml['paths'][path][method]['x-cli-plugin'] in plugins:
if m in menu.children:
menu.children.remove(m)
continue

menu_name = self.cfg_yml['paths'][path][method].get('summary') or \
self.cfg_yml['paths'][path][method].get('description')

Expand Down Expand Up @@ -576,6 +593,8 @@ def get_input(self, values=[], text='Selection', default=None, itype=None,
default = False
else:
type_text = "Type: " + itype
if values:
type_text += ', Valid values: {}'.format(self.colored_text(', '.join(values), bold_color))

if help_text:
help_text = help_text.strip('.') + '. ' + type_text
Expand All @@ -594,7 +613,7 @@ def get_input(self, values=[], text='Selection', default=None, itype=None,

if not default is None:
default_text = str(default).lower() if itype == 'boolean' else str(default)
text += self.colored_text(' [' + default_text + ']', 11)
text += ' [<b>' + default_text + '</b>]'
if itype == 'integer':
default = int(default)

Expand All @@ -605,7 +624,9 @@ def get_input(self, values=[], text='Selection', default=None, itype=None,
values = ['_true', '_false']

while True:
selection = input(' ' * spacing + self.colored_text(text, 20) + ' ')
#selection = input(' ' * spacing + self.colored_text(text, 20) + ' ')
html_completer = WordCompleter(values)
selection = prompt(HTML(' ' * spacing + text + ' '), completer=html_completer)
selection = selection.strip()
if selection.startswith('_file '):
fname = selection.split()[1]
Expand Down Expand Up @@ -1529,7 +1550,6 @@ def print_fields():

def display_menu(self, menu):
clear()
print(self.colored_text("*** WARNING! This software is experimental ***", warning_color))
self.current_menu = menu

self.print_underlined(menu.name)
Expand Down
Loading