21 #include <zypp-core/zyppng/pipelines/Transform> 22 #include <zypp-core/zyppng/pipelines/Expected> 23 #include <zypp-core/zyppng/pipelines/MTry> 24 #include <zypp-media/ng/Provide> 25 #include <zypp-media/ng/ProvideSpec> 27 #include <zypp/ng/Context> 28 #include <zypp/ng/UserRequest> 40 template<
class Executor,
class OpType>
41 struct RepoInfoProvideKeyLogic :
public LogicBase<Executor, OpType> {
43 using ZyppContextRefType = MaybeAsyncContextRef<OpType>;
44 using ZyppContextType = remove_smart_ptr_t<ZyppContextRefType>;
45 using ProvideType =
typename ZyppContextType::ProvideType;
46 using MediaHandle =
typename ProvideType::MediaHandle;
47 using ProvideRes =
typename ProvideType::Res;
49 RepoInfoProvideKeyLogic( ZyppContextRefType &&zyppContext,
zypp::RepoInfo &&info, std::string &&keyID_r,
zypp::Pathname &&targetDirectory_r )
60 MaybeAsyncRef<zypp::filesystem::Pathname> execute () {
62 using zyppng::operators::operator|;
69 importKeysInTargetDir();
91 executor()->info(
" gpgkey=" + url.
asString() );
92 return fetchKey( url )
105 }
catch (
const std::exception & e ) {
108 MIL <<
"Key import from url:'"<<url<<
"' failed." << std::endl;
116 | [
this]( std::list<expected<void>> && ) ->zypp::Pathname {
117 return writeKeysToTargetDir();
123 MaybeAsyncRef<zyppng::expected<zypp::ManagedFile>> fetchKey (
const zypp::Url &url ) {
128 void importKeysInTargetDir () {
136 [
this](
const zypp::Pathname & dir_r,
const std::string & str_r ){
150 ERR <<
"Error importing cached key from file '"<<dir_r/str_r<<
"'."<<std::endl;
163 MIL <<
"KEY ID in KEYRING: " << key.id() << std::endl;
167 std::ofstream fout( keyFile.
c_str(), std::ios_base::out | std::ios_base::trunc );
182 ERR <<
"Error when exporting key from temporary keychain." << std::endl;
200 struct AsyncRepoInfoProvideKey :
public RepoInfoProvideKeyLogic<AsyncRepoInfoProvideKey, zyppng::AsyncOp<zypp::Pathname>>
202 using RepoInfoProvideKeyLogic::RepoInfoProvideKeyLogic;
203 bool info(
const std::string & msg_r,
const UserData & userData_r =
UserData() ) {
209 struct SyncRepoInfoProvideKey :
public RepoInfoProvideKeyLogic<SyncRepoInfoProvideKey, zyppng::SyncOp<zypp::Pathname>>
211 using RepoInfoProvideKeyLogic::RepoInfoProvideKeyLogic;
212 bool info(
const std::string & msg_r,
const UserData & userData_r =
UserData() ) {
220 return SyncRepoInfoProvideKey::run( std::move(ctx), std::move(info), std::move(keyID_r), std::move(targetDirectory_r) );
225 return AsyncRepoInfoProvideKey::run( std::move(ctx), std::move(info), std::move(keyID_r), std::move(targetDirectory_r) );
int assert_dir(const Pathname &path, unsigned mode)
Like 'mkdir -p'.
url_set gpgKeyUrls() const
The list of gpgkey URLs defined for this repo.
auto transform(Transformation &&transformation)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
void dumpTrustedPublicKey(const std::string &id, std::ostream &stream)
String matching (STRING|SUBSTRING|GLOB|REGEX).
Class representing one GPG Public Keys data.
int dirForEach(const Pathname &dir_r, const StrMatcher &matcher_r, function< bool(const Pathname &, const char *const)> fnc_r)
const char * c_str() const
String representation.
const zypp::Pathname _targetDirectory_r
What is known about a repository.
std::list< PublicKeyData > trustedPublicKeyData()
Get a list of trusted public key data in the keyring (key data only)
std::string asUserString() const
User string: label (alias or name)
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
const std::string _keyIDStr
static const ValueType month
const std::string _keyID_r
std::string asString(TInt val, char zero='0', char one='1')
For printing bits.
bool empty() const
Test for an empty path.
ZyppContextRefType _zyppContext
zypp::callback::UserData UserData
const zypp::RepoInfo _info
std::string asString() const
Returns a default string representation of the Url object.
bool gpgKeyUrlsEmpty() const
Whether gpgkey URLs are defined.
Provide a new empty temporary directory and recursively delete it when no longer needed.
int unlink(const Pathname &path)
Like 'unlink'.
zypp::KeyRing _tempKeyRing
#define ZYPP_ENABLE_LOGIC_BASE(Executor, OpType)
std::conditional_t< isAsync, AsyncOpRef< T >, T > makeReadyResult(T &&result)
void multiKeyImport(const Pathname &keyfile_r, bool trusted_r=false)
Initial import from RpmDb.
static expected success(ConsParams &&...params)
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
std::shared_ptr< AsyncOp< T > > AsyncOpRef
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Base class for Exception.
static Date now()
Return the current time.
zypp::Pathname provideKey(SyncContextRef ctx, zypp::RepoInfo info, std::string keyID_r, zypp::Pathname targetDirectory_r)
std::string getPathName(EEncoding eflag=zypp::url::E_DECODED) const
Returns the path name from the URL.
auto and_then(Fun &&function)
zypp::filesystem::TmpDir _tmpKeyRingDir
Wrapper class for ::stat/::lstat.
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
bool isKeyTrusted(const std::string &id)
true if the key id is trusted