You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2020/11/26 05:40:58 UTC
[GitHub] [apisix] backnero opened a new issue #2855: request help: adminapi supports yaml as the configuration center
backnero opened a new issue #2855:
URL: https://github.com/apache/apisix/issues/2855
### Issue description
When the configuration center is yaml, can adminapi support the GET method to get the list and detailed information of routing, upstream, service, ssl, etc.
Only need to support get request
### Environment
* apisix version (cmd: `apisix version`):
* OS:
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734087767
Admin API server only connects the etcd cluster, it could not know the dispatched yaml files.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734521667
> Hi, @backnero. I think your request help like get a YAML file content through adminapi?
If this, I think you can write a plugin to support.
No. We can't do it because plugin can't add API to the admin API.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734575541
>
>
> > > Hi, @backnero. I think your request help like get a YAML file content through adminapi?
> > > If this, I think you can write a plugin to support.
> >
> >
> > No. We can't do it because plugin can't add API to the admin API.
>
> Yeah. Can't add admin API, but we can add a route to return that info.
The route is added in the data panel, not the admin API. So there is impossible to expose the info in admin API if you are not using etcd.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tokers commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
tokers commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734791895
The existing admin api will be removed in the future, so may be is not suitable to add new configuration center again.
cc @moonming
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] backnero commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734091545
I now use yaml as the configuration center, and there is a requirement that I need to obtain routing, service, upstream lists, and routing id information through interfaces.
Can it be expanded through plugin?
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] backnero commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734593790
It may be the problem I stated. For me, it doesn’t have to be adminapi. The interface released by the plug-in is also ok, just get the information
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] starsz edited a comment on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
starsz edited a comment on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734544018
> > Hi, @backnero. I think your request help like get a YAML file content through adminapi?
> > If this, I think you can write a plugin to support.
>
> No. We can't do it because plugin can't add API to the admin API.
Yeah. Can't add admin API, but we can add a route to return that info.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] backnero commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734589523
As long as routing, service, upstream and other information can be obtained, because yaml is used as the configuration center, configuration addition, deletion and modification will all be performed in yaml.
```
-- function _M.api()
-- return {
-- {
-- methods = {"GET"},
-- uri = "/apisix/routers/",
-- handler = getrouters,
-- }
-- }
-- end
```
Maybe it can be similar to this, I don't know what method should be used to obtain routing information.
```
local co_yaml = read_apisix_yaml()
-- local config_data = yaml.parse(co_yaml)
core.log.error("yaml:::::: ",core.json.delay_encode(co_yaml))
```
I try to use the method in core/conf_yaml.lua to get yaml information,
Can print out part of the yaml content, but don’t know how to continue
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander closed issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
spacewander closed issue #2855:
URL: https://github.com/apache/apisix/issues/2855
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734626600
@backnero
You can take a look at how we do in
https://github.com/apache/apisix/blob/f4161d39a495879edffbc75e2099f6e487bae81d/apisix/http/router/radixtree_uri.lua#L84
Don't forget to protect your route via https://github.com/apache/apisix/blob/master/doc/plugin-interceptors.md
I will close this issue as it is off topic now. Feel free to open a new one if needed.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] tokers removed a comment on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
tokers removed a comment on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734791895
The existing admin api will be removed in the future, so may be is not suitable to add new configuration center again.
cc @moonming
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] starsz commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
starsz commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734544018
> > Hi, @backnero. I think your request help like get a YAML file content through adminapi?
> > If this, I think you can write a plugin to support.
>
> No. We can't do it because plugin can't add API to the admin API.
Yeah. Can't add API, but we can add a route to return that info.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] starsz edited a comment on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
starsz edited a comment on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734350777
Hi, @backnero. I think your request help like get a YAML file content through adminapi?
If this, I think you can write a plugin to support.
Besides, if you want to obtain routing, service, upstream lists, and routing id information through interfaces. You can also write a plugin to support.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] backnero commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734676433
```
local user_routes, err = core.config.new("/routes", {
automatic = true,
item_schema = core.schema.route,
filter = filter,
})
```
What is the reason user_routes.value does not exist
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] backnero commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
backnero commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734712258
```
local core = require("apisix.core")
local ipairs = ipairs
local ngx = ngx
local ngx_time = ngx.time
local sub_str = string.sub
local plugin_name = "dev"
local http = require("resty.http")
local json = require("apisix.core.json")
local type = type
local string = string
-- local router = require("apisix.router")
-- local get_routes = router.http_routes
-- local profile = require("apisix.core.profile")
-- local lfs = require("lfs")
-- local re_find = ngx.re.find
local yaml = require("tinyyaml")
-- local apisix_yaml_path = profile:yaml_path("apisix")
local loadstring = loadstring
local user_routes
local router = require("resty.radixtree")
local schema = {
type = "object",
properties = {
},
}
local _M = {
version = 0.1,
priority = 70000,
type = 'auth',
name = plugin_name,
schema = schema,
}
function _M.check_schema(conf)
core.log.info("input conf: ", core.json.delay_encode(conf))
local ok, err = core.schema.check(schema, conf)
if not ok then
return false, err
end
return true
end
local function fail_response(message, init_values)
local response = init_values or {}
response.message = message
return response
end
local function success_response(message, init_values)
local response = init_values or {}
response.message = message
return response
end
local function create_radixtree_router(routes)
local uri_routes = {}
local uri_router
routes = routes or {}
core.table.clear(uri_routes)
for _, route in ipairs(routes) do
core.log.error("route for: ", core.json.delay_encode(route, true))
if type(route) == "table" then
local filter_fun, err
if route.value.filter_func then
filter_fun, err = loadstring(
"return " .. route.value.filter_func,
"router#" .. route.value.id)
if not filter_fun then
core.log.error("failed to load filter function: ", err,
" route id: ", route.value.id)
goto CONTINUE
end
filter_fun = filter_fun()
end
core.log.error("insert uri route: ",
core.json.delay_encode(route.value))
core.table.insert(uri_routes, {
paths = route.value.uris or route.value.uri,
methods = route.value.methods,
priority = route.value.priority,
hosts = route.value.hosts or route.value.host,
remote_addrs = route.value.remote_addrs
or route.value.remote_addr,
vars = route.value.vars,
filter_fun = filter_fun,
handler = function (api_ctx, match_opts)
api_ctx.matched_params = nil
api_ctx.matched_route = route
api_ctx.curr_req_matched = match_opts.matched
end
})
::CONTINUE::
end
end
-- core.log.error("route items:2 ",core.json.uri_routes)
uri_router = router.new(uri_routes)
core.response.exit(200, success_response(nil, {routes = uri_routes}))
end
function get_routes()
local user_routes, err = core.config.new("/routes", {
automatic = true,
item_schema = core.schema.route,
filter = filter,
})
create_radixtree_router(user_routes.values)
-- core.log.error("route items:1 ", core.json.uri_routes)
end
function _M.api()
return {
{
methods = {"GET"},
uri = "/apisix/plugin/routes",
handler = get_routes,
}
}
end
return _M
```
response
```
{
"routes": {}
}
```
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] starsz commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
starsz commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734350777
Hi, @backnero. I think your request help like get a YAML file content through adminapi?
If this, I think you can write a plugin to support.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander commented on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734095142
I doubt if it can be expanded through plugin. As far as I know, people who use yaml store the original configuration in their internal system, and dispatch the generated yaml file via agents. Maybe you can write the API in your internal system.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
[GitHub] [apisix] spacewander edited a comment on issue #2855: request help: adminapi supports yaml as the configuration center
Posted by GitBox <gi...@apache.org>.
spacewander edited a comment on issue #2855:
URL: https://github.com/apache/apisix/issues/2855#issuecomment-734575541
>
>
> > > Hi, @backnero. I think your request help like get a YAML file content through adminapi?
> > > If this, I think you can write a plugin to support.
> >
> >
> > No. We can't do it because plugin can't add API to the admin API.
>
> Yeah. Can't add admin API, but we can add a route to return that info.
The route is added in the data panel, not in the admin API. So there is impossible to expose the info in admin API if you are not using etcd.
----------------------------------------------------------------
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.
For queries about this service, please contact Infrastructure at:
users@infra.apache.org