libzypp 17.37.17
repoinfowf.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "repoinfowf.h"
18#include <zypp/KeyRing.h>
19#include <zypp-common/PublicKey.h>
20#include <zypp/ZYppCallbacks.h>
21
22#include <utility>
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>
28#include <zypp/MediaSetAccess.h>
29#include <zypp/ng/Context>
30#include <zypp/ng/UserRequest>
32
33namespace zyppng {
34
35 namespace {
36
37 using namespace zyppng::operators;
38
39 template<class Executor, class OpType>
40 struct FetchGpgKeysLogic : public LogicBase<Executor, OpType> {
41
42 using ZyppContextRefType = MaybeAsyncContextRef<OpType>;
43 using ZyppContextType = remove_smart_ptr_t<ZyppContextRefType>;
44 using ProvideType = typename ZyppContextType::ProvideType;
45 using MediaHandle = typename ProvideType::MediaHandle;
46 using ProvideRes = typename ProvideType::Res;
47
48 FetchGpgKeysLogic( ZyppContextRefType &&zyppContext, zypp::RepoInfo &&info )
49 : _reports( std::move(zyppContext ))
50 , _info( std::move(info) )
51 { }
52
53 ZYPP_ENABLE_LOGIC_BASE( Executor, OpType );
54
55 MaybeAsyncRef<expected<void>> execute () {
56 using namespace zyppng::operators;
57 using zyppng::operators::operator|;
58 using zyppng::expected;
59
60 zypp::RepoInfo::url_set gpgKeyUrls = _info.gpgKeyUrls();
61
62 if ( gpgKeyUrls.empty() ) {
63 if ( !_info.baseUrlsEmpty()
64 && zypp::repo::RepoMirrorList::urlSupportsMirrorLink(*_info.baseUrlsBegin()) ) {
65
66 MIL << "No gpgkey URL specified, but d.o.o server detected. Trying to generate the key file path." << std::endl;
67
68 zypp::Url bUrl = *_info.baseUrlsBegin();
69 zypp::repo::RepoType::Type rType = _info.type().toEnum ();
70 switch( rType ) {
72 bUrl.appendPathName( _info.path() / "/repodata/repomd.xml.key" );
73 gpgKeyUrls.push_back( bUrl );
74 break;
76 bUrl.appendPathName( _info.path() / "/content.key" );
77 gpgKeyUrls.push_back( bUrl );
78 break;
81 MIL << "Repo type is not known, unable to generate the gpgkey Url on the fly." << std::endl;
82 break;
83 }
84 }
85 }
86
87 if ( gpgKeyUrls.empty () )
89 }
90
91 _keysDownloaded.clear();
92
93 // no key in the cache is what we are looking for, lets download
94 // all keys specified in gpgkey= entries
95
96 // translator: %1% is a repositories name
97 _reports.info( zypp::str::Format(_("Looking for gpg keys in repository %1%.") ) % _info.asUserString() );
98
99 return std::move(gpgKeyUrls)
100 | transform( [this]( const zypp::Url &url ) {
101
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> {
105 try {
106 zypp::PublicKey key(f.file());
107 if ( !key.isValid() )
108 return expected<void>::error(std::make_exception_ptr( zypp::Exception("Invalid public key.") ));
109
110 // import all keys into our keyring
111 _reports.zyppContext()->keyRing()->multiKeyImport(f.file(), false);
112
113 } catch ( const std::exception & e ) {
114 //ignore and continue to next url
115 ZYPP_CAUGHT(e);
116 MIL << "Key import from url:'"<<url<<"' failed." << std::endl;
118 }
119
121 });
122 } )
123 | [this]( std::list<expected<void>> && ) {
125 };
126 }
127
128 protected:
129 JobReportHelper<ZyppContextRefType> _reports;
130 const zypp::RepoInfo _info;
131 std::set<std::string> _keysDownloaded;
132 };
133
134 }
135
137 {
138 return SimpleExecutor<FetchGpgKeysLogic, SyncOp<expected<void>>>::run( std::move(ctx), std::move(info) );
139 }
140
142 {
143 return SimpleExecutor<FetchGpgKeysLogic, AsyncOp<expected<void>>>::run( std::move(ctx), std::move(info) );
144 }
145
146}
What is known about a repository.
Definition RepoInfo.h:72
std::list< Url > url_set
Definition RepoInfo.h:108
std::string asString() const
Returns a default string representation of the Url object.
Definition Url.cc:515
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Definition Url.cc:804
static bool urlSupportsMirrorLink(const zypp::Url &url)
const zypp::Pathname file() const
Definition provideres.cc:21
static expected success(ConsParams &&...params)
Definition expected.h:115
#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)
Definition asyncop.h:297
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
typename remove_smart_ptr< T >::type remove_smart_ptr_t
ResultType and_then(const expected< T, E > &exp, Function &&f)
Definition expected.h:423
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Definition transform.h:31
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:471
#define _(MSG)
Definition Gettext.h:39
#define MIL
Definition Logger.h:100