diff --git a/service/lib/agama/autoyast/converter.rb b/service/lib/agama/autoyast/converter.rb index 1ceddcb269..171b8ba42b 100755 --- a/service/lib/agama/autoyast/converter.rb +++ b/service/lib/agama/autoyast/converter.rb @@ -52,7 +52,7 @@ class Converter # Sections which have a corresponding reader. The reader is expected to be # named in Pascal case and adding "Reader" as suffix (e.g., "L10nReader"). SECTIONS = [ - "localization", "product", "root", "scripts", "software", "storage", "user" + "files", "localization", "product", "root", "scripts", "software", "storage", "user" ].freeze # Builds the Agama profile diff --git a/service/lib/agama/autoyast/files_reader.rb b/service/lib/agama/autoyast/files_reader.rb new file mode 100755 index 0000000000..b760dc64bc --- /dev/null +++ b/service/lib/agama/autoyast/files_reader.rb @@ -0,0 +1,95 @@ +# frozen_string_literal: true + +# Copyright (c) [2024] SUSE LLC +# +# All Rights Reserved. +# +# This program is free software; you can redistribute it and/or modify it +# under the terms of version 2 of the GNU General Public License as published +# by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. +# +# You should have received a copy of the GNU General Public License along +# with this program; if not, contact SUSE LLC. +# +# To contact SUSE LLC about this file by physical or electronic mail, you may +# find current contact information at www.suse.com. + +require "yast" + +# :nodoc: +module Agama + module AutoYaST + # Builds the Agama "files" section from an AutoYaST profile. + class FilesReader + # @param profile [ProfileHash] AutoYaST profile + def initialize(profile) + @profile = profile + end + + # Returns a hash corresponding to Agama "files" section. + # + # If there is no files-related information, it returns an empty hash. + # + # @return [Hash] Agama "files" section + def read + return {} if profile["files"].nil? + + # files section contains list of file nodes. + # supported file sub-elements: + # - file_location (a file source path) (-> source) + # - file_contents (a file content) (-> source) + # - file_path (this one seems to be the only mandatory, + # a file destination or directory to be created if ends with '/') + # (-> destination) + # - file_owner (-> owner) + # - file_permissions (permissions) + # + # unsupported for now: + # - file_script + files = profile.fetch_as_array("files") + + files_json = files.reduce([]) do |res, f| + file = file_source(f) + file = file.merge(file_owner(f)) + + file["destination"] = f["file_path"] if f["file_path"] + file["permissions"] = f["file_permissions"] if f["file_permissions"] + + res.push(file) + end + + { "files" => files_json } + end + + private + + attr_reader :profile + + def file_source(file) + return {} if file.nil? || file.empty? + + if file.key?("file_location") + { "url": file["file_location"] } + elsif file.key?("file_contents") + { "content": file["file_contents"] } + else + {} + end + end + + def file_owner(file) + return {} if file.nil? || file.empty? || !file["file_owner"] + + { + "user": file["file_owner"].split(/\./).first, + "group": file["file_owner"].split(/\./).last, + } + end + end + end +end diff --git a/service/share/autoyast-compat.json b/service/share/autoyast-compat.json index 0e8ef83e7d..148945f1e6 100644 --- a/service/share/autoyast-compat.json +++ b/service/share/autoyast-compat.json @@ -7,7 +7,7 @@ { "key": "dhcp-server", "support": "no" }, { "key": "dns-server", "support": "no" }, { "key": "fcoe-client", "support": "no" }, - { "key": "files", "support": "planned" }, + { "key": "files", "support": "yes" }, { "key": "firstboot", "support": "no" }, { "key": "ftp-server", "support": "no" }, { "key": "general", "support": "no" },