libzypp 17.37.10

repoinfowf.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9#include "repoinfowf.h"
10#include <zypp/ng/reporthelper.h>
11#include <zypp/repo/RepoMirrorList.h>
12#include <zypp/ng/workflows/contextfacade.h>
13#include <zypp-core/ManagedFile.h>
14#include <zypp-core/base/String.h>
15#include <zypp-core/base/Gettext.h>
16#include <zypp-core/fs/TmpPath.h>
17#include <zypp/base/StrMatcher.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>
31#include <zypp/ng/workflows/logichelpers.h>
32
33 namespace 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 ) {
71 case zypp::repo::RepoType::RPMMD_e:
72 bUrl.appendPathName( _info.path() / "/repodata/repomd.xml.key" );
73 gpgKeyUrls.push_back( bUrl );
74 break;
75 case zypp::repo::RepoType::YAST2_e:
76 bUrl.appendPathName( _info.path() / "/content.key" );
77 gpgKeyUrls.push_back( bUrl );
78 break;
79 case zypp::repo::RepoType::NONE_e:
80 case zypp::repo::RepoType::RPMPLAINDIR_e: {
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 () )
88 return makeReadyResult( expected<void>::success() );
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;
117 return expected<void>::error( ZYPP_FWD_CURRENT_EXCPT() );
118 }
119
120 return expected<void>::success();
121 });
122 } )
123 | [this]( std::list<expected<void>> && ) {
124 return expected<void>::success();
125 };
126 }
127
128 protected:
129 JobReportHelper<ZyppContextRefType> _reports;
130 const zypp::RepoInfo _info;
131 std::set<std::string> _keysDownloaded;
132 };
133
134 }
135
136 expected<void> RepoInfoWorkflow::fetchGpgKeys( SyncContextRef ctx, zypp::RepoInfo info )
137 {
138 return SimpleExecutor<FetchGpgKeysLogic, SyncOp<expected<void>>>::run( std::move(ctx), std::move(info) );
139 }
140
141 AsyncOpRef<expected<void>> RepoInfoWorkflow::fetchGpgKeys(ContextRef ctx, zypp::RepoInfo info )
142 {
143 return SimpleExecutor<FetchGpgKeysLogic, AsyncOp<expected<void>>>::run( std::move(ctx), std::move(info) );
144 }
145
146}
KeyRing.h
MediaSetAccess.h
RepoMirrorList.h
StrMatcher.h
ZYppCallbacks.h
zypp::RepoInfo
What is known about a repository.
Definition RepoInfo.h:72
zypp::RepoInfo::url_set
std::list< Url > url_set
Definition RepoInfo.h:108
zypp::Url::asString
std::string asString() const
Returns a default string representation of the Url object.
Definition Url.cc:515
zypp::Url::appendPathName
void appendPathName(const Pathname &path_r, EEncoding eflag_r=zypp::url::E_DECODED)
Extend the path name.
Definition Url.cc:804
zypp::repo::RepoMirrorList::urlSupportsMirrorLink
static bool urlSupportsMirrorLink(const zypp::Url &url)
Definition RepoMirrorList.cc:417
zyppng::ProvideRes::file
const zypp::Pathname file() const
Definition provideres.cc:21
zyppng::expected
Definition expected.h:27
zyppng::expected::success
static expected success(ConsParams &&...params)
Definition expected.h:115
zyppng::expected::error
E & error()
Definition expected.h:225
contextfacade.h
logichelpers.h
ZYPP_ENABLE_LOGIC_BASE
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
Definition logichelpers.h:223
zyppng::RepoInfoWorkflow::fetchGpgKeys
expected< void > fetchGpgKeys(SyncContextRef ctx, zypp::RepoInfo info)
Definition repoinfowf.cc:136
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::makeReadyResult
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
Definition asyncop.h:297
zyppng::AsyncOpRef
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Definition asyncop.h:255
zyppng::remove_smart_ptr_t
typename remove_smart_ptr< T >::type remove_smart_ptr_t
Definition type_traits.h:133
zyppng::and_then
ResultType and_then(const expected< T, E > &exp, Function &&f)
Definition expected.h:423
zyppng::transform
Container< Ret > transform(Container< Msg, CArgs... > &&val, Transformation &&transformation)
Definition transform.h:31
repoinfowf.h
reporthelper.h
zypp::repo::RepoType::Type
Type
Definition RepoType.h:36
zypp::repo::RepoType::RPMMD_e
@ RPMMD_e
Definition RepoType.h:38
zypp::repo::RepoType::NONE_e
@ NONE_e
Definition RepoType.h:37
zypp::repo::RepoType::YAST2_e
@ YAST2_e
Definition RepoType.h:39
zypp::repo::RepoType::RPMPLAINDIR_e
@ RPMPLAINDIR_e
Definition RepoType.h:40
zyppng::LogicBase
Definition logichelpers.h:161
zyppng::SimpleExecutor
Definition logichelpers.h:212
ManagedFile.h
ZYPP_CAUGHT
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
ZYPP_FWD_CURRENT_EXCPT
#define ZYPP_FWD_CURRENT_EXCPT()
Drops a logline and returns the current Exception as a std::exception_ptr.
Definition Exception.h:471
Gettext.h
_
#define _(MSG)
Definition Gettext.h:39
MIL
#define MIL
Definition Logger.h:100
String.h
TmpPath.h