mirror of
https://github.com/absmach/magistrala.git
synced 2026-06-23 04:10:28 +00:00
NOISSUE - Fix gRPC client naming (#22)
* Fix Auth gRPC server name Signed-off-by: dborovcanin <dusan.borovcanin@abstractmachines.fr> * Rename import aliases Signed-off-by: dborovcanin <dusan.borovcanin@abstractmachines.fr> * Rename issuer name to Magistrala Signed-off-by: dborovcanin <dusan.borovcanin@abstractmachines.fr> --------- Signed-off-by: dborovcanin <dusan.borovcanin@abstractmachines.fr> Co-authored-by: dborovcanin <dusan.borovcanin@abstractmachines.fr>
This commit is contained in:
+71
-71
@@ -7,16 +7,16 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
kitgrpc "github.com/go-kit/kit/transport/grpc"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
const svcName = "mainflux.AuthService"
|
||||
const svcName = "magistrala.AuthService"
|
||||
|
||||
var _ mainflux.AuthServiceClient = (*grpcClient)(nil)
|
||||
var _ magistrala.AuthServiceClient = (*grpcClient)(nil)
|
||||
|
||||
type grpcClient struct {
|
||||
issue endpoint.Endpoint
|
||||
@@ -36,7 +36,7 @@ type grpcClient struct {
|
||||
}
|
||||
|
||||
// NewClient returns new gRPC client instance.
|
||||
func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServiceClient {
|
||||
func NewClient(conn *grpc.ClientConn, timeout time.Duration) magistrala.AuthServiceClient {
|
||||
return &grpcClient{
|
||||
issue: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -44,7 +44,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"Issue",
|
||||
encodeIssueRequest,
|
||||
decodeIssueResponse,
|
||||
mainflux.Token{},
|
||||
magistrala.Token{},
|
||||
).Endpoint(),
|
||||
login: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -52,7 +52,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"Login",
|
||||
encodeLoginRequest,
|
||||
decodeLoginResponse,
|
||||
mainflux.Token{},
|
||||
magistrala.Token{},
|
||||
).Endpoint(),
|
||||
refresh: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -60,7 +60,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"Refresh",
|
||||
encodeRefreshRequest,
|
||||
decodeRefreshResponse,
|
||||
mainflux.Token{},
|
||||
magistrala.Token{},
|
||||
).Endpoint(),
|
||||
identify: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -68,7 +68,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"Identify",
|
||||
encodeIdentifyRequest,
|
||||
decodeIdentifyResponse,
|
||||
mainflux.IdentityRes{},
|
||||
magistrala.IdentityRes{},
|
||||
).Endpoint(),
|
||||
authorize: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -76,7 +76,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"Authorize",
|
||||
encodeAuthorizeRequest,
|
||||
decodeAuthorizeResponse,
|
||||
mainflux.AuthorizeRes{},
|
||||
magistrala.AuthorizeRes{},
|
||||
).Endpoint(),
|
||||
addPolicy: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -84,7 +84,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"AddPolicy",
|
||||
encodeAddPolicyRequest,
|
||||
decodeAddPolicyResponse,
|
||||
mainflux.AddPolicyRes{},
|
||||
magistrala.AddPolicyRes{},
|
||||
).Endpoint(),
|
||||
deletePolicy: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -92,7 +92,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"DeletePolicy",
|
||||
encodeDeletePolicyRequest,
|
||||
decodeDeletePolicyResponse,
|
||||
mainflux.DeletePolicyRes{},
|
||||
magistrala.DeletePolicyRes{},
|
||||
).Endpoint(),
|
||||
listObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -100,7 +100,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"ListObjects",
|
||||
encodeListObjectsRequest,
|
||||
decodeListObjectsResponse,
|
||||
mainflux.ListObjectsRes{},
|
||||
magistrala.ListObjectsRes{},
|
||||
).Endpoint(),
|
||||
listAllObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -108,7 +108,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"ListAllObjects",
|
||||
encodeListObjectsRequest,
|
||||
decodeListObjectsResponse,
|
||||
mainflux.ListObjectsRes{},
|
||||
magistrala.ListObjectsRes{},
|
||||
).Endpoint(),
|
||||
countObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -116,7 +116,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"CountObjects",
|
||||
encodeCountObjectsRequest,
|
||||
decodeCountObjectsResponse,
|
||||
mainflux.CountObjectsRes{},
|
||||
magistrala.CountObjectsRes{},
|
||||
).Endpoint(),
|
||||
listSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -124,7 +124,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"ListSubjects",
|
||||
encodeListSubjectsRequest,
|
||||
decodeListSubjectsResponse,
|
||||
mainflux.ListSubjectsRes{},
|
||||
magistrala.ListSubjectsRes{},
|
||||
).Endpoint(),
|
||||
listAllSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -132,7 +132,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"ListAllSubjects",
|
||||
encodeListSubjectsRequest,
|
||||
decodeListSubjectsResponse,
|
||||
mainflux.ListSubjectsRes{},
|
||||
magistrala.ListSubjectsRes{},
|
||||
).Endpoint(),
|
||||
countSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
@@ -140,14 +140,14 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) mainflux.AuthServic
|
||||
"CountSubjects",
|
||||
encodeCountSubjectsRequest,
|
||||
decodeCountSubjectsResponse,
|
||||
mainflux.CountSubjectsRes{},
|
||||
magistrala.CountSubjectsRes{},
|
||||
).Endpoint(),
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
func (client grpcClient) Issue(ctx context.Context, req *mainflux.IssueReq, _ ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (client grpcClient) Issue(ctx context.Context, req *magistrala.IssueReq, _ ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -155,19 +155,19 @@ func (client grpcClient) Issue(ctx context.Context, req *mainflux.IssueReq, _ ..
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.(*mainflux.Token), nil
|
||||
return res.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func encodeIssueRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(issueReq)
|
||||
return &mainflux.IssueReq{Id: req.id, Type: uint32(req.keyType)}, nil
|
||||
return &magistrala.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) {
|
||||
func (client grpcClient) Login(ctx context.Context, req *magistrala.LoginReq, _ ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -175,19 +175,19 @@ func (client grpcClient) Login(ctx context.Context, req *mainflux.LoginReq, _ ..
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.(*mainflux.Token), nil
|
||||
return res.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func encodeLoginRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(issueReq)
|
||||
return &mainflux.LoginReq{Id: req.id}, nil
|
||||
return &magistrala.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) {
|
||||
func (client grpcClient) Refresh(ctx context.Context, req *magistrala.RefreshReq, _ ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -195,19 +195,19 @@ func (client grpcClient) Refresh(ctx context.Context, req *mainflux.RefreshReq,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return res.(*mainflux.Token), nil
|
||||
return res.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func encodeRefreshRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(refreshReq)
|
||||
return &mainflux.RefreshReq{Value: req.value}, nil
|
||||
return &magistrala.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) {
|
||||
func (client grpcClient) Identify(ctx context.Context, token *magistrala.IdentityReq, _ ...grpc.CallOption) (*magistrala.IdentityRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -217,20 +217,20 @@ func (client grpcClient) Identify(ctx context.Context, token *mainflux.IdentityR
|
||||
}
|
||||
|
||||
ir := res.(identityRes)
|
||||
return &mainflux.IdentityRes{Id: ir.id}, nil
|
||||
return &magistrala.IdentityRes{Id: ir.id}, nil
|
||||
}
|
||||
|
||||
func encodeIdentifyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(identityReq)
|
||||
return &mainflux.IdentityReq{Token: req.token}, nil
|
||||
return &magistrala.IdentityReq{Token: req.token}, nil
|
||||
}
|
||||
|
||||
func decodeIdentifyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.IdentityRes)
|
||||
res := grpcRes.(*magistrala.IdentityRes)
|
||||
return identityRes{id: res.GetId()}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) Authorize(ctx context.Context, req *mainflux.AuthorizeReq, _ ...grpc.CallOption) (r *mainflux.AuthorizeRes, err error) {
|
||||
func (client grpcClient) Authorize(ctx context.Context, req *magistrala.AuthorizeReq, _ ...grpc.CallOption) (r *magistrala.AuthorizeRes, err error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -245,21 +245,21 @@ func (client grpcClient) Authorize(ctx context.Context, req *mainflux.AuthorizeR
|
||||
Object: req.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.AuthorizeRes{}, err
|
||||
return &magistrala.AuthorizeRes{}, err
|
||||
}
|
||||
|
||||
ar := res.(authorizeRes)
|
||||
return &mainflux.AuthorizeRes{Authorized: ar.authorized, Id: ar.id}, err
|
||||
return &magistrala.AuthorizeRes{Authorized: ar.authorized, Id: ar.id}, err
|
||||
}
|
||||
|
||||
func decodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.AuthorizeRes)
|
||||
res := grpcRes.(*magistrala.AuthorizeRes)
|
||||
return authorizeRes{authorized: res.Authorized, id: res.Id}, nil
|
||||
}
|
||||
|
||||
func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(authReq)
|
||||
return &mainflux.AuthorizeReq{
|
||||
return &magistrala.AuthorizeReq{
|
||||
Namespace: req.Namespace,
|
||||
SubjectType: req.SubjectType,
|
||||
Subject: req.Subject,
|
||||
@@ -271,7 +271,7 @@ func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) AddPolicy(ctx context.Context, in *mainflux.AddPolicyReq, opts ...grpc.CallOption) (*mainflux.AddPolicyRes, error) {
|
||||
func (client grpcClient) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -285,21 +285,21 @@ func (client grpcClient) AddPolicy(ctx context.Context, in *mainflux.AddPolicyRe
|
||||
Object: in.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.AddPolicyRes{}, err
|
||||
return &magistrala.AddPolicyRes{}, err
|
||||
}
|
||||
|
||||
apr := res.(addPolicyRes)
|
||||
return &mainflux.AddPolicyRes{Authorized: apr.authorized}, err
|
||||
return &magistrala.AddPolicyRes{Authorized: apr.authorized}, err
|
||||
}
|
||||
|
||||
func decodeAddPolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.AddPolicyRes)
|
||||
res := grpcRes.(*magistrala.AddPolicyRes)
|
||||
return addPolicyRes{authorized: res.Authorized}, nil
|
||||
}
|
||||
|
||||
func encodeAddPolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(policyReq)
|
||||
return &mainflux.AddPolicyReq{
|
||||
return &magistrala.AddPolicyReq{
|
||||
Namespace: req.Namespace,
|
||||
SubjectType: req.SubjectType,
|
||||
Subject: req.Subject,
|
||||
@@ -310,7 +310,7 @@ func encodeAddPolicyRequest(_ context.Context, grpcReq interface{}) (interface{}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) DeletePolicy(ctx context.Context, in *mainflux.DeletePolicyReq, opts ...grpc.CallOption) (*mainflux.DeletePolicyRes, error) {
|
||||
func (client grpcClient) DeletePolicy(ctx context.Context, in *magistrala.DeletePolicyReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -324,21 +324,21 @@ func (client grpcClient) DeletePolicy(ctx context.Context, in *mainflux.DeletePo
|
||||
Object: in.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.DeletePolicyRes{}, err
|
||||
return &magistrala.DeletePolicyRes{}, err
|
||||
}
|
||||
|
||||
dpr := res.(deletePolicyRes)
|
||||
return &mainflux.DeletePolicyRes{Deleted: dpr.deleted}, err
|
||||
return &magistrala.DeletePolicyRes{Deleted: dpr.deleted}, err
|
||||
}
|
||||
|
||||
func decodeDeletePolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.DeletePolicyRes)
|
||||
res := grpcRes.(*magistrala.DeletePolicyRes)
|
||||
return deletePolicyRes{deleted: res.GetDeleted()}, nil
|
||||
}
|
||||
|
||||
func encodeDeletePolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(policyReq)
|
||||
return &mainflux.DeletePolicyReq{
|
||||
return &magistrala.DeletePolicyReq{
|
||||
Namespace: req.Namespace,
|
||||
SubjectType: req.SubjectType,
|
||||
Subject: req.Subject,
|
||||
@@ -349,7 +349,7 @@ func encodeDeletePolicyRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
||||
func (client grpcClient) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -363,21 +363,21 @@ func (client grpcClient) ListObjects(ctx context.Context, in *mainflux.ListObjec
|
||||
Object: in.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.ListObjectsRes{}, err
|
||||
return &magistrala.ListObjectsRes{}, err
|
||||
}
|
||||
|
||||
lpr := res.(listObjectsRes)
|
||||
return &mainflux.ListObjectsRes{Policies: lpr.policies}, err
|
||||
return &magistrala.ListObjectsRes{Policies: lpr.policies}, err
|
||||
}
|
||||
|
||||
func decodeListObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.ListObjectsRes)
|
||||
res := grpcRes.(*magistrala.ListObjectsRes)
|
||||
return listObjectsRes{policies: res.GetPolicies()}, nil
|
||||
}
|
||||
|
||||
func encodeListObjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(listObjectsReq)
|
||||
return &mainflux.ListObjectsReq{
|
||||
return &magistrala.ListObjectsReq{
|
||||
Namespace: req.Namespace,
|
||||
SubjectType: req.SubjectType,
|
||||
Subject: req.Subject,
|
||||
@@ -388,7 +388,7 @@ func encodeListObjectsRequest(_ context.Context, grpcReq interface{}) (interface
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListAllObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
||||
func (client grpcClient) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -402,14 +402,14 @@ func (client grpcClient) ListAllObjects(ctx context.Context, in *mainflux.ListOb
|
||||
Object: in.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.ListObjectsRes{}, err
|
||||
return &magistrala.ListObjectsRes{}, err
|
||||
}
|
||||
|
||||
lpr := res.(listObjectsRes)
|
||||
return &mainflux.ListObjectsRes{Policies: lpr.policies}, err
|
||||
return &magistrala.ListObjectsRes{Policies: lpr.policies}, err
|
||||
}
|
||||
|
||||
func (client grpcClient) CountObjects(ctx context.Context, in *mainflux.CountObjectsReq, opts ...grpc.CallOption) (*mainflux.CountObjectsRes, error) {
|
||||
func (client grpcClient) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -423,21 +423,21 @@ func (client grpcClient) CountObjects(ctx context.Context, in *mainflux.CountObj
|
||||
Object: in.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.CountObjectsRes{}, err
|
||||
return &magistrala.CountObjectsRes{}, err
|
||||
}
|
||||
|
||||
cp := res.(countObjectsRes)
|
||||
return &mainflux.CountObjectsRes{Count: int64(cp.count)}, err
|
||||
return &magistrala.CountObjectsRes{Count: int64(cp.count)}, err
|
||||
}
|
||||
|
||||
func decodeCountObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.CountObjectsRes)
|
||||
res := grpcRes.(*magistrala.CountObjectsRes)
|
||||
return countObjectsRes{count: int(res.GetCount())}, nil
|
||||
}
|
||||
|
||||
func encodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(countObjectsReq)
|
||||
return &mainflux.CountObjectsReq{
|
||||
return &magistrala.CountObjectsReq{
|
||||
Namespace: req.Namespace,
|
||||
SubjectType: req.SubjectType,
|
||||
Subject: req.Subject,
|
||||
@@ -448,7 +448,7 @@ func encodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
||||
func (client grpcClient) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -463,21 +463,21 @@ func (client grpcClient) ListSubjects(ctx context.Context, in *mainflux.ListSubj
|
||||
NextPageToken: in.GetNextPageToken(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.ListSubjectsRes{}, err
|
||||
return &magistrala.ListSubjectsRes{}, err
|
||||
}
|
||||
|
||||
lpr := res.(listSubjectsRes)
|
||||
return &mainflux.ListSubjectsRes{Policies: lpr.policies}, err
|
||||
return &magistrala.ListSubjectsRes{Policies: lpr.policies}, err
|
||||
}
|
||||
|
||||
func decodeListSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.ListSubjectsRes)
|
||||
res := grpcRes.(*magistrala.ListSubjectsRes)
|
||||
return listSubjectsRes{policies: res.GetPolicies()}, nil
|
||||
}
|
||||
|
||||
func encodeListSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(listSubjectsReq)
|
||||
return &mainflux.ListSubjectsReq{
|
||||
return &magistrala.ListSubjectsReq{
|
||||
Namespace: req.Namespace,
|
||||
SubjectType: req.SubjectType,
|
||||
Subject: req.Subject,
|
||||
@@ -488,7 +488,7 @@ func encodeListSubjectsRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListAllSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
||||
func (client grpcClient) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -502,14 +502,14 @@ func (client grpcClient) ListAllSubjects(ctx context.Context, in *mainflux.ListS
|
||||
Object: in.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.ListSubjectsRes{}, err
|
||||
return &magistrala.ListSubjectsRes{}, err
|
||||
}
|
||||
|
||||
lpr := res.(listSubjectsRes)
|
||||
return &mainflux.ListSubjectsRes{Policies: lpr.policies}, err
|
||||
return &magistrala.ListSubjectsRes{Policies: lpr.policies}, err
|
||||
}
|
||||
|
||||
func (client grpcClient) CountSubjects(ctx context.Context, in *mainflux.CountSubjectsReq, opts ...grpc.CallOption) (*mainflux.CountSubjectsRes, error) {
|
||||
func (client grpcClient) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) {
|
||||
ctx, close := context.WithTimeout(ctx, client.timeout)
|
||||
defer close()
|
||||
|
||||
@@ -523,21 +523,21 @@ func (client grpcClient) CountSubjects(ctx context.Context, in *mainflux.CountSu
|
||||
Object: in.GetObject(),
|
||||
})
|
||||
if err != nil {
|
||||
return &mainflux.CountSubjectsRes{}, err
|
||||
return &magistrala.CountSubjectsRes{}, err
|
||||
}
|
||||
|
||||
cp := res.(countSubjectsRes)
|
||||
return &mainflux.CountSubjectsRes{Count: int64(cp.count)}, err
|
||||
return &magistrala.CountSubjectsRes{Count: int64(cp.count)}, err
|
||||
}
|
||||
|
||||
func decodeCountSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(*mainflux.CountSubjectsRes)
|
||||
res := grpcRes.(*magistrala.CountSubjectsRes)
|
||||
return countSubjectsRes{count: int(res.GetCount())}, nil
|
||||
}
|
||||
|
||||
func encodeCountSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(countSubjectsReq)
|
||||
return &mainflux.CountSubjectsReq{
|
||||
return &magistrala.CountSubjectsReq{
|
||||
Namespace: req.Namespace,
|
||||
SubjectType: req.SubjectType,
|
||||
Subject: req.Subject,
|
||||
|
||||
+50
-50
@@ -6,7 +6,7 @@ package grpc
|
||||
import (
|
||||
"context"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
@@ -15,10 +15,10 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var _ mainflux.AuthServiceServer = (*grpcServer)(nil)
|
||||
var _ magistrala.AuthServiceServer = (*grpcServer)(nil)
|
||||
|
||||
type grpcServer struct {
|
||||
mainflux.UnimplementedAuthServiceServer
|
||||
magistrala.UnimplementedAuthServiceServer
|
||||
issue kitgrpc.Handler
|
||||
login kitgrpc.Handler
|
||||
refresh kitgrpc.Handler
|
||||
@@ -35,7 +35,7 @@ type grpcServer struct {
|
||||
}
|
||||
|
||||
// NewServer returns new AuthServiceServer instance.
|
||||
func NewServer(svc auth.Service) mainflux.AuthServiceServer {
|
||||
func NewServer(svc auth.Service) magistrala.AuthServiceServer {
|
||||
return &grpcServer{
|
||||
issue: kitgrpc.NewServer(
|
||||
(issueEndpoint(svc)),
|
||||
@@ -105,129 +105,129 @@ func NewServer(svc auth.Service) mainflux.AuthServiceServer {
|
||||
}
|
||||
}
|
||||
|
||||
func (s *grpcServer) Issue(ctx context.Context, req *mainflux.IssueReq) (*mainflux.Token, error) {
|
||||
func (s *grpcServer) Issue(ctx context.Context, req *magistrala.IssueReq) (*magistrala.Token, error) {
|
||||
_, res, err := s.issue.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.Token), nil
|
||||
return res.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) Login(ctx context.Context, req *mainflux.LoginReq) (*mainflux.Token, error) {
|
||||
func (s *grpcServer) Login(ctx context.Context, req *magistrala.LoginReq) (*magistrala.Token, error) {
|
||||
_, res, err := s.login.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.Token), nil
|
||||
return res.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) Refresh(ctx context.Context, req *mainflux.RefreshReq) (*mainflux.Token, error) {
|
||||
func (s *grpcServer) Refresh(ctx context.Context, req *magistrala.RefreshReq) (*magistrala.Token, error) {
|
||||
_, res, err := s.refresh.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.Token), nil
|
||||
return res.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) Identify(ctx context.Context, token *mainflux.IdentityReq) (*mainflux.IdentityRes, error) {
|
||||
func (s *grpcServer) Identify(ctx context.Context, token *magistrala.IdentityReq) (*magistrala.IdentityRes, error) {
|
||||
_, res, err := s.identify.ServeGRPC(ctx, token)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.IdentityRes), nil
|
||||
return res.(*magistrala.IdentityRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) Authorize(ctx context.Context, req *mainflux.AuthorizeReq) (*mainflux.AuthorizeRes, error) {
|
||||
func (s *grpcServer) Authorize(ctx context.Context, req *magistrala.AuthorizeReq) (*magistrala.AuthorizeRes, error) {
|
||||
_, res, err := s.authorize.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.AuthorizeRes), nil
|
||||
return res.(*magistrala.AuthorizeRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) AddPolicy(ctx context.Context, req *mainflux.AddPolicyReq) (*mainflux.AddPolicyRes, error) {
|
||||
func (s *grpcServer) AddPolicy(ctx context.Context, req *magistrala.AddPolicyReq) (*magistrala.AddPolicyRes, error) {
|
||||
_, res, err := s.addPolicy.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.AddPolicyRes), nil
|
||||
return res.(*magistrala.AddPolicyRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) DeletePolicy(ctx context.Context, req *mainflux.DeletePolicyReq) (*mainflux.DeletePolicyRes, error) {
|
||||
func (s *grpcServer) DeletePolicy(ctx context.Context, req *magistrala.DeletePolicyReq) (*magistrala.DeletePolicyRes, error) {
|
||||
_, res, err := s.deletePolicy.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.DeletePolicyRes), nil
|
||||
return res.(*magistrala.DeletePolicyRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListObjects(ctx context.Context, req *mainflux.ListObjectsReq) (*mainflux.ListObjectsRes, error) {
|
||||
func (s *grpcServer) ListObjects(ctx context.Context, req *magistrala.ListObjectsReq) (*magistrala.ListObjectsRes, error) {
|
||||
_, res, err := s.listObjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.ListObjectsRes), nil
|
||||
return res.(*magistrala.ListObjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListAllObjects(ctx context.Context, req *mainflux.ListObjectsReq) (*mainflux.ListObjectsRes, error) {
|
||||
func (s *grpcServer) ListAllObjects(ctx context.Context, req *magistrala.ListObjectsReq) (*magistrala.ListObjectsRes, error) {
|
||||
_, res, err := s.listAllObjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.ListObjectsRes), nil
|
||||
return res.(*magistrala.ListObjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) CountObjects(ctx context.Context, req *mainflux.CountObjectsReq) (*mainflux.CountObjectsRes, error) {
|
||||
func (s *grpcServer) CountObjects(ctx context.Context, req *magistrala.CountObjectsReq) (*magistrala.CountObjectsRes, error) {
|
||||
_, res, err := s.countObjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.CountObjectsRes), nil
|
||||
return res.(*magistrala.CountObjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListSubjects(ctx context.Context, req *mainflux.ListSubjectsReq) (*mainflux.ListSubjectsRes, error) {
|
||||
func (s *grpcServer) ListSubjects(ctx context.Context, req *magistrala.ListSubjectsReq) (*magistrala.ListSubjectsRes, error) {
|
||||
_, res, err := s.listSubjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.ListSubjectsRes), nil
|
||||
return res.(*magistrala.ListSubjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListAllSubjects(ctx context.Context, req *mainflux.ListSubjectsReq) (*mainflux.ListSubjectsRes, error) {
|
||||
func (s *grpcServer) ListAllSubjects(ctx context.Context, req *magistrala.ListSubjectsReq) (*magistrala.ListSubjectsRes, error) {
|
||||
_, res, err := s.listAllSubjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.ListSubjectsRes), nil
|
||||
return res.(*magistrala.ListSubjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) CountSubjects(ctx context.Context, req *mainflux.CountSubjectsReq) (*mainflux.CountSubjectsRes, error) {
|
||||
func (s *grpcServer) CountSubjects(ctx context.Context, req *magistrala.CountSubjectsReq) (*magistrala.CountSubjectsRes, error) {
|
||||
_, res, err := s.countSubjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
}
|
||||
return res.(*mainflux.CountSubjectsRes), nil
|
||||
return res.(*magistrala.CountSubjectsRes), nil
|
||||
}
|
||||
|
||||
func decodeIssueRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.IssueReq)
|
||||
req := grpcReq.(*magistrala.IssueReq)
|
||||
return issueReq{id: req.GetId(), keyType: auth.KeyType(req.GetType())}, nil
|
||||
}
|
||||
|
||||
func decodeLoginRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.LoginReq)
|
||||
req := grpcReq.(*magistrala.LoginReq)
|
||||
return issueReq{id: req.GetId(), keyType: auth.AccessKey}, nil
|
||||
}
|
||||
|
||||
func decodeRefreshRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.RefreshReq)
|
||||
req := grpcReq.(*magistrala.RefreshReq)
|
||||
return refreshReq{value: req.GetValue()}, nil
|
||||
}
|
||||
|
||||
func encodeIssueResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(issueRes)
|
||||
|
||||
return &mainflux.Token{
|
||||
return &magistrala.Token{
|
||||
AccessToken: res.accessToken,
|
||||
RefreshToken: &res.refreshToken,
|
||||
AccessType: res.accessType,
|
||||
@@ -235,17 +235,17 @@ func encodeIssueResponse(_ context.Context, grpcRes interface{}) (interface{}, e
|
||||
}
|
||||
|
||||
func decodeIdentifyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.IdentityReq)
|
||||
req := grpcReq.(*magistrala.IdentityReq)
|
||||
return identityReq{token: req.GetToken()}, nil
|
||||
}
|
||||
|
||||
func encodeIdentifyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(identityRes)
|
||||
return &mainflux.IdentityRes{Id: res.id}, nil
|
||||
return &magistrala.IdentityRes{Id: res.id}, nil
|
||||
}
|
||||
|
||||
func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.AuthorizeReq)
|
||||
req := grpcReq.(*magistrala.AuthorizeReq)
|
||||
return authReq{
|
||||
Namespace: req.GetNamespace(),
|
||||
SubjectType: req.GetSubjectType(),
|
||||
@@ -260,11 +260,11 @@ func decodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}
|
||||
|
||||
func encodeAuthorizeResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(authorizeRes)
|
||||
return &mainflux.AuthorizeRes{Authorized: res.authorized, Id: res.id}, nil
|
||||
return &magistrala.AuthorizeRes{Authorized: res.authorized, Id: res.id}, nil
|
||||
}
|
||||
|
||||
func decodeAddPolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.AddPolicyReq)
|
||||
req := grpcReq.(*magistrala.AddPolicyReq)
|
||||
return policyReq{
|
||||
Namespace: req.GetNamespace(),
|
||||
SubjectType: req.GetSubjectType(),
|
||||
@@ -278,11 +278,11 @@ func decodeAddPolicyRequest(_ context.Context, grpcReq interface{}) (interface{}
|
||||
|
||||
func encodeAddPolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(addPolicyRes)
|
||||
return &mainflux.AddPolicyRes{Authorized: res.authorized}, nil
|
||||
return &magistrala.AddPolicyRes{Authorized: res.authorized}, nil
|
||||
}
|
||||
|
||||
func decodeDeletePolicyRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.DeletePolicyReq)
|
||||
req := grpcReq.(*magistrala.DeletePolicyReq)
|
||||
return policyReq{
|
||||
Namespace: req.GetNamespace(),
|
||||
SubjectType: req.GetSubjectType(),
|
||||
@@ -296,11 +296,11 @@ func decodeDeletePolicyRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
|
||||
func encodeDeletePolicyResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(deletePolicyRes)
|
||||
return &mainflux.DeletePolicyRes{Deleted: res.deleted}, nil
|
||||
return &magistrala.DeletePolicyRes{Deleted: res.deleted}, nil
|
||||
}
|
||||
|
||||
func decodeListObjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.ListObjectsReq)
|
||||
req := grpcReq.(*magistrala.ListObjectsReq)
|
||||
return listObjectsReq{
|
||||
Namespace: req.GetNamespace(),
|
||||
SubjectType: req.GetSubjectType(),
|
||||
@@ -316,11 +316,11 @@ func decodeListObjectsRequest(_ context.Context, grpcReq interface{}) (interface
|
||||
|
||||
func encodeListObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(listObjectsRes)
|
||||
return &mainflux.ListObjectsRes{Policies: res.policies}, nil
|
||||
return &magistrala.ListObjectsRes{Policies: res.policies}, nil
|
||||
}
|
||||
|
||||
func decodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.CountObjectsReq)
|
||||
req := grpcReq.(*magistrala.CountObjectsReq)
|
||||
return countObjectsReq{
|
||||
Namespace: req.GetNamespace(),
|
||||
SubjectType: req.GetSubjectType(),
|
||||
@@ -334,11 +334,11 @@ func decodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
|
||||
func encodeCountObjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(countObjectsRes)
|
||||
return &mainflux.CountObjectsRes{Count: int64(res.count)}, nil
|
||||
return &magistrala.CountObjectsRes{Count: int64(res.count)}, nil
|
||||
}
|
||||
|
||||
func decodeListSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.ListSubjectsReq)
|
||||
req := grpcReq.(*magistrala.ListSubjectsReq)
|
||||
return listSubjectsReq{
|
||||
Namespace: req.GetNamespace(),
|
||||
SubjectType: req.GetSubjectType(),
|
||||
@@ -352,11 +352,11 @@ func decodeListSubjectsRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
|
||||
func encodeListSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(listSubjectsRes)
|
||||
return &mainflux.ListSubjectsRes{Policies: res.policies}, nil
|
||||
return &magistrala.ListSubjectsRes{Policies: res.policies}, nil
|
||||
}
|
||||
|
||||
func decodeCountSubjectsRequest(_ context.Context, grpcReq interface{}) (interface{}, error) {
|
||||
req := grpcReq.(*mainflux.CountSubjectsReq)
|
||||
req := grpcReq.(*magistrala.CountSubjectsReq)
|
||||
return countSubjectsReq{
|
||||
Namespace: req.GetNamespace(),
|
||||
SubjectType: req.GetSubjectType(),
|
||||
@@ -370,7 +370,7 @@ func decodeCountSubjectsRequest(_ context.Context, grpcReq interface{}) (interfa
|
||||
|
||||
func encodeCountSubjectsResponse(_ context.Context, grpcRes interface{}) (interface{}, error) {
|
||||
res := grpcRes.(countObjectsRes)
|
||||
return &mainflux.CountObjectsRes{Count: int64(res.count)}, nil
|
||||
return &magistrala.CountObjectsRes{Count: int64(res.count)}, nil
|
||||
}
|
||||
|
||||
func encodeError(err error) error {
|
||||
|
||||
@@ -22,7 +22,7 @@ func key() auth.Key {
|
||||
return auth.Key{
|
||||
ID: "66af4a67-3823-438a-abd7-efdb613eaef6",
|
||||
Type: auth.AccessKey,
|
||||
Issuer: "mainflux.auth",
|
||||
Issuer: "magistrala.auth",
|
||||
Subject: "66af4a67-3823-438a-abd7-efdb613eaef6",
|
||||
IssuedAt: time.Now().UTC().Add(-10 * time.Second).Round(time.Second),
|
||||
ExpiresAt: exp,
|
||||
|
||||
@@ -24,7 +24,7 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
issuerName = "mainflux.auth"
|
||||
issuerName = "magistrala.auth"
|
||||
tokenType = "type"
|
||||
)
|
||||
|
||||
|
||||
+34
-34
@@ -6,7 +6,7 @@ package mocks
|
||||
import (
|
||||
context "context"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"google.golang.org/grpc"
|
||||
@@ -14,104 +14,104 @@ import (
|
||||
|
||||
const InvalidValue = "invalid"
|
||||
|
||||
var _ mainflux.AuthServiceClient = (*Service)(nil)
|
||||
var _ magistrala.AuthServiceClient = (*Service)(nil)
|
||||
|
||||
type Service struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *Service) Issue(ctx context.Context, in *mainflux.IssueReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (m *Service) Issue(ctx context.Context, in *magistrala.IssueReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
if in.GetId() == InvalidValue || in.GetId() == "" {
|
||||
return &mainflux.Token{}, errors.ErrAuthentication
|
||||
return &magistrala.Token{}, errors.ErrAuthentication
|
||||
}
|
||||
|
||||
return ret.Get(0).(*mainflux.Token), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.Token), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) Login(ctx context.Context, in *mainflux.LoginReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (m *Service) Login(ctx context.Context, in *magistrala.LoginReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
if in.GetId() == InvalidValue || in.GetId() == "" {
|
||||
return &mainflux.Token{}, errors.ErrAuthentication
|
||||
return &magistrala.Token{}, errors.ErrAuthentication
|
||||
}
|
||||
|
||||
return ret.Get(0).(*mainflux.Token), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.Token), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) Refresh(ctx context.Context, in *mainflux.RefreshReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (m *Service) Refresh(ctx context.Context, in *magistrala.RefreshReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
if in.GetValue() == InvalidValue || in.GetValue() == "" {
|
||||
return &mainflux.Token{}, errors.ErrAuthentication
|
||||
return &magistrala.Token{}, errors.ErrAuthentication
|
||||
}
|
||||
|
||||
return ret.Get(0).(*mainflux.Token), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.Token), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) Identify(ctx context.Context, in *mainflux.IdentityReq, opts ...grpc.CallOption) (*mainflux.IdentityRes, error) {
|
||||
func (m *Service) Identify(ctx context.Context, in *magistrala.IdentityReq, opts ...grpc.CallOption) (*magistrala.IdentityRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
if in.GetToken() == InvalidValue || in.GetToken() == "" {
|
||||
return &mainflux.IdentityRes{}, errors.ErrAuthentication
|
||||
return &magistrala.IdentityRes{}, errors.ErrAuthentication
|
||||
}
|
||||
|
||||
return ret.Get(0).(*mainflux.IdentityRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.IdentityRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) Authorize(ctx context.Context, in *mainflux.AuthorizeReq, opts ...grpc.CallOption) (*mainflux.AuthorizeRes, error) {
|
||||
func (m *Service) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
if in.GetSubject() == InvalidValue || in.GetSubject() == "" {
|
||||
return &mainflux.AuthorizeRes{Authorized: false}, errors.ErrAuthorization
|
||||
return &magistrala.AuthorizeRes{Authorized: false}, errors.ErrAuthorization
|
||||
}
|
||||
if in.GetObject() == InvalidValue || in.GetObject() == "" {
|
||||
return &mainflux.AuthorizeRes{Authorized: false}, errors.ErrAuthorization
|
||||
return &magistrala.AuthorizeRes{Authorized: false}, errors.ErrAuthorization
|
||||
}
|
||||
|
||||
return ret.Get(0).(*mainflux.AuthorizeRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.AuthorizeRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) AddPolicy(ctx context.Context, in *mainflux.AddPolicyReq, opts ...grpc.CallOption) (*mainflux.AddPolicyRes, error) {
|
||||
func (m *Service) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.AddPolicyRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.AddPolicyRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) DeletePolicy(ctx context.Context, in *mainflux.DeletePolicyReq, opts ...grpc.CallOption) (*mainflux.DeletePolicyRes, error) {
|
||||
func (m *Service) DeletePolicy(ctx context.Context, in *magistrala.DeletePolicyReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.DeletePolicyRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.DeletePolicyRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) ListObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
||||
func (m *Service) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.ListObjectsRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.ListObjectsRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) ListAllObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
||||
func (m *Service) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.ListObjectsRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.ListObjectsRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) CountObjects(ctx context.Context, in *mainflux.CountObjectsReq, opts ...grpc.CallOption) (*mainflux.CountObjectsRes, error) {
|
||||
func (m *Service) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.CountObjectsRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.CountObjectsRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) ListSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
||||
func (m *Service) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.ListSubjectsRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.ListSubjectsRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) ListAllSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
||||
func (m *Service) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.ListSubjectsRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.ListSubjectsRes), ret.Error(1)
|
||||
}
|
||||
|
||||
func (m *Service) CountSubjects(ctx context.Context, in *mainflux.CountSubjectsReq, opts ...grpc.CallOption) (*mainflux.CountSubjectsRes, error) {
|
||||
func (m *Service) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
|
||||
return ret.Get(0).(*mainflux.CountSubjectsRes), ret.Error(1)
|
||||
return ret.Get(0).(*magistrala.CountSubjectsRes), ret.Error(1)
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
authmocks "github.com/absmach/magistrala/auth/mocks"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
bsapi "github.com/absmach/magistrala/bootstrap/api"
|
||||
@@ -168,7 +168,7 @@ func dec(in []byte) ([]byte, error) {
|
||||
return in, nil
|
||||
}
|
||||
|
||||
func newService(url string, auth mainflux.AuthServiceClient) bootstrap.Service {
|
||||
func newService(url string, auth magistrala.AuthServiceClient) bootstrap.Service {
|
||||
things := mocks.NewConfigsRepository()
|
||||
config := mfsdk.Config{
|
||||
ThingsURL: url,
|
||||
@@ -191,7 +191,7 @@ func generateChannels() map[string]mfgroups.Group {
|
||||
return channels
|
||||
}
|
||||
|
||||
func newThingsService() (things.Service, mfgroups.Service, mainflux.AuthServiceClient) {
|
||||
func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServiceClient) {
|
||||
auth := new(authmocks.Service)
|
||||
thingCache := thmocks.NewCache()
|
||||
idProvider := uuid.NewMock()
|
||||
|
||||
@@ -13,7 +13,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
authmocks "github.com/absmach/magistrala/auth/mocks"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
"github.com/absmach/magistrala/bootstrap/events/producer"
|
||||
@@ -80,7 +80,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func newService(url string, auth mainflux.AuthServiceClient) bootstrap.Service {
|
||||
func newService(url string, auth magistrala.AuthServiceClient) bootstrap.Service {
|
||||
configs := mocks.NewConfigsRepository()
|
||||
config := mfsdk.Config{
|
||||
ThingsURL: url,
|
||||
@@ -90,7 +90,7 @@ func newService(url string, auth mainflux.AuthServiceClient) bootstrap.Service {
|
||||
return bootstrap.New(auth, configs, sdk, encKey)
|
||||
}
|
||||
|
||||
func newThingsService() (things.Service, mfgroups.Service, mainflux.AuthServiceClient) {
|
||||
func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServiceClient) {
|
||||
auth := new(authmocks.Service)
|
||||
thingCache := thmocks.NewCache()
|
||||
idProvider := uuid.NewMock()
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"encoding/hex"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
)
|
||||
@@ -103,14 +103,14 @@ type ConfigReader interface {
|
||||
}
|
||||
|
||||
type bootstrapService struct {
|
||||
auth mainflux.AuthServiceClient
|
||||
auth magistrala.AuthServiceClient
|
||||
configs ConfigRepository
|
||||
sdk mfsdk.SDK
|
||||
encKey []byte
|
||||
}
|
||||
|
||||
// New returns new Bootstrap service.
|
||||
func New(auth mainflux.AuthServiceClient, configs ConfigRepository, sdk mfsdk.SDK, encKey []byte) Service {
|
||||
func New(auth magistrala.AuthServiceClient, configs ConfigRepository, sdk mfsdk.SDK, encKey []byte) Service {
|
||||
return &bootstrapService{
|
||||
configs: configs,
|
||||
sdk: sdk,
|
||||
@@ -365,7 +365,7 @@ func (bs bootstrapService) identify(ctx context.Context, token string) (string,
|
||||
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
||||
defer cancel()
|
||||
|
||||
res, err := bs.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
res, err := bs.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return "", errors.ErrAuthentication
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
"sort"
|
||||
"testing"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
authmocks "github.com/absmach/magistrala/auth/mocks"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
"github.com/absmach/magistrala/bootstrap/mocks"
|
||||
@@ -60,7 +60,7 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func newService(url string, auth mainflux.AuthServiceClient) bootstrap.Service {
|
||||
func newService(url string, auth magistrala.AuthServiceClient) bootstrap.Service {
|
||||
things := mocks.NewConfigsRepository()
|
||||
config := mfsdk.Config{
|
||||
ThingsURL: url,
|
||||
@@ -70,7 +70,7 @@ func newService(url string, auth mainflux.AuthServiceClient) bootstrap.Service {
|
||||
return bootstrap.New(auth, things, sdk, encKey)
|
||||
}
|
||||
|
||||
func newThingsService() (things.Service, mfgroups.Service, mainflux.AuthServiceClient) {
|
||||
func newThingsService() (things.Service, mfgroups.Service, magistrala.AuthServiceClient) {
|
||||
auth := new(authmocks.Service)
|
||||
thingCache := thmocks.NewCache()
|
||||
idProvider := uuid.NewMock()
|
||||
|
||||
+8
-8
@@ -7,7 +7,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/certs/pki"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
mfsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
@@ -45,14 +45,14 @@ type Service interface {
|
||||
}
|
||||
|
||||
type certsService struct {
|
||||
auth mainflux.AuthServiceClient
|
||||
auth magistrala.AuthServiceClient
|
||||
certsRepo Repository
|
||||
sdk mfsdk.SDK
|
||||
pki pki.Agent
|
||||
}
|
||||
|
||||
// New returns new Certs service.
|
||||
func New(auth mainflux.AuthServiceClient, certs Repository, sdk mfsdk.SDK, pki pki.Agent) Service {
|
||||
func New(auth magistrala.AuthServiceClient, certs Repository, sdk mfsdk.SDK, pki pki.Agent) Service {
|
||||
return &certsService{
|
||||
certsRepo: certs,
|
||||
sdk: sdk,
|
||||
@@ -80,7 +80,7 @@ type Cert struct {
|
||||
}
|
||||
|
||||
func (cs *certsService) IssueCert(ctx context.Context, token, thingID string, ttl string) (Cert, error) {
|
||||
owner, err := cs.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
owner, err := cs.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return Cert{}, err
|
||||
}
|
||||
@@ -113,7 +113,7 @@ func (cs *certsService) IssueCert(ctx context.Context, token, thingID string, tt
|
||||
|
||||
func (cs *certsService) RevokeCert(ctx context.Context, token, thingID string) (Revoke, error) {
|
||||
var revoke Revoke
|
||||
u, err := cs.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
u, err := cs.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return revoke, err
|
||||
}
|
||||
@@ -143,7 +143,7 @@ func (cs *certsService) RevokeCert(ctx context.Context, token, thingID string) (
|
||||
}
|
||||
|
||||
func (cs *certsService) ListCerts(ctx context.Context, token, thingID string, offset, limit uint64) (Page, error) {
|
||||
u, err := cs.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
u, err := cs.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return Page{}, err
|
||||
}
|
||||
@@ -166,7 +166,7 @@ func (cs *certsService) ListCerts(ctx context.Context, token, thingID string, of
|
||||
}
|
||||
|
||||
func (cs *certsService) ListSerials(ctx context.Context, token, thingID string, offset, limit uint64) (Page, error) {
|
||||
u, err := cs.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
u, err := cs.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return Page{}, err
|
||||
}
|
||||
@@ -175,7 +175,7 @@ func (cs *certsService) ListSerials(ctx context.Context, token, thingID string,
|
||||
}
|
||||
|
||||
func (cs *certsService) ViewCert(ctx context.Context, token, serialID string) (Cert, error) {
|
||||
u, err := cs.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
u, err := cs.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return Cert{}, err
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
"github.com/absmach/magistrala/bootstrap/api"
|
||||
"github.com/absmach/magistrala/bootstrap/events/consumer"
|
||||
@@ -141,7 +141,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, bootstrap.NewConfigReader([]byte(cfg.EncKey)), logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, auth mainflux.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgclient.Config) (bootstrap.Service, error) {
|
||||
func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgclient.Config) (bootstrap.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
|
||||
repoConfig := bootstrappg.NewConfigRepository(database, logger)
|
||||
|
||||
+3
-3
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/certs"
|
||||
"github.com/absmach/magistrala/certs/api"
|
||||
vault "github.com/absmach/magistrala/certs/pki"
|
||||
@@ -145,7 +145,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -162,7 +162,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(auth mainflux.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgclient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
func newService(auth magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger mflog.Logger, cfg config, dbConfig pgclient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
certsRepo := certspg.NewRepository(database, logger)
|
||||
config := mfsdk.Config{
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
"github.com/absmach/magistrala/consumers/notifiers"
|
||||
"github.com/absmach/magistrala/consumers/notifiers/api"
|
||||
@@ -141,7 +141,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -158,7 +158,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth mainflux.AuthServiceClient, c config, sc mfsmpp.Config, logger mflog.Logger) notifiers.Service {
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth magistrala.AuthServiceClient, c config, sc mfsmpp.Config, logger mflog.Logger) notifiers.Service {
|
||||
database := notifierpg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierpg.New(database))
|
||||
idp := ulid.New()
|
||||
|
||||
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
"github.com/absmach/magistrala/consumers/notifiers"
|
||||
"github.com/absmach/magistrala/consumers/notifiers/api"
|
||||
@@ -151,7 +151,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth mainflux.AuthServiceClient, c config, ec email.Config, logger mflog.Logger) (notifiers.Service, error) {
|
||||
func newService(db *sqlx.DB, tracer trace.Tracer, auth magistrala.AuthServiceClient, c config, ec email.Config, logger mflog.Logger) (notifiers.Service, error) {
|
||||
database := notifierpg.NewDatabase(db, tracer)
|
||||
repo := tracing.New(tracer, notifierpg.New(database))
|
||||
idp := ulid.New()
|
||||
|
||||
+5
-5
@@ -11,7 +11,7 @@ import (
|
||||
"os"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/absmach/magistrala/internal/clients/jaeger"
|
||||
@@ -136,7 +136,7 @@ func main() {
|
||||
}
|
||||
defer cacheclient.Close()
|
||||
|
||||
var auth mainflux.AuthServiceClient
|
||||
var auth magistrala.AuthServiceClient
|
||||
|
||||
switch cfg.StandaloneID != "" && cfg.StandaloneToken != "" {
|
||||
case true:
|
||||
@@ -178,12 +178,12 @@ func main() {
|
||||
}
|
||||
regiterAuthzServer := func(srv *grpc.Server) {
|
||||
reflection.Register(srv)
|
||||
mainflux.RegisterAuthzServiceServer(srv, grpcapi.NewServer(csvc))
|
||||
magistrala.RegisterAuthzServiceServer(srv, grpcapi.NewServer(csvc))
|
||||
}
|
||||
gs := grpcserver.New(ctx, cancel, svcName, grpcServerConfig, regiterAuthzServer, logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := callhome.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := callhome.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -205,7 +205,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth mainflux.AuthServiceClient, cacheClient *redis.Client, keyDuration, esURL string, tracer trace.Tracer, logger mflog.Logger) (things.Service, groups.Service, error) {
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth magistrala.AuthServiceClient, cacheClient *redis.Client, keyDuration, esURL string, tracer trace.Tracer, logger mflog.Logger) (things.Service, groups.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := thingspg.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
|
||||
+4
-4
@@ -10,7 +10,7 @@ import (
|
||||
"log"
|
||||
"os"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/absmach/magistrala/internal/clients/jaeger"
|
||||
@@ -119,7 +119,7 @@ func main() {
|
||||
}()
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
var auth mainflux.AuthServiceClient
|
||||
var auth magistrala.AuthServiceClient
|
||||
switch cfg.StandaloneID != "" && cfg.StandaloneToken != "" {
|
||||
case true:
|
||||
auth = localusers.NewAuthService(cfg.StandaloneID, cfg.StandaloneToken)
|
||||
@@ -154,7 +154,7 @@ func main() {
|
||||
hs := httpserver.New(ctx, cancel, svcName, httpServerConfig, twapi.MakeHandler(svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, id string, ps messaging.PubSub, cfg config, users mainflux.AuthServiceClient, tracer trace.Tracer, db *mongo.Database, cacheclient *redis.Client, logger mflog.Logger) (twins.Service, error) {
|
||||
func newService(ctx context.Context, id string, ps messaging.PubSub, cfg config, users magistrala.AuthServiceClient, tracer trace.Tracer, db *mongo.Database, cacheclient *redis.Client, logger mflog.Logger) (twins.Service, error) {
|
||||
twinRepo := twmongodb.NewTwinRepository(db)
|
||||
twinRepo = tracing.TwinRepositoryMiddleware(tracer, twinRepo)
|
||||
|
||||
|
||||
+3
-3
@@ -12,7 +12,7 @@ import (
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal"
|
||||
authclient "github.com/absmach/magistrala/internal/clients/grpc/auth"
|
||||
jaegerclient "github.com/absmach/magistrala/internal/clients/jaeger"
|
||||
@@ -167,7 +167,7 @@ func main() {
|
||||
httpSrv := httpserver.New(ctx, cancel, svcName, httpServerConfig, capi.MakeHandler(csvc, gsvc, mux, logger, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, mainflux.Version, logger, cancel)
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
go chc.CallHome(ctx)
|
||||
}
|
||||
|
||||
@@ -184,7 +184,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, auth mainflux.AuthServiceClient, db *sqlx.DB, dbConfig pgclient.Config, tracer trace.Tracer, c config, ec email.Config, logger mflog.Logger) (users.Service, groups.Service, error) {
|
||||
func newService(ctx context.Context, auth magistrala.AuthServiceClient, db *sqlx.DB, dbConfig pgclient.Config, tracer trace.Tracer, c config, ec email.Config, logger mflog.Logger) (users.Service, groups.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := clientspg.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/consumers"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
@@ -39,16 +39,16 @@ type Service interface {
|
||||
var _ Service = (*notifierService)(nil)
|
||||
|
||||
type notifierService struct {
|
||||
auth mainflux.AuthServiceClient
|
||||
auth magistrala.AuthServiceClient
|
||||
subs SubscriptionsRepository
|
||||
idp mainflux.IDProvider
|
||||
idp magistrala.IDProvider
|
||||
notifier Notifier
|
||||
errCh chan error
|
||||
from string
|
||||
}
|
||||
|
||||
// New instantiates the subscriptions service implementation.
|
||||
func New(auth mainflux.AuthServiceClient, subs SubscriptionsRepository, idp mainflux.IDProvider, notifier Notifier, from string) Service {
|
||||
func New(auth magistrala.AuthServiceClient, subs SubscriptionsRepository, idp magistrala.IDProvider, notifier Notifier, from string) Service {
|
||||
return ¬ifierService{
|
||||
auth: auth,
|
||||
subs: subs,
|
||||
@@ -60,7 +60,7 @@ func New(auth mainflux.AuthServiceClient, subs SubscriptionsRepository, idp main
|
||||
}
|
||||
|
||||
func (ns *notifierService) CreateSubscription(ctx context.Context, token string, sub Subscription) (string, error) {
|
||||
res, err := ns.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
res, err := ns.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -74,7 +74,7 @@ func (ns *notifierService) CreateSubscription(ctx context.Context, token string,
|
||||
}
|
||||
|
||||
func (ns *notifierService) ViewSubscription(ctx context.Context, token, id string) (Subscription, error) {
|
||||
if _, err := ns.auth.Identify(ctx, &mainflux.IdentityReq{Token: token}); err != nil {
|
||||
if _, err := ns.auth.Identify(ctx, &magistrala.IdentityReq{Token: token}); err != nil {
|
||||
return Subscription{}, err
|
||||
}
|
||||
|
||||
@@ -82,7 +82,7 @@ func (ns *notifierService) ViewSubscription(ctx context.Context, token, id strin
|
||||
}
|
||||
|
||||
func (ns *notifierService) ListSubscriptions(ctx context.Context, token string, pm PageMetadata) (Page, error) {
|
||||
if _, err := ns.auth.Identify(ctx, &mainflux.IdentityReq{Token: token}); err != nil {
|
||||
if _, err := ns.auth.Identify(ctx, &magistrala.IdentityReq{Token: token}); err != nil {
|
||||
return Page{}, err
|
||||
}
|
||||
|
||||
@@ -90,7 +90,7 @@ func (ns *notifierService) ListSubscriptions(ctx context.Context, token string,
|
||||
}
|
||||
|
||||
func (ns *notifierService) RemoveSubscription(ctx context.Context, token, id string) error {
|
||||
if _, err := ns.auth.Identify(ctx, &mainflux.IdentityReq{Token: token}); err != nil {
|
||||
if _, err := ns.auth.Identify(ctx, &magistrala.IdentityReq{Token: token}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
authgrpc "github.com/absmach/magistrala/auth/api/grpc"
|
||||
grpcclient "github.com/absmach/magistrala/internal/clients/grpc"
|
||||
"github.com/absmach/magistrala/internal/env"
|
||||
@@ -20,7 +20,7 @@ const (
|
||||
var errGrpcConfig = errors.New("failed to load grpc configuration")
|
||||
|
||||
// Setup loads Auth gRPC configuration from environment variable and creates new Auth gRPC API.
|
||||
func Setup(svcName string) (mainflux.AuthServiceClient, grpcclient.ClientHandler, error) {
|
||||
func Setup(svcName string) (magistrala.AuthServiceClient, grpcclient.ClientHandler, error) {
|
||||
config := grpcclient.Config{}
|
||||
if err := env.Parse(&config, env.Options{Prefix: envAuthGrpcPrefix}); err != nil {
|
||||
return nil, nil, errors.Wrap(errGrpcConfig, err)
|
||||
@@ -34,7 +34,7 @@ func Setup(svcName string) (mainflux.AuthServiceClient, grpcclient.ClientHandler
|
||||
}
|
||||
|
||||
// Setup loads Auth gRPC configuration from environment variable and creates new Auth gRPC API.
|
||||
func SetupAuthz(svcName string) (mainflux.AuthzServiceClient, grpcclient.ClientHandler, error) {
|
||||
func SetupAuthz(svcName string) (magistrala.AuthzServiceClient, grpcclient.ClientHandler, error) {
|
||||
config := grpcclient.Config{}
|
||||
if err := env.Parse(&config, env.Options{Prefix: envAuthzGrpcPrefix}); err != nil {
|
||||
return nil, nil, errors.Wrap(errGrpcConfig, err)
|
||||
|
||||
+24
-24
@@ -8,7 +8,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
@@ -48,12 +48,12 @@ const (
|
||||
|
||||
type service struct {
|
||||
groups groups.Repository
|
||||
auth mainflux.AuthServiceClient
|
||||
idProvider mainflux.IDProvider
|
||||
auth magistrala.AuthServiceClient
|
||||
idProvider magistrala.IDProvider
|
||||
}
|
||||
|
||||
// NewService returns a new Clients service implementation.
|
||||
func NewService(g groups.Repository, idp mainflux.IDProvider, auth mainflux.AuthServiceClient) groups.Service {
|
||||
func NewService(g groups.Repository, idp magistrala.IDProvider, auth magistrala.AuthServiceClient) groups.Service {
|
||||
return service{
|
||||
groups: g,
|
||||
idProvider: idp,
|
||||
@@ -92,7 +92,7 @@ func (svc service) CreateGroup(ctx context.Context, token string, g groups.Group
|
||||
return groups.Group{}, err
|
||||
}
|
||||
|
||||
policy := mainflux.AddPolicyReq{
|
||||
policy := magistrala.AddPolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: ownerID,
|
||||
Relation: ownerRelation,
|
||||
@@ -104,7 +104,7 @@ func (svc service) CreateGroup(ctx context.Context, token string, g groups.Group
|
||||
}
|
||||
|
||||
if g.Parent != "" {
|
||||
policy = mainflux.AddPolicyReq{
|
||||
policy = magistrala.AddPolicyReq{
|
||||
SubjectType: groupType,
|
||||
Subject: g.Parent,
|
||||
Relation: parentGroupRelation,
|
||||
@@ -139,7 +139,7 @@ func (svc service) ListGroups(ctx context.Context, token string, memberKind, mem
|
||||
if _, err := svc.authorizeKind(ctx, userType, usersKind, userID, viewPermission, thingType, memberID); err != nil {
|
||||
return groups.Page{}, err
|
||||
}
|
||||
cids, err := svc.auth.ListAllSubjects(ctx, &mainflux.ListSubjectsReq{
|
||||
cids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: groupType,
|
||||
Permission: groupRelation,
|
||||
ObjectType: thingType,
|
||||
@@ -157,7 +157,7 @@ func (svc service) ListGroups(ctx context.Context, token string, memberKind, mem
|
||||
return groups.Page{}, err
|
||||
}
|
||||
|
||||
gids, err := svc.auth.ListAllObjects(ctx, &mainflux.ListObjectsReq{
|
||||
gids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: groupType,
|
||||
Subject: memberID,
|
||||
Permission: parentGroupRelation,
|
||||
@@ -174,7 +174,7 @@ func (svc service) ListGroups(ctx context.Context, token string, memberKind, mem
|
||||
if _, err := svc.authorizeKind(ctx, userType, usersKind, userID, viewPermission, groupType, memberID); err != nil {
|
||||
return groups.Page{}, err
|
||||
}
|
||||
gids, err := svc.auth.ListAllSubjects(ctx, &mainflux.ListSubjectsReq{
|
||||
gids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: groupType,
|
||||
Permission: parentGroupRelation,
|
||||
ObjectType: groupType,
|
||||
@@ -193,7 +193,7 @@ func (svc service) ListGroups(ctx context.Context, token string, memberKind, mem
|
||||
if _, err := svc.authorizeKind(ctx, userType, usersKind, userID, ownerRelation, userType, memberID); err != nil {
|
||||
return groups.Page{}, err
|
||||
}
|
||||
gids, err := svc.auth.ListAllObjects(ctx, &mainflux.ListObjectsReq{
|
||||
gids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: userType,
|
||||
Subject: memberID,
|
||||
Permission: gm.Permission,
|
||||
@@ -231,7 +231,7 @@ func (svc service) ListMembers(ctx context.Context, token, groupID, permission,
|
||||
}
|
||||
switch memberKind {
|
||||
case thingsKind:
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &mainflux.ListObjectsReq{
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: groupType,
|
||||
Subject: groupID,
|
||||
Relation: groupRelation,
|
||||
@@ -256,7 +256,7 @@ func (svc service) ListMembers(ctx context.Context, token, groupID, permission,
|
||||
Members: members,
|
||||
}, nil
|
||||
case usersKind:
|
||||
uids, err := svc.auth.ListAllSubjects(ctx, &mainflux.ListSubjectsReq{
|
||||
uids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: userType,
|
||||
Permission: permission,
|
||||
Object: groupID,
|
||||
@@ -329,11 +329,11 @@ func (svc service) Assign(ctx context.Context, token, groupID, relation, memberK
|
||||
return err
|
||||
}
|
||||
|
||||
prs := []*mainflux.AddPolicyReq{}
|
||||
prs := []*magistrala.AddPolicyReq{}
|
||||
switch memberKind {
|
||||
case thingsKind:
|
||||
for _, memberID := range memberIDs {
|
||||
prs = append(prs, &mainflux.AddPolicyReq{
|
||||
prs = append(prs, &magistrala.AddPolicyReq{
|
||||
SubjectType: groupType,
|
||||
Subject: groupID,
|
||||
Relation: relation,
|
||||
@@ -343,7 +343,7 @@ func (svc service) Assign(ctx context.Context, token, groupID, relation, memberK
|
||||
}
|
||||
case groupsKind:
|
||||
for _, memberID := range memberIDs {
|
||||
prs = append(prs, &mainflux.AddPolicyReq{
|
||||
prs = append(prs, &magistrala.AddPolicyReq{
|
||||
SubjectType: groupType,
|
||||
Subject: memberID,
|
||||
Relation: relation,
|
||||
@@ -353,7 +353,7 @@ func (svc service) Assign(ctx context.Context, token, groupID, relation, memberK
|
||||
}
|
||||
case usersKind:
|
||||
for _, memberID := range memberIDs {
|
||||
prs = append(prs, &mainflux.AddPolicyReq{
|
||||
prs = append(prs, &magistrala.AddPolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: memberID,
|
||||
Relation: relation,
|
||||
@@ -379,12 +379,12 @@ func (svc service) Unassign(ctx context.Context, token, groupID, relation, membe
|
||||
return err
|
||||
}
|
||||
|
||||
prs := []*mainflux.DeletePolicyReq{}
|
||||
prs := []*magistrala.DeletePolicyReq{}
|
||||
|
||||
switch memberKind {
|
||||
case thingsKind:
|
||||
for _, memberID := range memberIDs {
|
||||
prs = append(prs, &mainflux.DeletePolicyReq{
|
||||
prs = append(prs, &magistrala.DeletePolicyReq{
|
||||
SubjectType: groupType,
|
||||
Subject: groupID,
|
||||
Relation: relation,
|
||||
@@ -394,7 +394,7 @@ func (svc service) Unassign(ctx context.Context, token, groupID, relation, membe
|
||||
}
|
||||
case groupsKind:
|
||||
for _, memberID := range memberIDs {
|
||||
prs = append(prs, &mainflux.DeletePolicyReq{
|
||||
prs = append(prs, &magistrala.DeletePolicyReq{
|
||||
SubjectType: groupType,
|
||||
Subject: memberID,
|
||||
Relation: relation,
|
||||
@@ -404,7 +404,7 @@ func (svc service) Unassign(ctx context.Context, token, groupID, relation, membe
|
||||
}
|
||||
case usersKind:
|
||||
for _, memberID := range memberIDs {
|
||||
prs = append(prs, &mainflux.DeletePolicyReq{
|
||||
prs = append(prs, &magistrala.DeletePolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: memberID,
|
||||
Relation: relation,
|
||||
@@ -443,7 +443,7 @@ func (svc service) filterAllowedGroupIDsOfUserID(ctx context.Context, userID str
|
||||
}
|
||||
|
||||
func (svc service) listAllGroupsOfUserID(ctx context.Context, userID string, permission string) ([]string, error) {
|
||||
allowedIDs, err := svc.auth.ListAllObjects(ctx, &mainflux.ListObjectsReq{
|
||||
allowedIDs, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: userType,
|
||||
Subject: userID,
|
||||
Permission: permission,
|
||||
@@ -473,7 +473,7 @@ func (svc service) changeGroupStatus(ctx context.Context, token string, group gr
|
||||
}
|
||||
|
||||
func (svc service) identify(ctx context.Context, token string) (string, error) {
|
||||
user, err := svc.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
user, err := svc.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -481,7 +481,7 @@ func (svc service) identify(ctx context.Context, token string) (string, error) {
|
||||
}
|
||||
|
||||
func (svc service) authorize(ctx context.Context, subjectType, subject, permission, objectType, object string) (string, error) {
|
||||
req := &mainflux.AuthorizeReq{
|
||||
req := &magistrala.AuthorizeReq{
|
||||
SubjectType: subjectType,
|
||||
SubjectKind: tokenKind,
|
||||
Subject: subject,
|
||||
@@ -500,7 +500,7 @@ func (svc service) authorize(ctx context.Context, subjectType, subject, permissi
|
||||
}
|
||||
|
||||
func (svc service) authorizeKind(ctx context.Context, subjectType, subjectKind, subject, permission, objectType, object string) (string, error) {
|
||||
req := &mainflux.AuthorizeReq{
|
||||
req := &magistrala.AuthorizeReq{
|
||||
SubjectType: subjectType,
|
||||
SubjectKind: subjectKind,
|
||||
Subject: subject,
|
||||
|
||||
@@ -6,14 +6,14 @@ package api
|
||||
import (
|
||||
"context"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/readers"
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
)
|
||||
|
||||
func listMessagesEndpoint(svc readers.MessageRepository, uauth mainflux.AuthServiceClient, taauth mainflux.AuthzServiceClient) endpoint.Endpoint {
|
||||
func listMessagesEndpoint(svc readers.MessageRepository, uauth magistrala.AuthServiceClient, taauth magistrala.AuthzServiceClient) endpoint.Endpoint {
|
||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
||||
req := request.(listMessagesReq)
|
||||
if err := req.validate(); err != nil {
|
||||
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/readers"
|
||||
@@ -49,7 +49,7 @@ const (
|
||||
var errUserAccess = errors.New("user has no permission")
|
||||
|
||||
// MakeHandler returns a HTTP handler for API endpoints.
|
||||
func MakeHandler(svc readers.MessageRepository, uauth mainflux.AuthServiceClient, taauth mainflux.AuthzServiceClient, svcName, instanceID string) http.Handler {
|
||||
func MakeHandler(svc readers.MessageRepository, uauth magistrala.AuthServiceClient, taauth magistrala.AuthzServiceClient, svcName, instanceID string) http.Handler {
|
||||
opts := []kithttp.ServerOption{
|
||||
kithttp.ServerErrorEncoder(encodeError),
|
||||
}
|
||||
@@ -62,7 +62,7 @@ func MakeHandler(svc readers.MessageRepository, uauth mainflux.AuthServiceClient
|
||||
opts...,
|
||||
))
|
||||
|
||||
mux.GetFunc("/health", mainflux.Health(svcName, instanceID))
|
||||
mux.GetFunc("/health", magistrala.Health(svcName, instanceID))
|
||||
mux.Handle("/metrics", promhttp.Handler())
|
||||
|
||||
return mux
|
||||
@@ -167,7 +167,7 @@ func decodeList(_ context.Context, r *http.Request) (interface{}, error) {
|
||||
func encodeResponse(_ context.Context, w http.ResponseWriter, response interface{}) error {
|
||||
w.Header().Set("Content-Type", contentType)
|
||||
|
||||
if ar, ok := response.(mainflux.Response); ok {
|
||||
if ar, ok := response.(magistrala.Response); ok {
|
||||
for k, v := range ar.Headers() {
|
||||
w.Header().Set(k, v)
|
||||
}
|
||||
@@ -218,10 +218,10 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
func authorize(ctx context.Context, req listMessagesReq, uauth mainflux.AuthServiceClient, taauth mainflux.AuthzServiceClient) (err error) {
|
||||
func authorize(ctx context.Context, req listMessagesReq, uauth magistrala.AuthServiceClient, taauth magistrala.AuthzServiceClient) (err error) {
|
||||
switch {
|
||||
case req.token != "":
|
||||
if _, err = uauth.Authorize(ctx, &mainflux.AuthorizeReq{
|
||||
if _, err = uauth.Authorize(ctx, &magistrala.AuthorizeReq{
|
||||
SubjectType: userType,
|
||||
SubjectKind: tokenKind,
|
||||
Subject: req.token,
|
||||
@@ -237,7 +237,7 @@ func authorize(ctx context.Context, req listMessagesReq, uauth mainflux.AuthServ
|
||||
}
|
||||
return nil
|
||||
case req.key != "":
|
||||
if _, err = taauth.Authorize(ctx, &mainflux.AuthorizeReq{
|
||||
if _, err = taauth.Authorize(ctx, &magistrala.AuthorizeReq{
|
||||
SubjectType: groupType,
|
||||
Subject: req.key,
|
||||
ObjectType: thingType,
|
||||
|
||||
+15
-15
@@ -6,7 +6,7 @@ import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
@@ -31,15 +31,15 @@ const (
|
||||
)
|
||||
|
||||
type service struct {
|
||||
auth mainflux.AuthServiceClient
|
||||
auth magistrala.AuthServiceClient
|
||||
clients postgres.Repository
|
||||
clientCache Cache
|
||||
idProvider mainflux.IDProvider
|
||||
idProvider magistrala.IDProvider
|
||||
grepo mfgroups.Repository
|
||||
}
|
||||
|
||||
// NewService returns a new Clients service implementation.
|
||||
func NewService(uauth mainflux.AuthServiceClient, c postgres.Repository, grepo mfgroups.Repository, tcache Cache, idp mainflux.IDProvider) Service {
|
||||
func NewService(uauth magistrala.AuthServiceClient, c postgres.Repository, grepo mfgroups.Repository, tcache Cache, idp magistrala.IDProvider) Service {
|
||||
return service{
|
||||
auth: uauth,
|
||||
clients: c,
|
||||
@@ -49,13 +49,13 @@ func NewService(uauth mainflux.AuthServiceClient, c postgres.Repository, grepo m
|
||||
}
|
||||
}
|
||||
|
||||
func (svc service) Authorize(ctx context.Context, req *mainflux.AuthorizeReq) (string, error) {
|
||||
func (svc service) Authorize(ctx context.Context, req *magistrala.AuthorizeReq) (string, error) {
|
||||
thingID, err := svc.Identify(ctx, req.GetSubject())
|
||||
if err != nil {
|
||||
return "", errors.ErrAuthentication
|
||||
}
|
||||
|
||||
r := &mainflux.AuthorizeReq{
|
||||
r := &magistrala.AuthorizeReq{
|
||||
SubjectType: groupType,
|
||||
Subject: req.GetObject(),
|
||||
ObjectType: thingType,
|
||||
@@ -74,7 +74,7 @@ func (svc service) Authorize(ctx context.Context, req *mainflux.AuthorizeReq) (s
|
||||
}
|
||||
|
||||
func (svc service) CreateThings(ctx context.Context, token string, cls ...mfclients.Client) ([]mfclients.Client, error) {
|
||||
user, err := svc.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
user, err := svc.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return []mfclients.Client{}, errors.Wrap(errors.ErrAuthorization, err)
|
||||
}
|
||||
@@ -110,7 +110,7 @@ func (svc service) CreateThings(ctx context.Context, token string, cls ...mfclie
|
||||
}
|
||||
|
||||
for _, c := range saved {
|
||||
policy := mainflux.AddPolicyReq{
|
||||
policy := magistrala.AddPolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: user.GetId(),
|
||||
Relation: ownerRelation,
|
||||
@@ -174,7 +174,7 @@ func (svc service) ListClients(ctx context.Context, token string, reqUserID stri
|
||||
}
|
||||
|
||||
func (svc service) listClientIDs(ctx context.Context, userID, permission string) ([]string, error) {
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &mainflux.ListObjectsReq{
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: userType,
|
||||
Subject: userID,
|
||||
Permission: permission,
|
||||
@@ -188,7 +188,7 @@ func (svc service) listClientIDs(ctx context.Context, userID, permission string)
|
||||
|
||||
func (svc service) filterAllowedThingIDs(ctx context.Context, userID, permission string, thingIDs []string) ([]string, error) {
|
||||
var ids []string
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &mainflux.ListObjectsReq{
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: userType,
|
||||
Subject: userID,
|
||||
Permission: permission,
|
||||
@@ -311,7 +311,7 @@ func (svc service) Share(ctx context.Context, token, id, relation string, userid
|
||||
}
|
||||
|
||||
for _, userid := range userids {
|
||||
addPolicyReq := &mainflux.AddPolicyReq{
|
||||
addPolicyReq := &magistrala.AddPolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: userid,
|
||||
Relation: relation,
|
||||
@@ -337,7 +337,7 @@ func (svc service) Unshare(ctx context.Context, token, id, relation string, user
|
||||
}
|
||||
|
||||
for _, userid := range userids {
|
||||
delPolicyReq := &mainflux.DeletePolicyReq{
|
||||
delPolicyReq := &magistrala.DeletePolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: userid,
|
||||
Relation: relation,
|
||||
@@ -378,7 +378,7 @@ func (svc service) ListClientsByGroup(ctx context.Context, token, groupID string
|
||||
return mfclients.MembersPage{}, err
|
||||
}
|
||||
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &mainflux.ListObjectsReq{
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: groupType,
|
||||
Subject: groupID,
|
||||
Permission: groupRelation,
|
||||
@@ -419,7 +419,7 @@ func (svc service) Identify(ctx context.Context, key string) (string, error) {
|
||||
}
|
||||
|
||||
func (svc service) identify(ctx context.Context, token string) (string, error) {
|
||||
user, err := svc.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
user, err := svc.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -428,7 +428,7 @@ func (svc service) identify(ctx context.Context, token string) (string, error) {
|
||||
}
|
||||
|
||||
func (svc *service) authorize(ctx context.Context, subjType, subjKind, subj, perm, objType, obj string) (string, error) {
|
||||
req := &mainflux.AuthorizeReq{
|
||||
req := &magistrala.AuthorizeReq{
|
||||
SubjectType: subjType,
|
||||
SubjectKind: subjKind,
|
||||
Subject: subj,
|
||||
|
||||
@@ -6,12 +6,12 @@ package standalone
|
||||
import (
|
||||
"context"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var _ mainflux.AuthServiceClient = (*singleUserRepo)(nil)
|
||||
var _ magistrala.AuthServiceClient = (*singleUserRepo)(nil)
|
||||
|
||||
type singleUserRepo struct {
|
||||
id string
|
||||
@@ -19,69 +19,69 @@ type singleUserRepo struct {
|
||||
}
|
||||
|
||||
// NewAuthService creates single user repository for constrained environments.
|
||||
func NewAuthService(id, token string) mainflux.AuthServiceClient {
|
||||
func NewAuthService(id, token string) magistrala.AuthServiceClient {
|
||||
return singleUserRepo{
|
||||
id: id,
|
||||
token: token,
|
||||
}
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) Login(ctx context.Context, in *mainflux.LoginReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (repo singleUserRepo) Login(ctx context.Context, in *magistrala.LoginReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) Refresh(ctx context.Context, in *mainflux.RefreshReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (repo singleUserRepo) Refresh(ctx context.Context, in *magistrala.RefreshReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) Issue(ctx context.Context, in *mainflux.IssueReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
|
||||
func (repo singleUserRepo) Issue(ctx context.Context, in *magistrala.IssueReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) Identify(ctx context.Context, in *mainflux.IdentityReq, opts ...grpc.CallOption) (*mainflux.IdentityRes, error) {
|
||||
func (repo singleUserRepo) Identify(ctx context.Context, in *magistrala.IdentityReq, opts ...grpc.CallOption) (*magistrala.IdentityRes, error) {
|
||||
if repo.token != in.GetToken() {
|
||||
return nil, errors.ErrAuthentication
|
||||
}
|
||||
|
||||
return &mainflux.IdentityRes{Id: repo.id}, nil
|
||||
return &magistrala.IdentityRes{Id: repo.id}, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) Authorize(ctx context.Context, in *mainflux.AuthorizeReq, opts ...grpc.CallOption) (*mainflux.AuthorizeRes, error) {
|
||||
func (repo singleUserRepo) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) {
|
||||
if repo.id != in.Subject {
|
||||
return &mainflux.AuthorizeRes{Authorized: false}, errors.ErrAuthorization
|
||||
return &magistrala.AuthorizeRes{Authorized: false}, errors.ErrAuthorization
|
||||
}
|
||||
|
||||
return &mainflux.AuthorizeRes{Authorized: true}, nil
|
||||
return &magistrala.AuthorizeRes{Authorized: true}, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) AddPolicy(ctx context.Context, in *mainflux.AddPolicyReq, opts ...grpc.CallOption) (*mainflux.AddPolicyRes, error) {
|
||||
func (repo singleUserRepo) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) DeletePolicy(ctx context.Context, in *mainflux.DeletePolicyReq, opts ...grpc.CallOption) (*mainflux.DeletePolicyRes, error) {
|
||||
func (repo singleUserRepo) DeletePolicy(ctx context.Context, in *magistrala.DeletePolicyReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) ListObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
||||
func (repo singleUserRepo) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) ListAllObjects(ctx context.Context, in *mainflux.ListObjectsReq, opts ...grpc.CallOption) (*mainflux.ListObjectsRes, error) {
|
||||
func (repo singleUserRepo) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) CountObjects(ctx context.Context, in *mainflux.CountObjectsReq, opts ...grpc.CallOption) (*mainflux.CountObjectsRes, error) {
|
||||
func (repo singleUserRepo) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) ListSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
||||
func (repo singleUserRepo) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) ListAllSubjects(ctx context.Context, in *mainflux.ListSubjectsReq, opts ...grpc.CallOption) (*mainflux.ListSubjectsRes, error) {
|
||||
func (repo singleUserRepo) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) CountSubjects(ctx context.Context, in *mainflux.CountSubjectsReq, opts ...grpc.CallOption) (*mainflux.CountSubjectsRes, error) {
|
||||
func (repo singleUserRepo) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
+10
-10
@@ -10,7 +10,7 @@ import (
|
||||
"math"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
@@ -73,10 +73,10 @@ var crudOp = map[string]string{
|
||||
|
||||
type twinsService struct {
|
||||
publisher messaging.Publisher
|
||||
auth mainflux.AuthServiceClient
|
||||
auth magistrala.AuthServiceClient
|
||||
twins TwinRepository
|
||||
states StateRepository
|
||||
idProvider mainflux.IDProvider
|
||||
idProvider magistrala.IDProvider
|
||||
channelID string
|
||||
twinCache TwinCache
|
||||
logger logger.Logger
|
||||
@@ -85,7 +85,7 @@ type twinsService struct {
|
||||
var _ Service = (*twinsService)(nil)
|
||||
|
||||
// New instantiates the twins service implementation.
|
||||
func New(publisher messaging.Publisher, auth mainflux.AuthServiceClient, twins TwinRepository, tcache TwinCache, sr StateRepository, idp mainflux.IDProvider, chann string, logger logger.Logger) Service {
|
||||
func New(publisher messaging.Publisher, auth magistrala.AuthServiceClient, twins TwinRepository, tcache TwinCache, sr StateRepository, idp magistrala.IDProvider, chann string, logger logger.Logger) Service {
|
||||
return &twinsService{
|
||||
publisher: publisher,
|
||||
auth: auth,
|
||||
@@ -102,7 +102,7 @@ func (ts *twinsService) AddTwin(ctx context.Context, token string, twin Twin, de
|
||||
var id string
|
||||
var b []byte
|
||||
defer ts.publish(ctx, &id, &err, crudOp["createSucc"], crudOp["createFail"], &b)
|
||||
res, err := ts.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
res, err := ts.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return Twin{}, err
|
||||
}
|
||||
@@ -145,7 +145,7 @@ func (ts *twinsService) UpdateTwin(ctx context.Context, token string, twin Twin,
|
||||
var id string
|
||||
defer ts.publish(ctx, &id, &err, crudOp["updateSucc"], crudOp["updateFail"], &b)
|
||||
|
||||
_, err = ts.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
_, err = ts.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return errors.ErrAuthentication
|
||||
}
|
||||
@@ -195,7 +195,7 @@ func (ts *twinsService) ViewTwin(ctx context.Context, token, twinID string) (tw
|
||||
var b []byte
|
||||
defer ts.publish(ctx, &twinID, &err, crudOp["getSucc"], crudOp["getFail"], &b)
|
||||
|
||||
_, err = ts.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
_, err = ts.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return Twin{}, err
|
||||
}
|
||||
@@ -214,7 +214,7 @@ func (ts *twinsService) RemoveTwin(ctx context.Context, token, twinID string) (e
|
||||
var b []byte
|
||||
defer ts.publish(ctx, &twinID, &err, crudOp["removeSucc"], crudOp["removeFail"], &b)
|
||||
|
||||
_, err = ts.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
_, err = ts.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return errors.ErrAuthentication
|
||||
}
|
||||
@@ -227,7 +227,7 @@ func (ts *twinsService) RemoveTwin(ctx context.Context, token, twinID string) (e
|
||||
}
|
||||
|
||||
func (ts *twinsService) ListTwins(ctx context.Context, token string, offset uint64, limit uint64, name string, metadata Metadata) (Page, error) {
|
||||
res, err := ts.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
res, err := ts.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return Page{}, errors.ErrAuthentication
|
||||
}
|
||||
@@ -236,7 +236,7 @@ func (ts *twinsService) ListTwins(ctx context.Context, token string, offset uint
|
||||
}
|
||||
|
||||
func (ts *twinsService) ListStates(ctx context.Context, token string, offset uint64, limit uint64, twinID string) (StatesPage, error) {
|
||||
_, err := ts.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
_, err := ts.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return StatesPage{}, errors.ErrAuthentication
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ func (lm *loggingMiddleware) RegisterClient(ctx context.Context, token string, c
|
||||
// If the request fails, it logs the error.
|
||||
func (lm *loggingMiddleware) IssueToken(ctx context.Context, identity, secret string) (t *mainflux.Token, err error) {
|
||||
defer func(begin time.Time) {
|
||||
message := fmt.Sprintf("Method issue_token of type %s for client %s took %s to complete", t.AccessType, identity, time.Since(begin))
|
||||
message := fmt.Sprintf("Method issue_token of type %s for client %s took %s to complete", t.GetAccessType(), identity, time.Since(begin))
|
||||
if err != nil {
|
||||
lm.logger.Warn(fmt.Sprintf("%s with error: %s.", message, err))
|
||||
return
|
||||
|
||||
+16
-16
@@ -8,7 +8,7 @@ import (
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
mainflux "github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
"github.com/absmach/magistrala/internal/apiutil"
|
||||
mfclients "github.com/absmach/magistrala/pkg/clients"
|
||||
@@ -39,15 +39,15 @@ var (
|
||||
|
||||
type service struct {
|
||||
clients postgres.Repository
|
||||
idProvider mainflux.IDProvider
|
||||
auth mainflux.AuthServiceClient
|
||||
idProvider magistrala.IDProvider
|
||||
auth magistrala.AuthServiceClient
|
||||
hasher Hasher
|
||||
email Emailer
|
||||
passRegex *regexp.Regexp
|
||||
}
|
||||
|
||||
// NewService returns a new Users service implementation.
|
||||
func NewService(crepo postgres.Repository, auth mainflux.AuthServiceClient, emailer Emailer, hasher Hasher, idp mainflux.IDProvider, pr *regexp.Regexp) Service {
|
||||
func NewService(crepo postgres.Repository, auth magistrala.AuthServiceClient, emailer Emailer, hasher Hasher, idp magistrala.IDProvider, pr *regexp.Regexp) Service {
|
||||
return service{
|
||||
clients: crepo,
|
||||
auth: auth,
|
||||
@@ -98,20 +98,20 @@ func (svc service) RegisterClient(ctx context.Context, token string, cli mfclien
|
||||
return client, nil
|
||||
}
|
||||
|
||||
func (svc service) IssueToken(ctx context.Context, identity, secret string) (*mainflux.Token, error) {
|
||||
func (svc service) IssueToken(ctx context.Context, identity, secret string) (*magistrala.Token, error) {
|
||||
dbUser, err := svc.clients.RetrieveByIdentity(ctx, identity)
|
||||
if err != nil {
|
||||
return &mainflux.Token{}, err
|
||||
return &magistrala.Token{}, err
|
||||
}
|
||||
if err := svc.hasher.Compare(secret, dbUser.Credentials.Secret); err != nil {
|
||||
return &mainflux.Token{}, errors.Wrap(errors.ErrLogin, err)
|
||||
return &magistrala.Token{}, errors.Wrap(errors.ErrLogin, err)
|
||||
}
|
||||
|
||||
return svc.auth.Issue(ctx, &mainflux.IssueReq{Id: dbUser.ID, Type: 0})
|
||||
return svc.auth.Issue(ctx, &magistrala.IssueReq{Id: dbUser.ID, Type: 0})
|
||||
}
|
||||
|
||||
func (svc service) RefreshToken(ctx context.Context, refreshToken string) (*mainflux.Token, error) {
|
||||
return svc.auth.Refresh(ctx, &mainflux.RefreshReq{Value: refreshToken})
|
||||
func (svc service) RefreshToken(ctx context.Context, refreshToken string) (*magistrala.Token, error) {
|
||||
return svc.auth.Refresh(ctx, &magistrala.RefreshReq{Value: refreshToken})
|
||||
}
|
||||
|
||||
func (svc service) ViewClient(ctx context.Context, token string, id string) (mfclients.Client, error) {
|
||||
@@ -235,7 +235,7 @@ func (svc service) GenerateResetToken(ctx context.Context, email, host string) e
|
||||
if err != nil || client.Credentials.Identity == "" {
|
||||
return errors.ErrNotFound
|
||||
}
|
||||
issueReq := &mainflux.IssueReq{
|
||||
issueReq := &magistrala.IssueReq{
|
||||
Id: client.ID,
|
||||
Type: uint32(auth.RecoveryKey),
|
||||
}
|
||||
@@ -401,7 +401,7 @@ func (svc service) ListMembers(ctx context.Context, token, objectKind string, ob
|
||||
if _, err := svc.authorize(ctx, userType, tokenKind, token, authzPerm, objectType, objectID); err != nil {
|
||||
return mfclients.MembersPage{}, err
|
||||
}
|
||||
uids, err := svc.auth.ListAllSubjects(ctx, &mainflux.ListSubjectsReq{
|
||||
uids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: userType,
|
||||
Permission: pm.Permission,
|
||||
Object: objectID,
|
||||
@@ -435,7 +435,7 @@ func (svc *service) isOwner(ctx context.Context, clientID, ownerID string) error
|
||||
}
|
||||
|
||||
func (svc *service) authorize(ctx context.Context, subjType, subjKind, subj, perm, objType, obj string) (string, error) {
|
||||
req := &mainflux.AuthorizeReq{
|
||||
req := &magistrala.AuthorizeReq{
|
||||
SubjectType: subjType,
|
||||
SubjectKind: subjKind,
|
||||
Subject: subj,
|
||||
@@ -455,7 +455,7 @@ func (svc *service) authorize(ctx context.Context, subjType, subjKind, subj, per
|
||||
}
|
||||
|
||||
func (svc service) Identify(ctx context.Context, token string) (string, error) {
|
||||
user, err := svc.auth.Identify(ctx, &mainflux.IdentityReq{Token: token})
|
||||
user, err := svc.auth.Identify(ctx, &magistrala.IdentityReq{Token: token})
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -464,7 +464,7 @@ func (svc service) Identify(ctx context.Context, token string) (string, error) {
|
||||
|
||||
func (svc service) updateOwnerPolicy(ctx context.Context, previousOwnerID, ownerID, userID string) error {
|
||||
if previousOwnerID != "" {
|
||||
if _, err := svc.auth.DeletePolicy(ctx, &mainflux.DeletePolicyReq{
|
||||
if _, err := svc.auth.DeletePolicy(ctx, &magistrala.DeletePolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: previousOwnerID,
|
||||
Relation: ownerRelation,
|
||||
@@ -479,7 +479,7 @@ func (svc service) updateOwnerPolicy(ctx context.Context, previousOwnerID, owner
|
||||
|
||||
func (svc service) addOwnerPolicy(ctx context.Context, ownerID, userID string) error {
|
||||
if ownerID != "" {
|
||||
if _, err := svc.auth.AddPolicy(ctx, &mainflux.AddPolicyReq{
|
||||
if _, err := svc.auth.AddPolicy(ctx, &magistrala.AddPolicyReq{
|
||||
SubjectType: userType,
|
||||
Subject: ownerID,
|
||||
Relation: ownerRelation,
|
||||
|
||||
Reference in New Issue
Block a user