From 7ca6ff4ae0f553955703f20d4feb7c70eeadd5c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Imobach=20Gonz=C3=A1lez=20Sosa?= Date: Fri, 11 Oct 2024 15:55:24 +0100 Subject: [PATCH] fix(service): run scripts --- service/lib/agama/http.rb | 28 +++++++++++++++++ service/lib/agama/http/scripts.rb | 52 +++++++++++++++++++++++++++++++ service/lib/agama/manager.rb | 8 ++++- 3 files changed, 87 insertions(+), 1 deletion(-) create mode 100644 service/lib/agama/http.rb create mode 100644 service/lib/agama/http/scripts.rb diff --git a/service/lib/agama/http.rb b/service/lib/agama/http.rb new file mode 100644 index 000000000..4bfd1ff88 --- /dev/null +++ b/service/lib/agama/http.rb @@ -0,0 +1,28 @@ +# 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. + +module Agama + # Namespace for HTTP clients + module HTTP + end +end + +require "agama/http/scripts" diff --git a/service/lib/agama/http/scripts.rb b/service/lib/agama/http/scripts.rb new file mode 100644 index 000000000..71ba60770 --- /dev/null +++ b/service/lib/agama/http/scripts.rb @@ -0,0 +1,52 @@ +# 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 "uri" + +module Agama + module HTTP + # FIXME: to be moved to the manager + class ScriptsClient + def initialize + @base_url = "http://localhost/api" + end + + def run + Net::HTTP.post(uri("/scripts/run")) + end + + private + + def uri(path) + URI.join(@base_url, path) + end + + def headers + @headers = { + Accept: "application/json", + Authorization: "Bearer #{auth_token}" + } + end + + def auth_token + File.read("/run/agama/token") + end + end + end +end diff --git a/service/lib/agama/manager.rb b/service/lib/agama/manager.rb index 51067c0e1..426ef247c 100644 --- a/service/lib/agama/manager.rb +++ b/service/lib/agama/manager.rb @@ -32,6 +32,7 @@ require "agama/dbus/clients/software" require "agama/dbus/clients/storage" require "agama/helpers" +require "agama/http" Yast.import "Stage" @@ -102,8 +103,9 @@ def config_phase installation_phase.config start_progress_with_descriptions( - _("Analyze disks"), _("Configure software") + _("Running user defined scripts"), _("Analyze disks"), _("Configure software") ) + scripts.run progress.step { storage.probe } progress.step { software.probe } @@ -168,6 +170,10 @@ def software end end + def scripts + @scripts ||= HTTP::Scripts.new + end + # ProxySetup instance # # @return [ProxySetup]