Skip to content

Commit

Permalink
MG-2060 - Remove int32 type in policy interface (#2131)
Browse files Browse the repository at this point in the history
Signed-off-by: nyagamunene <[email protected]>
  • Loading branch information
nyagamunene authored Apr 4, 2024
1 parent 8b930e8 commit 987c853
Show file tree
Hide file tree
Showing 17 changed files with 120 additions and 148 deletions.
24 changes: 12 additions & 12 deletions auth.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions auth.proto
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ message ListObjectsReq {
string object = 7;
string object_type = 8;
string nextPageToken = 9;
int32 limit = 10;
uint64 limit = 10;
}

message ListObjectsRes {
Expand All @@ -153,7 +153,7 @@ message CountObjectsReq {
string nextPageToken = 9;
}

message CountObjectsRes { int64 count = 1; }
message CountObjectsRes { uint64 count = 1; }

message ListSubjectsReq {
string domain = 1;
Expand All @@ -165,7 +165,7 @@ message ListSubjectsReq {
string object = 7;
string object_type = 8;
string nextPageToken = 9;
int32 limit = 10;
uint64 limit = 10;
}

message ListSubjectsRes {
Expand All @@ -185,7 +185,7 @@ message CountSubjectsReq {
string nextPageToken = 9;
}

message CountSubjectsRes { int64 count = 1; }
message CountSubjectsRes { uint64 count = 1; }

message ListPermissionsReq {
string domain = 1;
Expand Down
8 changes: 4 additions & 4 deletions auth/api/grpc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,12 +555,12 @@ func (client grpcClient) CountObjects(ctx context.Context, in *magistrala.CountO
}

cp := res.(countObjectsRes)
return &magistrala.CountObjectsRes{Count: int64(cp.count)}, nil
return &magistrala.CountObjectsRes{Count: cp.count}, nil
}

func decodeCountObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(*magistrala.CountObjectsRes)
return countObjectsRes{count: int(res.GetCount())}, nil
return countObjectsRes{count: res.GetCount()}, nil
}

func encodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
Expand Down Expand Up @@ -655,12 +655,12 @@ func (client grpcClient) CountSubjects(ctx context.Context, in *magistrala.Count
}

cp := res.(countSubjectsRes)
return &magistrala.CountSubjectsRes{Count: int64(cp.count)}, err
return &magistrala.CountSubjectsRes{Count: cp.count}, err
}

func decodeCountSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(*magistrala.CountSubjectsRes)
return countSubjectsRes{count: int(res.GetCount())}, nil
return countSubjectsRes{count: res.GetCount()}, nil
}

func encodeCountSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
Expand Down
4 changes: 2 additions & 2 deletions auth/api/grpc/endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ func TestCountObects(t *testing.T) {
},
}
for _, tc := range cases {
repoCall := svc.On("CountObjects", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(int(tc.countObjectsRes.Count), tc.err)
repoCall := svc.On("CountObjects", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.countObjectsRes.Count, tc.err)
apr, err := client.CountObjects(context.Background(), tc.countObjectsReq)
if apr != nil {
assert.Equal(t, tc.countObjectsRes, apr, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.countObjectsRes, apr))
Expand Down Expand Up @@ -868,7 +868,7 @@ func TestCountSubjects(t *testing.T) {
},
}
for _, tc := range cases {
repoCall := svc.On("CountSubjects", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(int(tc.countSubjectsRes.Count), tc.err)
repoCall := svc.On("CountSubjects", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(tc.countSubjectsRes.Count, tc.err)
apr, err := client.CountSubjects(context.Background(), tc.countSubjectsReq)
if apr != nil {
assert.Equal(t, tc.countSubjectsRes, apr, fmt.Sprintf("%s: expected %v got %v", tc.desc, tc.countSubjectsRes, apr))
Expand Down
4 changes: 2 additions & 2 deletions auth/api/grpc/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ type listObjectsReq struct {
ObjectType string
Object string
NextPageToken string
Limit int32
Limit uint64
}

type countObjectsReq struct {
Expand All @@ -135,7 +135,7 @@ type listSubjectsReq struct {
ObjectType string
Object string
NextPageToken string
Limit int32
Limit uint64
}

type countSubjectsReq struct {
Expand Down
4 changes: 2 additions & 2 deletions auth/api/grpc/responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type listObjectsRes struct {
}

type countObjectsRes struct {
count int
count uint64
}

type listSubjectsRes struct {
Expand All @@ -50,7 +50,7 @@ type listSubjectsRes struct {
}

type countSubjectsRes struct {
count int
count uint64
}

type listPermissionsRes struct {
Expand Down
4 changes: 2 additions & 2 deletions auth/api/grpc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func decodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interfac

func encodeCountObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(countObjectsRes)
return &magistrala.CountObjectsRes{Count: int64(res.count)}, nil
return &magistrala.CountObjectsRes{Count: res.count}, nil
}

func decodeListSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
Expand Down Expand Up @@ -483,7 +483,7 @@ func decodeCountSubjectsRequest(_ context.Context, grpcReq interface{}) (interfa

func encodeCountSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
res := grpcRes.(countSubjectsRes)
return &magistrala.CountSubjectsRes{Count: int64(res.count)}, nil
return &magistrala.CountSubjectsRes{Count: res.count}, nil
}

func decodeListPermissionsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
Expand Down
8 changes: 4 additions & 4 deletions auth/api/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func LoggingMiddleware(svc auth.Service, logger *slog.Logger) auth.Service {
return &loggingMiddleware{logger, svc}
}

func (lm *loggingMiddleware) ListObjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit int32) (p auth.PolicyPage, err error) {
func (lm *loggingMiddleware) ListObjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit uint64) (p auth.PolicyPage, err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
Expand Down Expand Up @@ -65,7 +65,7 @@ func (lm *loggingMiddleware) ListAllObjects(ctx context.Context, pr auth.PolicyR
return lm.svc.ListAllObjects(ctx, pr)
}

func (lm *loggingMiddleware) CountObjects(ctx context.Context, pr auth.PolicyReq) (count int, err error) {
func (lm *loggingMiddleware) CountObjects(ctx context.Context, pr auth.PolicyReq) (count uint64, err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
Expand All @@ -80,7 +80,7 @@ func (lm *loggingMiddleware) CountObjects(ctx context.Context, pr auth.PolicyReq
return lm.svc.CountObjects(ctx, pr)
}

func (lm *loggingMiddleware) ListSubjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit int32) (p auth.PolicyPage, err error) {
func (lm *loggingMiddleware) ListSubjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit uint64) (p auth.PolicyPage, err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
Expand Down Expand Up @@ -118,7 +118,7 @@ func (lm *loggingMiddleware) ListAllSubjects(ctx context.Context, pr auth.Policy
return lm.svc.ListAllSubjects(ctx, pr)
}

func (lm *loggingMiddleware) CountSubjects(ctx context.Context, pr auth.PolicyReq) (count int, err error) {
func (lm *loggingMiddleware) CountSubjects(ctx context.Context, pr auth.PolicyReq) (count uint64, err error) {
defer func(begin time.Time) {
args := []any{
slog.String("duration", time.Since(begin).String()),
Expand Down
8 changes: 4 additions & 4 deletions auth/api/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func MetricsMiddleware(svc auth.Service, counter metrics.Counter, latency metric
}
}

func (ms *metricsMiddleware) ListObjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit int32) (p auth.PolicyPage, err error) {
func (ms *metricsMiddleware) ListObjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit uint64) (p auth.PolicyPage, err error) {
defer func(begin time.Time) {
ms.counter.With("method", "list_objects").Add(1)
ms.latency.With("method", "list_objects").Observe(time.Since(begin).Seconds())
Expand All @@ -48,15 +48,15 @@ func (ms *metricsMiddleware) ListAllObjects(ctx context.Context, pr auth.PolicyR
return ms.svc.ListAllObjects(ctx, pr)
}

func (ms *metricsMiddleware) CountObjects(ctx context.Context, pr auth.PolicyReq) (count int, err error) {
func (ms *metricsMiddleware) CountObjects(ctx context.Context, pr auth.PolicyReq) (count uint64, err error) {
defer func(begin time.Time) {
ms.counter.With("method", "count_objects").Add(1)
ms.latency.With("method", "count_objects").Observe(time.Since(begin).Seconds())
}(time.Now())
return ms.svc.CountObjects(ctx, pr)
}

func (ms *metricsMiddleware) ListSubjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit int32) (p auth.PolicyPage, err error) {
func (ms *metricsMiddleware) ListSubjects(ctx context.Context, pr auth.PolicyReq, nextPageToken string, limit uint64) (p auth.PolicyPage, err error) {
defer func(begin time.Time) {
ms.counter.With("method", "list_subjects").Add(1)
ms.latency.With("method", "list_subjects").Observe(time.Since(begin).Seconds())
Expand All @@ -74,7 +74,7 @@ func (ms *metricsMiddleware) ListAllSubjects(ctx context.Context, pr auth.Policy
return ms.svc.ListAllSubjects(ctx, pr)
}

func (ms *metricsMiddleware) CountSubjects(ctx context.Context, pr auth.PolicyReq) (count int, err error) {
func (ms *metricsMiddleware) CountSubjects(ctx context.Context, pr auth.PolicyReq) (count uint64, err error) {
defer func(begin time.Time) {
ms.counter.With("method", "count_subjects").Add(1)
ms.latency.With("method", "count_subjects").Observe(time.Since(begin).Seconds())
Expand Down
Loading

0 comments on commit 987c853

Please sign in to comment.