Skip to content

Commit 30a6cbe

Browse files
authored
Merge pull request #14131 from lovesegfault/curl-based-s3-pieces
refactor(libstore): extract S3 URL parsing into separate files
2 parents 251479b + b72898b commit 30a6cbe

File tree

7 files changed

+76
-59
lines changed

7 files changed

+76
-59
lines changed

src/libstore-tests/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ sources = files(
7777
'realisation.cc',
7878
'references.cc',
7979
's3-binary-cache-store.cc',
80-
's3.cc',
80+
's3-url.cc',
8181
'serve-protocol.cc',
8282
'ssh-store.cc',
8383
'store-reference.cc',

src/libstore-tests/s3.cc renamed to src/libstore-tests/s3-url.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "nix/store/s3.hh"
1+
#include "nix/store/s3-url.hh"
22
#include "nix/util/tests/gmock-matchers.hh"
33

44
#if NIX_WITH_S3_SUPPORT

src/libstore/include/nix/store/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ headers = [ config_pub_h ] + files(
7272
'remote-store.hh',
7373
'restricted-store.hh',
7474
's3-binary-cache-store.hh',
75+
's3-url.hh',
7576
's3.hh',
7677
'serve-protocol-connection.hh',
7778
'serve-protocol-impl.hh',
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#pragma once
2+
///@file
3+
#include "nix/store/config.hh"
4+
5+
#if NIX_WITH_S3_SUPPORT
6+
7+
# include "nix/util/url.hh"
8+
# include "nix/util/util.hh"
9+
10+
# include <optional>
11+
# include <string>
12+
# include <variant>
13+
# include <vector>
14+
15+
namespace nix {
16+
17+
/**
18+
* Parsed S3 URL.
19+
*/
20+
struct ParsedS3URL
21+
{
22+
std::string bucket;
23+
/**
24+
* @see ParsedURL::path. This is a vector for the same reason.
25+
* Unlike ParsedURL::path this doesn't include the leading empty segment,
26+
* since the bucket name is necessary.
27+
*/
28+
std::vector<std::string> key;
29+
std::optional<std::string> profile;
30+
std::optional<std::string> region;
31+
std::optional<std::string> scheme;
32+
/**
33+
* The endpoint can be either missing, be an absolute URI (with a scheme like `http:`)
34+
* or an authority (so an IP address or a registered name).
35+
*/
36+
std::variant<std::monostate, ParsedURL, ParsedURL::Authority> endpoint;
37+
38+
std::optional<std::string> getEncodedEndpoint() const
39+
{
40+
return std::visit(
41+
overloaded{
42+
[](std::monostate) -> std::optional<std::string> { return std::nullopt; },
43+
[](const auto & authorityOrUrl) -> std::optional<std::string> { return authorityOrUrl.to_string(); },
44+
},
45+
endpoint);
46+
}
47+
48+
static ParsedS3URL parse(const ParsedURL & uri);
49+
50+
/**
51+
* Convert this ParsedS3URL to HTTPS ParsedURL for use with curl's AWS SigV4 authentication
52+
*/
53+
ParsedURL toHttpsUrl() const;
54+
55+
auto operator<=>(const ParsedS3URL & other) const = default;
56+
};
57+
58+
} // namespace nix
59+
60+
#endif

src/libstore/include/nix/store/s3.hh

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
#if NIX_WITH_S3_SUPPORT
55

66
# include "nix/util/ref.hh"
7-
# include "nix/util/url.hh"
8-
# include "nix/util/util.hh"
7+
# include "nix/store/s3-url.hh"
98

10-
# include <optional>
119
# include <string>
12-
# include <variant>
1310

1411
namespace Aws {
1512
namespace Client {
@@ -48,47 +45,6 @@ struct S3Helper
4845
FileTransferResult getObject(const std::string & bucketName, const std::string & key);
4946
};
5047

51-
/**
52-
* Parsed S3 URL.
53-
*/
54-
struct ParsedS3URL
55-
{
56-
std::string bucket;
57-
/**
58-
* @see ParsedURL::path. This is a vector for the same reason.
59-
* Unlike ParsedURL::path this doesn't include the leading empty segment,
60-
* since the bucket name is necessary.
61-
*/
62-
std::vector<std::string> key;
63-
std::optional<std::string> profile;
64-
std::optional<std::string> region;
65-
std::optional<std::string> scheme;
66-
/**
67-
* The endpoint can be either missing, be an absolute URI (with a scheme like `http:`)
68-
* or an authority (so an IP address or a registered name).
69-
*/
70-
std::variant<std::monostate, ParsedURL, ParsedURL::Authority> endpoint;
71-
72-
std::optional<std::string> getEncodedEndpoint() const
73-
{
74-
return std::visit(
75-
overloaded{
76-
[](std::monostate) -> std::optional<std::string> { return std::nullopt; },
77-
[](const auto & authorityOrUrl) -> std::optional<std::string> { return authorityOrUrl.to_string(); },
78-
},
79-
endpoint);
80-
}
81-
82-
static ParsedS3URL parse(const ParsedURL & uri);
83-
84-
/**
85-
* Convert this ParsedS3URL to HTTPS ParsedURL for use with curl's AWS SigV4 authentication
86-
*/
87-
ParsedURL toHttpsUrl() const;
88-
89-
auto operator<=>(const ParsedS3URL & other) const = default;
90-
};
91-
9248
} // namespace nix
9349

9450
#endif

src/libstore/meson.build

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ sources = files(
329329
'remote-store.cc',
330330
'restricted-store.cc',
331331
's3-binary-cache-store.cc',
332-
's3.cc',
332+
's3-url.cc',
333333
'serve-protocol-connection.cc',
334334
'serve-protocol.cc',
335335
'sqlite.cc',

src/libstore/s3.cc renamed to src/libstore/s3-url.cc

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
#include "nix/store/s3.hh"
2-
#include "nix/util/split.hh"
3-
#include "nix/util/url.hh"
4-
#include "nix/util/util.hh"
5-
#include "nix/util/canon-path.hh"
6-
#include "nix/util/strings-inline.hh"
1+
#include "nix/store/s3-url.hh"
72

8-
#include <ranges>
3+
#if NIX_WITH_S3_SUPPORT
94

10-
namespace nix {
5+
# include "nix/util/error.hh"
6+
# include "nix/util/split.hh"
7+
# include "nix/util/strings-inline.hh"
8+
9+
# include <ranges>
10+
# include <string_view>
1111

1212
using namespace std::string_view_literals;
1313

14-
#if NIX_WITH_S3_SUPPORT
14+
namespace nix {
1515

1616
ParsedS3URL ParsedS3URL::parse(const ParsedURL & parsed)
1717
try {
@@ -116,6 +116,6 @@ ParsedURL ParsedS3URL::toHttpsUrl() const
116116
endpoint);
117117
}
118118

119-
#endif
120-
121119
} // namespace nix
120+
121+
#endif

0 commit comments

Comments
 (0)