Skip to content

Commit

Permalink
fix(service): run scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
imobachgs committed Oct 11, 2024
1 parent eb74d4d commit 7ca6ff4
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 1 deletion.
28 changes: 28 additions & 0 deletions service/lib/agama/http.rb
Original file line number Diff line number Diff line change
@@ -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"
52 changes: 52 additions & 0 deletions service/lib/agama/http/scripts.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 7 additions & 1 deletion service/lib/agama/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
require "agama/dbus/clients/software"
require "agama/dbus/clients/storage"
require "agama/helpers"
require "agama/http"

Yast.import "Stage"

Expand Down Expand Up @@ -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 }

Expand Down Expand Up @@ -168,6 +170,10 @@ def software
end
end

def scripts
@scripts ||= HTTP::Scripts.new
end

# ProxySetup instance
#
# @return [ProxySetup]
Expand Down

0 comments on commit 7ca6ff4

Please sign in to comment.