mirror of
https://github.com/mainflux/mainflux.git
synced 2025-05-01 13:48:56 +08:00

* Return Auth service Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Compose to run with SpiceDB and Auth svc Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth gRPC API Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove Users' policies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Groups to internal Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use shared groups in Users Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove unused code Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use pkg Groups in Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove Things groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Make imports consistent Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Groups networking Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Remove things groups-specific API Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Things Clients to the root Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Move Clients to Users root Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Temporarily remove tracing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix imports Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add buffer config for gRPC Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth type for Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use Auth for login Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add temporary solution for refresh token Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Tokenizer interface Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Updade tokens issuing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix token issuing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update JWT validator and refactor Tokenizer Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Rename access timeout Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Rename login to authenticate Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update Identify to use SubjectID Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add Auth to Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Use the Auth service for Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update auth schema Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix Auth for Groups Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add auth for addons (#14) Signed-off-by: Arvindh <arvindh91@gmail.com> Speparate Login and Refresh tokens Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Merge authN and authZ requests for things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add connect and disconnect Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update sharing Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Fix policies addition and removal Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Update relation with roels Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Add gRPC to Things Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Assign and Unassign members to group and Listing of Group members (#15) * add auth for addons Signed-off-by: Arvindh <arvindh91@gmail.com> * add assign and unassign to group Signed-off-by: Arvindh <arvindh91@gmail.com> * add group incomplete repo implementation Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Move coap mqtt and ws policies to spicedb (#16) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Remove old policies Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> NOISSUE - Things authorize to return thingID (#18) This commit modifies the authorize endpoint to the grpc endpoint to return thingID. The authorize endpoint allows adapters to get the publisher of the message. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Add Groups to users service (#17) * add assign and unassign to group Signed-off-by: Arvindh <arvindh91@gmail.com> * add group incomplete repo implementation Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users stable 1 Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users stable 2 Signed-off-by: Arvindh <arvindh91@gmail.com> * groups for users & things Signed-off-by: Arvindh <arvindh91@gmail.com> * Amend signature Signed-off-by: Arvindh <arvindh91@gmail.com> * fix merge error Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Fix es code (#21) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Fix Bugs (#20) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Test e2e (#19) * fix: connect method Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix: e2e Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * fix changes in sdk and e2e Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(docker): remove unnecessary port mapping Remove the port mapping for MQTT broker in the docker-compose.yml file. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Enable group listing Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(responses): update ChannelsPage struct The ChannelsPage struct in the responses.go file has been updated. The "Channels" field has been renamed to "Groups" to provide more accurate naming. This change ensures consistency and clarity in the codebase. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(things): add UpdateClientSecret method Add the UpdateClientSecret method to the things service. This method allows updating the client secret for a specific client identified by the provided token, id, and key parameters. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Use smaller buffers for gRPC Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Clean up tests (#22) Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add Connect Disconnect endpoints (#23) * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix bugs Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Things share with users (#25) * fix list of things in a channel and Add connect disconnect endpoint Signed-off-by: Arvindh <arvindh91@gmail.com> * add: things share with other users Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Rename gRPC Services (#24) * Rename things and users auth service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * docs: add authorization docs for gRPC services Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Rename things and users grpc services Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * Remove mainflux.env package Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: Listing of things, channels, groups, users (#26) * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> * add: listing of channels, users, groups, things Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Users (#27) * feat(groups): rename redis package to events - Renamed the `redis` package to `events` in the `internal/groups` directory. - Updated the file paths and names accordingly. - This change reflects the more accurate purpose of the package and improves code organization. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(auth): Modify identity method Change request and response of identity method Add accessToken and refreshToken to Token response Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * clean up users, remove dead code Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(users): add unit tests for user service This commit adds unit tests for the user service in the `users` package. The tests cover various scenarios and ensure the correct behavior of the service. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Add: List of user groups & removed repeating code in groups (#29) * removed repeating code in list groups Signed-off-by: Arvindh <arvindh91@gmail.com> * add: list of user group Signed-off-by: Arvindh <arvindh91@gmail.com> * fix: otel handler operator name for endpoints Signed-off-by: Arvindh <arvindh91@gmail.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Things Service (#28) * Rework things service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * add tests Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Clean Up Auth Service (#30) * clean up auth service Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> * feat(auth): remove unused import Remove the unused import of `emptypb` in `auth.pb.go`. This import is not being used in the codebase and can be safely removed. Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> --------- Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * NOISSUE - Update API docs (#31) Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Remove TODO comments and cleanup the code Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> * Update dependenices Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> --------- Signed-off-by: Arvindh <arvindh91@gmail.com> Signed-off-by: dusanb94 <dusan.borovcanin@mainflux.com> Signed-off-by: Rodney Osodo <28790446+rodneyosodo@users.noreply.github.com> Signed-off-by: rodneyosodo <blackd0t@protonmail.com> Co-authored-by: b1ackd0t <28790446+rodneyosodo@users.noreply.github.com> Co-authored-by: Arvindh <30824765+arvindh123@users.noreply.github.com>
549 lines
16 KiB
Go
549 lines
16 KiB
Go
// Copyright (c) Mainflux
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package grpc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/go-kit/kit/endpoint"
|
|
kitgrpc "github.com/go-kit/kit/transport/grpc"
|
|
"github.com/mainflux/mainflux"
|
|
"github.com/mainflux/mainflux/auth"
|
|
"google.golang.org/grpc"
|
|
)
|
|
|
|
const svcName = "mainflux.AuthService"
|
|
|
|
var _ mainflux.AuthServiceClient = (*grpcClient)(nil)
|
|
|
|
type grpcClient struct {
|
|
issue endpoint.Endpoint
|
|
login endpoint.Endpoint
|
|
refresh endpoint.Endpoint
|
|
identify endpoint.Endpoint
|
|
authorize endpoint.Endpoint
|
|
addPolicy endpoint.Endpoint
|
|
deletePolicy endpoint.Endpoint
|
|
listObjects endpoint.Endpoint
|
|
listAllObjects endpoint.Endpoint
|
|
countObjects endpoint.Endpoint
|
|
listSubjects endpoint.Endpoint
|
|
listAllSubjects endpoint.Endpoint
|
|
countSubjects endpoint.Endpoint
|
|
timeout time.Duration
|
|
}
|
|
|
|
// NewClient returns new gRPC client instance.
|
|
func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServiceClient {
|
|
return &grpcClient{
|
|
issue: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"Issue",
|
|
encodeIssueRequest,
|
|
decodeIssueResponse,
|
|
mainflux.Token{},
|
|
).Endpoint(),
|
|
login: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"Login",
|
|
encodeLoginRequest,
|
|
decodeLoginResponse,
|
|
mainflux.Token{},
|
|
).Endpoint(),
|
|
refresh: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"Refresh",
|
|
encodeRefreshRequest,
|
|
decodeRefreshResponse,
|
|
mainflux.Token{},
|
|
).Endpoint(),
|
|
identify: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"Identify",
|
|
encodeIdentifyRequest,
|
|
decodeIdentifyResponse,
|
|
mainflux.IdentityRes{},
|
|
).Endpoint(),
|
|
authorize: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"Authorize",
|
|
encodeAuthorizeRequest,
|
|
decodeAuthorizeResponse,
|
|
mainflux.AuthorizeRes{},
|
|
).Endpoint(),
|
|
addPolicy: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"AddPolicy",
|
|
encodeAddPolicyRequest,
|
|
decodeAddPolicyResponse,
|
|
mainflux.AddPolicyRes{},
|
|
).Endpoint(),
|
|
deletePolicy: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"DeletePolicy",
|
|
encodeDeletePolicyRequest,
|
|
decodeDeletePolicyResponse,
|
|
mainflux.DeletePolicyRes{},
|
|
).Endpoint(),
|
|
listObjects: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"ListObjects",
|
|
encodeListObjectsRequest,
|
|
decodeListObjectsResponse,
|
|
mainflux.ListObjectsRes{},
|
|
).Endpoint(),
|
|
listAllObjects: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"ListAllObjects",
|
|
encodeListObjectsRequest,
|
|
decodeListObjectsResponse,
|
|
mainflux.ListObjectsRes{},
|
|
).Endpoint(),
|
|
countObjects: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"CountObjects",
|
|
encodeCountObjectsRequest,
|
|
decodeCountObjectsResponse,
|
|
mainflux.CountObjectsRes{},
|
|
).Endpoint(),
|
|
listSubjects: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"ListSubjects",
|
|
encodeListSubjectsRequest,
|
|
decodeListSubjectsResponse,
|
|
mainflux.ListSubjectsRes{},
|
|
).Endpoint(),
|
|
listAllSubjects: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"ListAllSubjects",
|
|
encodeListSubjectsRequest,
|
|
decodeListSubjectsResponse,
|
|
mainflux.ListSubjectsRes{},
|
|
).Endpoint(),
|
|
countSubjects: kitgrpc.NewClient(
|
|
conn,
|
|
svcName,
|
|
"CountSubjects",
|
|
encodeCountSubjectsRequest,
|
|
decodeCountSubjectsResponse,
|
|
mainflux.CountSubjectsRes{},
|
|
).Endpoint(),
|
|
|
|
timeout: timeout,
|
|
}
|
|
}
|
|
|
|
func (client grpcClient) Issue(ctx context.Context, req *mainflux.IssueReq, _ ...grpc.CallOption) (*mainflux.Token, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.issue(ctx, issueReq{id: req.GetId(), keyType: auth.KeyType(req.Type)})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return res.(*mainflux.Token), nil
|
|
}
|
|
|
|
func encodeIssueRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(issueReq)
|
|
return &mainflux.IssueReq{Id: req.id, Type: uint32(req.keyType)}, nil
|
|
}
|
|
|
|
func decodeIssueResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
return grpcRes, nil
|
|
}
|
|
|
|
func (client grpcClient) Login(ctx context.Context, req *mainflux.LoginReq, _ ...grpc.CallOption) (*mainflux.Token, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.login(ctx, issueReq{id: req.GetId(), keyType: auth.APIKey})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return res.(*mainflux.Token), nil
|
|
}
|
|
|
|
func encodeLoginRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(issueReq)
|
|
return &mainflux.LoginReq{Id: req.id}, nil
|
|
}
|
|
|
|
func decodeLoginResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
return grpcRes, nil
|
|
}
|
|
|
|
func (client grpcClient) Refresh(ctx context.Context, req *mainflux.RefreshReq, _ ...grpc.CallOption) (*mainflux.Token, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.refresh(ctx, refreshReq{value: req.GetValue()})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return res.(*mainflux.Token), nil
|
|
}
|
|
|
|
func encodeRefreshRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(refreshReq)
|
|
return &mainflux.RefreshReq{Value: req.value}, nil
|
|
}
|
|
|
|
func decodeRefreshResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
return grpcRes, nil
|
|
}
|
|
|
|
func (client grpcClient) Identify(ctx context.Context, token *mainflux.IdentityReq, _ ...grpc.CallOption) (*mainflux.IdentityRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.identify(ctx, identityReq{token: token.GetToken()})
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
ir := res.(identityRes)
|
|
return &mainflux.IdentityRes{Id: ir.id}, nil
|
|
}
|
|
|
|
func encodeIdentifyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(identityReq)
|
|
return &mainflux.IdentityReq{Token: req.token}, nil
|
|
}
|
|
|
|
func decodeIdentifyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.IdentityRes)
|
|
return identityRes{id: res.GetId()}, nil
|
|
}
|
|
|
|
func (client grpcClient) Authorize(ctx context.Context, req *mainflux.AuthorizeReq, _ ...grpc.CallOption) (r *mainflux.AuthorizeRes, err error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.authorize(ctx, authReq{
|
|
Namespace: req.GetNamespace(),
|
|
SubjectType: req.GetSubjectType(),
|
|
Subject: req.GetSubject(),
|
|
SubjectKind: req.GetSubjectKind(),
|
|
Relation: req.GetRelation(),
|
|
Permission: req.GetPermission(),
|
|
ObjectType: req.GetObjectType(),
|
|
Object: req.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.AuthorizeRes{}, err
|
|
}
|
|
|
|
ar := res.(authorizeRes)
|
|
return &mainflux.AuthorizeRes{Authorized: ar.authorized, Id: ar.id}, err
|
|
}
|
|
|
|
func decodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.AuthorizeRes)
|
|
return authorizeRes{authorized: res.Authorized, id: res.Id}, nil
|
|
}
|
|
|
|
func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(authReq)
|
|
return &mainflux.AuthorizeReq{
|
|
Namespace: req.Namespace,
|
|
SubjectType: req.SubjectType,
|
|
Subject: req.Subject,
|
|
SubjectKind: req.SubjectKind,
|
|
Relation: req.Relation,
|
|
Permission: req.Permission,
|
|
ObjectType: req.ObjectType,
|
|
Object: req.Object,
|
|
}, nil
|
|
}
|
|
|
|
func (client grpcClient) AddPolicy(ctx context.Context, in *mainflux.AddPolicyReq, opts ...grpc.CallOption) (*mainflux.AddPolicyRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.addPolicy(ctx, policyReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.AddPolicyRes{}, err
|
|
}
|
|
|
|
apr := res.(addPolicyRes)
|
|
return &mainflux.AddPolicyRes{Authorized: apr.authorized}, err
|
|
}
|
|
|
|
func decodeAddPolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.AddPolicyRes)
|
|
return addPolicyRes{authorized: res.Authorized}, nil
|
|
}
|
|
|
|
func encodeAddPolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(policyReq)
|
|
return &mainflux.AddPolicyReq{
|
|
Namespace: req.Namespace,
|
|
SubjectType: req.SubjectType,
|
|
Subject: req.Subject,
|
|
Relation: req.Relation,
|
|
Permission: req.Permission,
|
|
ObjectType: req.ObjectType,
|
|
Object: req.Object,
|
|
}, nil
|
|
}
|
|
|
|
func (client grpcClient) DeletePolicy(ctx context.Context, in *mainflux.DeletePolicyReq, opts ...grpc.CallOption) (*mainflux.DeletePolicyRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.deletePolicy(ctx, policyReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.DeletePolicyRes{}, err
|
|
}
|
|
|
|
dpr := res.(deletePolicyRes)
|
|
return &mainflux.DeletePolicyRes{Deleted: dpr.deleted}, err
|
|
}
|
|
|
|
func decodeDeletePolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.DeletePolicyRes)
|
|
return deletePolicyRes{deleted: res.GetDeleted()}, nil
|
|
}
|
|
|
|
func encodeDeletePolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(policyReq)
|
|
return &mainflux.DeletePolicyReq{
|
|
Namespace: req.Namespace,
|
|
SubjectType: req.SubjectType,
|
|
Subject: req.Subject,
|
|
Relation: req.Relation,
|
|
Permission: req.Permission,
|
|
ObjectType: req.ObjectType,
|
|
Object: req.Object,
|
|
}, nil
|
|
}
|
|
|
|
func (client grpcClient) ListObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.listObjects(ctx, listObjectsReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.ListObjectsRes{}, err
|
|
}
|
|
|
|
lpr := res.(listObjectsRes)
|
|
return &mainflux.ListObjectsRes{Policies: lpr.policies}, err
|
|
}
|
|
|
|
func decodeListObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.ListObjectsRes)
|
|
return listObjectsRes{policies: res.GetPolicies()}, nil
|
|
}
|
|
|
|
func encodeListObjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(listObjectsReq)
|
|
return &mainflux.ListObjectsReq{
|
|
Namespace: req.Namespace,
|
|
SubjectType: req.SubjectType,
|
|
Subject: req.Subject,
|
|
Relation: req.Relation,
|
|
Permission: req.Permission,
|
|
ObjectType: req.ObjectType,
|
|
Object: req.Object,
|
|
}, nil
|
|
}
|
|
|
|
func (client grpcClient) ListAllObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.listAllObjects(ctx, listObjectsReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.ListObjectsRes{}, err
|
|
}
|
|
|
|
lpr := res.(listObjectsRes)
|
|
return &mainflux.ListObjectsRes{Policies: lpr.policies}, err
|
|
}
|
|
|
|
func (client grpcClient) CountObjects(ctx context.Context, in *mainflux.CountObjectsReq, opts ...grpc.CallOption) (*mainflux.CountObjectsRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.countObjects(ctx, listObjectsReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.CountObjectsRes{}, err
|
|
}
|
|
|
|
cp := res.(countObjectsRes)
|
|
return &mainflux.CountObjectsRes{Count: int64(cp.count)}, err
|
|
}
|
|
|
|
func decodeCountObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.CountObjectsRes)
|
|
return countObjectsRes{count: int(res.GetCount())}, nil
|
|
}
|
|
|
|
func encodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(countObjectsReq)
|
|
return &mainflux.CountObjectsReq{
|
|
Namespace: req.Namespace,
|
|
SubjectType: req.SubjectType,
|
|
Subject: req.Subject,
|
|
Relation: req.Relation,
|
|
Permission: req.Permission,
|
|
ObjectType: req.ObjectType,
|
|
Object: req.Object,
|
|
}, nil
|
|
}
|
|
|
|
func (client grpcClient) ListSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.listSubjects(ctx, listSubjectsReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
NextPageToken: in.GetNextPageToken()})
|
|
if err != nil {
|
|
return &mainflux.ListSubjectsRes{}, err
|
|
}
|
|
|
|
lpr := res.(listSubjectsRes)
|
|
return &mainflux.ListSubjectsRes{Policies: lpr.policies}, err
|
|
}
|
|
|
|
func decodeListSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.ListSubjectsRes)
|
|
return listSubjectsRes{policies: res.GetPolicies()}, nil
|
|
}
|
|
|
|
func encodeListSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(listSubjectsReq)
|
|
return &mainflux.ListSubjectsReq{
|
|
Namespace: req.Namespace,
|
|
SubjectType: req.SubjectType,
|
|
Subject: req.Subject,
|
|
Relation: req.Relation,
|
|
Permission: req.Permission,
|
|
ObjectType: req.ObjectType,
|
|
Object: req.Object,
|
|
}, nil
|
|
}
|
|
|
|
func (client grpcClient) ListAllSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.listAllSubjects(ctx, listSubjectsReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.ListSubjectsRes{}, err
|
|
}
|
|
|
|
lpr := res.(listSubjectsRes)
|
|
return &mainflux.ListSubjectsRes{Policies: lpr.policies}, err
|
|
}
|
|
|
|
func (client grpcClient) CountSubjects(ctx context.Context, in *mainflux.CountSubjectsReq, opts ...grpc.CallOption) (*mainflux.CountSubjectsRes, error) {
|
|
ctx, close := context.WithTimeout(ctx, client.timeout)
|
|
defer close()
|
|
|
|
res, err := client.countSubjects(ctx, countSubjectsReq{
|
|
Namespace: in.GetNamespace(),
|
|
SubjectType: in.GetSubjectType(),
|
|
Subject: in.GetSubject(),
|
|
Relation: in.GetRelation(),
|
|
Permission: in.GetPermission(),
|
|
ObjectType: in.GetObjectType(),
|
|
Object: in.GetObject(),
|
|
})
|
|
if err != nil {
|
|
return &mainflux.CountSubjectsRes{}, err
|
|
}
|
|
|
|
cp := res.(countSubjectsRes)
|
|
return &mainflux.CountSubjectsRes{Count: int64(cp.count)}, err
|
|
}
|
|
|
|
func decodeCountSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
|
res := grpcRes.(*mainflux.CountSubjectsRes)
|
|
return countSubjectsRes{count: int(res.GetCount())}, nil
|
|
}
|
|
|
|
func encodeCountSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
|
req := grpcReq.(countSubjectsReq)
|
|
return &mainflux.CountSubjectsReq{
|
|
Namespace: req.Namespace,
|
|
SubjectType: req.SubjectType,
|
|
Subject: req.Subject,
|
|
Relation: req.Relation,
|
|
Permission: req.Permission,
|
|
ObjectType: req.ObjectType,
|
|
Object: req.Object,
|
|
}, nil
|
|
}
|