Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mirrors #2795

Merged
merged 5 commits into from
Nov 7, 2023
Merged

Add mirrors #2795

merged 5 commits into from
Nov 7, 2023

Conversation

Hind-M
Copy link
Member

@Hind-M Hind-M commented Aug 29, 2023

No description provided.

@SylvainCorlay
Copy link
Member

Let's rebase and get this in!


namespace mamba
{
class CURLHandle;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be exposed in public headers.

virtual std::string format_url(const std::string& path) const;
virtual std::string get_auth_header(const std::string& path) const;
virtual bool needs_preparation(const std::string& path) const;
virtual void prepare(const std::string& path, CURLHandle& handle);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Private virtual methods should be preferred.


protected:

Protocol m_protocol;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Data should not me exposed to inheriting classes, prefer private data and protected accessors.

HTTPMirror(const std::string& url);
~HTTPMirror();

bool authenticate(CURLHandle& handle, const std::string& user, const std::string& password);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Design: this requires the user to know the exact type or mirror, which violates the LSP principle.

std::string get_repo(const std::string& repo) const;
std::string get_auth_url(const std::string& repo, const std::string& scope) const;
std::string get_manifest_url(const std::string& repo, const std::string& reference) const;
std::string get_preupload_url(const std::string& repo) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These should be private methods.

@@ -446,6 +446,21 @@ namespace mamba
return *this;
}

CURLHandle& CURLHandle::set_url(const std::string& url, const proxy_map_type& proxies)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should not be required, ot deserves a better name if we need to reset the URL of an existing handler.


// Utility function
// TODO leave it here or put it in a namespace, or move it to utils?
std::pair<std::string, std::string> split_path_tag(const std::string& path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should retrurn a struct (this is more expressive)

std::size_t max_ranges = 256;
};

class Mirror
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation about what are mirrors and general expectation about what they provide would help here.
Also some member functions meaning coudl be clearified below.


const std::string m_url;

// TODO put these in a struct?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this TODO still relevant?

{
public:

HTTPMirror(const std::string& url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit for single argument constructors.

{
public:

Mirror(const std::string& url);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explicit for single argument constructors.

};

// Utility function
// TODO leave it here or put it in a namespace, or move it to utils?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it could be moved in string utilities?


void OCIMirror::prepare(const std::string& path, CURLHandle& handle)
{
auto [split_path, split_tag] = split_path_tag(path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const


if (data && data->token.empty() && need_auth())
{
std::string auth_url = get_auth_url(split_path, m_scope);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const

{
std::string auth_url = get_auth_url(split_path, m_scope);

// TODO to be checked
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are the todos in this function still relevant?


OCIMirror::AuthData* OCIMirror::get_data(const std::string& path) const
{
auto [split_path, _] = split_path_tag(path);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const


namespace mamba
{
TEST_SUITE("mirror")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's planned but I note this as a future reminder: needs test, and one of the first one would be to implement a test mirror and make it work with the mechanism handling mirrors (no downloading required). Then for tests requiring some downloading, I suppose they will need to be somewhat optional?

@JohanMabille
Copy link
Member

JohanMabille commented Nov 7, 2023

Let's address the comments when we plug the mirrors in the downloaders

@JohanMabille JohanMabille merged commit 2b948ce into mamba-org:main Nov 7, 2023
23 checks passed
@Hind-M Hind-M deleted the mirror_oci branch November 13, 2023 09:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants