-
Notifications
You must be signed in to change notification settings - Fork 74
Added proxy setup service #696
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1d94bef
Added proxy setup service
teclator 4385a7b
Moved to lib, added test and documentation
teclator 94c5387
Apply suggestions from code review
teclator 8083217
Improved proxy URL documentation
teclator 999718d
Update doc/boot_arguments.md
teclator b1c76c5
Do not read current config
teclator 37196ad
Fix setup-service.sh
teclator 24c6619
Revert "Fix setup-service.sh"
teclator 7743dce
Fix setup-service
teclator 548dd65
Apply suggestions from code review
teclator d8bdfea
Added changelog
teclator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # EditorConfig is awesome: https://EditorConfig.org | ||
|
|
||
| # top-most EditorConfig file | ||
| root = true | ||
|
|
||
| # 2 space indentation | ||
| [{*.sh}] | ||
| indent_style = space | ||
| indent_size = 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| #!/usr/bin/env ruby | ||
| # frozen_string_literal: true | ||
|
|
||
| require "agama/proxy_setup" | ||
|
|
||
| Agama::ProxySetup.instance.run |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright (c) [2023] 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" | ||
| require "uri" | ||
|
|
||
| module Agama | ||
| # This class is responsible of parsing the proxy url from the kernel cmdline or configured | ||
| # through the dracut ask prompt configuration file (/etc/cmdline-menu.conf) during the boot | ||
| # proccess of the system writing the configuration to /etc/sysconfig/proxy | ||
| class ProxySetup | ||
| include Singleton | ||
| include Yast | ||
| include Logger | ||
|
|
||
| CMDLINE_PATH = "/proc/cmdline" | ||
| CMDLINE_MENU_CONF = "/etc/cmdline-menu.conf" | ||
|
|
||
| # @return [URI::Generic] | ||
| attr_accessor :proxy | ||
|
|
||
| # Constructor | ||
| def initialize | ||
| Yast.import "Proxy" | ||
| end | ||
|
|
||
| def run | ||
| read | ||
| write | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def read | ||
| self.proxy = proxy_from_cmdline || proxy_from_dracut | ||
| end | ||
|
|
||
| def proxy_from_dracut | ||
| return unless File.exist?(CMDLINE_MENU_CONF) | ||
|
|
||
| options = File.read(CMDLINE_MENU_CONF) | ||
| proxy_url_from(options) | ||
| end | ||
|
|
||
| def proxy_url_from(options) | ||
| proxy_url = options.split.find { |o| o.start_with?(/proxy/i) } | ||
| return unless proxy_url | ||
|
|
||
| URI(proxy_url.downcase.gsub("proxy=", "")) | ||
| end | ||
|
|
||
| def proxy_from_cmdline | ||
| return unless File.exist?(CMDLINE_PATH) | ||
|
|
||
| options = File.read(CMDLINE_PATH) | ||
| proxy_url_from(options) | ||
| end | ||
|
|
||
| def proxy_import_settings | ||
| proto = proxy.scheme | ||
| # save user name and password separately | ||
| settings = { | ||
| "proxy_user" => proxy.user, | ||
| "proxy_password" => proxy.password, | ||
| "enabled" => true | ||
| } | ||
| proxy.user = nil | ||
| proxy.password = nil | ||
|
|
||
| settings["#{proto}_proxy"] = proxy.to_s | ||
| # Use the proxy also for https and ftp | ||
| if proto == "http" | ||
| settings["https_proxy"] = proxy.to_s | ||
| settings["ftp_proxy"] = proxy.to_s | ||
| end | ||
| settings | ||
| end | ||
|
|
||
| def write | ||
| return unless proxy | ||
|
|
||
| settings = proxy_import_settings | ||
| Proxy.Import(settings) | ||
|
|
||
| log.info "Writing proxy settings: #{proxy.scheme}_proxy = '#{proxy}'" | ||
| log.debug "Writing proxy settings: #{settings}" | ||
|
|
||
| Proxy.Write | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| [Unit] | ||
| Description=Configure wide proxy setup for agama and systemd services | ||
| Before=agama.service | ||
| Wants=local-fs.target | ||
|
|
||
| [Service] | ||
| Type=oneshot | ||
| ExecStart=/usr/bin/agama-proxy-setup | ||
|
|
||
| [Install] | ||
| WantedBy=default.target | ||
|
|
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright (c) [2023] 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_relative "../test_helper" | ||
| require "agama/proxy_setup" | ||
|
|
||
| describe Agama::ProxySetup do | ||
| subject(:proxy) { described_class.instance } | ||
| before do | ||
| proxy.proxy = nil | ||
| end | ||
|
|
||
| describe "#run" do | ||
| let(:file_content) { "proxy=#{proxy_url}" } | ||
| let(:proxy_url) { "https://yast:1234@192.168.122.1:3128" } | ||
|
|
||
| before do | ||
| allow(Yast::Proxy).to receive(:Read) | ||
| allow(Yast::Proxy).to receive(:Write) | ||
| end | ||
|
|
||
| context "when some configuration is given through the kernel command line" do | ||
| before do | ||
| allow(proxy).to receive(:proxy_from_cmdline).and_return(URI(proxy_url)) | ||
| allow(proxy).to receive(:write) | ||
| end | ||
|
|
||
| it "reads the given proxy configuraion" do | ||
| expect(proxy.proxy).to be_nil | ||
| proxy.run | ||
| expect(proxy.proxy).to be_a(URI) | ||
| end | ||
|
|
||
| it "writes the proxy configuration to /etc/sysconfig/proxy" do | ||
| allow(proxy).to receive(:write).and_call_original | ||
| expect(Yast::Proxy).to receive(:Write) | ||
| proxy.run | ||
| config = Yast::Proxy.Export | ||
| expect(config).to include("https_proxy" => "https://192.168.122.1:3128", | ||
| "proxy_password" => "1234", | ||
| "proxy_user" => "yast", | ||
| "enabled" => true) | ||
| end | ||
|
|
||
| context "when an http url is given" do | ||
| let(:proxy_url) { "http://192.168.122.1:3128" } | ||
|
|
||
| it "sets also the https and ftp with the same url" do | ||
| allow(proxy).to receive(:write).and_call_original | ||
| proxy.run | ||
| config = Yast::Proxy.Export | ||
| expect(config).to include("http_proxy" => "http://192.168.122.1:3128", | ||
| "https_proxy" => "http://192.168.122.1:3128", | ||
| "ftp_proxy" => "http://192.168.122.1:3128", | ||
| "enabled" => true) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.