Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion service/lib/agama/autoyast/converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
95 changes: 95 additions & 0 deletions service/lib/agama/autoyast/files_reader.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion service/share/autoyast-compat.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
Loading