Commit b7496b82 authored by 张醒狮's avatar 张醒狮

add search assert rpc

parent 3a81ddff
package client
const ()
...@@ -9,8 +9,8 @@ import ( ...@@ -9,8 +9,8 @@ import (
) )
type ResourceCenterClient struct { type ResourceCenterClient struct {
conn *grpc.ClientConn Conn *grpc.ClientConn
client pb.ResourceCenterClient Client pb.ResourceCenterClient
} }
func NewResourceCenterClient(addr string) (*ResourceCenterClient, error) { func NewResourceCenterClient(addr string) (*ResourceCenterClient, error) {
...@@ -18,11 +18,11 @@ func NewResourceCenterClient(addr string) (*ResourceCenterClient, error) { ...@@ -18,11 +18,11 @@ func NewResourceCenterClient(addr string) (*ResourceCenterClient, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
return &ResourceCenterClient{conn: conn, client: pb.NewResourceCenterClient(conn)}, nil return &ResourceCenterClient{Conn: conn, Client: pb.NewResourceCenterClient(conn)}, nil
} }
func (rc *ResourceCenterClient) Close() error { func (rc *ResourceCenterClient) Close() error {
return rc.conn.Close() return rc.Conn.Close()
} }
func (rc *ResourceCenterClient) GetOwnership(ctx context.Context, resourceId string) (*pb.OwnershipResponse, error) { func (rc *ResourceCenterClient) GetOwnership(ctx context.Context, resourceId string) (*pb.OwnershipResponse, error) {
...@@ -31,5 +31,61 @@ func (rc *ResourceCenterClient) GetOwnership(ctx context.Context, resourceId str ...@@ -31,5 +31,61 @@ func (rc *ResourceCenterClient) GetOwnership(ctx context.Context, resourceId str
ctx, cancel := context.WithTimeout(ctx, 3*time.Second) ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
defer cancel() defer cancel()
return rc.client.GetOwnership(ctx, req) return rc.Client.GetOwnership(ctx, req)
}
func (rc *ResourceCenterClient) SearchAsset(ctx context.Context, resourceType string, opts ...Option) (*pb.AssetResponse, error) {
req := &pb.AssetRequest{ResourceType: resourceType}
for _, f := range opts {
f(req)
}
ctx, cancel := context.WithTimeout(ctx, 3*time.Second)
defer cancel()
return rc.Client.SearchAsset(ctx, req)
}
type Option func(*pb.AssetRequest)
func WithResourceName(name string) Option {
return func(req *pb.AssetRequest) {
req.ResourceName = name
}
}
func WithRegionId(regionId string) Option {
return func(req *pb.AssetRequest) {
req.RegionId = regionId
}
}
func WithTeam(team string) Option {
return func(req *pb.AssetRequest) {
req.Team = team
}
}
func WithGroup(group string) Option {
return func(req *pb.AssetRequest) {
req.Group = group
}
}
func WithApp(app string) Option {
return func(req *pb.AssetRequest) {
req.App = app
}
}
func WithMode(mode int32) Option {
return func(req *pb.AssetRequest) {
req.Mode = mode
}
}
func WithResourceGroupId(resourceGroupId string) Option {
return func(req *pb.AssetRequest) {
req.ResourceGroupId = resourceGroupId
}
} }
This diff is collapsed.
...@@ -21,6 +21,30 @@ message OwnershipResponse { ...@@ -21,6 +21,30 @@ message OwnershipResponse {
int32 mode = 2; int32 mode = 2;
} }
service ResourceCenter { message AssetRequest {
rpc GetOwnership(OwnershipRequest) returns(OwnershipResponse); string resource_name = 1;
string resource_type = 2;
string resource_group_id = 3;
string region_id = 4;
string team = 5;
string group = 6;
string app = 7;
int32 mode = 8;
}
message AssetResponse {
repeated AssertInfo items = 1;
} }
message AssertInfo {
string resource_id = 1;
string resource_type = 2;
string resource_name = 3;
string region_id = 4;
int32 mode = 5;
}
service ResourceCenter {
rpc GetOwnership(OwnershipRequest) returns (OwnershipResponse);
rpc SearchAsset(AssetRequest) returns (AssetResponse);
}
\ No newline at end of file
...@@ -20,6 +20,7 @@ const _ = grpc.SupportPackageIsVersion7 ...@@ -20,6 +20,7 @@ const _ = grpc.SupportPackageIsVersion7
const ( const (
ResourceCenter_GetOwnership_FullMethodName = "/guidon.ResourceCenter/GetOwnership" ResourceCenter_GetOwnership_FullMethodName = "/guidon.ResourceCenter/GetOwnership"
ResourceCenter_SearchAsset_FullMethodName = "/guidon.ResourceCenter/SearchAsset"
) )
// ResourceCenterClient is the client API for ResourceCenter service. // ResourceCenterClient is the client API for ResourceCenter service.
...@@ -27,6 +28,7 @@ const ( ...@@ -27,6 +28,7 @@ const (
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type ResourceCenterClient interface { type ResourceCenterClient interface {
GetOwnership(ctx context.Context, in *OwnershipRequest, opts ...grpc.CallOption) (*OwnershipResponse, error) GetOwnership(ctx context.Context, in *OwnershipRequest, opts ...grpc.CallOption) (*OwnershipResponse, error)
SearchAsset(ctx context.Context, in *AssetRequest, opts ...grpc.CallOption) (*AssetResponse, error)
} }
type resourceCenterClient struct { type resourceCenterClient struct {
...@@ -46,11 +48,21 @@ func (c *resourceCenterClient) GetOwnership(ctx context.Context, in *OwnershipRe ...@@ -46,11 +48,21 @@ func (c *resourceCenterClient) GetOwnership(ctx context.Context, in *OwnershipRe
return out, nil return out, nil
} }
func (c *resourceCenterClient) SearchAsset(ctx context.Context, in *AssetRequest, opts ...grpc.CallOption) (*AssetResponse, error) {
out := new(AssetResponse)
err := c.cc.Invoke(ctx, ResourceCenter_SearchAsset_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
// ResourceCenterServer is the server API for ResourceCenter service. // ResourceCenterServer is the server API for ResourceCenter service.
// All implementations must embed UnimplementedResourceCenterServer // All implementations must embed UnimplementedResourceCenterServer
// for forward compatibility // for forward compatibility
type ResourceCenterServer interface { type ResourceCenterServer interface {
GetOwnership(context.Context, *OwnershipRequest) (*OwnershipResponse, error) GetOwnership(context.Context, *OwnershipRequest) (*OwnershipResponse, error)
SearchAsset(context.Context, *AssetRequest) (*AssetResponse, error)
mustEmbedUnimplementedResourceCenterServer() mustEmbedUnimplementedResourceCenterServer()
} }
...@@ -61,6 +73,9 @@ type UnimplementedResourceCenterServer struct { ...@@ -61,6 +73,9 @@ type UnimplementedResourceCenterServer struct {
func (UnimplementedResourceCenterServer) GetOwnership(context.Context, *OwnershipRequest) (*OwnershipResponse, error) { func (UnimplementedResourceCenterServer) GetOwnership(context.Context, *OwnershipRequest) (*OwnershipResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetOwnership not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetOwnership not implemented")
} }
func (UnimplementedResourceCenterServer) SearchAsset(context.Context, *AssetRequest) (*AssetResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SearchAsset not implemented")
}
func (UnimplementedResourceCenterServer) mustEmbedUnimplementedResourceCenterServer() {} func (UnimplementedResourceCenterServer) mustEmbedUnimplementedResourceCenterServer() {}
// UnsafeResourceCenterServer may be embedded to opt out of forward compatibility for this service. // UnsafeResourceCenterServer may be embedded to opt out of forward compatibility for this service.
...@@ -92,6 +107,24 @@ func _ResourceCenter_GetOwnership_Handler(srv interface{}, ctx context.Context, ...@@ -92,6 +107,24 @@ func _ResourceCenter_GetOwnership_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _ResourceCenter_SearchAsset_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AssetRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ResourceCenterServer).SearchAsset(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: ResourceCenter_SearchAsset_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ResourceCenterServer).SearchAsset(ctx, req.(*AssetRequest))
}
return interceptor(ctx, in, info, handler)
}
// ResourceCenter_ServiceDesc is the grpc.ServiceDesc for ResourceCenter service. // ResourceCenter_ServiceDesc is the grpc.ServiceDesc for ResourceCenter service.
// It's only intended for direct use with grpc.RegisterService, // It's only intended for direct use with grpc.RegisterService,
// and not to be introspected or modified (even as a copy) // and not to be introspected or modified (even as a copy)
...@@ -103,6 +136,10 @@ var ResourceCenter_ServiceDesc = grpc.ServiceDesc{ ...@@ -103,6 +136,10 @@ var ResourceCenter_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetOwnership", MethodName: "GetOwnership",
Handler: _ResourceCenter_GetOwnership_Handler, Handler: _ResourceCenter_GetOwnership_Handler,
}, },
{
MethodName: "SearchAsset",
Handler: _ResourceCenter_SearchAsset_Handler,
},
}, },
Streams: []grpc.StreamDesc{}, Streams: []grpc.StreamDesc{},
Metadata: "pb/resource.proto", Metadata: "pb/resource.proto",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment