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