Skip to content

Commit

Permalink
feat: jans-cli logout (ref: #706) (#723)
Browse files Browse the repository at this point in the history
  • Loading branch information
devrimyatar authored Jan 27, 2022
1 parent 89215ac commit 0cc51bc
Showing 1 changed file with 28 additions and 22 deletions.
50 changes: 28 additions & 22 deletions jans-cli/cli/config_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def join(self):
'scim_client_id': 'your jans scim client id',
'scim_client_secret': 'client secret for your jans scim client'}

config.write(config_ini_fn.open('w'))
self.write_config()

print(
"Pelase fill {} or set environmental variables jans_host, jans_client_id ,and jans_client_secret and re-run".format(config_ini_fn)
Expand Down Expand Up @@ -286,6 +286,10 @@ def get_yaml(self):
json.dump(self.cfg_yml, w, indent=2)
return self.cfg_yml

def write_config(self):
with open(config_ini_fn, 'w') as w:
config.write(w)

def get_rest_client(self):
rest = swagger_client.rest.RESTClientObject(self.swagger_configuration)
if args.key_password:
Expand Down Expand Up @@ -483,8 +487,7 @@ def get_jwt_access_token(self):
self.access_token = result['access_token']
access_token_enc = encode_decode(self.access_token)
config['DEFAULT']['access_token_enc'] = access_token_enc
with open(config_ini_fn, 'w') as w:
config.write(w)
self.write_config()


def get_access_token(self, scope):
Expand Down Expand Up @@ -554,7 +557,8 @@ def get_input(self, values=[], text='Selection', default=None, itype=None,
help_text=None, sitype=None, enforce='__true__',
example=None, spacing=0
):
print(self.colored_text("b: back, q: quit", grey_color))
if 'b' in values and 'q' in values and 'x' in values:
print(self.colored_text("b: back, q: quit x: lougout and quit", grey_color))
print()
type_text = ''
if itype:
Expand Down Expand Up @@ -608,14 +612,6 @@ def get_input(self, values=[], text='Selection', default=None, itype=None,
print(self.colored_text("File {} does not exist".format(fname), warning_color))
continue

if selection == '_x':
if self.current_menu.parent:
self.display_menu(self.current_menu.parent)
else:
print("Quiting...")
sys.exit()
break

if itype == 'boolean' and not selection:
return False

Expand All @@ -634,6 +630,16 @@ def get_input(self, values=[], text='Selection', default=None, itype=None,
print("Quiting...")
sys.exit()

if 'x' in values and selection == 'x':
print("Logging out...")
if 'access_token_enc' in config['DEFAULT']:
config['DEFAULT'].pop('access_token_enc')
self.write_config()
print("Quiting...")
sys.exit()
break


if itype == 'object' and sitype:
try:
object_ = self.check_type(selection, itype)
Expand Down Expand Up @@ -926,7 +932,7 @@ def process_get(self, endpoint, return_value=False):
return api_response
return False

selections = ['q', 'b']
selections = ['q', 'x', 'b']
item_counters = []
tabulated = False

Expand Down Expand Up @@ -1197,7 +1203,7 @@ def process_post(self, endpoint):
fields_numbers.append(str(i + 1))

while True:
optional_selection = self.get_input(values=['q', 'c'] + fields_numbers,
optional_selection = self.get_input(values=['q', 'x', 'c'] + fields_numbers,
help_text="c: continue, #: populate field")
if optional_selection == 'c':
break
Expand All @@ -1211,7 +1217,7 @@ def process_post(self, endpoint):
model_unmapped = self.unmap_model(model)
self.print_colored_output(model_unmapped)

selection = self.get_input(values=['q', 'b', 'y', 'n'], text='Continue?')
selection = self.get_input(values=['q', 'x', 'b', 'y', 'n'], text='Continue?')

else:
selection = 'y'
Expand All @@ -1234,7 +1240,7 @@ def process_post(self, endpoint):
except:
print(self.colored_text(str(api_response), success_color))

selection = self.get_input(values=['q', 'b'])
selection = self.get_input(values=['q', 'x', 'b'])
if selection in ('b', 'n'):
self.display_menu(endpoint.parent)

Expand All @@ -1245,7 +1251,7 @@ def process_delete(self, endpoint):
else:
url_param_val = ''
selection = self.get_input(text="Are you sure want to delete {} ?".format(url_param_val),
values=['b', 'y', 'n', 'q'])
values=['b', 'y', 'n', 'q', 'x'])
if selection in ('b', 'n'):
self.display_menu(endpoint.parent)
elif selection == 'y':
Expand All @@ -1261,7 +1267,7 @@ def process_delete(self, endpoint):
if api_response is None:
print(self.colored_text("\nEntry {} was deleted successfully\n".format(url_param_val), success_color))

selection = self.get_input(['b', 'q'])
selection = self.get_input(['b', 'q', 'x'])
if selection == 'b':
self.display_menu(endpoint.parent)

Expand Down Expand Up @@ -1433,7 +1439,7 @@ def process_put(self, endpoint):
api_response_unmapped = self.unmap_model(api_response)
self.print_colored_output(api_response_unmapped)

selection = self.get_input(values=['q', 'b'])
selection = self.get_input(values=['q', 'x', 'b'])
if selection == 'b':
self.display_menu(endpoint.parent)

Expand All @@ -1460,7 +1466,7 @@ def print_fields():

print_fields()
changed_items = []
selection_list = ['q', 'b', 'v', 's', 'l'] + item_numbers
selection_list = ['q', 'x', 'b', 'v', 's', 'l'] + item_numbers
help_text = 'q: quit, v: view, s: save, l: list fields #: update field'

while True:
Expand Down Expand Up @@ -1511,7 +1517,7 @@ def print_fields():
break

if go_back:
selection = self.get_input(values=['q', 'b'])
selection = self.get_input(values=['q', 'x', 'b'])
if selection == 'b':
self.display_menu(endpoint.parent)
else:
Expand All @@ -1524,7 +1530,7 @@ def display_menu(self, menu):

self.print_underlined(menu.name)

selection_values = ['q', 'b']
selection_values = ['q', 'x', 'b']

menu_numbering = {}

Expand Down

0 comments on commit 0cc51bc

Please sign in to comment.