Skip to content

Commit

Permalink
Truncate tags to 250 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimShtein authored and ronlavi2412 committed Jan 13, 2022
1 parent da5c0f5 commit d5567b1
Showing 2 changed files with 23 additions and 1 deletion.
9 changes: 8 additions & 1 deletion lib/foreman_inventory_upload/generators/tags.rb
Original file line number Diff line number Diff line change
@@ -13,14 +13,15 @@ def generate
organizations +
content_data +
satellite_server_data
).reject { |key, value| value.empty? }
).reject { |key, value| value.empty? }.map { |key, value| [key, truncated_value(value)] }
end

def generate_parameters
return [] unless Setting[:include_parameter_tags]

(@host.host_params || {})
.select { |_name, value| value.present? || value.is_a?(FalseClass) }
.map { |key, value| [key, truncated_value(value)] }
end

private
@@ -57,6 +58,12 @@ def satellite_server_data
['organization_id', @host.organization_id.to_s],
]
end

def truncated_value(value)
return 'Original value exceeds 250 characters' if value.to_s.length > 250

value
end
end
end
end
15 changes: 15 additions & 0 deletions test/unit/tags_generator_test.rb
Original file line number Diff line number Diff line change
@@ -103,6 +103,21 @@ class TagsGeneratorTest < ActiveSupport::TestCase
assert_equal 0, actual.count
end

test 'truncates parameter tags' do
Setting[:include_parameter_tags] = true

@host.stubs(:host_params).returns(
{
'str_param' => 'a' * 251,
}
)

generator = create_generator
actual = Hash[generator.generate_parameters]

assert_equal 'Original value exceeds 250 characters', actual['str_param']
end

private

def create_generator

0 comments on commit d5567b1

Please sign in to comment.