Update: align component feed identities
This commit is contained in:
3 files changed
+100
-11
No files matched your search
+74
-7
@@ -101,6 +101,21 @@ namespace Void::Update
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] bool
|
||||
valid_prefixed_hash(std::string_view value, std::string_view prefix,
|
||||
std::size_t hexadecimalSize) noexcept
|
||||
{
|
||||
if (!value.starts_with(prefix)) {
|
||||
return false;
|
||||
}
|
||||
const auto hexadecimal = value.substr(prefix.size());
|
||||
return hexadecimal.size() == hexadecimalSize &&
|
||||
std::ranges::all_of(hexadecimal, [](const char character) {
|
||||
return (character >= '0' && character <= '9') ||
|
||||
(character >= 'a' && character <= 'f');
|
||||
});
|
||||
}
|
||||
|
||||
[[nodiscard]] bool valid_hex(std::string_view value,
|
||||
std::size_t size) noexcept
|
||||
{
|
||||
@@ -395,6 +410,20 @@ namespace Void::Update
|
||||
return std::optional<std::string>{value->as_string()};
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::Result::Result<std::optional<std::string>>
|
||||
optional_string(const Json::Value& object, std::string_view name)
|
||||
{
|
||||
const auto* value = object.find(name);
|
||||
if (value == nullptr || value->is_null()) {
|
||||
return std::optional<std::string>{};
|
||||
}
|
||||
if (!value->is_string()) {
|
||||
return Void::Result::fail(std::format(
|
||||
"Component feed: {} must be null or a string", name));
|
||||
}
|
||||
return std::optional<std::string>{value->as_string()};
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::Result::Result<
|
||||
std::map<std::string, Semver::VersionRange>>
|
||||
parse_dependencies(const Json::Value& object)
|
||||
@@ -421,6 +450,27 @@ namespace Void::Update
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::Result::Result<std::map<std::string, std::string>>
|
||||
parse_dependency_constraints(const Json::Value& object)
|
||||
{
|
||||
const auto* dependencies = object.find("dependencies");
|
||||
if (dependencies == nullptr || !dependencies->is_object()) {
|
||||
return Void::Result::fail(
|
||||
"Component feed: dependencies must be an object");
|
||||
}
|
||||
std::map<std::string, std::string> result;
|
||||
for (const auto& [component, value] : dependencies->as_object()) {
|
||||
if (!valid_token(component, 256) || !value.is_string() ||
|
||||
value.as_string().empty() ||
|
||||
value.as_string().size() > 512) {
|
||||
return Void::Result::fail(
|
||||
"Component feed: dependency contains an unsafe field");
|
||||
}
|
||||
result.emplace(component, value.as_string());
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
[[nodiscard]] Void::Result::Result<ComponentDocumentHeader>
|
||||
parse_component_header(const Json::Value& document,
|
||||
std::string_view expectedDocument,
|
||||
@@ -490,12 +540,14 @@ namespace Void::Update
|
||||
auto sequence = unsigned_number<std::uint64_t>(value, "sequence");
|
||||
auto latestUrl = string_member(value, "latestUrl");
|
||||
auto artifactSha = string_member(value, "artifactSha256");
|
||||
auto dependencyConstraints = parse_dependency_constraints(value);
|
||||
auto dependencies = parse_dependencies(value);
|
||||
if (!componentId || !pluginId || !kind || !versionText ||
|
||||
!activation || !sequence || !latestUrl || !artifactSha ||
|
||||
!dependencies || !valid_token(*componentId, 256) ||
|
||||
!valid_token(*kind, 128) || !valid_token(*activation, 128) ||
|
||||
!bounded_url(*latestUrl) || !valid_sha256(*artifactSha)) {
|
||||
!dependencyConstraints || !dependencies ||
|
||||
!valid_token(*componentId, 256) || !valid_token(*kind, 128) ||
|
||||
!valid_token(*activation, 128) || !bounded_url(*latestUrl) ||
|
||||
!valid_sha256(*artifactSha)) {
|
||||
return Void::Result::fail(
|
||||
"Component feed: catalog entry contains an unsafe field");
|
||||
}
|
||||
@@ -510,6 +562,7 @@ namespace Void::Update
|
||||
.kind = std::move(*kind),
|
||||
.componentVersion = std::move(*version),
|
||||
.activation = std::move(*activation),
|
||||
.dependencyConstraints = std::move(*dependencyConstraints),
|
||||
.dependencies = std::move(*dependencies),
|
||||
.sequence = *sequence,
|
||||
.latestUrl = std::move(*latestUrl),
|
||||
@@ -690,19 +743,28 @@ namespace Void::Update
|
||||
auto componentVersion = string_member(*document, "componentVersion");
|
||||
auto sourceSha = string_member(*document, "sourceSha");
|
||||
auto sourceTreeHash = string_member(*document, "sourceTreeHash");
|
||||
auto abiHash = string_member(*document, "abiHash");
|
||||
auto abiHash = optional_string(*document, "abiHash");
|
||||
auto artifactIdentity = string_member(*document, "artifactIdentity");
|
||||
auto activation = string_member(*document, "activation");
|
||||
auto platform = string_member(*document, "platform");
|
||||
auto architecture = string_member(*document, "architecture");
|
||||
auto toolchainContract = string_member(*document, "toolchainContract");
|
||||
auto dependencyConstraints = parse_dependency_constraints(*document);
|
||||
auto dependencies = parse_dependencies(*document);
|
||||
const auto* artifactValue = document->find("artifact");
|
||||
if (!header || !componentId || !pluginId || !kind ||
|
||||
!componentVersion || !sourceSha || !sourceTreeHash || !abiHash ||
|
||||
!artifactIdentity || !activation || !dependencies ||
|
||||
!artifactIdentity || !activation || !platform || !architecture ||
|
||||
!toolchainContract || !dependencyConstraints || !dependencies ||
|
||||
artifactValue == nullptr || !artifactValue->is_object() ||
|
||||
!valid_token(*componentId, 256) || !valid_token(*kind, 128) ||
|
||||
!valid_token(*artifactIdentity, 256) ||
|
||||
!valid_token(*activation, 128) || !valid_hex(*sourceSha, 40) ||
|
||||
!valid_sha256(*sourceTreeHash) || !valid_sha256(*abiHash)) {
|
||||
!valid_token(*activation, 128) || !valid_token(*platform, 64) ||
|
||||
!valid_token(*architecture, 64) ||
|
||||
!valid_token(*toolchainContract, 256) ||
|
||||
!valid_hex(*sourceSha, 40) ||
|
||||
!valid_prefixed_hash(*sourceTreeHash, "git-sha1:", 40) ||
|
||||
(*abiHash && !valid_prefixed_hash(**abiHash, "sha256:", 64))) {
|
||||
return Void::Result::fail(
|
||||
"Component feed: release contains an unsafe field");
|
||||
}
|
||||
@@ -737,6 +799,10 @@ namespace Void::Update
|
||||
.abiHash = std::move(*abiHash),
|
||||
.artifactIdentity = std::move(*artifactIdentity),
|
||||
.activation = std::move(*activation),
|
||||
.platform = std::move(*platform),
|
||||
.architecture = std::move(*architecture),
|
||||
.toolchainContract = std::move(*toolchainContract),
|
||||
.dependencyConstraints = std::move(*dependencyConstraints),
|
||||
.dependencies = std::move(*dependencies),
|
||||
.artifact = {.name = std::move(*artifactName),
|
||||
.url = std::move(*artifactUrl),
|
||||
@@ -769,6 +835,7 @@ namespace Void::Update
|
||||
value.artifact.sha256 != entry.artifactSha256 ||
|
||||
value.activation != entry.activation ||
|
||||
value.pluginId != entry.pluginId || value.kind != entry.kind ||
|
||||
value.dependencyConstraints != entry.dependencyConstraints ||
|
||||
value.dependencies.size() != entry.dependencies.size()) {
|
||||
return Void::Result::fail(std::format(
|
||||
"Component set: release {} does not match the catalog",
|
||||
|
||||
Reference in new issue
Block a user