1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-08 19:46:02 +01:00

Merge pull request #14131 from lovesegfault/curl-based-s3-pieces

refactor(libstore): extract S3 URL parsing into separate files
This commit is contained in:
Sergei Zimmerman 2025-10-01 19:39:46 +00:00 committed by GitHub
commit 30a6cbe90b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 76 additions and 59 deletions

View file

@ -77,7 +77,7 @@ sources = files(
'realisation.cc',
'references.cc',
's3-binary-cache-store.cc',
's3.cc',
's3-url.cc',
'serve-protocol.cc',
'ssh-store.cc',
'store-reference.cc',

View file

@ -1,4 +1,4 @@
#include "nix/store/s3.hh"
#include "nix/store/s3-url.hh"
#include "nix/util/tests/gmock-matchers.hh"
#if NIX_WITH_S3_SUPPORT

View file

@ -72,6 +72,7 @@ headers = [ config_pub_h ] + files(
'remote-store.hh',
'restricted-store.hh',
's3-binary-cache-store.hh',
's3-url.hh',
's3.hh',
'serve-protocol-connection.hh',
'serve-protocol-impl.hh',

View file

@ -0,0 +1,60 @@
#pragma once
///@file
#include "nix/store/config.hh"
#if NIX_WITH_S3_SUPPORT
# include "nix/util/url.hh"
# include "nix/util/util.hh"
# include <optional>
# include <string>
# include <variant>
# include <vector>
namespace nix {
/**
* Parsed S3 URL.
*/
struct ParsedS3URL
{
std::string bucket;
/**
* @see ParsedURL::path. This is a vector for the same reason.
* Unlike ParsedURL::path this doesn't include the leading empty segment,
* since the bucket name is necessary.
*/
std::vector<std::string> key;
std::optional<std::string> profile;
std::optional<std::string> region;
std::optional<std::string> scheme;
/**
* The endpoint can be either missing, be an absolute URI (with a scheme like `http:`)
* or an authority (so an IP address or a registered name).
*/
std::variant<std::monostate, ParsedURL, ParsedURL::Authority> endpoint;
std::optional<std::string> getEncodedEndpoint() const
{
return std::visit(
overloaded{
[](std::monostate) -> std::optional<std::string> { return std::nullopt; },
[](const auto & authorityOrUrl) -> std::optional<std::string> { return authorityOrUrl.to_string(); },
},
endpoint);
}
static ParsedS3URL parse(const ParsedURL & uri);
/**
* Convert this ParsedS3URL to HTTPS ParsedURL for use with curl's AWS SigV4 authentication
*/
ParsedURL toHttpsUrl() const;
auto operator<=>(const ParsedS3URL & other) const = default;
};
} // namespace nix
#endif

View file

@ -4,12 +4,9 @@
#if NIX_WITH_S3_SUPPORT
# include "nix/util/ref.hh"
# include "nix/util/url.hh"
# include "nix/util/util.hh"
# include "nix/store/s3-url.hh"
# include <optional>
# include <string>
# include <variant>
namespace Aws {
namespace Client {
@ -48,47 +45,6 @@ struct S3Helper
FileTransferResult getObject(const std::string & bucketName, const std::string & key);
};
/**
* Parsed S3 URL.
*/
struct ParsedS3URL
{
std::string bucket;
/**
* @see ParsedURL::path. This is a vector for the same reason.
* Unlike ParsedURL::path this doesn't include the leading empty segment,
* since the bucket name is necessary.
*/
std::vector<std::string> key;
std::optional<std::string> profile;
std::optional<std::string> region;
std::optional<std::string> scheme;
/**
* The endpoint can be either missing, be an absolute URI (with a scheme like `http:`)
* or an authority (so an IP address or a registered name).
*/
std::variant<std::monostate, ParsedURL, ParsedURL::Authority> endpoint;
std::optional<std::string> getEncodedEndpoint() const
{
return std::visit(
overloaded{
[](std::monostate) -> std::optional<std::string> { return std::nullopt; },
[](const auto & authorityOrUrl) -> std::optional<std::string> { return authorityOrUrl.to_string(); },
},
endpoint);
}
static ParsedS3URL parse(const ParsedURL & uri);
/**
* Convert this ParsedS3URL to HTTPS ParsedURL for use with curl's AWS SigV4 authentication
*/
ParsedURL toHttpsUrl() const;
auto operator<=>(const ParsedS3URL & other) const = default;
};
} // namespace nix
#endif

View file

@ -329,7 +329,7 @@ sources = files(
'remote-store.cc',
'restricted-store.cc',
's3-binary-cache-store.cc',
's3.cc',
's3-url.cc',
'serve-protocol-connection.cc',
'serve-protocol.cc',
'sqlite.cc',

View file

@ -1,17 +1,17 @@
#include "nix/store/s3.hh"
#include "nix/util/split.hh"
#include "nix/util/url.hh"
#include "nix/util/util.hh"
#include "nix/util/canon-path.hh"
#include "nix/util/strings-inline.hh"
#include "nix/store/s3-url.hh"
#include <ranges>
#if NIX_WITH_S3_SUPPORT
namespace nix {
# include "nix/util/error.hh"
# include "nix/util/split.hh"
# include "nix/util/strings-inline.hh"
# include <ranges>
# include <string_view>
using namespace std::string_view_literals;
#if NIX_WITH_S3_SUPPORT
namespace nix {
ParsedS3URL ParsedS3URL::parse(const ParsedURL & parsed)
try {
@ -116,6 +116,6 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
endpoint);
}
#endif
} // namespace nix
#endif