22#include <zypp-core/ng/pipelines/Transform>
23#include <zypp-core/ng/pipelines/Expected>
24#include <zypp-core/ng/pipelines/MTry>
26#include <zypp-media/ng/ProvideSpec>
27#include <zypp/ng/Context>
28#include <zypp/ng/UserRequest>
35 using namespace zyppng::operators;
37 struct FetchGpgKeysLogic {
39 using ZyppContextRefType =ContextRef;
40 using ZyppContextType = Context;
42 using MediaHandle =
typename ProvideType::MediaHandle;
43 using ProvideRes =
typename ProvideType::Res;
45 FetchGpgKeysLogic( ZyppContextRefType &&zyppContext, zypp::RepoInfo &&info )
46 : _reports( std::move(zyppContext ))
47 , _info( std::move(info) )
50 MaybeAwaitable<expected<void>> execute () {
51 using namespace zyppng::operators;
52 using zyppng::operators::operator|;
53 using zyppng::expected;
57 if ( gpgKeyUrls.empty() ) {
58 if ( !_info.baseUrlsEmpty()
61 MIL <<
"No gpgkey URL specified, but d.o.o server detected. Trying to generate the key file path." << std::endl;
63 zypp::Url bUrl = *_info.baseUrlsBegin();
68 gpgKeyUrls.push_back( bUrl );
72 gpgKeyUrls.push_back( bUrl );
76 MIL <<
"Repo type is not known, unable to generate the gpgkey Url on the fly." << std::endl;
82 if ( gpgKeyUrls.empty () )
86 _keysDownloaded.clear();
92 _reports.info( zypp::str::Format(
_(
"Looking for gpg keys in repository %1%.") ) % _info.asUserString() );
94 return std::move(gpgKeyUrls)
95 |
transform( [
this](
const zypp::Url &url ) {
97 _reports.info(
" gpgkey=" + url.
asString() );
98 return _reports.zyppContext()->provider ()->provide( url, zyppng::ProvideFileSpec().setMirrorsAllowed(
false) )
99 |
and_then( [
this, url]( ProvideRes f ) -> expected<void> {
101 zypp::PublicKey key(f.
file());
102 if ( !key.isValid() )
106 _reports.zyppContext()->keyRing()->multiKeyImport(f.
file(),
false);
108 }
catch (
const std::exception & e ) {
111 MIL <<
"Key import from url:'"<<url<<
"' failed." << std::endl;
118 | []( std::list<expected<void>> && ) {
124 JobReportHelper _reports;
125 const zypp::RepoInfo _info;
126 std::set<std::string> _keysDownloaded;
133 FetchGpgKeysLogic impl( std::move(ctx), std::move(info) );
134 zypp_co_return zypp_co_await( impl.execute () );
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
What is known about a repository.
std::string asString() const
Returns a default string representation of the Url object.
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
static bool urlSupportsMirrorLink(const zypp::Url &url)
const zypp::Pathname file() const
static expected success(ConsParams &&...params)
MaybeAwaitable< expected< void > > fetchGpgKeys(ContextRef ctx, zypp::RepoInfo info)
ResultType and_then(const expected< T, E > &exp, Function &&f)
auto transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)