Skip to content

Commit

Permalink
Move uriSchemes to *StoreConfig
Browse files Browse the repository at this point in the history
It is a property of the configuration of a store --- how a store URL is
parsed into a store config, not a store itself.

Progress towards NixOS#10766
  • Loading branch information
Ericson2314 committed Jul 16, 2024
1 parent 7f52356 commit 6768f4e
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions src/libstore/http-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,14 @@ struct HttpBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig

const std::string name() override { return "HTTP Binary Cache Store"; }

static std::set<std::string> uriSchemes()
{
static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1";
auto ret = std::set<std::string>({"http", "https"});
if (forceHttp) ret.insert("file");
return ret;
}

std::string doc() override
{
return
Expand Down Expand Up @@ -81,14 +89,6 @@ class HttpBinaryCacheStore : public virtual HttpBinaryCacheStoreConfig, public v
}
}

static std::set<std::string> uriSchemes()
{
static bool forceHttp = getEnv("_NIX_FORCE_HTTP") == "1";
auto ret = std::set<std::string>({"http", "https"});
if (forceHttp) ret.insert("file");
return ret;
}

protected:

void maybeDisable()
Expand Down
4 changes: 2 additions & 2 deletions src/libstore/legacy-ssh-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ struct LegacySSHStoreConfig : virtual CommonSSHStoreConfig

const std::string name() override { return "SSH Store"; }

static std::set<std::string> uriSchemes() { return {"ssh"}; }

std::string doc() override;
};

Expand All @@ -46,8 +48,6 @@ struct LegacySSHStore : public virtual LegacySSHStoreConfig, public virtual Stor

SSHMaster master;

static std::set<std::string> uriSchemes() { return {"ssh"}; }

LegacySSHStore(
std::string_view scheme,
std::string_view host,
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/local-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ struct LocalBinaryCacheStoreConfig : virtual BinaryCacheStoreConfig

const std::string name() override { return "Local Binary Cache Store"; }

static std::set<std::string> uriSchemes();

std::string doc() override
{
return
Expand Down Expand Up @@ -53,8 +55,6 @@ class LocalBinaryCacheStore : public virtual LocalBinaryCacheStoreConfig, public
return "file://" + binaryCacheDir;
}

static std::set<std::string> uriSchemes();

protected:

bool fileExists(const std::string & path) override;
Expand Down Expand Up @@ -123,7 +123,7 @@ bool LocalBinaryCacheStore::fileExists(const std::string & path)
return pathExists(binaryCacheDir + "/" + path);
}

std::set<std::string> LocalBinaryCacheStore::uriSchemes()
std::set<std::string> LocalBinaryCacheStoreConfig::uriSchemes()
{
if (getEnv("_NIX_FORCE_HTTP") == "1")
return {};
Expand Down
10 changes: 5 additions & 5 deletions src/libstore/local-overlay-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ struct LocalOverlayStoreConfig : virtual LocalStoreConfig
return ExperimentalFeature::LocalOverlayStore;
}

static std::set<std::string> uriSchemes()
{
return { "local-overlay" };
}

std::string doc() override;

protected:
Expand Down Expand Up @@ -99,11 +104,6 @@ public:
throw UsageError("local-overlay:// store url doesn't support path part, only scheme and query params");
}

static std::set<std::string> uriSchemes()
{
return { "local-overlay" };
}

std::string getUri() override
{
return "local-overlay://";
Expand Down
6 changes: 3 additions & 3 deletions src/libstore/local-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ struct LocalStoreConfig : virtual LocalFSStoreConfig

const std::string name() override { return "Local Store"; }

static std::set<std::string> uriSchemes()
{ return {"local"}; }

std::string doc() override;
};

Expand Down Expand Up @@ -144,9 +147,6 @@ public:

~LocalStore();

static std::set<std::string> uriSchemes()
{ return {"local"}; }

/**
* Implementations of abstract store API methods.
*/
Expand Down
5 changes: 2 additions & 3 deletions src/libstore/s3-binary-cache-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,8 @@ struct S3BinaryCacheStoreConfig : virtual BinaryCacheStoreConfig

const std::string name() override { return "S3 Binary Cache Store"; }

static std::set<std::string> uriSchemes() { return {"s3"}; }

std::string doc() override
{
return
Expand Down Expand Up @@ -521,9 +523,6 @@ struct S3BinaryCacheStoreImpl : virtual S3BinaryCacheStoreConfig, public virtual
{
return std::nullopt;
}

static std::set<std::string> uriSchemes() { return {"s3"}; }

};

static RegisterStoreImplementation<S3BinaryCacheStoreImpl, S3BinaryCacheStoreConfig> regS3BinaryCacheStore;
Expand Down
10 changes: 5 additions & 5 deletions src/libstore/ssh-store.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ struct MountedSSHStoreConfig : virtual SSHStoreConfig, virtual LocalFSStoreConfi

const std::string name() override { return "Experimental SSH Store with filesystem mounted"; }

static std::set<std::string> uriSchemes()
{
return {"mounted-ssh-ng"};
}

std::string doc() override
{
return
Expand Down Expand Up @@ -163,11 +168,6 @@ class MountedSSHStore : public virtual MountedSSHStoreConfig, public virtual SSH
};
}

static std::set<std::string> uriSchemes()
{
return {"mounted-ssh-ng"};
}

std::string getUri() override
{
return *uriSchemes().begin() + "://" + host;
Expand Down
7 changes: 4 additions & 3 deletions src/libstore/uds-remote-store.hh
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ struct UDSRemoteStoreConfig : virtual LocalFSStoreConfig, virtual RemoteStoreCon
*/
std::optional<std::string> path;

static std::set<std::string> uriSchemes()
{ return {scheme}; }

protected:
static constexpr char const * scheme = "unix";

public:
static std::set<std::string> uriSchemes()
{ return {scheme}; }
};

class UDSRemoteStore : public virtual UDSRemoteStoreConfig
Expand Down

0 comments on commit 6768f4e

Please sign in to comment.