except KeyError: abort(404) try: if action == 'add': result = regi.add_cert(request.args['cn']) elif action == 'get': result = regi.get_config(request.args['cn']) elif action == 'list': result = regi.list_certs(request.args.get('cn', None)) elif action == 'revoke': result = regi.revoke_cert(request.args['cn']) elif action == 'remove': result = regi.remove_cert(request.args['cn']) else: abort(400) except KeyError: abort(400) except registrar.EntryNotFoundError: abort(404) return json.dumps(result, cls=registrar.RegistrarEncoder) if __name__ == '__main__': for dirname in os.listdir(registrar.OPENVPN_BASE): registrars[dirname] = registrar.Registrar(dirname) app.run(debug=True, host='0.0.0.0', port=port) # ssl_context=(cert_path, key_path))
parser_list.add_argument('client', nargs='?', default=None, help="name of the client") args = parser.parse_args() return args if __name__ == "__main__": logging.basicConfig(level=logging.ERROR) args = parse_args() regi = registrar.Registrar(args.challenge, args.openvpn, args.easyrsa) if args.action == 'add': if args.recreate: regi.remove_cert(args.client) regi.add_cert(args.client) elif args.action == 'get': if args.add: regi.add_cert(args.client) print(regi.get_config(args.client)) elif args.action == 'revoke': regi.revoke_cert(args.client) elif args.action == 'remove':
op_indices[0], arg)) indices.sort() for start_idx, end_idx, arg in reversed(indices): arg_toks = tokens[end_idx + 1:] tokens = tokens[:start_idx] args[arg] = " ".join(arg_toks) return args #TODO move to unit test if __name__ == "__main__": import registrar r = registrar.Registrar() i = Interpreter(r) def directions(**kwargs): if not all(map(lambda x: x in kwargs, ("from", "to"))): return "Missing arguments." print "Getting directions from {0} to {1}".format( kwargs["from"], kwargs["to"]) directions_grammar = { "to": ["ending at", "to"], "from": ["starting at", "from"] } r.register_service("directions", directions, directions_grammar, "Gets directions", "ns")