-
Notifications
You must be signed in to change notification settings - Fork 668
/
standalone.go
99 lines (75 loc) · 3.48 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0
package standalone
import (
"context"
"github.com/absmach/magistrala"
svcerr "github.com/absmach/magistrala/pkg/errors"
"google.golang.org/grpc"
)
var _ magistrala.AuthServiceClient = (*singleUserRepo)(nil)
type singleUserRepo struct {
id string
token string
}
// NewAuthService creates single user repository for constrained environments.
func NewAuthService(id, token string) magistrala.AuthServiceClient {
return singleUserRepo{
id: id,
token: token,
}
}
func (repo singleUserRepo) Login(ctx context.Context, in *magistrala.IssueReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
return nil, nil
}
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 *magistrala.IssueReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
return nil, nil
}
func (repo singleUserRepo) Identify(ctx context.Context, in *magistrala.IdentityReq, opts ...grpc.CallOption) (*magistrala.IdentityRes, error) {
if repo.token != in.GetToken() {
return nil, svcerr.ErrAuthentication
}
return &magistrala.IdentityRes{Id: repo.id}, nil
}
func (repo singleUserRepo) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) {
if repo.id != in.Subject {
return &magistrala.AuthorizeRes{Authorized: false}, svcerr.ErrAuthorization
}
return &magistrala.AuthorizeRes{Authorized: true}, nil
}
func (repo singleUserRepo) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
return nil, nil
}
func (repo singleUserRepo) AddPolicies(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption) (*magistrala.AddPoliciesRes, error) {
return nil, nil
}
func (repo singleUserRepo) DeletePolicy(ctx context.Context, in *magistrala.DeletePolicyReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
return nil, nil
}
func (repo singleUserRepo) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePoliciesRes, error) {
return nil, nil
}
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 *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
return nil, nil
}
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 *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
return nil, nil
}
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 *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) {
return nil, nil
}
func (repo singleUserRepo) ListPermissions(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption) (*magistrala.ListPermissionsRes, error) {
return nil, nil
}