MySQL 9.1.0
Source Code Documentation
keyring_frontend.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2019, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_KEYRING_FRONTEND_INCLUDED
27#define ROUTER_KEYRING_FRONTEND_INCLUDED
28
29#include <iostream> // cerr
30#include <istream>
31#include <string>
32#include <vector>
33
35
36/**
37 * exception thrown by the frontend.
38 *
39 * Should be presented to the user.
40 */
41class FrontendError : public std::runtime_error {
42 public:
43 FrontendError(const std::string &what) : std::runtime_error(what) {}
44};
45
46/**
47 * frontend error that involved the command-line options.
48 *
49 * should be handled by showing the user the help-text or a hint how to get the
50 * help
51 */
52class UsageError : public FrontendError {
53 public:
54 UsageError(const std::string &what) : FrontendError(what) {}
55};
56
57/**
58 * passwd file management frontend.
59 */
61 public:
62 enum class Cmd {
63 Init,
64 Set,
65 Get,
66 Delete,
67 List,
68 Export,
74 };
75 struct Config {
77 std::string keyring_filename;
79 std::string master_key_reader;
80 std::string master_key_writer;
81 std::string username;
82 std::string field;
83 std::string value;
84 };
85
86 KeyringFrontend(const std::string &exe_name,
87 const std::vector<std::string> &args,
88 std::istream &is = std::cin, std::ostream &os = std::cout,
89 std::ostream &es = std::cerr);
90
91 /**
92 * run frontend according to configuration.
93 *
94 * @return exit-status
95 * @retval EXIT_FAILURE on error
96 * @retval EXIT_SUCCESS on success
97 */
98 int run();
99
100 /**
101 * get help text.
102 *
103 * @param screen_width wraps text at screen-width
104 * @returns help text
105 */
106 std::string get_help(const size_t screen_width = 80) const;
107
108 /**
109 * get version text.
110 */
111 static std::string get_version() noexcept;
112
113 private:
114 void init_from_arguments(const std::vector<std::string> &arguments);
115
117 void prepare_args();
119
121 CmdArgHandler arg_handler_{true}; // allow arguments
122 std::istream &cin_;
123 std::ostream &cout_;
124 std::ostream &cerr_;
125
126 Config config_; // must be last as init_from_arguments depends on cin, ...
127 // and arg_handler_
128};
129#endif
Defining the commandline argument handler class CmdArgHandler.
Handles command line arguments.
Definition: arg_handler.h:141
exception thrown by the frontend.
Definition: passwd.h:42
FrontendError(const std::string &what)
Definition: keyring_frontend.h:43
passwd file management frontend.
Definition: keyring_frontend.h:60
static std::string get_version() noexcept
get version text.
Definition: keyring_frontend.cc:79
void init_from_arguments(const std::vector< std::string > &arguments)
Definition: keyring_frontend.cc:56
Cmd
Definition: keyring_frontend.h:62
void prepare_args()
prepare arguments and cmds.
Definition: keyring_frontend.cc:543
std::ostream & cout_
Definition: keyring_frontend.h:123
std::string read_password()
int run()
run frontend according to configuration.
Definition: keyring_frontend.cc:652
Config config_
Definition: keyring_frontend.h:126
CmdArgHandler arg_handler_
Definition: keyring_frontend.h:121
std::istream & cin_
Definition: keyring_frontend.h:122
std::ostream & cerr_
Definition: keyring_frontend.h:124
KeyringFrontend(const std::string &exe_name, const std::vector< std::string > &args, std::istream &is=std::cin, std::ostream &os=std::cout, std::ostream &es=std::cerr)
Definition: keyring_frontend.cc:67
void prepare_command_options()
Definition: keyring_frontend.cc:845
std::string get_help(const size_t screen_width=80) const
get help text.
Definition: keyring_frontend.cc:91
std::string program_name_
Definition: keyring_frontend.h:120
frontend error that involved the command-line options.
Definition: passwd.h:53
UsageError(const std::string &what)
Definition: keyring_frontend.h:54
Definition: gcs_xcom_synode.h:64
std::vector< T, ut::allocator< T > > vector
Specialization of vector which uses allocator.
Definition: ut0new.h:2876
Definition: keyring_frontend.h:75
std::string username
Definition: keyring_frontend.h:81
Cmd cmd
Definition: keyring_frontend.h:76
std::string value
Definition: keyring_frontend.h:83
std::string keyring_filename
Definition: keyring_frontend.h:77
std::string master_key_reader
Definition: keyring_frontend.h:79
std::string master_key_writer
Definition: keyring_frontend.h:80
std::string master_keyring_filename
Definition: keyring_frontend.h:78
std::string field
Definition: keyring_frontend.h:82