mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-07-15 14:34:14 +00:00
API: add option to fetch only tags from ListInbounds (#4870)
* feat: add new method for get only inbound tags from core. ListTags. * refactor: simplify creating response. * refactor: move getting tags in already exist method via option.
This commit is contained in:
parent
cb1afb33e6
commit
486d005986
4 changed files with 36 additions and 11 deletions
|
@ -103,13 +103,22 @@ func (s *handlerServer) AlterInbound(ctx context.Context, request *AlterInboundR
|
||||||
func (s *handlerServer) ListInbounds(ctx context.Context, request *ListInboundsRequest) (*ListInboundsResponse, error) {
|
func (s *handlerServer) ListInbounds(ctx context.Context, request *ListInboundsRequest) (*ListInboundsResponse, error) {
|
||||||
handlers := s.ihm.ListHandlers(ctx)
|
handlers := s.ihm.ListHandlers(ctx)
|
||||||
response := &ListInboundsResponse{}
|
response := &ListInboundsResponse{}
|
||||||
for _, handler := range handlers {
|
if request.GetIsOnlyTags() {
|
||||||
response.Inbounds = append(response.Inbounds, &core.InboundHandlerConfig{
|
for _, handler := range handlers {
|
||||||
Tag: handler.Tag(),
|
response.Inbounds = append(response.Inbounds, &core.InboundHandlerConfig{
|
||||||
ReceiverSettings: handler.ReceiverSettings(),
|
Tag: handler.Tag(),
|
||||||
ProxySettings: handler.ProxySettings(),
|
})
|
||||||
})
|
}
|
||||||
|
} else {
|
||||||
|
for _, handler := range handlers {
|
||||||
|
response.Inbounds = append(response.Inbounds, &core.InboundHandlerConfig{
|
||||||
|
Tag: handler.Tag(),
|
||||||
|
ReceiverSettings: handler.ReceiverSettings(),
|
||||||
|
ProxySettings: handler.ProxySettings(),
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -368,6 +368,8 @@ type ListInboundsRequest struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
unknownFields protoimpl.UnknownFields
|
unknownFields protoimpl.UnknownFields
|
||||||
|
|
||||||
|
IsOnlyTags bool `protobuf:"varint,1,opt,name=isOnlyTags,proto3" json:"isOnlyTags,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *ListInboundsRequest) Reset() {
|
func (x *ListInboundsRequest) Reset() {
|
||||||
|
@ -400,6 +402,13 @@ func (*ListInboundsRequest) Descriptor() ([]byte, []int) {
|
||||||
return file_app_proxyman_command_command_proto_rawDescGZIP(), []int{8}
|
return file_app_proxyman_command_command_proto_rawDescGZIP(), []int{8}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *ListInboundsRequest) GetIsOnlyTags() bool {
|
||||||
|
if x != nil {
|
||||||
|
return x.IsOnlyTags
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
type ListInboundsResponse struct {
|
type ListInboundsResponse struct {
|
||||||
state protoimpl.MessageState
|
state protoimpl.MessageState
|
||||||
sizeCache protoimpl.SizeCache
|
sizeCache protoimpl.SizeCache
|
||||||
|
@ -993,9 +1002,11 @@ var file_app_proxyman_command_command_proto_rawDesc = []byte{
|
||||||
0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2e, 0x54, 0x79, 0x70,
|
0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2e, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x2e, 0x54, 0x79, 0x70,
|
||||||
0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61,
|
0x65, 0x64, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x52, 0x09, 0x6f, 0x70, 0x65, 0x72, 0x61,
|
||||||
0x74, 0x69, 0x6f, 0x6e, 0x22, 0x16, 0x0a, 0x14, 0x41, 0x6c, 0x74, 0x65, 0x72, 0x49, 0x6e, 0x62,
|
0x74, 0x69, 0x6f, 0x6e, 0x22, 0x16, 0x0a, 0x14, 0x41, 0x6c, 0x74, 0x65, 0x72, 0x49, 0x6e, 0x62,
|
||||||
0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x15, 0x0a, 0x13,
|
0x6f, 0x75, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x35, 0x0a, 0x13,
|
||||||
0x4c, 0x69, 0x73, 0x74, 0x49, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75,
|
0x4c, 0x69, 0x73, 0x74, 0x49, 0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x73, 0x52, 0x65, 0x71, 0x75,
|
||||||
0x65, 0x73, 0x74, 0x22, 0x53, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x6e, 0x62, 0x6f, 0x75,
|
0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x73, 0x4f, 0x6e, 0x6c, 0x79, 0x54, 0x61, 0x67,
|
||||||
|
0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0a, 0x69, 0x73, 0x4f, 0x6e, 0x6c, 0x79, 0x54,
|
||||||
|
0x61, 0x67, 0x73, 0x22, 0x53, 0x0a, 0x14, 0x4c, 0x69, 0x73, 0x74, 0x49, 0x6e, 0x62, 0x6f, 0x75,
|
||||||
0x6e, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x69,
|
0x6e, 0x64, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3b, 0x0a, 0x08, 0x69,
|
||||||
0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e,
|
0x6e, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x1f, 0x2e,
|
||||||
0x78, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x62, 0x6f, 0x75, 0x6e,
|
0x78, 0x72, 0x61, 0x79, 0x2e, 0x63, 0x6f, 0x72, 0x65, 0x2e, 0x49, 0x6e, 0x62, 0x6f, 0x75, 0x6e,
|
||||||
|
|
|
@ -37,7 +37,9 @@ message AlterInboundRequest {
|
||||||
|
|
||||||
message AlterInboundResponse {}
|
message AlterInboundResponse {}
|
||||||
|
|
||||||
message ListInboundsRequest {}
|
message ListInboundsRequest {
|
||||||
|
bool isOnlyTags = 1;
|
||||||
|
}
|
||||||
|
|
||||||
message ListInboundsResponse {
|
message ListInboundsResponse {
|
||||||
repeated core.InboundHandlerConfig inbounds = 1;
|
repeated core.InboundHandlerConfig inbounds = 1;
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
var cmdListInbounds = &base.Command{
|
var cmdListInbounds = &base.Command{
|
||||||
CustomFlags: true,
|
CustomFlags: true,
|
||||||
UsageLine: "{{.Exec}} api lsi [--server=127.0.0.1:8080]",
|
UsageLine: "{{.Exec}} api lsi [--server=127.0.0.1:8080] [--isOnlyTags=true]",
|
||||||
Short: "List inbounds",
|
Short: "List inbounds",
|
||||||
Long: `
|
Long: `
|
||||||
List inbounds in Xray.
|
List inbounds in Xray.
|
||||||
|
@ -29,14 +29,17 @@ Example:
|
||||||
|
|
||||||
func executeListInbounds(cmd *base.Command, args []string) {
|
func executeListInbounds(cmd *base.Command, args []string) {
|
||||||
setSharedFlags(cmd)
|
setSharedFlags(cmd)
|
||||||
|
var isOnlyTagsStr string
|
||||||
|
cmd.Flag.StringVar(&isOnlyTagsStr, "isOnlyTags", "", "")
|
||||||
cmd.Flag.Parse(args)
|
cmd.Flag.Parse(args)
|
||||||
|
isOnlyTags := isOnlyTagsStr == "true"
|
||||||
|
|
||||||
conn, ctx, close := dialAPIServer()
|
conn, ctx, close := dialAPIServer()
|
||||||
defer close()
|
defer close()
|
||||||
|
|
||||||
client := handlerService.NewHandlerServiceClient(conn)
|
client := handlerService.NewHandlerServiceClient(conn)
|
||||||
|
|
||||||
resp, err := client.ListInbounds(ctx, &handlerService.ListInboundsRequest{})
|
resp, err := client.ListInbounds(ctx, &handlerService.ListInboundsRequest{IsOnlyTags: isOnlyTags})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
base.Fatalf("failed to list inbounds: %s", err)
|
base.Fatalf("failed to list inbounds: %s", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue