/
standalone.go
70 lines (53 loc) · 2.28 KB
/
standalone.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) Mainflux
// SPDX-License-Identifier: Apache-2.0
package standalone
import (
"context"
"github.com/MainfluxLabs/mainflux"
"github.com/MainfluxLabs/mainflux/pkg/errors"
"github.com/golang/protobuf/ptypes/empty"
"google.golang.org/grpc"
)
var errUnsupported = errors.New("not supported in standalone mode")
var _ mainflux.AuthServiceClient = (*singleUserRepo)(nil)
type singleUserRepo struct {
email string
token string
}
// NewAuthService creates single user repository for constrained environments.
func NewAuthService(email, token string) mainflux.AuthServiceClient {
return singleUserRepo{
email: email,
token: token,
}
}
func (repo singleUserRepo) Issue(ctx context.Context, req *mainflux.IssueReq, opts ...grpc.CallOption) (*mainflux.Token, error) {
if repo.token != req.GetEmail() {
return nil, errors.ErrAuthentication
}
return &mainflux.Token{Value: repo.token}, nil
}
func (repo singleUserRepo) Identify(ctx context.Context, token *mainflux.Token, opts ...grpc.CallOption) (*mainflux.UserIdentity, error) {
if repo.token != token.GetValue() {
return nil, errors.ErrAuthentication
}
return &mainflux.UserIdentity{Id: repo.email, Email: repo.email}, nil
}
func (repo singleUserRepo) Authorize(ctx context.Context, req *mainflux.AuthorizeReq, _ ...grpc.CallOption) (r *empty.Empty, err error) {
return &empty.Empty{}, errUnsupported
}
func (repo singleUserRepo) AddPolicy(ctx context.Context, in *mainflux.PolicyReq, opts ...grpc.CallOption) (r *empty.Empty, err error) {
return &empty.Empty{}, errUnsupported
}
func (repo singleUserRepo) Members(ctx context.Context, req *mainflux.MembersReq, _ ...grpc.CallOption) (r *mainflux.MembersRes, err error) {
return &mainflux.MembersRes{}, errUnsupported
}
func (repo singleUserRepo) Assign(ctx context.Context, req *mainflux.Assignment, _ ...grpc.CallOption) (r *empty.Empty, err error) {
return &empty.Empty{}, errUnsupported
}
func (repo singleUserRepo) AssignRole(ctx context.Context, req *mainflux.AssignRoleReq, _ ...grpc.CallOption) (r *empty.Empty, err error) {
return &empty.Empty{}, errUnsupported
}
func (repo singleUserRepo) RetrieveRole(ctx context.Context, req *mainflux.RetrieveRoleReq, _ ...grpc.CallOption) (r *mainflux.RetrieveRoleRes, err error) {
return &mainflux.RetrieveRoleRes{}, errUnsupported
}