mirror of
https://github.com/NixOS/nix.git
synced 2025-11-09 20:16:03 +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:
commit
30a6cbe90b
7 changed files with 76 additions and 59 deletions
|
|
@ -77,7 +77,7 @@ sources = files(
|
||||||
'realisation.cc',
|
'realisation.cc',
|
||||||
'references.cc',
|
'references.cc',
|
||||||
's3-binary-cache-store.cc',
|
's3-binary-cache-store.cc',
|
||||||
's3.cc',
|
's3-url.cc',
|
||||||
'serve-protocol.cc',
|
'serve-protocol.cc',
|
||||||
'ssh-store.cc',
|
'ssh-store.cc',
|
||||||
'store-reference.cc',
|
'store-reference.cc',
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
#include "nix/store/s3.hh"
|
#include "nix/store/s3-url.hh"
|
||||||
#include "nix/util/tests/gmock-matchers.hh"
|
#include "nix/util/tests/gmock-matchers.hh"
|
||||||
|
|
||||||
#if NIX_WITH_S3_SUPPORT
|
#if NIX_WITH_S3_SUPPORT
|
||||||
|
|
@ -72,6 +72,7 @@ headers = [ config_pub_h ] + files(
|
||||||
'remote-store.hh',
|
'remote-store.hh',
|
||||||
'restricted-store.hh',
|
'restricted-store.hh',
|
||||||
's3-binary-cache-store.hh',
|
's3-binary-cache-store.hh',
|
||||||
|
's3-url.hh',
|
||||||
's3.hh',
|
's3.hh',
|
||||||
'serve-protocol-connection.hh',
|
'serve-protocol-connection.hh',
|
||||||
'serve-protocol-impl.hh',
|
'serve-protocol-impl.hh',
|
||||||
|
|
|
||||||
60
src/libstore/include/nix/store/s3-url.hh
Normal file
60
src/libstore/include/nix/store/s3-url.hh
Normal 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
|
||||||
|
|
@ -4,12 +4,9 @@
|
||||||
#if NIX_WITH_S3_SUPPORT
|
#if NIX_WITH_S3_SUPPORT
|
||||||
|
|
||||||
# include "nix/util/ref.hh"
|
# include "nix/util/ref.hh"
|
||||||
# include "nix/util/url.hh"
|
# include "nix/store/s3-url.hh"
|
||||||
# include "nix/util/util.hh"
|
|
||||||
|
|
||||||
# include <optional>
|
|
||||||
# include <string>
|
# include <string>
|
||||||
# include <variant>
|
|
||||||
|
|
||||||
namespace Aws {
|
namespace Aws {
|
||||||
namespace Client {
|
namespace Client {
|
||||||
|
|
@ -48,47 +45,6 @@ struct S3Helper
|
||||||
FileTransferResult getObject(const std::string & bucketName, const std::string & key);
|
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
|
} // namespace nix
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
|
|
@ -329,7 +329,7 @@ sources = files(
|
||||||
'remote-store.cc',
|
'remote-store.cc',
|
||||||
'restricted-store.cc',
|
'restricted-store.cc',
|
||||||
's3-binary-cache-store.cc',
|
's3-binary-cache-store.cc',
|
||||||
's3.cc',
|
's3-url.cc',
|
||||||
'serve-protocol-connection.cc',
|
'serve-protocol-connection.cc',
|
||||||
'serve-protocol.cc',
|
'serve-protocol.cc',
|
||||||
'sqlite.cc',
|
'sqlite.cc',
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,17 @@
|
||||||
#include "nix/store/s3.hh"
|
#include "nix/store/s3-url.hh"
|
||||||
|
|
||||||
|
#if NIX_WITH_S3_SUPPORT
|
||||||
|
|
||||||
|
# include "nix/util/error.hh"
|
||||||
# include "nix/util/split.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/util/strings-inline.hh"
|
||||||
|
|
||||||
# include <ranges>
|
# include <ranges>
|
||||||
|
# include <string_view>
|
||||||
namespace nix {
|
|
||||||
|
|
||||||
using namespace std::string_view_literals;
|
using namespace std::string_view_literals;
|
||||||
|
|
||||||
#if NIX_WITH_S3_SUPPORT
|
namespace nix {
|
||||||
|
|
||||||
ParsedS3URL ParsedS3URL::parse(const ParsedURL & parsed)
|
ParsedS3URL ParsedS3URL::parse(const ParsedURL & parsed)
|
||||||
try {
|
try {
|
||||||
|
|
@ -116,6 +116,6 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
|
||||||
endpoint);
|
endpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
} // namespace nix
|
} // namespace nix
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue