-
Notifications
You must be signed in to change notification settings - Fork 72
/
advisory_shared.hpp
187 lines (150 loc) · 6.32 KB
/
advisory_shared.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
Copyright Contributors to the libdnf project.
This file is part of libdnf: https://github.com/rpm-software-management/libdnf/
Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation, either version 2.1 of the License, or
(at your option) any later version.
Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef DNF5_COMMANDS_ARGUMENTS_HPP
#define DNF5_COMMANDS_ARGUMENTS_HPP
#include "utils/string.hpp"
#include <libdnf5-cli/session.hpp>
#include <libdnf5/advisory/advisory_query.hpp>
#include <libdnf5/base/base_weak.hpp>
#include <libdnf5/utils/bgettext/bgettext-lib.h>
#include <optional>
namespace dnf5 {
inline std::optional<libdnf5::advisory::AdvisoryQuery> advisory_query_from_cli_input(
libdnf5::Base & base,
const std::vector<std::string> & advisory_names,
bool advisory_security,
bool advisory_bugfix,
bool advisory_enhancement,
bool advisory_newpackage,
const std::vector<std::string> & advisory_severities,
const std::vector<std::string> & advisory_bzs,
const std::vector<std::string> & advisory_cves) {
std::vector<std::string> advisory_types;
if (advisory_security) {
advisory_types.emplace_back("security");
}
if (advisory_bugfix) {
advisory_types.emplace_back("bugfix");
}
if (advisory_enhancement) {
advisory_types.emplace_back("enhancement");
}
if (advisory_newpackage) {
advisory_types.emplace_back("newpackage");
}
if (!advisory_types.empty() || !advisory_severities.empty() || !advisory_names.empty() || !advisory_bzs.empty() ||
!advisory_cves.empty()) {
auto advisories = libdnf5::advisory::AdvisoryQuery(base);
advisories.clear();
// Filter by advisory name
if (!advisory_names.empty()) {
auto advisories_names = libdnf5::advisory::AdvisoryQuery(base);
advisories_names.filter_name(advisory_names);
advisories |= advisories_names;
}
// Filter by advisory type
if (!advisory_types.empty()) {
auto advisories_types = libdnf5::advisory::AdvisoryQuery(base);
advisories_types.filter_type(advisory_types);
advisories |= advisories_types;
}
// Filter by advisory severity
if (!advisory_severities.empty()) {
auto advisories_severities = libdnf5::advisory::AdvisoryQuery(base);
advisories_severities.filter_severity(advisory_severities);
advisories |= advisories_severities;
}
// Filter by advisory bz
if (!advisory_bzs.empty()) {
auto advisories_bzs = libdnf5::advisory::AdvisoryQuery(base);
advisories_bzs.filter_reference(advisory_bzs, {"bugzilla"});
advisories |= advisories_bzs;
}
// Filter by advisory cve
if (!advisory_cves.empty()) {
auto advisories_cves = libdnf5::advisory::AdvisoryQuery(base);
advisories_cves.filter_reference(advisory_cves, {"cve"});
advisories |= advisories_cves;
}
return advisories;
}
return std::nullopt;
}
class AdvisoryOption : public libdnf5::cli::session::AppendStringListOption {
public:
explicit AdvisoryOption(libdnf5::cli::session::Command & command)
: AppendStringListOption(
command,
"advisories",
'\0',
_("Limit to packages in advisories with specified name. List option."),
_("ADVISORY_NAME,...")) {}
};
class SecurityOption : public libdnf5::cli::session::BoolOption {
public:
explicit SecurityOption(libdnf5::cli::session::Command & command)
: BoolOption(command, "security", '\0', _("Limit to packages in security advisories."), false) {}
};
class BugfixOption : public libdnf5::cli::session::BoolOption {
public:
explicit BugfixOption(libdnf5::cli::session::Command & command)
: BoolOption(command, "bugfix", '\0', _("Limit to packages in bugfix advisories."), false) {}
};
class EnhancementOption : public libdnf5::cli::session::BoolOption {
public:
explicit EnhancementOption(libdnf5::cli::session::Command & command)
: BoolOption(command, "enhancement", '\0', _("Limit to packages in enhancement advisories."), false) {}
};
class NewpackageOption : public libdnf5::cli::session::BoolOption {
public:
explicit NewpackageOption(libdnf5::cli::session::Command & command)
: BoolOption(command, "newpackage", '\0', _("Limit to packages in newpackage advisories."), false) {}
};
class AdvisorySeverityOption : public libdnf5::cli::session::AppendStringListOption {
public:
explicit AdvisorySeverityOption(libdnf5::cli::session::Command & command)
: AppendStringListOption(
command,
"advisory-severities",
'\0',
_("Limit to packages in advisories with specified severity. List option. Can be "
"\"critical\", \"important\", \"moderate\", \"low\", \"none\"."),
_("ADVISORY_SEVERITY,..."),
"critical|important|moderate|low|none",
true) {}
};
class BzOption : public libdnf5::cli::session::AppendStringListOption {
public:
explicit BzOption(libdnf5::cli::session::Command & command)
: AppendStringListOption(
command,
"bzs",
'\0',
_("Limit to packages in advisories that fix a Bugzilla ID, Eg. 123123. List option."),
_("BUGZILLA_ID,...")) {}
};
class CveOption : public libdnf5::cli::session::AppendStringListOption {
public:
explicit CveOption(libdnf5::cli::session::Command & command)
: AppendStringListOption(
command,
"cves",
'\0',
_("Limit to packages in advisories that fix a CVE (Common Vulnerabilities and Exposures) "
"ID, Eg. CVE-2201-0123. List option."),
_("CVE_ID,...")) {}
};
} // namespace dnf5
#endif // DNF5_COMMANDS_ARGUMENTS_HPP