-
Notifications
You must be signed in to change notification settings - Fork 182
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reuse Redis connection in allow_domain method #38
Comments
Not a dumb question at all! You could establish a new redis connection inside the In the meantime, here's a workaround that I think might work to allow you to leverage the same connection in both places: local function get_redis_instance(redis_options)
local instance = ngx.ctx.auto_ssl_redis_instance
if instance then
return instance
end
instance = redis:new()
local ok, err
if redis_options["socket"] then
ok, err = instance:connect(redis_options["socket"])
else
ok, err = instance:connect(redis_options["host"], redis_options["port"])
end
if not ok then
return false, err
end
if redis_options["auth"] then
ok, err = instance:auth(redis_options["auth"])
if not ok then
return false, err
end
end
ngx.ctx.auto_ssl_redis_instance = instance
return instance
end
auto_ssl = (require "resty.auto-ssl").new()
local redis_options = {
host = "10.10.10.1"
}
auto_ssl:set("redis", redis_options)
auto_ssl:set("allow_domain", function(domain)
local redis_instance, instance_err = get_redis_instance(redis_options)
if instance_err then
return nil, instance_err
end
local res, err = redis_instance:get("WHATEVER...")
-- Do whatever else you need with redis_instance.
end)
auto_ssl:init() It's a bit ugly, but basically I'm just copying the private But again, I think providing a cleaner way to get at this connection object directly from the storage API would be better long term. |
Thanks for this! I'll check it out. |
Hey @GUI , has anything been done to enable this ? |
@aviatrix I don't know of any changes regarding this. Right now nobody knows what reusing that object would even look like, for a users point of view. Is there an interface idea you'd like to work out and propose? I'll be glad to give you some pointers on how to implement it. |
@luto Right now i've settled for the |
One small caveat : if you don't put |
The auto_ssl instance is now passed as the second argument to the `allow_domain` callback. If using the Redis storage adapter, then now the Redis connection can be accessed by `auto_ssl.storage.adapter:get_connection()`. This allows for more easily accessing the same redis connection in this callback function (or anywhere else the auto_ssl instance is available). This rolls back the change in 9703684 to rename the storage adapter instance inside the storage library, so it continues to just be `adapter` (instead of `storage_adapter`). This makes this access a bit easier and also keeps backwards compatibility with the previous release. See: #38
Well, better late than never, but this should finally be easier in the v0.12.0 release. You can now access the redis connection via |
@GUI Is it possible to get to |
The auto_ssl instance is now passed as the second argument to the `allow_domain` callback. If using the Redis storage adapter, then now the Redis connection can be accessed by `auto_ssl.storage.adapter:get_connection()`. This allows for more easily accessing the same redis connection in this callback function (or anywhere else the auto_ssl instance is available). This rolls back the change in 9703684 to rename the storage adapter instance inside the storage library, so it continues to just be `adapter` (instead of `storage_adapter`). This makes this access a bit easier and also keeps backwards compatibility with the previous release. See: auto-ssl/lua-resty-auto-ssl#38 Conflicts: README.md lib/resty/auto-ssl/ssl_certificate.lua
Sorry for a potentially dumb question, I've got no experience with Lua.
But is it possible to reuse the Redis connection within the
allow_domain
method for looking up permissable domains from a set stored there?We've played with a couple of different options, but would really like to keep a whitelist of domains in a DB somewhere it refers to and since there's already Redis support baked in, we may as well use it.
The text was updated successfully, but these errors were encountered: