Skip to content

Commit

Permalink
MG-2533 - Fix Linting Issues in Proto Files (absmach#2534)
Browse files Browse the repository at this point in the history
Signed-off-by: JeffMboya <[email protected]>
  • Loading branch information
JeffMboya authored Nov 18, 2024
1 parent c039b0a commit d9f3bca
Show file tree
Hide file tree
Showing 14 changed files with 150 additions and 147 deletions.
207 changes: 104 additions & 103 deletions auth.pb.go

Large diffs are not rendered by default.

28 changes: 15 additions & 13 deletions auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@ service DomainsService {
// field can be used to determine how to validate the token.
// Also, different tokens can be encoded in different ways.
message Token {
string accessToken = 1;
optional string refreshToken = 2;
string accessType = 3;
string access_token = 1;
optional string refresh_token = 2;
string access_type = 3;
}

message AuthNReq {
string token = 1;
string token = 1;
}

message AuthNRes {
string id = 1; // IMPROVEMENT NOTE: change name from "id" to "subject" , sub in jwt = user id + domain id //
string user_id = 2; // user id
string domain_id = 3; // domain id
string id = 1; // change "id" to "subject", sub in jwt = user + domain id
string user_id = 2; // user id
string domain_id = 3; // domain id
}

message IssueReq {
Expand Down Expand Up @@ -77,16 +77,18 @@ message AuthZRes {
string id = 2;
}

message DeleteUserRes { bool deleted = 1; }
message DeleteUserRes {
bool deleted = 1;
}

message DeleteUserReq{
string id = 1;
message DeleteUserReq {
string id = 1;
}

message ThingsAuthzReq {
string channelID = 1;
string thingID = 2;
string thingKey = 3;
string channel_id = 1;
string thing_id = 2;
string thing_key = 3;
string permission = 4;
}

Expand Down
6 changes: 3 additions & 3 deletions coap/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (svc *adapterService) Publish(ctx context.Context, key string, msg *messagi
ar := &magistrala.ThingsAuthzReq{
Permission: policies.PublishPermission,
ThingKey: key,
ChannelID: msg.GetChannel(),
ChannelId: msg.GetChannel(),
}
res, err := svc.things.Authorize(ctx, ar)
if err != nil {
Expand All @@ -73,7 +73,7 @@ func (svc *adapterService) Subscribe(ctx context.Context, key, chanID, subtopic
ar := &magistrala.ThingsAuthzReq{
Permission: policies.SubscribePermission,
ThingKey: key,
ChannelID: chanID,
ChannelId: chanID,
}
res, err := svc.things.Authorize(ctx, ar)
if err != nil {
Expand All @@ -98,7 +98,7 @@ func (svc *adapterService) Unsubscribe(ctx context.Context, key, chanID, subtopi
ar := &magistrala.ThingsAuthzReq{
Permission: policies.SubscribePermission,
ThingKey: key,
ChannelID: chanID,
ChannelId: chanID,
}
res, err := svc.things.Authorize(ctx, ar)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion http/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func TestPublish(t *testing.T) {

defer ts.Close()

things.On("Authorize", mock.Anything, &magistrala.ThingsAuthzReq{ThingKey: thingKey, ChannelID: chanID, Permission: "publish"}).Return(&magistrala.ThingsAuthzRes{Authorized: true, Id: ""}, nil)
things.On("Authorize", mock.Anything, &magistrala.ThingsAuthzReq{ThingKey: thingKey, ChannelId: chanID, Permission: "publish"}).Return(&magistrala.ThingsAuthzRes{Authorized: true, Id: ""}, nil)
things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.ThingsAuthzRes{Authorized: false, Id: ""}, nil)

cases := map[string]struct {
Expand Down
2 changes: 1 addition & 1 deletion http/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) e
}
ar := &magistrala.ThingsAuthzReq{
ThingKey: tok,
ChannelID: msg.Channel,
ChannelId: msg.Channel,
Permission: policies.PublishPermission,
}
res, err := h.things.Authorize(ctx, ar)
Expand Down
2 changes: 1 addition & 1 deletion mqtt/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ func (h *handler) authAccess(ctx context.Context, password, topic, action string
ar := &magistrala.ThingsAuthzReq{
Permission: action,
ThingKey: password,
ChannelID: chanID,
ChannelId: chanID,
}
res, err := h.things.Authorize(ctx, ar)
if err != nil {
Expand Down
12 changes: 6 additions & 6 deletions pkg/messaging/message.proto
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ option go_package = "./messaging";

// Message represents a message emitted by the Magistrala adapters layer.
message Message {
string channel = 1;
string subtopic = 2;
string publisher = 3;
string protocol = 4;
bytes payload = 5;
int64 created = 6; // Unix timestamp in nanoseconds
string channel = 1;
string subtopic = 2;
string publisher = 3;
string protocol = 4;
bytes payload = 5;
int64 created = 6; // Unix timestamp in nanoseconds
}
2 changes: 1 addition & 1 deletion readers/api/transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func authorize(ctx context.Context, req listMessagesReq, authn mgauthn.Authentic
case req.key != "":
if _, err = things.Authorize(ctx, &magistrala.ThingsAuthzReq{
ThingKey: req.key,
ChannelID: req.chanID,
ChannelId: req.chanID,
Permission: policies.SubscribePermission,
}); err != nil {
e, ok := status.FromError(err)
Expand Down
8 changes: 4 additions & 4 deletions things/api/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ func (client grpcClient) Authorize(ctx context.Context, req *magistrala.ThingsAu
defer cancel()

res, err := client.authorize(ctx, things.AuthzReq{
ClientID: req.GetThingID(),
ClientID: req.GetThingId(),
ClientKey: req.GetThingKey(),
ChannelID: req.GetChannelID(),
ChannelID: req.GetChannelId(),
Permission: req.GetPermission(),
})
if err != nil {
Expand All @@ -70,8 +70,8 @@ func decodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{
func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(things.AuthzReq)
return &magistrala.ThingsAuthzReq{
ChannelID: req.ChannelID,
ThingID: req.ClientID,
ChannelId: req.ChannelID,
ThingId: req.ClientID,
ThingKey: req.ClientKey,
Permission: req.Permission,
}, nil
Expand Down
14 changes: 7 additions & 7 deletions things/api/grpc/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func TestAuthorize(t *testing.T) {
thingID: thingID,
req: &magistrala.ThingsAuthzReq{
ThingKey: clientKey,
ChannelID: channelID,
ChannelId: channelID,
Permission: policies.PublishPermission,
},
authorizeReq: things.AuthzReq{
Expand All @@ -89,7 +89,7 @@ func TestAuthorize(t *testing.T) {
desc: "authorize with invalid key",
req: &magistrala.ThingsAuthzReq{
ThingKey: invalid,
ChannelID: channelID,
ChannelId: channelID,
Permission: policies.PublishPermission,
},
authorizeReq: things.AuthzReq{
Expand All @@ -108,7 +108,7 @@ func TestAuthorize(t *testing.T) {
thingID: thingID,
req: &magistrala.ThingsAuthzReq{
ThingKey: clientKey,
ChannelID: channelID,
ChannelId: channelID,
Permission: policies.PublishPermission,
},
authorizeReq: things.AuthzReq{
Expand All @@ -127,7 +127,7 @@ func TestAuthorize(t *testing.T) {
thingID: thingID,
req: &magistrala.ThingsAuthzReq{
ThingKey: clientKey,
ChannelID: channelID,
ChannelId: channelID,
Permission: invalid,
},
authorizeReq: things.AuthzReq{
Expand All @@ -145,7 +145,7 @@ func TestAuthorize(t *testing.T) {
thingID: thingID,
req: &magistrala.ThingsAuthzReq{
ThingKey: clientKey,
ChannelID: invalid,
ChannelId: invalid,
Permission: policies.PublishPermission,
},
authorizeReq: things.AuthzReq{
Expand All @@ -163,7 +163,7 @@ func TestAuthorize(t *testing.T) {
thingID: thingID,
req: &magistrala.ThingsAuthzReq{
ThingKey: clientKey,
ChannelID: "",
ChannelId: "",
Permission: policies.PublishPermission,
},
authorizeReq: things.AuthzReq{
Expand All @@ -181,7 +181,7 @@ func TestAuthorize(t *testing.T) {
thingID: thingID,
req: &magistrala.ThingsAuthzReq{
ThingKey: clientKey,
ChannelID: channelID,
ChannelId: channelID,
Permission: "",
},
authorizeReq: things.AuthzReq{
Expand Down
4 changes: 2 additions & 2 deletions things/api/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ func (s *grpcServer) Authorize(ctx context.Context, req *magistrala.ThingsAuthzR
func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
req := grpcReq.(*magistrala.ThingsAuthzReq)
return authorizeReq{
ThingID: req.GetThingID(),
ThingID: req.GetThingId(),
ThingKey: req.GetThingKey(),
ChannelID: req.GetChannelID(),
ChannelID: req.GetChannelId(),
Permission: req.GetPermission(),
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion ws/adapter.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (svc *adapterService) authorize(ctx context.Context, thingKey, chanID, acti
ar := &magistrala.ThingsAuthzReq{
Permission: action,
ThingKey: thingKey,
ChannelID: chanID,
ChannelId: chanID,
}
res, err := svc.things.Authorize(ctx, ar)
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions ws/api/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ func TestHandshake(t *testing.T) {
ts, err := newProxyHTPPServer(handler, target)
require.Nil(t, err)
defer ts.Close()
things.On("Authorize", mock.Anything, &magistrala.ThingsAuthzReq{ThingKey: thingKey, ChannelID: id, Permission: "publish"}).Return(&magistrala.ThingsAuthzRes{Authorized: true, Id: "1"}, nil)
things.On("Authorize", mock.Anything, &magistrala.ThingsAuthzReq{ThingKey: thingKey, ChannelID: id, Permission: "subscribe"}).Return(&magistrala.ThingsAuthzRes{Authorized: true, Id: "2"}, nil)
things.On("Authorize", mock.Anything, &magistrala.ThingsAuthzReq{ThingKey: thingKey, ChannelId: id, Permission: "publish"}).Return(&magistrala.ThingsAuthzRes{Authorized: true, Id: "1"}, nil)
things.On("Authorize", mock.Anything, &magistrala.ThingsAuthzReq{ThingKey: thingKey, ChannelId: id, Permission: "subscribe"}).Return(&magistrala.ThingsAuthzRes{Authorized: true, Id: "2"}, nil)
things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthZRes{Authorized: false, Id: "3"}, nil)
pubsub.On("Subscribe", mock.Anything, mock.Anything).Return(nil)
pubsub.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
Expand Down
4 changes: 2 additions & 2 deletions ws/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) e
ar := &magistrala.ThingsAuthzReq{
Permission: policies.PublishPermission,
ThingKey: token,
ChannelID: chanID,
ChannelId: chanID,
}
res, err := h.things.Authorize(ctx, ar)
if err != nil {
Expand Down Expand Up @@ -232,7 +232,7 @@ func (h *handler) authAccess(ctx context.Context, password, topic, action string
ar := &magistrala.ThingsAuthzReq{
Permission: action,
ThingKey: password,
ChannelID: chanID,
ChannelId: chanID,
}
res, err := h.things.Authorize(ctx, ar)
if err != nil {
Expand Down

0 comments on commit d9f3bca

Please sign in to comment.