ipanocloud commented on issue #9698:
URL: https://github.com/apache/apisix/issues/9698#issuecomment-1611009644
> > snc-app-info
>
> Is this all the code for the plugin you added?
```
local require = require
local core = require("apisix.core")
local tostring = tostring
local apps
local schema = {
type = "object",
properties = {
allow_degradation = { type = "boolean", default = false }
}
}
local plugin_name = "snc-app-info"
local _M = {
version = 0.1,
priority = 94,
name = plugin_name,
schema = schema,
}
function _M.check_schema(conf)
local ok, err = core.schema.check(schema, conf)
if not ok then
return false, err
end
return true
end
function _M.apps()
if not apps then
return nil, nil
end
return apps.values, apps.conf_version
end
function _M.get_by_id(app_id)
local app
local apps = core.config.fetch_created_obj("/apps")
if apps then
app = apps:get(tostring(app_id))
end
if not app then
core.log.warn("failed to find app by id from shared dict: ", app_id)
local key = "/apps/" .. app_id
local res, err = core.etcd.get(key, not app_id)
if not res then
core.log.error("failed to fetch client info from etcd: ", err,
", ", app_id)
return 503, "failed to fetch client info by " .. "app id [" ..
app_id .. "]: " .. err
end
if res.status == 404 then
return 404, nil
end
return nil, res.body.node.value
end
return nil, app.value
end
function _M.init()
local err
apps, err = core.config.new("/apps", {
automatic = true,
filter = function(app)
core.log.debug("filter app: ", core.json.delay_encode(app, true))
end,
})
if not apps then
core.log.error("failed to sync /apps: ", err)
end
end
return _M
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]