karafka/karafka

View on GitHub
bin/create_token

Summary

Maintainability
Test Coverage
#!/usr/bin/env ruby

require 'openssl'
require 'base64'
require 'json'
require 'date'

PRIVATE_KEY_LOCATION = File.join(Dir.home, '.ssh', 'karafka-pro', 'id_rsa')

# Name of the entity that acquires the license
ENTITY = ARGV[0]

raise ArgumentError, 'Entity missing' if ENTITY.nil? || ENTITY.empty?

pro_token_data = { entity: ENTITY }

# This code uses my private key to generate a new token for Karafka Pro capabilities
private_key = OpenSSL::PKey::RSA.new(File.read(PRIVATE_KEY_LOCATION))

bin_key = private_key.private_encrypt(pro_token_data.to_json)

puts Base64.encode64(bin_key)