diff options
Diffstat (limited to 'app/services/packages/rpm')
5 files changed, 122 insertions, 0 deletions
diff --git a/app/services/packages/rpm/repository_metadata/base_builder.rb b/app/services/packages/rpm/repository_metadata/base_builder.rb new file mode 100644 index 00000000000..9d76336d764 --- /dev/null +++ b/app/services/packages/rpm/repository_metadata/base_builder.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true +module Packages + module Rpm + module RepositoryMetadata + class BaseBuilder + def execute + build_empty_structure + end + + private + + def build_empty_structure + Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| + xml.public_send(self.class::ROOT_TAG, self.class::ROOT_ATTRIBUTES) # rubocop:disable GitlabSecurity/PublicSend + end.to_xml + end + end + end + end +end diff --git a/app/services/packages/rpm/repository_metadata/build_filelist_xml.rb b/app/services/packages/rpm/repository_metadata/build_filelist_xml.rb new file mode 100644 index 00000000000..01fb36f4b91 --- /dev/null +++ b/app/services/packages/rpm/repository_metadata/build_filelist_xml.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +module Packages + module Rpm + module RepositoryMetadata + class BuildFilelistXml < ::Packages::Rpm::RepositoryMetadata::BaseBuilder + ROOT_TAG = 'filelists' + ROOT_ATTRIBUTES = { + xmlns: 'http://linux.duke.edu/metadata/filelists', + packages: '0' + }.freeze + end + end + end +end diff --git a/app/services/packages/rpm/repository_metadata/build_other_xml.rb b/app/services/packages/rpm/repository_metadata/build_other_xml.rb new file mode 100644 index 00000000000..4bf61c901a3 --- /dev/null +++ b/app/services/packages/rpm/repository_metadata/build_other_xml.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +module Packages + module Rpm + module RepositoryMetadata + class BuildOtherXml < ::Packages::Rpm::RepositoryMetadata::BaseBuilder + ROOT_TAG = 'otherdata' + ROOT_ATTRIBUTES = { + xmlns: 'http://linux.duke.edu/metadata/other', + packages: '0' + }.freeze + end + end + end +end diff --git a/app/services/packages/rpm/repository_metadata/build_primary_xml.rb b/app/services/packages/rpm/repository_metadata/build_primary_xml.rb new file mode 100644 index 00000000000..affb41677c2 --- /dev/null +++ b/app/services/packages/rpm/repository_metadata/build_primary_xml.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true +module Packages + module Rpm + module RepositoryMetadata + class BuildPrimaryXml < ::Packages::Rpm::RepositoryMetadata::BaseBuilder + ROOT_TAG = 'metadata' + ROOT_ATTRIBUTES = { + xmlns: 'http://linux.duke.edu/metadata/common', + 'xmlns:rpm': 'http://linux.duke.edu/metadata/rpm', + packages: '0' + }.freeze + end + end + end +end diff --git a/app/services/packages/rpm/repository_metadata/build_repomd_xml.rb b/app/services/packages/rpm/repository_metadata/build_repomd_xml.rb new file mode 100644 index 00000000000..c6cfd77815d --- /dev/null +++ b/app/services/packages/rpm/repository_metadata/build_repomd_xml.rb @@ -0,0 +1,59 @@ +# frozen_string_literal: true +module Packages + module Rpm + module RepositoryMetadata + class BuildRepomdXml + attr_reader :data + + ROOT_ATTRIBUTES = { + xmlns: 'http://linux.duke.edu/metadata/repo', + 'xmlns:rpm': 'http://linux.duke.edu/metadata/rpm' + }.freeze + + # Expected `data` structure + # + # data = { + # filelists: { + # checksum: { type: "sha256", value: "123" }, + # location: { href: "repodata/123-filelists.xml.gz" }, + # ... + # }, + # ... + # } + def initialize(data) + @data = data + end + + def execute + build_repomd + end + + private + + def build_repomd + Nokogiri::XML::Builder.new(encoding: 'UTF-8') do |xml| + xml.repomd(ROOT_ATTRIBUTES) do + xml.revision Time.now.to_i + build_data_info(xml) + end + end.to_xml + end + + def build_data_info(xml) + data.each do |filename, info| + xml.data(type: filename) do + build_file_info(info, xml) + end + end + end + + def build_file_info(info, xml) + info.each do |key, attributes| + value = attributes.delete(:value) + xml.public_send(key, value, attributes) # rubocop:disable GitlabSecurity/PublicSend + end + end + end + end + end +end |