NOISSUE - Add IsChannelOwner grpc endpoint (#1366)

* Add CanAccessChannelByOwner grpc endpoint

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Rename grpc endpoint to IsChannelOwner

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Add tests for IsChannelOwner grpc

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Bump protoc version

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>

* Make proto

Signed-off-by: Darko Draskovic <darko.draskovic@gmail.com>
This commit is contained in:
Darko Draskovic
2021-02-22 19:41:59 +01:00
committed by GitHub
parent 7834cc48b3
commit 7ba3fdb3bf
15 changed files with 674 additions and 52 deletions
+506 -48
View File
@@ -82,6 +82,61 @@ func (m *AccessByKeyReq) GetChanID() string {
return ""
}
type ChannelOwnerReq struct {
Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
ChanID string `protobuf:"bytes,2,opt,name=chanID,proto3" json:"chanID,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ChannelOwnerReq) Reset() { *m = ChannelOwnerReq{} }
func (m *ChannelOwnerReq) String() string { return proto.CompactTextString(m) }
func (*ChannelOwnerReq) ProtoMessage() {}
func (*ChannelOwnerReq) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{1}
}
func (m *ChannelOwnerReq) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ChannelOwnerReq) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ChannelOwnerReq.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *ChannelOwnerReq) XXX_Merge(src proto.Message) {
xxx_messageInfo_ChannelOwnerReq.Merge(m, src)
}
func (m *ChannelOwnerReq) XXX_Size() int {
return m.Size()
}
func (m *ChannelOwnerReq) XXX_DiscardUnknown() {
xxx_messageInfo_ChannelOwnerReq.DiscardUnknown(m)
}
var xxx_messageInfo_ChannelOwnerReq proto.InternalMessageInfo
func (m *ChannelOwnerReq) GetOwner() string {
if m != nil {
return m.Owner
}
return ""
}
func (m *ChannelOwnerReq) GetChanID() string {
if m != nil {
return m.ChanID
}
return ""
}
type ThingID struct {
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
@@ -93,7 +148,7 @@ func (m *ThingID) Reset() { *m = ThingID{} }
func (m *ThingID) String() string { return proto.CompactTextString(m) }
func (*ThingID) ProtoMessage() {}
func (*ThingID) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{1}
return fileDescriptor_8bbd6f3875b0e874, []int{2}
}
func (m *ThingID) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -129,6 +184,53 @@ func (m *ThingID) GetValue() string {
return ""
}
type ChannelID struct {
Value string `protobuf:"bytes,1,opt,name=value,proto3" json:"value,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *ChannelID) Reset() { *m = ChannelID{} }
func (m *ChannelID) String() string { return proto.CompactTextString(m) }
func (*ChannelID) ProtoMessage() {}
func (*ChannelID) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{3}
}
func (m *ChannelID) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
}
func (m *ChannelID) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
if deterministic {
return xxx_messageInfo_ChannelID.Marshal(b, m, deterministic)
} else {
b = b[:cap(b)]
n, err := m.MarshalToSizedBuffer(b)
if err != nil {
return nil, err
}
return b[:n], nil
}
}
func (m *ChannelID) XXX_Merge(src proto.Message) {
xxx_messageInfo_ChannelID.Merge(m, src)
}
func (m *ChannelID) XXX_Size() int {
return m.Size()
}
func (m *ChannelID) XXX_DiscardUnknown() {
xxx_messageInfo_ChannelID.DiscardUnknown(m)
}
var xxx_messageInfo_ChannelID proto.InternalMessageInfo
func (m *ChannelID) GetValue() string {
if m != nil {
return m.Value
}
return ""
}
type AccessByIDReq struct {
ThingID string `protobuf:"bytes,1,opt,name=thingID,proto3" json:"thingID,omitempty"`
ChanID string `protobuf:"bytes,2,opt,name=chanID,proto3" json:"chanID,omitempty"`
@@ -141,7 +243,7 @@ func (m *AccessByIDReq) Reset() { *m = AccessByIDReq{} }
func (m *AccessByIDReq) String() string { return proto.CompactTextString(m) }
func (*AccessByIDReq) ProtoMessage() {}
func (*AccessByIDReq) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{2}
return fileDescriptor_8bbd6f3875b0e874, []int{4}
}
func (m *AccessByIDReq) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -198,7 +300,7 @@ func (m *Token) Reset() { *m = Token{} }
func (m *Token) String() string { return proto.CompactTextString(m) }
func (*Token) ProtoMessage() {}
func (*Token) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{3}
return fileDescriptor_8bbd6f3875b0e874, []int{5}
}
func (m *Token) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -246,7 +348,7 @@ func (m *UserIdentity) Reset() { *m = UserIdentity{} }
func (m *UserIdentity) String() string { return proto.CompactTextString(m) }
func (*UserIdentity) ProtoMessage() {}
func (*UserIdentity) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{4}
return fileDescriptor_8bbd6f3875b0e874, []int{6}
}
func (m *UserIdentity) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -302,7 +404,7 @@ func (m *IssueReq) Reset() { *m = IssueReq{} }
func (m *IssueReq) String() string { return proto.CompactTextString(m) }
func (*IssueReq) ProtoMessage() {}
func (*IssueReq) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{5}
return fileDescriptor_8bbd6f3875b0e874, []int{7}
}
func (m *IssueReq) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -365,7 +467,7 @@ func (m *AuthorizeReq) Reset() { *m = AuthorizeReq{} }
func (m *AuthorizeReq) String() string { return proto.CompactTextString(m) }
func (*AuthorizeReq) ProtoMessage() {}
func (*AuthorizeReq) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{6}
return fileDescriptor_8bbd6f3875b0e874, []int{8}
}
func (m *AuthorizeReq) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -426,7 +528,7 @@ func (m *AuthorizeRes) Reset() { *m = AuthorizeRes{} }
func (m *AuthorizeRes) String() string { return proto.CompactTextString(m) }
func (*AuthorizeRes) ProtoMessage() {}
func (*AuthorizeRes) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{7}
return fileDescriptor_8bbd6f3875b0e874, []int{9}
}
func (m *AuthorizeRes) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -475,7 +577,7 @@ func (m *Assignment) Reset() { *m = Assignment{} }
func (m *Assignment) String() string { return proto.CompactTextString(m) }
func (*Assignment) ProtoMessage() {}
func (*Assignment) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{8}
return fileDescriptor_8bbd6f3875b0e874, []int{10}
}
func (m *Assignment) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -540,7 +642,7 @@ func (m *MembersReq) Reset() { *m = MembersReq{} }
func (m *MembersReq) String() string { return proto.CompactTextString(m) }
func (*MembersReq) ProtoMessage() {}
func (*MembersReq) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{9}
return fileDescriptor_8bbd6f3875b0e874, []int{11}
}
func (m *MembersReq) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -619,7 +721,7 @@ func (m *MembersRes) Reset() { *m = MembersRes{} }
func (m *MembersRes) String() string { return proto.CompactTextString(m) }
func (*MembersRes) ProtoMessage() {}
func (*MembersRes) Descriptor() ([]byte, []int) {
return fileDescriptor_8bbd6f3875b0e874, []int{10}
return fileDescriptor_8bbd6f3875b0e874, []int{12}
}
func (m *MembersRes) XXX_Unmarshal(b []byte) error {
return m.Unmarshal(b)
@@ -685,7 +787,9 @@ func (m *MembersRes) GetMembers() []string {
func init() {
proto.RegisterType((*AccessByKeyReq)(nil), "mainflux.AccessByKeyReq")
proto.RegisterType((*ChannelOwnerReq)(nil), "mainflux.ChannelOwnerReq")
proto.RegisterType((*ThingID)(nil), "mainflux.ThingID")
proto.RegisterType((*ChannelID)(nil), "mainflux.ChannelID")
proto.RegisterType((*AccessByIDReq)(nil), "mainflux.AccessByIDReq")
proto.RegisterType((*Token)(nil), "mainflux.Token")
proto.RegisterType((*UserIdentity)(nil), "mainflux.UserIdentity")
@@ -700,44 +804,47 @@ func init() {
func init() { proto.RegisterFile("auth.proto", fileDescriptor_8bbd6f3875b0e874) }
var fileDescriptor_8bbd6f3875b0e874 = []byte{
// 585 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x53, 0xcb, 0x6e, 0xd3, 0x40,
0x14, 0xb5, 0xf3, 0xee, 0xa5, 0x29, 0x65, 0x54, 0x05, 0xcb, 0x88, 0x10, 0xcd, 0xaa, 0x2b, 0x17,
0x15, 0x10, 0x6c, 0x00, 0x25, 0x98, 0x85, 0x85, 0xd8, 0x98, 0x22, 0xb1, 0x75, 0x92, 0x49, 0x32,
0xe0, 0x47, 0xf0, 0x8c, 0x2b, 0xcc, 0x82, 0xef, 0xe0, 0x0b, 0xf8, 0x14, 0xc4, 0x92, 0x4f, 0x40,
0xe1, 0x47, 0xd0, 0x3c, 0x9c, 0x4c, 0xc1, 0xa9, 0xd8, 0xcd, 0xb9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0x6e, 0xff, 0x3b, 0x2f,
0x93, 0xe1, 0x0e, 0x3c, 0x95, 0x54, 0xaf, 0x4a, 0xaa, 0xf7, 0x52, 0x24, 0x15, 0x5b, 0xe8, 0x3e,
0xf4, 0x94, 0xbd, 0x17, 0x25, 0xba, 0x69, 0x88, 0x88, 0xff, 0x51, 0xab, 0x7a, 0xfe, 0xad, 0x01,
0x37, 0x84, 0xa7, 0xaa, 0x35, 0x3c, 0x68, 0x4b, 0xbb, 0x23, 0xb4, 0xeb, 0xae, 0xfc, 0xef, 0xfe,
0x4d, 0x89, 0x2d, 0xf4, 0xe8, 0x3a, 0xc5, 0xc1, 0xae, 0x60, 0x26, 0x0f, 0x5b, 0xe8, 0x29, 0x1c,
0x6c, 0x9d, 0x8c, 0x8c, 0x36, 0x33, 0x24, 0x6e, 0x7d, 0x9d, 0x61, 0x0b, 0x3d, 0x81, 0x8e, 0x32,
0x36, 0x3a, 0x31, 0x7a, 0xb6, 0x56, 0xbf, 0xe6, 0x85, 0x1e, 0x43, 0x57, 0x1b, 0xc7, 0x1c, 0xdd,
0x79, 0xd9, 0xad, 0xab, 0x32, 0x6c, 0x4d, 0x8e, 0x7f, 0x6c, 0x86, 0xf6, 0xcf, 0xcd, 0xd0, 0xfe,
0xb5, 0x19, 0xda, 0x5f, 0x7f, 0x0f, 0xad, 0x69, 0x47, 0x92, 0x3f, 0xf8, 0x13, 0x00, 0x00, 0xff,
0xff, 0x38, 0x9d, 0x1e, 0x82, 0x4e, 0x05, 0x00, 0x00,
// 634 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x8c, 0x54, 0xcd, 0x6e, 0xd3, 0x4c,
0x14, 0x75, 0xfe, 0x93, 0xfb, 0x35, 0x69, 0xbf, 0x51, 0x15, 0x8c, 0x11, 0xa1, 0xcc, 0xaa, 0x2b,
0x17, 0x15, 0x10, 0x6c, 0xa0, 0x4a, 0xeb, 0x2e,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 0xca, 0x52, 0x6c, 0x1c, 0xef, 0xfc, 0xb8, 0x9c, 0x34, 0x7e, 0x5e, 0x4e, 0x1a,
0xbf, 0x2e, 0x27, 0x8d, 0x6f, 0xbf, 0x27, 0xc6, 0xac, 0x2b, 0xc8, 0x1f, 0xfe, 0x09, 0x00, 0x00,
0xff, 0xff, 0x14, 0xf9, 0x10, 0x64, 0xf9, 0x05, 0x00, 0x00,
}
// Reference imports to suppress errors if they are not otherwise used.
@@ -753,6 +860,7 @@ const _ = grpc.SupportPackageIsVersion4
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.
type ThingsServiceClient interface {
CanAccessByKey(ctx context.Context, in *AccessByKeyReq, opts ...grpc.CallOption) (*ThingID, error)
IsChannelOwner(ctx context.Context, in *ChannelOwnerReq, opts ...grpc.CallOption) (*empty.Empty, error)
CanAccessByID(ctx context.Context, in *AccessByIDReq, opts ...grpc.CallOption) (*empty.Empty, error)
Identify(ctx context.Context, in *Token, opts ...grpc.CallOption) (*ThingID, error)
}
@@ -774,6 +882,15 @@ func (c *thingsServiceClient) CanAccessByKey(ctx context.Context, in *AccessByKe
return out, nil
}
func (c *thingsServiceClient) IsChannelOwner(ctx context.Context, in *ChannelOwnerReq, opts ...grpc.CallOption) (*empty.Empty, error) {
out := new(empty.Empty)
err := c.cc.Invoke(ctx, "/mainflux.ThingsService/IsChannelOwner", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *thingsServiceClient) CanAccessByID(ctx context.Context, in *AccessByIDReq, opts ...grpc.CallOption) (*empty.Empty, error) {
out := new(empty.Empty)
err := c.cc.Invoke(ctx, "/mainflux.ThingsService/CanAccessByID", in, out, opts...)
@@ -795,6 +912,7 @@ func (c *thingsServiceClient) Identify(ctx context.Context, in *Token, opts ...g
// ThingsServiceServer is the server API for ThingsService service.
type ThingsServiceServer interface {
CanAccessByKey(context.Context, *AccessByKeyReq) (*ThingID, error)
IsChannelOwner(context.Context, *ChannelOwnerReq) (*empty.Empty, error)
CanAccessByID(context.Context, *AccessByIDReq) (*empty.Empty, error)
Identify(context.Context, *Token) (*ThingID, error)
}
@@ -806,6 +924,9 @@ type UnimplementedThingsServiceServer struct {
func (*UnimplementedThingsServiceServer) CanAccessByKey(ctx context.Context, req *AccessByKeyReq) (*ThingID, error) {
return nil, status.Errorf(codes.Unimplemented, "method CanAccessByKey not implemented")
}
func (*UnimplementedThingsServiceServer) IsChannelOwner(ctx context.Context, req *ChannelOwnerReq) (*empty.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method IsChannelOwner not implemented")
}
func (*UnimplementedThingsServiceServer) CanAccessByID(ctx context.Context, req *AccessByIDReq) (*empty.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method CanAccessByID not implemented")
}
@@ -835,6 +956,24 @@ func _ThingsService_CanAccessByKey_Handler(srv interface{}, ctx context.Context,
return interceptor(ctx, in, info, handler)
}
func _ThingsService_IsChannelOwner_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ChannelOwnerReq)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(ThingsServiceServer).IsChannelOwner(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/mainflux.ThingsService/IsChannelOwner",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(ThingsServiceServer).IsChannelOwner(ctx, req.(*ChannelOwnerReq))
}
return interceptor(ctx, in, info, handler)
}
func _ThingsService_CanAccessByID_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(AccessByIDReq)
if err := dec(in); err != nil {
@@ -879,6 +1018,10 @@ var _ThingsService_serviceDesc = grpc.ServiceDesc{
MethodName: "CanAccessByKey",
Handler: _ThingsService_CanAccessByKey_Handler,
},
{
MethodName: "IsChannelOwner",
Handler: _ThingsService_IsChannelOwner_Handler,
},
{
MethodName: "CanAccessByID",
Handler: _ThingsService_CanAccessByID_Handler,
@@ -1149,6 +1292,47 @@ func (m *AccessByKeyReq) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *ChannelOwnerReq) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ChannelOwnerReq) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ChannelOwnerReq) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.ChanID) > 0 {
i -= len(m.ChanID)
copy(dAtA[i:], m.ChanID)
i = encodeVarintAuth(dAtA, i, uint64(len(m.ChanID)))
i--
dAtA[i] = 0x12
}
if len(m.Owner) > 0 {
i -= len(m.Owner)
copy(dAtA[i:], m.Owner)
i = encodeVarintAuth(dAtA, i, uint64(len(m.Owner)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *ThingID) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
@@ -1183,6 +1367,40 @@ func (m *ThingID) MarshalToSizedBuffer(dAtA []byte) (int, error) {
return len(dAtA) - i, nil
}
func (m *ChannelID) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
n, err := m.MarshalToSizedBuffer(dAtA[:size])
if err != nil {
return nil, err
}
return dAtA[:n], nil
}
func (m *ChannelID) MarshalTo(dAtA []byte) (int, error) {
size := m.Size()
return m.MarshalToSizedBuffer(dAtA[:size])
}
func (m *ChannelID) MarshalToSizedBuffer(dAtA []byte) (int, error) {
i := len(dAtA)
_ = i
var l int
_ = l
if m.XXX_unrecognized != nil {
i -= len(m.XXX_unrecognized)
copy(dAtA[i:], m.XXX_unrecognized)
}
if len(m.Value) > 0 {
i -= len(m.Value)
copy(dAtA[i:], m.Value)
i = encodeVarintAuth(dAtA, i, uint64(len(m.Value)))
i--
dAtA[i] = 0xa
}
return len(dAtA) - i, nil
}
func (m *AccessByIDReq) Marshal() (dAtA []byte, err error) {
size := m.Size()
dAtA = make([]byte, size)
@@ -1625,6 +1843,26 @@ func (m *AccessByKeyReq) Size() (n int) {
return n
}
func (m *ChannelOwnerReq) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Owner)
if l > 0 {
n += 1 + l + sovAuth(uint64(l))
}
l = len(m.ChanID)
if l > 0 {
n += 1 + l + sovAuth(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *ThingID) Size() (n int) {
if m == nil {
return 0
@@ -1641,6 +1879,22 @@ func (m *ThingID) Size() (n int) {
return n
}
func (m *ChannelID) Size() (n int) {
if m == nil {
return 0
}
var l int
_ = l
l = len(m.Value)
if l > 0 {
n += 1 + l + sovAuth(uint64(l))
}
if m.XXX_unrecognized != nil {
n += len(m.XXX_unrecognized)
}
return n
}
func (m *AccessByIDReq) Size() (n int) {
if m == nil {
return 0
@@ -1968,6 +2222,124 @@ func (m *AccessByKeyReq) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *ChannelOwnerReq) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAuth
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ChannelOwnerReq: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ChannelOwnerReq: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Owner", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAuth
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthAuth
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthAuth
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Owner = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
case 2:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field ChanID", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAuth
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthAuth
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthAuth
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.ChanID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipAuth(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthAuth
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthAuth
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *ThingID) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
@@ -2054,6 +2426,92 @@ func (m *ThingID) Unmarshal(dAtA []byte) error {
}
return nil
}
func (m *ChannelID) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
for iNdEx < l {
preIndex := iNdEx
var wire uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAuth
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
wire |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
fieldNum := int32(wire >> 3)
wireType := int(wire & 0x7)
if wireType == 4 {
return fmt.Errorf("proto: ChannelID: wiretype end group for non-group")
}
if fieldNum <= 0 {
return fmt.Errorf("proto: ChannelID: illegal tag %d (wire type %d)", fieldNum, wire)
}
switch fieldNum {
case 1:
if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Value", wireType)
}
var stringLen uint64
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowAuth
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
stringLen |= uint64(b&0x7F) << shift
if b < 0x80 {
break
}
}
intStringLen := int(stringLen)
if intStringLen < 0 {
return ErrInvalidLengthAuth
}
postIndex := iNdEx + intStringLen
if postIndex < 0 {
return ErrInvalidLengthAuth
}
if postIndex > l {
return io.ErrUnexpectedEOF
}
m.Value = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex
default:
iNdEx = preIndex
skippy, err := skipAuth(dAtA[iNdEx:])
if err != nil {
return err
}
if skippy < 0 {
return ErrInvalidLengthAuth
}
if (iNdEx + skippy) < 0 {
return ErrInvalidLengthAuth
}
if (iNdEx + skippy) > l {
return io.ErrUnexpectedEOF
}
m.XXX_unrecognized = append(m.XXX_unrecognized, dAtA[iNdEx:iNdEx+skippy]...)
iNdEx += skippy
}
}
if iNdEx > l {
return io.ErrUnexpectedEOF
}
return nil
}
func (m *AccessByIDReq) Unmarshal(dAtA []byte) error {
l := len(dAtA)
iNdEx := 0
+10
View File
@@ -9,6 +9,7 @@ import "google/protobuf/empty.proto";
service ThingsService {
rpc CanAccessByKey(AccessByKeyReq) returns (ThingID) {}
rpc IsChannelOwner(ChannelOwnerReq) returns (google.protobuf.Empty) {}
rpc CanAccessByID(AccessByIDReq) returns (google.protobuf.Empty) {}
rpc Identify(Token) returns (ThingID) {}
}
@@ -26,10 +27,19 @@ message AccessByKeyReq {
string chanID = 2;
}
message ChannelOwnerReq {
string owner = 1;
string chanID = 2;
}
message ThingID {
string value = 1;
}
message ChannelID {
string value = 1;
}
message AccessByIDReq {
string thingID = 1;
string chanID = 2;
+4
View File
@@ -218,6 +218,10 @@ func (svc *mainfluxThings) CanAccessByID(context.Context, string, string) error
panic("not implemented")
}
func (svc *mainfluxThings) IsChannelOwner(context.Context, string, string) error {
panic("not implemented")
}
func (svc *mainfluxThings) Identify(context.Context, string) (string, error) {
panic("not implemented")
}
+4
View File
@@ -54,6 +54,10 @@ func (tc thingsClient) CanAccessByID(context.Context, *mainflux.AccessByIDReq, .
panic("not implemented")
}
func (tc thingsClient) IsChannelOwner(context.Context, *mainflux.ChannelOwnerReq, ...grpc.CallOption) (*empty.Empty, error) {
panic("not implemented")
}
func (tc thingsClient) Identify(ctx context.Context, req *mainflux.Token, opts ...grpc.CallOption) (*mainflux.ThingID, error) {
panic("not implemented")
}
+4
View File
@@ -42,6 +42,10 @@ func (svc thingsServiceMock) CanAccessByID(context.Context, *mainflux.AccessByID
panic("not implemented")
}
func (svc thingsServiceMock) IsChannelOwner(context.Context, *mainflux.ChannelOwnerReq, ...grpc.CallOption) (*empty.Empty, error) {
panic("not implemented")
}
func (svc thingsServiceMock) Identify(context.Context, *mainflux.Token, ...grpc.CallOption) (*mainflux.ThingID, error) {
panic("not implemented")
}
+1 -1
View File
@@ -1,7 +1,7 @@
# This script contains commands to be executed by the CI tool.
NPROC=$(nproc)
GO_VERSION=1.14.4
PROTOC_VERSION=3.11.4
PROTOC_VERSION=3.12.3
PROTOC_GEN_VERSION=v1.4.2
PROTOC_GOFAST_VERSION=v1.3.1
GRPC_VERSION=v1.29.1
+25
View File
@@ -22,6 +22,7 @@ type grpcClient struct {
timeout time.Duration
canAccessByKey endpoint.Endpoint
canAccessByID endpoint.Endpoint
isChannelOwner endpoint.Endpoint
identify endpoint.Endpoint
}
@@ -47,6 +48,14 @@ func NewClient(conn *grpc.ClientConn, tracer opentracing.Tracer, timeout time.Du
decodeEmptyResponse,
empty.Empty{},
).Endpoint()),
isChannelOwner: kitot.TraceClient(tracer, "is_channel_owner")(kitgrpc.NewClient(
conn,
svcName,
"IsChannelOwner",
encodeIsChannelOwner,
decodeEmptyResponse,
empty.Empty{},
).Endpoint()),
identify: kitot.TraceClient(tracer, "identify")(kitgrpc.NewClient(
conn,
svcName,
@@ -86,6 +95,17 @@ func (client grpcClient) CanAccessByID(ctx context.Context, req *mainflux.Access
return &empty.Empty{}, er.err
}
func (client grpcClient) IsChannelOwner(ctx context.Context, req *mainflux.ChannelOwnerReq, _ ...grpc.CallOption) (*empty.Empty, error) {
ar := channelOwnerReq{owner: req.GetOwner(), chanID: req.GetChanID()}
res, err := client.isChannelOwner(ctx, ar)
if err != nil {
return nil, err
}
er := res.(emptyRes)
return &empty.Empty{}, er.err
}
func (client grpcClient) Identify(ctx context.Context, req *mainflux.Token, _ ...grpc.CallOption) (*mainflux.ThingID, error) {
ctx, cancel := context.WithTimeout(ctx, client.timeout)
defer cancel()
@@ -109,6 +129,11 @@ func encodeCanAccessByIDRequest(_ context.Context, grpcReq interface{}) (interfa
return &mainflux.AccessByIDReq{ThingID: req.thingID, ChanID: req.chanID}, nil
}
func encodeIsChannelOwner(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(channelOwnerReq)
return &mainflux.ChannelOwnerReq{Owner: req.owner, ChanID: req.chanID}, nil
}
func encodeIdentifyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(identifyReq)
return &mainflux.Token{Value: req.key}, nil
+12
View File
@@ -37,6 +37,18 @@ func canAccessByIDEndpoint(svc things.Service) endpoint.Endpoint {
}
}
func isChannelOwnerEndpoint(svc things.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(channelOwnerReq)
if err := req.validate(); err != nil {
return nil, err
}
err := svc.IsChannelOwner(ctx, req.chanID, req.owner)
return emptyRes{err: err}, err
}
}
func identifyEndpoint(svc things.Service) endpoint.Endpoint {
return func(ctx context.Context, request interface{}) (interface{}, error) {
req := request.(identifyReq)
+13
View File
@@ -31,6 +31,19 @@ func (req accessByIDReq) validate() error {
return nil
}
type channelOwnerReq struct {
owner string
chanID string
}
func (req channelOwnerReq) validate() error {
if req.owner == "" || req.chanID == "" {
return things.ErrMalformedEntity
}
return nil
}
type identifyReq struct {
key string
}
+20
View File
@@ -21,6 +21,7 @@ var _ mainflux.ThingsServiceServer = (*grpcServer)(nil)
type grpcServer struct {
canAccessByKey kitgrpc.Handler
canAccessByID kitgrpc.Handler
isChannelOwner kitgrpc.Handler
identify kitgrpc.Handler
}
@@ -37,6 +38,11 @@ func NewServer(tracer opentracing.Tracer, svc things.Service) mainflux.ThingsSer
decodeCanAccessByIDRequest,
encodeEmptyResponse,
),
isChannelOwner: kitgrpc.NewServer(
isChannelOwnerEndpoint(svc),
decodeIsChannelOwnerRequest,
encodeEmptyResponse,
),
identify: kitgrpc.NewServer(
kitot.TraceServer(tracer, "identify")(identifyEndpoint(svc)),
decodeIdentifyRequest,
@@ -63,6 +69,15 @@ func (gs *grpcServer) CanAccessByID(ctx context.Context, req *mainflux.AccessByI
return res.(*empty.Empty), nil
}
func (gs *grpcServer) IsChannelOwner(ctx context.Context, req *mainflux.ChannelOwnerReq) (*empty.Empty, error) {
_, res, err := gs.isChannelOwner.ServeGRPC(ctx, req)
if err != nil {
return nil, encodeError(err)
}
return res.(*empty.Empty), nil
}
func (gs *grpcServer) Identify(ctx context.Context, req *mainflux.Token) (*mainflux.ThingID, error) {
_, res, err := gs.identify.ServeGRPC(ctx, req)
if err != nil {
@@ -82,6 +97,11 @@ func decodeCanAccessByIDRequest(_ context.Context, grpcReq interface{}) (interfa
return accessByIDReq{thingID: req.GetThingID(), chanID: req.GetChanID()}, nil
}
func decodeIsChannelOwnerRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(*mainflux.ChannelOwnerReq)
return channelOwnerReq{owner: req.GetOwner(), chanID: req.GetChanID()}, nil
}
func decodeIdentifyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(*mainflux.Token)
return identifyReq{key: req.GetValue()}, nil
+14
View File
@@ -253,6 +253,20 @@ func (lm *loggingMiddleware) CanAccessByID(ctx context.Context, chanID, thingID
return lm.svc.CanAccessByID(ctx, chanID, thingID)
}
func (lm *loggingMiddleware) IsChannelOwner(ctx context.Context, owner, chanID string) (err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method is_channel_owner for channel %s and user %s took %s to complete", chanID, owner, time.Since(begin))
if err != nil {
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err))
return
}
lm.logger.Info(fmt.Sprintf("%s without errors.", message))
}(time.Now())
return lm.svc.IsChannelOwner(ctx, owner, chanID)
}
func (lm *loggingMiddleware) Identify(ctx context.Context, key string) (id string, err error) {
defer func(begin time.Time) {
message := fmt.Sprintf("Method identify for token %s and thing %s took %s to complete", key, id, time.Since(begin))
+9
View File
@@ -184,6 +184,15 @@ func (ms *metricsMiddleware) CanAccessByID(ctx context.Context, chanID, thingID
return ms.svc.CanAccessByID(ctx, chanID, thingID)
}
func (ms *metricsMiddleware) IsChannelOwner(ctx context.Context, owner, chanID string) error {
defer func(begin time.Time) {
ms.counter.With("method", "is_channel_owner").Add(1)
ms.latency.With("method", "is_channel_owner").Observe(time.Since(begin).Seconds())
}(time.Now())
return ms.svc.CanAccessByID(ctx, owner, chanID)
}
func (ms *metricsMiddleware) Identify(ctx context.Context, key string) (string, error) {
defer func(begin time.Time) {
ms.counter.With("method", "identify").Add(1)
+4
View File
@@ -237,6 +237,10 @@ func (es eventStore) CanAccessByID(ctx context.Context, chanID string, thingID s
return es.svc.CanAccessByID(ctx, chanID, thingID)
}
func (es eventStore) IsChannelOwner(ctx context.Context, owner, chanID string) error {
return es.svc.IsChannelOwner(ctx, owner, chanID)
}
func (es eventStore) Identify(ctx context.Context, key string) (string, error) {
return es.svc.Identify(ctx, key)
}
+13 -3
View File
@@ -54,7 +54,7 @@ var (
// Service specifies an API that must be fullfiled by the domain service
// implementation, and all of its decorators (e.g. logging & metrics).
type Service interface {
// CreateThings adds a list of things to the user identified by the provided key.
// CreateThings adds things to the user identified by the provided key.
CreateThings(ctx context.Context, token string, things ...Thing) ([]Thing, error)
// UpdateThing updates the thing identified by the provided ID, that
@@ -82,7 +82,7 @@ type Service interface {
// belongs to the user identified by the provided key.
RemoveThing(ctx context.Context, token, id string) error
// CreateChannels adds a list of channels to the user identified by the provided key.
// CreateChannels adds channels to the user identified by the provided key.
CreateChannels(ctx context.Context, token string, channels ...Channel) ([]Channel, error)
// UpdateChannel updates the channel identified by the provided ID, that
@@ -121,6 +121,10 @@ type Service interface {
// the given thing and returns error if it cannot.
CanAccessByID(ctx context.Context, chanID, thingID string) error
// IsChannelOwner determines whether the channel can be accessed by
// the given user and returns error if it cannot.
IsChannelOwner(ctx context.Context, owner, chanID string) error
// Identify returns thing ID for given thing key.
Identify(ctx context.Context, key string) (string, error)
@@ -377,6 +381,13 @@ func (ts *thingsService) CanAccessByID(ctx context.Context, chanID, thingID stri
return nil
}
func (ts *thingsService) IsChannelOwner(ctx context.Context, owner, chanID string) error {
if _, err := ts.channels.RetrieveByID(ctx, owner, chanID); err != nil {
return err
}
return nil
}
func (ts *thingsService) Identify(ctx context.Context, key string) (string, error) {
id, err := ts.thingCache.ID(ctx, key)
if err == nil {
@@ -431,7 +442,6 @@ func (ts *thingsService) ListGroups(ctx context.Context, token string, level uin
return groups.GroupPage{}, errors.Wrap(ErrUnauthorizedAccess, err)
}
return ts.groups.RetrieveAll(ctx, level, gm)
}
func (ts *thingsService) ListParents(ctx context.Context, token string, childID string, level uint64, gm groups.Metadata) (groups.GroupPage, error) {
+35
View File
@@ -22,6 +22,7 @@ const (
wrongValue = "wrong-value"
email = "user@example.com"
token = "token"
token2 = "token2"
n = uint64(10)
)
@@ -1232,6 +1233,40 @@ func TestCanAccessByID(t *testing.T) {
}
}
func TestIsChannelOwner(t *testing.T) {
svc := newService(map[string]string{token: email, token2: "john.doe@email.net"})
chs, err := svc.CreateChannels(context.Background(), token, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
ownedCh := chs[0]
chs, err = svc.CreateChannels(context.Background(), token2, channel)
require.Nil(t, err, fmt.Sprintf("unexpected error: %s\n", err))
nonOwnedCh := chs[0]
cases := map[string]struct {
channel string
err error
}{
"user owns channel": {
channel: ownedCh.ID,
err: nil,
},
"user does not own channel": {
channel: nonOwnedCh.ID,
err: things.ErrNotFound,
},
"access to non-existing channel": {
channel: wrongID,
err: things.ErrNotFound,
},
}
for desc, tc := range cases {
err := svc.IsChannelOwner(context.Background(), email, tc.channel)
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", desc, tc.err, err))
}
}
func TestIdentify(t *testing.T) {
svc := newService(map[string]string{token: email})