Last active
August 12, 2019 11:48
-
-
Save shal/1be4ec9996c93561d990e1eca59419f6 to your computer and use it in GitHub Desktop.
Modified rake task for barong api-keys generation
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
# frozen_string_literal: true | |
# To execute with optional user and api keys amount. | |
# rake generate:users -- -n=1000 | |
require 'faker' | |
namespace 'generate' do | |
desc 'Build Application container' | |
task :users => :environment do | |
### Parse options | |
options = {} | |
o = OptionParser.new | |
o.banner = 'Usage: rake generate:users [-n=100]' | |
o.on('-n NUMBER', '--number NUMBER') { |num| options[:num] = num.to_i } | |
args = o.order!(ARGV) {} | |
o.parse!(args) | |
options[:num] = 10 if options[:num].nil? | |
users = [] | |
options[:num].times do |i| | |
email = Faker::Internet.email | |
passwd = Faker::Internet.password(min_length: 10, special_characters: true) | |
user = User.create(email: email, password: passwd, level: 3, state: 'active', otp: true) | |
api_key = APIKey.create(user_id: user.id, kid: SecureRandom.hex(8), algorithm: 'HS256') | |
secret = SecureRandom.hex(16) | |
SecretStorage.store_secret(secret, api_key.kid) | |
users.push({ | |
'uid' => user.uid, | |
'email' => user.email, | |
'password' => passwd, | |
'kid' => api_key.kid, | |
'secret' => secret | |
}) | |
end | |
File.write('tmp/users.yml', users.to_yaml) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment