Skip to content

Commit

Permalink
Minor Channel refactoring (#2852)
Browse files Browse the repository at this point in the history
* Allow setting new token in CondaURL

* Use user and password in Channel

* Remove empty user in auth tests

* Mark URL::str const

* Store channel url in CondaURL

* Respect proper percent encoding in Channel

* Add zos-z to specs::Platform

* Replace channel.cpp known_platforms

* Remove optional from Channel ctor

* No need for const in return by value
  • Loading branch information
AntoinePrv authored Sep 26, 2023
1 parent a2b0f9c commit 1151ff3
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 128 deletions.
22 changes: 10 additions & 12 deletions libmamba/include/mamba/core/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@

#include "mamba/specs/conda_url.hpp"


namespace mamba
{
class Context;
Expand Down Expand Up @@ -46,9 +45,11 @@ namespace mamba
const std::string& name() const;
const std::string& canonical_name() const;
const std::vector<std::string>& platforms() const;
const std::optional<std::string>& auth() const;
const std::optional<std::string>& token() const;
const std::optional<std::string>& package_filename() const;
std::optional<std::string> auth() const;
std::optional<std::string> user() const;
std::optional<std::string> password() const;
std::optional<std::string> token() const;
std::optional<std::string> package_filename() const;
const validation::RepoChecker&
repo_checker(Context& context, MultiPackageCache& caches) const;

Expand All @@ -62,24 +63,21 @@ namespace mamba
private:

Channel(
std::string scheme,
std::string_view scheme,
std::string location,
std::string name,
std::string canonical_name,
std::optional<std::string> auth = {},
std::optional<std::string> token = {},
std::optional<std::string> package_filename = {}
std::string_view user = {},
std::string_view password = {},
std::string_view token = {},
std::string_view package_filename = {}
);

specs::CondaURL m_url;
std::string m_scheme;
std::string m_location;
std::string m_name;
std::string m_canonical_name;
std::vector<std::string> m_platforms;
std::optional<std::string> m_auth;
std::optional<std::string> m_token;
std::optional<std::string> m_package_filename;

// This is used to make sure that there is a unique repo for every channel
mutable std::unique_ptr<validation::RepoChecker> p_repo_checker;
Expand Down
7 changes: 6 additions & 1 deletion libmamba/include/mamba/specs/conda_url.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,12 @@ namespace mamba::specs
/** Return the Conda token, as delimited with "/t/", or empty if there isn't any. */
[[nodiscard]] auto token() const -> std::string_view;

/** Set a token if the URL already contains one, or throw an error. */
/**
* Set a token.
*
* If the URL already contains one replace it at the same location, otherwise, add it at
* the begining of the path.
*/
void set_token(std::string_view token);

/** Clear the token and return ``true`` if it exists, otherwise return ``false``. */
Expand Down
3 changes: 3 additions & 0 deletions libmamba/include/mamba/specs/platform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace mamba::specs
win_32,
win_64,
win_arm64,
zos_z,

// For reflexion purposes only
count_,
Expand Down Expand Up @@ -120,6 +121,8 @@ namespace mamba::specs
return "win-64";
case Platform::win_arm64:
return "win-arm64";
case Platform::zos_z:
return "zos-z";
default:
return "";
}
Expand Down
2 changes: 1 addition & 1 deletion libmamba/include/mamba/util/url.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ namespace mamba::util
auto clear_fragment() -> std::string;

/** Return the full, exact, encoded URL. */
[[nodiscard]] auto str() -> std::string;
[[nodiscard]] auto str() const -> std::string;

/**
* Return the full decoded url.
Expand Down
Loading

0 comments on commit 1151ff3

Please sign in to comment.