#include "step/configuration/step_parse_rpk_manifest.h"
#include <pkgmgr-info.h>
+#include <pkgmgr_parser.h>
-#include <rpk_manifest_handlers/package_handler.h>
#include <rpk_manifest_handlers/allowed_package_handler.h>
+#include <rpk_manifest_handlers/author_handler.h>
+#include <rpk_manifest_handlers/description_handler.h>
+#include <rpk_manifest_handlers/dependencies_handler.h>
+#include <rpk_manifest_handlers/package_handler.h>
+
#include <common/installer_context.h>
#include <common/step/step.h>
const char kAllowedPackageKey[] = "manifest.allowed-package";
+const char kAuthorKey[] = "manifest.author";
+
+const char kDescriptionKey[] = "manifest.description";
+
+const char kDependenciesKey[] = "manifest.dependencies";
} // namespace
<< parser_->GetErrorMessage();
return Step::Status::PARSE_ERROR;
}
+
/*
// TODO: add this code when recovery logic has added
// write pkgid for recovery file
context_->recovery_info.get().recovery_file->WriteAndCommitFileContent();
}
*/
+
LOG(INFO) << "Parsed package id: " << info->package();
switch (store_location_) {
if (!FillAllowedPackageInfo(manifest))
return false;
- // author
- if (!FillAuthor(manifest))
+ if (!FillAuthorInfo(manifest))
return false;
- // description
- if (!FillDescription(manifest))
+ if (!FillDescriptionInfo(manifest))
return false;
- // dependencies
- if (!FillDependencies(manifest))
+ if (!FillDependencyInfo(manifest))
return false;
return true;
auto& allowed_pkg_list = allowed_pkg_info_list->allowed_packages();
if (allowed_pkg_list.size() == 0)
return true;
+
/*
// TODO: this should be activated after manifest has variables for these
for (auto& allowed_pkg : allowed_pkg_list) {
return true;
}
-bool StepParseRpkManifest::FillAuthor(manifest_x* manifest) {
+bool StepParseRpkManifest::FillAuthorInfo(manifest_x* manifest) {
+ std::shared_ptr<const rpk::parse::AuthorInfo> author_info =
+ std::static_pointer_cast<const rpk::parse::AuthorInfo>(
+ parser_->GetManifestData(kAuthorKey));
+ if (!author_info)
+ return true;
+
+ author_x* author = reinterpret_cast<author_x*>(calloc(1, sizeof(author_x)));
+ if (!author) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
+ author->text = strdup(author_info->name().c_str());
+ author->email = strdup(author_info->email().c_str());
+ author->href = strdup(author_info->href().c_str());
+ author->lang = strdup(DEFAULT_LOCALE);
+ manifest->author = g_list_append(manifest->author, author);
+
return true;
}
-bool StepParseRpkManifest::FillDescription(manifest_x* manifest) {
+bool StepParseRpkManifest::FillDescriptionInfo(manifest_x* manifest) {
+ std::shared_ptr<const rpk::parse::DescriptionInfoList> description_info =
+ std::static_pointer_cast<const rpk::parse::DescriptionInfoList>(
+ parser_->GetManifestData(kDescriptionKey));
+ if (!description_info)
+ return true;
+
+ for (auto& desc : description_info->descriptions) {
+ description_x* description = reinterpret_cast<description_x*>
+ (calloc(1, sizeof(description_x)));
+ if (!description) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
+ description->text = strdup(desc.description().c_str());
+ description->lang = !desc.xml_lang().empty() ?
+ strdup(desc.xml_lang().c_str()) : strdup(DEFAULT_LOCALE);
+ manifest->description = g_list_append(manifest->description, description);
+ }
+
return true;
}
- // dependencies
-bool StepParseRpkManifest::FillDependencies(manifest_x* manifest) {
+bool StepParseRpkManifest::FillDependencyInfo(manifest_x* manifest) {
+ std::shared_ptr<const rpk::parse::DependenciesInfo> dependencies_info =
+ std::static_pointer_cast<const rpk::parse::DependenciesInfo>(
+ parser_->GetManifestData(kDependenciesKey));
+ if (!dependencies_info)
+ return true;
+
+ for (const auto& dependency : dependencies_info->dependencies()) {
+ dependency_x* dep =
+ static_cast<dependency_x*>(calloc(1, sizeof(dependency_x)));
+ if (!dep) {
+ LOG(ERROR) << "Out of memory";
+ return false;
+ }
+ dep->depends_on = strdup(dependency.pkgid().c_str());
+ dep->type = strdup(dependency.type().c_str());
+ if (!dependency.required_version().empty())
+ dep->required_version = strdup(dependency.required_version().c_str());
+ manifest->dependencies = g_list_append(manifest->dependencies, dep);
+ }
+
return true;
}