19#include <zypp-common/PublicKey.h>
23#include <zypp-core/zyppng/pipelines/Transform>
24#include <zypp-core/zyppng/pipelines/Expected>
25#include <zypp-core/zyppng/pipelines/MTry>
26#include <zypp-media/ng/Provide>
27#include <zypp-media/ng/ProvideSpec>
29#include <zypp/ng/Context>
30#include <zypp/ng/UserRequest>
37 using namespace zyppng::operators;
39 template<
class Executor,
class OpType>
40 struct FetchGpgKeysLogic :
public LogicBase<Executor, OpType> {
42 using ZyppContextRefType = MaybeAsyncContextRef<OpType>;
44 using ProvideType =
typename ZyppContextType::ProvideType;
45 using MediaHandle =
typename ProvideType::MediaHandle;
46 using ProvideRes =
typename ProvideType::Res;
48 FetchGpgKeysLogic( ZyppContextRefType &&zyppContext, zypp::RepoInfo &&info )
49 : _reports( std::move(zyppContext ))
50 , _info( std::move(info) )
55 MaybeAsyncRef<expected<void>> execute () {
56 using namespace zyppng::operators;
57 using zyppng::operators::operator|;
58 using zyppng::expected;
62 if ( gpgKeyUrls.empty() ) {
63 if ( !_info.baseUrlsEmpty()
66 MIL <<
"No gpgkey URL specified, but d.o.o server detected. Trying to generate the key file path." << std::endl;
68 zypp::Url bUrl = *_info.baseUrlsBegin();
73 gpgKeyUrls.push_back( bUrl );
77 gpgKeyUrls.push_back( bUrl );
81 MIL <<
"Repo type is not known, unable to generate the gpgkey Url on the fly." << std::endl;
87 if ( gpgKeyUrls.empty () )
91 _keysDownloaded.clear();
97 _reports.info( zypp::str::Format(
_(
"Looking for gpg keys in repository %1%.") ) % _info.asUserString() );
99 return std::move(gpgKeyUrls)
100 |
transform( [
this](
const zypp::Url &url ) {
102 _reports.info(
" gpgkey=" + url.
asString() );
103 return _reports.zyppContext()->provider ()->provide( url, zyppng::ProvideFileSpec().setMirrorsAllowed(
false) )
104 |
and_then( [
this, url]( ProvideRes f ) -> expected<void> {
106 zypp::PublicKey key(f.
file());
107 if ( !key.isValid() )
111 _reports.zyppContext()->keyRing()->multiKeyImport(f.
file(),
false);
113 }
catch (
const std::exception & e ) {
116 MIL <<
"Key import from url:'"<<url<<
"' failed." << std::endl;
123 | [
this]( std::list<expected<void>> && ) {
129 JobReportHelper<ZyppContextRefType> _reports;
130 const zypp::RepoInfo _info;
131 std::set<std::string> _keysDownloaded;
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)
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
expected< void > fetchGpgKeys(SyncContextRef ctx, zypp::RepoInfo info)
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
std::shared_ptr< AsyncOp< T > > AsyncOpRef
typename remove_smart_ptr< T >::type remove_smart_ptr_t
ResultType and_then(const expected< T, E > &exp, Function &&f)
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
#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.