Skip to content

Commit

Permalink
Deduplicate code - create Repo:Impl:stringToProxyAuthMethods() method
Browse files Browse the repository at this point in the history
  • Loading branch information
jrohel authored and m-blaha committed Feb 25, 2021
1 parent 1d0a137 commit 2ea1601
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
3 changes: 3 additions & 0 deletions libdnf/repo/Repo-private.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ class Repo::Impl {
void attachLibsolvRepo(LibsolvRepo * libsolvRepo);
void detachLibsolvRepo();

// Converts configuration string of proxy authorization methods to librepo enum.
static LrAuth stringToProxyAuthMethods(const std::string & proxy_auth_method) noexcept;

std::string id;
Type type;
std::unique_ptr<ConfigRepo> conf;
Expand Down
34 changes: 16 additions & 18 deletions libdnf/repo/Repo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,15 +608,8 @@ std::unique_ptr<LrHandle> Repo::Impl::lrHandleInitRemote(const char *destdir)
handleSetOpt(h.get(), LRO_PROXY, conf->proxy().getValue().c_str());

//set proxy authorization method
auto proxyAuthMethodStr = conf->proxy_auth_method().getValue();
auto proxyAuthMethod = LR_AUTH_ANY;
for (auto & auth : PROXYAUTHMETHODS) {
if (proxyAuthMethodStr == auth.name) {
proxyAuthMethod = auth.code;
break;
}
}
handleSetOpt(h.get(), LRO_PROXYAUTHMETHODS, static_cast<long>(proxyAuthMethod));
auto proxyAuthMethods = stringToProxyAuthMethods(conf->proxy_auth_method().getValue());
handleSetOpt(h.get(), LRO_PROXYAUTHMETHODS, static_cast<long>(proxyAuthMethods));

if (!conf->proxy_username().empty()) {
userpwd = conf->proxy_username().getValue();
Expand Down Expand Up @@ -1531,6 +1524,18 @@ void Repo::Impl::detachLibsolvRepo()
attachLibsolvMutex.unlock();
}

LrAuth Repo::Impl::stringToProxyAuthMethods(const std::string & proxyAuthMethodStr) noexcept
{
auto proxyAuthMethods = LR_AUTH_ANY;
for (auto & auth : PROXYAUTHMETHODS) {
if (proxyAuthMethodStr == auth.name) {
proxyAuthMethods = auth.code;
break;
}
}
return proxyAuthMethods;
}

void Repo::setMaxMirrorTries(int maxMirrorTries)
{
pImpl->maxMirrorTries = maxMirrorTries;
Expand Down Expand Up @@ -1710,15 +1715,8 @@ static LrHandle * newHandle(ConfigMain * conf)
handleSetOpt(h, LRO_PROXY, conf->proxy().getValue().c_str());

//set proxy authorization method
auto proxyAuthMethodStr = conf->proxy_auth_method().getValue();
auto proxyAuthMethod = LR_AUTH_ANY;
for (auto & auth : PROXYAUTHMETHODS) {
if (proxyAuthMethodStr == auth.name) {
proxyAuthMethod = auth.code;
break;
}
}
handleSetOpt(h, LRO_PROXYAUTHMETHODS, static_cast<long>(proxyAuthMethod));
auto proxyAuthMethods = Repo::Impl::stringToProxyAuthMethods(conf->proxy_auth_method().getValue());
handleSetOpt(h, LRO_PROXYAUTHMETHODS, static_cast<long>(proxyAuthMethods));

if (!conf->proxy_username().empty()) {
auto userpwd = conf->proxy_username().getValue();
Expand Down

0 comments on commit 2ea1601

Please sign in to comment.