-
Notifications
You must be signed in to change notification settings - Fork 32
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
Add Global params for host obfuscation and migrate off settings #921
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
class ConvertObfuscationSettingsToParams < ActiveRecord::Migration[6.1] | ||
def change | ||
# Create the common parameters if they don't exist and set the default values to false | ||
CommonParameter.find_or_create_by!(name: 'obfuscate_inventory_hostnames', value: false) | ||
CommonParameter.find_or_create_by!(name: 'obfuscate_inventory_ips', value: false) | ||
|
||
# Copy the settings to the common parameters and remove the settings from the database | ||
# rubocop:disable Style/GuardClause | ||
if Setting.find_by(name: 'obfuscate_inventory_hostnames')&.value | ||
hostname_setting = CommonParameter.find_by(name: 'obfuscate_inventory_hostnames') | ||
hostname_setting.update!(value: Setting.find_by(name: 'obfuscate_inventory_hostnames')&.value) | ||
Setting.find_by(name: 'obfuscate_inventory_hostnames').destroy_all | ||
end | ||
|
||
if Setting.find_by(name: 'obfuscate_inventory_ips')&.value | ||
ip_setting = CommonParameter.find_by(name: 'obfuscate_inventory_ips') | ||
ip_setting.update!(value: Setting.find_by(name: 'obfuscate_inventory_ips')&.value) | ||
Setting.find_by(name: 'obfuscate_inventory_ips').destroy_all | ||
end | ||
# rubocop:enable Style/GuardClause | ||
end | ||
end |
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -61,7 +61,7 @@ def obfuscate_hostname?(host) | |||
insights_client_setting = ActiveModel::Type::Boolean.new.cast(insights_client_setting) | ||||
return insights_client_setting unless insights_client_setting.nil? | ||||
|
||||
Setting[:obfuscate_inventory_hostnames] | ||||
CommonParameter.find_by(name: 'obfuscate_inventory_hostnames')&.value | ||||
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. You should look for a value on the host, not just the common parameter, similar to foreman_rh_cloud/app/controllers/insights_cloud/api/machine_telemetries_controller.rb Line 87 in 48f9d74
|
||||
end | ||||
|
||||
def fqdn(host) | ||||
|
@@ -79,7 +79,7 @@ def obfuscate_ips?(host) | |||
insights_client_setting = ActiveModel::Type::Boolean.new.cast(insights_client_setting) | ||||
return insights_client_setting unless insights_client_setting.nil? | ||||
|
||||
Setting[:obfuscate_inventory_ips] | ||||
CommonParameter.find_by(name: 'obfuscate_inventory_ips')&.value | ||||
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. If it's a parameter, you have to look up the value on the host object itself: foreman_rh_cloud/app/controllers/insights_cloud/api/machine_telemetries_controller.rb Line 87 in 48f9d74
|
||||
end | ||||
|
||||
def host_ips(host) | ||||
|
@@ -114,7 +114,7 @@ def hostname_match | |||
foreman_hostname = ForemanRhCloud.foreman_host&.name | ||||
if bash_hostname == foreman_hostname | ||||
fqdn(ForemanRhCloud.foreman_host) | ||||
elsif Setting[:obfuscate_inventory_hostnames] | ||||
elsif CommonParameter.find_by(name: 'obfuscate_inventory_hostnames')&.value | ||||
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. If it's a parameter, you have to look up the value on the host object itself: foreman_rh_cloud/app/controllers/insights_cloud/api/machine_telemetries_controller.rb Line 87 in 48f9d74
|
||||
obfuscate_fqdn(bash_hostname) | ||||
else | ||||
bash_hostname | ||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,8 +23,8 @@ class MetadataGeneratorTest < ActiveSupport::TestCase | |
end | ||
|
||
test 'generates an empty report with hidden hostname and ip' do | ||
Setting[:obfuscate_inventory_hostnames] = true | ||
Setting[:obfuscate_inventory_ips] = true | ||
CommonParameter.find_or_create_by!(name: 'obfuscate_inventory_ips', value: true) | ||
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. If the parameter exists, I think this method will not reset its value. |
||
CommonParameter.find_or_create_by!(name: 'obfuscate_inventory_hostnames', value: true) | ||
@host = FactoryBot.create(:host, :managed) | ||
ForemanRhCloud.expects(:foreman_host_name).returns(@host.name) | ||
generator = ForemanInventoryUpload::Generators::Metadata.new | ||
|
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.
You can skip the
find_by
later in the code