libzypp  17.38.7
reporthelper.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
10 #include "reporthelper.h"
11 
12 #include <zypp/Digest.h>
13 #include <zypp/ng/userrequest.h>
14 
15 namespace zyppng {
16 
17 
19  : _ctx( std::move(ctx) )
20  { }
21 
22 
24  {
25 #ifdef ZYPP_ENABLE_ASYNC
26  std::string label = (zypp::str::Format(_("No digest for file %s.")) % file ).str();
27  auto req = BooleanChoiceRequest::create( label, false, AcceptNoDigestRequest::makeData(file) );
28  this->_ctx->sendUserRequest( req );
29  return req->choice ();
30 #else
31  return _report->askUserToAcceptNoDigest(file);
32 #endif
33  }
34 
35  bool DigestReportHelper::askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
36  {
37 #ifdef ZYPP_ENABLE_ASYNC
38  std::string label = (zypp::str::Format(_("Unknown digest %s for file %s.")) %name % file).str();
39  auto req = BooleanChoiceRequest::create( label, false, AcceptUnknownDigestRequest::makeData(file, name) );
40  this->_ctx->sendUserRequest( req );
41  return req->choice ();
42 #else
43  return _report->askUserToAccepUnknownDigest( file, name );
44 #endif
45  }
46 
47 
48  bool DigestReportHelper::askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
49  {
50 #ifdef ZYPP_ENABLE_ASYNC
51  std::string label = (zypp::str::Format(_("Digest verification failed for file '%s'")) % file).str();
52  auto req = BooleanChoiceRequest::create( label, false, AcceptWrongDigestRequest::makeData(file, requested, found) );
53  this->_ctx->sendUserRequest( req );
54  return req->choice ();
55 #else
56  return _report->askUserToAcceptWrongDigest( file, requested, found );
57 #endif
58  }
59 
60 
61  bool KeyRingReportHelper::askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext)
62  {
63 #ifdef ZYPP_ENABLE_ASYNC
64  std::string label;
65  if (keycontext.empty())
66  label = zypp::str::Format(
67  // TranslatorExplanation: speaking of a file
68  _("File '%s' is unsigned, continue?")) % file;
69  else
70  label = zypp::str::Format(
71  // TranslatorExplanation: speaking of a file
72  _("File '%s' from repository '%s' is unsigned, continue?"))
73  % file % keycontext.repoInfo().asUserString();
74 
75 
76  auto req = BooleanChoiceRequest::create ( label, false, AcceptUnsignedFileRequest::makeData ( file, keycontext ) );
77  this->_ctx->sendUserRequest ( req );
78  return req->choice ();
79 #else
80  return _report->askUserToAcceptUnsignedFile( file, keycontext );
81 #endif
82  }
83 
84 
86  {
87 #ifdef ZYPP_ENABLE_ASYNC
88  auto req = TrustKeyRequest::create(
89  _("Do you want to reject the key, trust temporarily, or trust always?"),
91  AcceptKeyRequest::makeData ( key, keycontext )
92  );
93  this->_ctx->sendUserRequest ( req );
94  return static_cast<zypp::KeyRingReport::KeyTrust>(req->choice());
95 #else
96  return _report->askUserToAcceptKey( key, keycontext );
97 #endif
98  }
99 
100 
102  {
103 #ifdef ZYPP_ENABLE_ASYNC
104  ERR << "Not implemented yet" << std::endl;
105  return false;
106 #else
107  return _report->askUserToAcceptPackageKey ( key_r, keycontext_r );
108 #endif
109  }
110 
111 
112  void KeyRingReportHelper::infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext)
113  {
114 #ifdef ZYPP_ENABLE_ASYNC
115  std::string label = zypp::str::Format( _("Key Name: %1%")) % keyData_r.name();
116  auto req = ShowMessageRequest::create( label, ShowMessageRequest::MType::Info, VerifyInfoEvent::makeData ( file_r, keyData_r, keycontext) );
117  this->_ctx->sendUserRequest ( req );
118 #else
119  return _report->infoVerify( file_r, keyData_r, keycontext );
120 #endif
121  }
122 
123 
124  void KeyRingReportHelper::reportAutoImportKey(const std::list<zypp::PublicKeyData> &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
125  {
126 #ifdef ZYPP_ENABLE_ASYNC
127  const std::string &lbl = zypp::str::Format( PL_( "Received %1% new package signing key from repository \"%2%\":",
128  "Received %1% new package signing keys from repository \"%2%\":",
129  keyDataList_r.size() )) % keyDataList_r.size() % keyContext_r.repoInfo().asUserString();
130  this->_ctx->sendUserRequest( ShowMessageRequest::create( lbl, ShowMessageRequest::MType::Info, KeyAutoImportInfoEvent::makeData( keyDataList_r, keySigning_r, keyContext_r) ) );
131 #else
132  return _report->reportAutoImportKey( keyDataList_r, keySigning_r, keyContext_r );
133 #endif
134  }
135 
136 
137  bool KeyRingReportHelper::askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext)
138  {
139 #ifdef ZYPP_ENABLE_ASYNC
140  std::string label;
141  if ( keycontext.empty() )
142  // translator: %1% is a file name
143  label = zypp::str::Format(_("Signature verification failed for file '%1%'.") ) % file;
144  else
145  // translator: %1% is a file name, %2% a repositories na me
146  label = zypp::str::Format(_("Signature verification failed for file '%1%' from repository '%2%'.") ) % file % keycontext.repoInfo().asUserString();
147 
148  // @TODO use a centralized Continue string!
149  label += std::string(" ") + _("Continue?");
150  auto req = BooleanChoiceRequest::create ( label, false, AcceptFailedVerificationRequest::makeData ( file, key, keycontext ) );
151  this->_ctx->sendUserRequest ( req );
152  return req->choice ();
153 #else
154  return _report->askUserToAcceptVerificationFailed( file, key, keycontext );
155 #endif
156  }
157 
158 
159  bool KeyRingReportHelper::askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const zypp::KeyContext &keycontext )
160  {
161 #ifdef ZYPP_ENABLE_ASYNC
162  std::string label;
163 
164  if (keycontext.empty())
165  label = zypp::str::Format(
166  // translators: the last %s is gpg key ID
167  _("File '%s' is signed with an unknown key '%s'. Continue?")) % file % id;
168  else
169  label = zypp::str::Format(
170  // translators: the last %s is gpg key ID
171  _("File '%s' from repository '%s' is signed with an unknown key '%s'. Continue?"))
172  % file % keycontext.repoInfo().asUserString() % id;
173 
174  auto req = BooleanChoiceRequest::create ( label, false, AcceptUnknownKeyRequest::makeData ( file, id, keycontext ) );
175  this->_ctx->sendUserRequest ( req );
176  return req->choice ();
177 #else
178  return _report->askUserToAcceptUnknownKey( file, id, keycontext );
179 #endif
180  }
181 
182 
183  bool JobReportHelper::debug(std::string msg_r, UserData userData_r)
184  {
185 #ifdef ZYPP_ENABLE_ASYNC
186  this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Debug, std::move(userData_r) ) );
187  return true;
188 #else
189  return zypp::JobReport::debug ( msg_r, userData_r );
190 #endif
191  }
192 
193 
194  bool JobReportHelper::info( std::string msg_r, UserData userData_r)
195  {
196 #ifdef ZYPP_ENABLE_ASYNC
197  this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Info, std::move(userData_r) ) );
198  return true;
199 #else
200  return zypp::JobReport::info ( msg_r, userData_r );
201 #endif
202  }
203 
204 
205  bool JobReportHelper::warning( std::string msg_r, UserData userData_r)
206  {
207 #ifdef ZYPP_ENABLE_ASYNC
208  this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Warning, std::move(userData_r) ) );
209  return true;
210 #else
211  return zypp::JobReport::warning ( msg_r, userData_r );
212 #endif
213  }
214 
215 
216  bool JobReportHelper::error( std::string msg_r, UserData userData_r)
217  {
218 #ifdef ZYPP_ENABLE_ASYNC
219  this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Error, std::move(userData_r) ) );
220  return true;
221 #else
222  return zypp::JobReport::error ( msg_r, userData_r );
223 #endif
224  }
225 
226 
227  bool JobReportHelper::important( std::string msg_r, UserData userData_r)
228  {
229 #ifdef ZYPP_ENABLE_ASYNC
230  this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Important, std::move(userData_r) ) );
231  return true;
232 #else
233  return zypp::JobReport::important ( msg_r, userData_r );
234 #endif
235  }
236 
237 
238  bool JobReportHelper::data( std::string msg_r, UserData userData_r)
239  {
240 #ifdef ZYPP_ENABLE_ASYNC
241  this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Data, std::move(userData_r) ) );
242  return true;
243 #else
244  return zypp::JobReport::data ( msg_r, userData_r );
245 #endif
246  }
247 }
bool askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
Definition: reporthelper.cc:48
bool error(std::string msg_r, UserData userData_r=UserData())
send error text
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
UserData makeData(const std::list< zypp::PublicKeyData > &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
Definition: userrequest.cc:110
bool askUserToAcceptUnknownKey(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext={})
bool askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext={})
Definition: reporthelper.cc:61
bool askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
UserData makeData(const zypp::Pathname &p, const std::string &name)
Definition: userrequest.cc:19
Class representing one GPG Public Keys data.
Definition: PublicKey.h:200
UserData makeData(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition: userrequest.cc:86
UserData makeData(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition: userrequest.cc:60
void reportAutoImportKey(const std::list< zypp::PublicKeyData > &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
detail::ReportHolder< zypp::DigestReport, Context::isAsync > _report
Definition: reporthelper.h:95
bool important(std::string msg_r, UserData userData_r=UserData())
send important message text
std::string name() const
Key name.
Definition: PublicKey.cc:415
String related utilities and Regular expression matching.
Definition: ansi.h:854
bool askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
Definition: reporthelper.cc:35
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
detail::ReportHolder< zypp::KeyRingReport, Context::isAsync > _report
Definition: reporthelper.h:127
std::string asUserString() const
User string: label (alias or name)
Definition: RepoInfoBase.h:87
UserData makeData(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition: userrequest.cc:77
Convenient building of std::string with boost::format.
Definition: String.h:253
BasicReportHelper(const BasicReportHelper &)=default
#define ERR
Definition: Logger.h:105
#define PL_(MSG1, MSG2, N)
Definition: Gettext.h:42
void infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext={})
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition: KeyRing.h:53
zypp::KeyRingReport::KeyTrust askUserToAcceptKey(const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
Definition: reporthelper.cc:85
bool data(std::string msg_r, UserData userData_r=UserData())
send data message
bool askUserToAcceptPackageKey(const zypp::PublicKey &key_r, const zypp::KeyContext &keycontext_r={})
repo::DownloadContextRef _ctx
Definition: rpmmd.cc:63
User has chosen not to trust the key.
Definition: userrequest.h:83
#define _(MSG)
Definition: Gettext.h:39
static bool important(const std::string &msg_r, const UserData &userData_r=UserData())
send important message text
static bool data(const std::string &msg_r, const UserData &userData_r=UserData())
send data message
UserData makeData(const zypp::PublicKey &key, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition: userrequest.cc:52
static bool debug(const std::string &msg_r, const UserData &userData_r=UserData())
send debug message text
bool info(std::string msg_r, UserData userData_r=UserData())
send message text
const RepoInfo repoInfo() const
Definition: KeyContext.h:18
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition: PublicKey.h:374
bool empty() const
Is the context unknown?
Definition: KeyContext.h:15
bool debug(std::string msg_r, UserData userData_r=UserData())
send debug message text
Typesafe passing of user data via callbacks.
Definition: UserData.h:39
UserData makeData(const zypp::Pathname &p)
Definition: userrequest.cc:13
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
bool askUserToAcceptNoDigest(const zypp::Pathname &file)
Definition: reporthelper.cc:23
UserData makeData(const zypp::Pathname &p, const std::string &requested, const std::string &found)
Definition: userrequest.cc:26
UserData makeData(const std::string &file, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition: userrequest.cc:69
bool warning(std::string msg_r, UserData userData_r=UserData())
send warning text