license key api for redis
This commit is contained in:
@@ -38,11 +38,11 @@ class ApplicationController < ActionController::Base
|
||||
end
|
||||
else
|
||||
# check for license file
|
||||
# if check_license
|
||||
# current_license(ENV["SX_PROVISION_URL"])
|
||||
# else
|
||||
# redirect_to activate_path
|
||||
# end
|
||||
if check_license
|
||||
current_license(ENV["SX_PROVISION_URL"])
|
||||
else
|
||||
redirect_to activate_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
class SymControlController < BaseController
|
||||
skip_before_action :verify_authenticity_token
|
||||
http_basic_authenticate_with name: "vip", password: "!abcABC01"
|
||||
|
||||
def run
|
||||
sym_path = "/home/yan/symmetric/"
|
||||
@@ -32,4 +33,14 @@ class SymControlController < BaseController
|
||||
end
|
||||
end
|
||||
|
||||
def get_key
|
||||
license = License.new(ENV["SX_PROVISION_URL"])
|
||||
status = license.get_key
|
||||
if status
|
||||
render :text => "<h1>Success!</h1>"
|
||||
else
|
||||
render :text => "<h1>Not Get!</h1>"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
@@ -45,7 +45,7 @@ class License
|
||||
if (@license["status"] == true)
|
||||
assign(aes_key, aes_iv)
|
||||
|
||||
Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
# Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
|
||||
redis = Redis.new
|
||||
redis.set(cache_key, Marshal.dump(@license))
|
||||
@@ -106,7 +106,7 @@ class License
|
||||
redis = Redis.new
|
||||
cache_license = redis.get(cache_key)
|
||||
|
||||
Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
# Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
|
||||
if cache_license.nil?
|
||||
cache = {"shop" => @activate["shop_name"], "key" => aes_key, "iv" => @activate["iv_key"], "renewable_date" => @activate["renewable_date"] }
|
||||
@@ -114,7 +114,7 @@ class License
|
||||
redis.set(cache_key, Marshal.dump(cache))
|
||||
end
|
||||
|
||||
Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
# Rails.logger.info "License - " + response.parsed_response.to_s
|
||||
|
||||
response = create_license_file(@activate)
|
||||
if(response[:status])
|
||||
@@ -136,7 +136,7 @@ class License
|
||||
response = self.class.get("/verify", @params)
|
||||
@varified = response.parsed_response
|
||||
|
||||
Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
|
||||
# Rails.logger.debug "License Remote Response - " + response.parsed_response.to_s
|
||||
if (@varified["status"])
|
||||
if (!check_expired(@varified["plan_next_renewal_date"]))
|
||||
return true
|
||||
@@ -227,6 +227,36 @@ class License
|
||||
# f.put
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
||||
# Re-get keys
|
||||
def get_key
|
||||
api_token = read_license_no_decrypt("api_token")
|
||||
shop_name = read_license_no_decrypt("shop_name")
|
||||
@params = { query: {lookup_type: "application", api_token: api_token} }
|
||||
response = self.class.get("/get_key", @params)
|
||||
@data = response.parsed_response
|
||||
|
||||
if (@data["status"])
|
||||
##Check from local redis - if available load local otherwise get from remote
|
||||
cache_key = "shop:#{shop_name}"
|
||||
|
||||
cache_license = nil
|
||||
|
||||
##Get redis connection from connection pool
|
||||
redis = Redis.new
|
||||
cache_license = redis.get(cache_key)
|
||||
|
||||
# Rails.logger.info "Cache key - " + cache_key.to_s
|
||||
|
||||
if cache_license.nil?
|
||||
cache = {"shop" => shop_name, "key" => @data["secret_key"], "iv" => @data["iv_key"], "renewable_date" => @data["plan_next_renewable_date"] }
|
||||
redis = Redis.new
|
||||
redis.set(cache_key, Marshal.dump(cache))
|
||||
end
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
Reference in New Issue
Block a user