license cloud done

This commit is contained in:
Yan
2017-11-16 20:46:03 +06:30
parent 178b3484be
commit 29322d952e
5 changed files with 64 additions and 30 deletions

View File

@@ -41,9 +41,11 @@ class License
cache_license = nil
##Get redis connection from connection pool
Redis.current do |conn|
cache_license = conn.get(cache_key)
end
redis = Redis.new
cache_license = redis.get(cache_key)
# Redis.current do |conn|
# cache_license = conn.get(cache_key)
# end
Rails.logger.info "Cache key - " + cache_key.to_s
if cache_license.nil?
@@ -54,22 +56,27 @@ class License
@license = response.parsed_response
if (@license["status"] == true)
assign()
Rails.logger.info "License - " + response.parsed_response.to_s
Redis.current do |conn|
##Remote - store the remote response in local redis cache
conn.set(cache_key, Marshal.dump(@license))
##ADD to List to remove later
conn.sadd("License:cache:keys", cache_key)
end
redis = Redis.new
redis.set(cache_key, Marshal.dump(@license))
# redis.sadd("License:cache:keys", cache_key)
# Redis.current do |conn|
# ##Remote - store the remote response in local redis cache
# conn.set(cache_key, Marshal.dump(@license))
# ##ADD to List to remove later
# conn.sadd("License:cache:keys", cache_key)
# end
return true
end
Rails.logger.info 'API License'
else
@license = Marshal.load(cache_license)
assign()
Rails.logger.info 'API License'
return true
end
end
@@ -223,7 +230,7 @@ class License
File.open("config/license.yml").each do |line|
if line.include? (key)
decrypted_line_array = line.split(":")
decrypted_line = AESCrypt.decrypt_data(decrypted_line_array[1], ENV['AES_KEY'], ENV['AES_IV'], ENV['CIPHER_TYPE'])
decrypted_line = AESCrypt.decrypt_data(decode_str(decrypted_line_array[1]), decode_str(ENV['AES_KEY']), decode_str(ENV['AES_IV']), ENV['CIPHER_TYPE'])
end
end
end
@@ -231,6 +238,10 @@ class License
private
def decode_str(str)
return Base64.decode64(str)
end
# License File Creation
def create_license_file(response_data)
if check_license_file
@@ -341,13 +352,21 @@ class License
# self.plan_max_products = @license["plan_max_products"].to_i
# self.plan_max_customers = @license["plan_max_customers"].to_i
# self.plan_active_connections = @license["plan_active_connections"].to_i
salt = @license["secret_key"]
# salt = @license["secret_key"]
if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] )
self.dbhost = AESCrypt.decrypt(@license["dbhost"], salt)
self.dbschema = AESCrypt.decrypt(@license["dbschema"], salt)
self.dbusername = AESCrypt.decrypt(@license["dbusername"], salt)
self.dbpassword = AESCrypt.decrypt(@license["dbpassword"], salt)
key = Base64.decode64(ENV['AES_KEY'])
iv = Base64.decode64(ENV['AES_IV'])
if (@license["dbhost"] || @license["dbschema"] || @license["dbusername"] || @license["dbpassword"] )
host = Base64.decode64(@license["dbhost"])
dbschema = Base64.decode64(@license["dbschema"])
dbusername = Base64.decode64(@license["dbusername"])
dbpassword = Base64.decode64(@license["dbpassword"])
self.dbhost = AESCrypt.decrypt_data(host, key, iv, ENV['CIPHER_TYPE'])
self.dbschema = AESCrypt.decrypt_data(dbschema, key, iv, ENV['CIPHER_TYPE'])
self.dbusername = AESCrypt.decrypt_data(dbusername, key, iv, ENV['CIPHER_TYPE'])
self.dbpassword = AESCrypt.decrypt_data(dbpassword, key, iv, ENV['CIPHER_TYPE'])
end
# self.exchange_unqiue_id = @license["exchange_unqiue_id"]