1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00
b1ackd0t 7cccba91c9
NOISSUE - Reformat Things and Users Policies Endpoint (#1831)
* Reformat Policies Enpoint to Take Sub Obj

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Add Redirect to `policies`

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Make Delete Endpoint not to Contain Body

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Remove gRPC unused functions

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Remove Redirect

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Update CLI

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Use Switch Statement

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Uncomment Commented Parts

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Add Empty Line

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Remove Unused gRPC Req and Resp

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Fix Listing of Policies

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Rename Authorize Functions For Users and Things Service

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

* Add Authorize To CLI

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>

---------

Signed-off-by: rodneyosodo <blackd0t@protonmail.com>
2023-07-28 14:39:13 +02:00

54 lines
1.7 KiB
Go

// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package mocks
import (
"context"
"github.com/mainflux/mainflux/pkg/errors"
"github.com/mainflux/mainflux/things/policies"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
var _ policies.AuthServiceClient = (*thingsClient)(nil)
// ServiceErrToken is used to simulate internal server error.
const ServiceErrToken = "unavailable"
type thingsClient struct {
things map[string]string
}
// NewThingsClient returns mock implementation of things service client.
func NewThingsClient(data map[string]string) policies.AuthServiceClient {
return &thingsClient{data}
}
func (tc thingsClient) Authorize(ctx context.Context, req *policies.AuthorizeReq, opts ...grpc.CallOption) (*policies.AuthorizeRes, error) {
secret := req.GetSubject()
// Since there is no appropriate way to simulate internal server error,
// we had to use this obscure approach. ErrorToken simulates gRPC
// call which returns internal server error.
if secret == ServiceErrToken {
return &policies.AuthorizeRes{ThingID: "", Authorized: false}, status.Error(codes.Internal, "internal server error")
}
if secret == "" {
return &policies.AuthorizeRes{ThingID: "", Authorized: false}, errors.ErrAuthentication
}
id, ok := tc.things[secret]
if !ok {
return &policies.AuthorizeRes{ThingID: "", Authorized: false}, status.Error(codes.Unauthenticated, "invalid credentials provided")
}
return &policies.AuthorizeRes{ThingID: id, Authorized: true}, nil
}
func (tc thingsClient) Identify(ctx context.Context, req *policies.IdentifyReq, opts ...grpc.CallOption) (*policies.IdentifyRes, error) {
panic("not implemented")
}