diff --git a/app/models/license.rb b/app/models/license.rb index ff1b7e96..b800f7ea 100755 --- a/app/models/license.rb +++ b/app/models/license.rb @@ -23,18 +23,18 @@ class License # @params = { query: { device: "SX", token: SECRETS_CONFIG['provision_key'] } } end - def detail_with_local_cache(lookup) - subdomain = request.subdomain.downcase - flag = ENV["AES_IV"] - # Check Exists IV - if flag == "<%= ENV['AES_IV'] %>" - # Export for Key - aes = MyAesCrypt.new - aes_key, aes_iv = aes.export_key(lookup) - else - aes_key = ENV["AES_KEY"] - aes_iv = ENV["AES_IV"] - end + def detail_with_local_cache(lookup) + + # flag = ENV["AES_IV"] + # # Check Exists IV + # if flag == "<%= ENV['AES_IV'] %>" + # # Export for Key + # aes = MyAesCrypt.new + # aes_key, aes_iv = aes.export_key(lookup) + # else + # aes_key = ENV["AES_KEY"] + # aes_iv = ENV["AES_IV"] + # end ##Check from local redis - if available load local otherwise get from remote cache_key = "#{lookup}:license:#{key}:hostname" diff --git a/app/models/my_aes_crypt.rb b/app/models/my_aes_crypt.rb index 4f200c3b..1473da45 100644 --- a/app/models/my_aes_crypt.rb +++ b/app/models/my_aes_crypt.rb @@ -1,5 +1,6 @@ require 'openssl' require 'base64' +require 'json' class MyAesCrypt @cipher = "" @@ -26,6 +27,21 @@ class MyAesCrypt return cipher_key, cipher_iv end + def export_to_file(passphrase) + file_path = "config/shops.json" + aes_key, aes_iv = export_key(passphrase) + tmpHash = { + "lookup" => passphrase, + "key" => aes_key, + "iv" => aes_iv + } + + File.open(file_path, "w") { |io| + io.write(tmpHash.to_json) + } + + end + private def encrypt(data) cipher.encrypt