Skip to content

Instantly share code, notes, and snippets.

@thomascate
Created October 31, 2019 15:44
Show Gist options
  • Save thomascate/025212eede4e0f9f5cf1bcf2086c8501 to your computer and use it in GitHub Desktop.
Save thomascate/025212eede4e0f9f5cf1bcf2086c8501 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'json'
require 'faker'
input_filename = ARGV[0]
output_filename = ARGV[1]
desired_size = (ARGV[2].to_f) * 1048576
ohai_object = JSON.parse(File.read(input_filename))
def add_package(ohai_object)
name = "#{Faker::Hacker.adjective}-#{Faker::Hacker.verb}-#{Faker::Hacker.noun}"
puts "adding package #{name}".gsub(/\s+/, "")
ohai_object['packages'][name] = {
'version' => "#{Faker::Number.within(1..20)}.#{Faker::Number.within(1..10)}-#{Faker::Number.within(1..20)}ubuntu1".gsub(/\s+/, ""),
'arch' => "amd64"
}
return ohai_object
end
def add_user(ohai_object)
name = "#{Faker::Name.first_name}_#{Faker::Name.last_name}"
puts "adding user #{name}"
id = get_new_id(ohai_object)
ohai_object['etc']['passwd'][name] = {
'dir' => "/home/#{name}",
'gid' => id,
'uid' => id,
'shell' => "/bin/cool_shell",
'gecos' => ""
}
return ohai_object
end
def get_new_id(ohai_object,test_id=1000)
while true
ohai_object['etc']['passwd'].each do |key, value|
if test_id == value['uid']
test_id = test_id + 1
next
end
end
break
end
return test_id
end
while JSON.generate(ohai_object).length < desired_size
cointoss = Faker::Number.within(1..2)
puts JSON.generate(ohai_object).length
if cointoss == 1
ohai_object = add_user(ohai_object)
else
ohai_object = add_package(ohai_object)
end
end
File.open(output_filename, 'w') { |file| file.write(JSON.generate(ohai_object)) }
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment