Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libstore-tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions src/libstore/include/nix/store/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
60 changes: 60 additions & 0 deletions src/libstore/include/nix/store/s3-url.hh
Original file line number Diff line number Diff line change
@@ -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
46 changes: 1 addition & 45 deletions src/libstore/include/nix/store/s3.hh
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion src/libstore/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
22 changes: 11 additions & 11 deletions src/libstore/s3.cc → src/libstore/s3-url.cc
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -116,6 +116,6 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
endpoint);
}

#endif

} // namespace nix

#endif
Loading