def main(host, user, password): questions = [Checkbox('tags', message='Tags', choices=get_tags())] tags = prompt(questions)['tags'] questions = [] extra_vars, passwords = get_vars(tags) for var in extra_vars: questions.append(Text(var, var)) extra_vars = prompt(questions) for item in passwords: extra_vars[item] = gen_pass() command = ['ansible-playbook', '-i %s,' % host, '-t %s' % ','.join(tags)] if extra_vars: command.append('-e "%s"' % ' '.join( ('%s=%s' % (k, v) for k, v in extra_vars.items()))) if user is not None: command.append('-u %s' % user) if password: command.append('-k') command.append('ansible.yml') res = ' '.join(command) pbcopy(res) echo('The follow command has been copied to clipboard:') echo(res)
def write_cert(name: str, org: str, duration: int, starttime: str, size: int, show: bool) -> None: """Generate SSL certificate keypair.""" app_path = find_app_path() cert_path = app_path / "agent_cert.pem" key_path = app_path / "agent_key.pem" start = starttime end = start + timedelta(days=duration * 365) label("Hostname: {cn}", cn=name) status(""" A self-signed certificate with the above hostname as the common name attribute will be generated. This hostname must be resolvable by hyperglass via either DNS or a host file, and must match the device's `address:` field in hyperglass's devices.yaml.""") use_name = confirm("Is this the correct hostname?", default=True) if not use_name: name = prompt("Please enter the correct hostname", type=str) all_ips = [f"{a} [{i}]" for i, a in get_addresses()] status(""" hyperglass-agent adds any IP addresses reachable by hyperglass as subject alternative names to the SSL certificate. Please select any IP addresses over which hyperglass may communicate with hyperglass-agent.""") ips = [Checkbox("ips", message="Select IPs", choices=all_ips)] selected = [i.split("[")[0].strip() for i in inquire(ips)["ips"]] selected_ips = [ip_address(i) for i in selected] cert, key = make_cert(cn=name, sans=selected_ips, o=org, start=start, end=end, size=size) if show: info(f'Public Key:\n{cert.decode("utf8")}') info(f'Private Key:\n{key.decode("utf8")}') with cert_path.open("wb") as cf: cf.write(cert) if not cert_path.exists(): error("Error writing public key to {f}", f=cert_path.absolute()) success("Wrote public key to: {f}", f=cert_path.absolute()) with key_path.open("wb") as kf: kf.write(key) if not key_path.exists(): error("Error writing private key to {f}", f=key_path.absolute()) success("Wrote private key to: {f}", f=key_path.absolute())
def main(self) -> dict: """ >>> QuizRouter().main() Returns a dictionary with key, main. Displays a checkbox based question with choices to pick from. """ questions = [ Checkbox(name="main", message="SELECT A QUIZ OPTION:", choices=["CREATE", "READ", "UPDATE", "DELETE"]) ] return prompt(questions)
def main(self) -> dict: """ >>> MainRouter().main() Returns a dictionary with key, main. Displays a checkbox based question with choices to pick from. """ questions = [ Checkbox( name="main", message="SELECT AN OPTION:", choices=["ADMIN", "PLAY", "EXIT"]) ] return prompt(questions)
def admin(self) -> dict: """ >>> MainRouter().admin() Returns a dictionary with key, admin. Displays a checkbox based question with choices to pick from. """ questions = [ Checkbox( name="admin", message="SELECT AN OPTION:", choices=["Category", "Quiz"]) ] return prompt(questions)
def outputList(fileList): # dl = [ id for id in getDownloadedFiles()] c = [ Checkbox('docs', message='List of Google Docs:', choices=[x['title'] for x in fileList]) ] # need to impliment already downloaded check, then return a clean # prompt list # Genorator is no longer optimized responses = prompt(c)['docs'] return [ file['id'] for file in fileList if file['title'] in responses and file['id'] not in getDownloadedFiles() ]
def play_quiz(self, quizzes: list) -> dict: """ >>> MainRouter().play() Returns a dictionary with key, quiz['id] from the quizzes. Displays a checkbox based question with choices to pick from. """ questions = [ Checkbox( name=quiz['id'], message=quiz['question'].upper(), choices=quiz['options'].split(", "),) for quiz in quizzes ] return prompt(questions)
def category(self, categories) -> dict: """ >>> MainRouter().category() Returns a dictionary with key, id. Displays a checkbox based question with choices to pick from. """ questions = [ Checkbox( name="id", message="CHOOSE CATEGORY:", choices=[ f"{row['id']} - {row['name']}" for row in categories]) ] return prompt(questions)
def quiz(self, quizzes) -> dict: """ >>> MainRouter().quiz() Returns a dictionary with key, main. Displays a checkbox based question with choices to pick from. """ questions = [ Checkbox( name="id", message="CHOOSE QUIZ:", choices=[ f"{row['id']} - {row['question']}" for row in quizzes]) ] return prompt(questions)
def play(self) -> dict: """ >>> MainRouter().play() Returns a dictionary with key, play. Displays a checkbox based question with choices to pick from. """ questions = [ Checkbox( name="play", message="PLAY BY:", choices=[ "CATEGORY - select all quizzes from a category", "QUIZ - select a particular question", "RANDOM - select a random question"]) ] return prompt(questions)
def generate_options(rhost: str) -> dict: """ dnsrecon -d {HOSTNAME} -n {Nameserver IP} -j {json file} """ questions = list() pre_questions = [ Confirm("use_ip", default=True, message="Use IP {0} for Name Server".format(rhost)), ] pre_answers = prompt(pre_questions) # If we decided against using an IP if not pre_answers["use_ip"]: questions.append(Text("name_server", message="Input Name Server")) # Are there items that match etc host defs domains = Util().ip_to_domains(rhost) if domains: questions.append( Checkbox("domains", message="Input domain to search", choices=domains)) else: questions.append(Text("domains", message="Input domain to search")) answers = prompt(questions) # annotate answers if pre_answers["use_ip"]: answers["name_server"] = rhost # if we put in only one domain name then turn it into a list if not hasattr(answers["domains"], "sort"): answers["domains"] = [answers["domains"]] return answers
########## LIST ######### # from inquirer import List, prompt # if __name__ == "__main__": # choices = ["Python", "C/C++", "Rust", "JavaScript", "Java"] # questions = [ # List(name="best_lang", message="What is the best language", # default=choices[-1], # the last option is the default # choices=choices) # ] # answer = prompt(questions) # print(answer) ########## CHECKBOX ######### from inquirer import Checkbox, prompt if __name__ == "__main__": questions = [ Checkbox(name="bool", message="Which of these will evaluate to True", choices=[1, 0, True, False, -1, "", "Yes", "No"], default=[False, -1]) ] answer = prompt(questions) print(answer)
"port": args.port, "keyBase": args.key } if args.remote is None or args.remote == '': remote = '130.237.202.97' else: remote = args.remote print("Bootstrap: create contact entry for this user") connection_manager = connection_manager(server=remote, local_user=local_user) connection_manager.connect() connection_manager.register_user() check_for_peers = [ Checkbox('Check for peers', message='Do you want to check for peers?', choices=['yes', 'no']) ] connection_manager.request_users() contactList = connection_manager.getContactList() while not contactList: answer = prompt(check_for_peers) if answer.get('Check for peers') == ['yes']: connection_manager.request_users() contactList = connection_manager.getContactList() else: break if not contactList:
def prompt_multiple_choices(choices): question = Checkbox('resources', message="What to send to the database?", choices=choices) selected = prompt([question])['resources'] return sorted(selected, key=choices.index)