-
Notifications
You must be signed in to change notification settings - Fork 26
Use more native methods of SmartProxy for validation #57
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
Open
ekohl
wants to merge
6
commits into
theforeman:master
Choose a base branch
from
ekohl:more-native-methods
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
91bafe7
Use load_test_settings in test helper
ekohl c4b8160
Add integration test
ekohl 88b0fc3
Use the rackup_path helper
ekohl b3d0c0d
Return a 404 if the public key file doesn't exist
ekohl a4e2ae3
Use more native methods of SmartProxy for validation
ekohl 47f71ca
Make dynflow an explicit dependency
ekohl 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
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
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,42 @@ | ||
| module Proxy | ||
| module RemoteExecution | ||
| module Ssh | ||
| module Validators | ||
| class SshLogLevel < ::Proxy::PluginValidators::Base | ||
| def validate!(settings) | ||
| setting_value = settings[@setting_name].to_s | ||
|
|
||
| unless @params.include?(setting_value) | ||
| raise ::Proxy::Error::ConfigurationError, "Parameter '#{@setting_name}' must be one of #{@params.join(', ')}" | ||
| end | ||
|
|
||
| current = ::Proxy::SETTINGS.log_level.to_s.downcase | ||
|
|
||
| # regular log levels correspond to upcased ssh logger levels | ||
| ssh, regular = [setting_value, current].map do |wanted| | ||
| @params.each_with_index.find { |value, _index| value == wanted }.last | ||
| end | ||
|
|
||
| if ssh < regular | ||
| raise ::Proxy::Error::ConfigurationError, "Parameter '#{@setting_name}' cannot be more verbose than regular log level (#{current})" | ||
| end | ||
|
|
||
| true | ||
| end | ||
| end | ||
|
|
||
| class RexSshMode < ::Proxy::PluginValidators::Base | ||
| def validate!(settings) | ||
| setting_value = settings[@setting_name] | ||
|
|
||
| unless @params.include?(setting_value) | ||
| raise ::Proxy::Error::ConfigurationError, "Parameter '#{@setting_name}' must be one of #{@params.join(', ')}" | ||
| end | ||
|
|
||
| true | ||
| end | ||
| 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
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,104 @@ | ||
| require 'test_helper' | ||
| require 'json' | ||
| require 'root/root' | ||
| require 'root/root_v2_api' | ||
| require 'smart_proxy_remote_execution_ssh/plugin' | ||
|
|
||
| class SmartProxyRemoteExecutionSshApiFeaturesTest < MiniTest::Test | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There is currently no test for the legacy async-ssh mode. Would probably be useful. |
||
| include Rack::Test::Methods | ||
|
|
||
| def app | ||
| Proxy::PluginInitializer.new(Proxy::Plugins.instance).initialize_plugins | ||
| Proxy::RootV2Api.new | ||
| end | ||
|
|
||
| def test_features_for_default_mode_without_dynflow | ||
| Proxy::LegacyModuleLoader.any_instance.expects(:load_configuration_file).with('dynflow.yml').returns(enabled: false) | ||
| Proxy::DefaultModuleLoader.any_instance.expects(:load_configuration_file).with('remote_execution_ssh.yml').returns( | ||
| enabled: true, | ||
| ssh_identity_key_file: FAKE_PRIVATE_KEY_FILE, | ||
| mqtt_broker: 'broker.example.com', | ||
| mqtt_port: 1883, | ||
| ) | ||
|
|
||
| get '/features' | ||
|
|
||
| response = JSON.parse(last_response.body) | ||
|
|
||
| mod = response['ssh'] | ||
| refute_nil(mod) | ||
| assert_equal('failed', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:ssh]) | ||
| assert_equal("Disabling all modules in the group ['ssh'] due to a failure in one of them: 'dynflow' required by 'ssh' could not be found.", | ||
| Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:ssh]) | ||
| end | ||
|
|
||
| def test_features_for_default_mode_with_dynflow | ||
| Proxy::LegacyModuleLoader.any_instance.expects(:load_configuration_file).with('dynflow.yml').returns(enabled: true) | ||
| Proxy::DefaultModuleLoader.any_instance.expects(:load_configuration_file).with('remote_execution_ssh.yml').returns( | ||
| enabled: true, | ||
| ssh_identity_key_file: FAKE_PRIVATE_KEY_FILE, | ||
| ) | ||
|
|
||
| get '/features' | ||
|
|
||
| response = JSON.parse(last_response.body) | ||
|
|
||
| mod = response['dynflow'] | ||
| refute_nil(mod) | ||
| assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:dynflow]) | ||
|
|
||
| mod = response['ssh'] | ||
| refute_nil(mod) | ||
| assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:ssh]) | ||
| assert_equal([], mod['capabilities'], 'Has no capabilities') | ||
| assert_equal({}, mod['settings'], 'Has no settings') | ||
| end | ||
|
|
||
| def test_features_for_pull_mqtt_mode_without_required_options | ||
| Proxy::LegacyModuleLoader.any_instance.expects(:load_configuration_file).with('dynflow.yml').returns(enabled: true) | ||
| Proxy::DefaultModuleLoader.any_instance.expects(:load_configuration_file).with('remote_execution_ssh.yml').returns( | ||
| enabled: true, | ||
| ssh_identity_key_file: FAKE_PRIVATE_KEY_FILE, | ||
| mode: 'pull-mqtt', | ||
| ) | ||
|
|
||
| get '/features' | ||
|
|
||
| response = JSON.parse(last_response.body) | ||
|
|
||
| mod = response['dynflow'] | ||
| refute_nil(mod) | ||
| assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:dynflow]) | ||
|
|
||
| mod = response['ssh'] | ||
| refute_nil(mod) | ||
| assert_equal('failed', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:ssh]) | ||
| assert_equal("Disabling all modules in the group ['ssh'] due to a failure in one of them: Parameter 'mqtt_broker' is expected to have a non-empty value", | ||
| Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:ssh]) | ||
| end | ||
|
|
||
| def test_features_with_dynflow_and_required_options | ||
| Proxy::LegacyModuleLoader.any_instance.expects(:load_configuration_file).with('dynflow.yml').returns(enabled: true) | ||
| Proxy::DefaultModuleLoader.any_instance.expects(:load_configuration_file).with('remote_execution_ssh.yml').returns( | ||
| enabled: true, | ||
| ssh_identity_key_file: FAKE_PRIVATE_KEY_FILE, | ||
| mode: 'pull-mqtt', | ||
| mqtt_broker: 'broker.example.com', | ||
| mqtt_port: 1883, | ||
| ) | ||
|
|
||
| get '/features' | ||
|
|
||
| response = JSON.parse(last_response.body) | ||
|
|
||
| mod = response['dynflow'] | ||
| refute_nil(mod) | ||
| assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:dynflow]) | ||
|
|
||
| mod = response['ssh'] | ||
| refute_nil(mod) | ||
| assert_equal('running', mod['state'], Proxy::LogBuffer::Buffer.instance.info[:failed_modules][:ssh]) | ||
| assert_equal([], mod['capabilities'], 'Has no capabilities') | ||
| assert_equal({}, mod['settings'], 'Has no settings') | ||
| 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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I reading it right that this doesn't expand the path?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it doesn't. Perhaps it needs to be in
load_programmable_settingsinstead oflib/smart_proxy_remote_execution_ssh.rb?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, does this plugin still use the SSH keys if MQTT is used? I think so due to cockpit, but I'm starting to wonder if this shouldn't be named
smart_proxy_remote_executioninstead of..._ssh.Does it make sense to expose the mode as a setting so you can externally read that out? Or as a capability?