diff --git a/src/libstore-tests/meson.build b/src/libstore-tests/meson.build index 915c10a38..1908e5cbc 100644 --- a/src/libstore-tests/meson.build +++ b/src/libstore-tests/meson.build @@ -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', diff --git a/src/libstore-tests/s3.cc b/src/libstore-tests/s3-url.cc similarity index 99% rename from src/libstore-tests/s3.cc rename to src/libstore-tests/s3-url.cc index 799e102fe..56ec4e40e 100644 --- a/src/libstore-tests/s3.cc +++ b/src/libstore-tests/s3-url.cc @@ -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 diff --git a/src/libstore/include/nix/store/meson.build b/src/libstore/include/nix/store/meson.build index 428ef00f3..f945f25ad 100644 --- a/src/libstore/include/nix/store/meson.build +++ b/src/libstore/include/nix/store/meson.build @@ -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', diff --git a/src/libstore/include/nix/store/s3-url.hh b/src/libstore/include/nix/store/s3-url.hh new file mode 100644 index 000000000..4f0a7b0c2 --- /dev/null +++ b/src/libstore/include/nix/store/s3-url.hh @@ -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 +# include +# include +# include + +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 key; + std::optional profile; + std::optional region; + std::optional 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 endpoint; + + std::optional getEncodedEndpoint() const + { + return std::visit( + overloaded{ + [](std::monostate) -> std::optional { return std::nullopt; }, + [](const auto & authorityOrUrl) -> std::optional { 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 diff --git a/src/libstore/include/nix/store/s3.hh b/src/libstore/include/nix/store/s3.hh index 0270eeda6..ba3adbc2a 100644 --- a/src/libstore/include/nix/store/s3.hh +++ b/src/libstore/include/nix/store/s3.hh @@ -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 # include -# include 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 key; - std::optional profile; - std::optional region; - std::optional 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 endpoint; - - std::optional getEncodedEndpoint() const - { - return std::visit( - overloaded{ - [](std::monostate) -> std::optional { return std::nullopt; }, - [](const auto & authorityOrUrl) -> std::optional { 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 diff --git a/src/libstore/meson.build b/src/libstore/meson.build index e3004ebf5..80c234bd5 100644 --- a/src/libstore/meson.build +++ b/src/libstore/meson.build @@ -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', diff --git a/src/libstore/s3.cc b/src/libstore/s3-url.cc similarity index 95% rename from src/libstore/s3.cc rename to src/libstore/s3-url.cc index 5396f43b9..947de60b0 100644 --- a/src/libstore/s3.cc +++ b/src/libstore/s3-url.cc @@ -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 +#if NIX_WITH_S3_SUPPORT -namespace nix { +# include "nix/util/error.hh" +# include "nix/util/split.hh" +# include "nix/util/strings-inline.hh" + +# include +# include 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