mirror of
https://github.com/absmach/supermq.git
synced 2026-06-23 07:10:19 +00:00
MG-2264 - Split Auth Client into Separate Clients for AuthN/AuthZ and Policy CRUD (#2392)
Signed-off-by: 1998-felix <felix.gateru@gmail.com>
This commit is contained in:
@@ -154,6 +154,8 @@ jobs:
|
||||
mv ./journal/mocks/repository.go ./journal/mocks/repository.go.tmp
|
||||
mv ./journal/mocks/service.go ./journal/mocks/service.go.tmp
|
||||
mv ./auth/mocks/auth_client.go ./auth/mocks/auth_client.go.tmp
|
||||
mv ./auth/mocks/policy_client.go ./auth/mocks/policy_client.go.tmp
|
||||
mv ./things/mocks/authz_client.go ./things/mocks/authz_client.go.tmp
|
||||
|
||||
make mocks
|
||||
|
||||
@@ -203,3 +205,5 @@ jobs:
|
||||
check_mock_changes ./journal/mocks/repository.go "Journal Repository ./journal/mocks/repository.go"
|
||||
check_mock_changes ./journal/mocks/service.go "Journal Service ./journal/mocks/service.go"
|
||||
check_mock_changes ./auth/mocks/auth_client.go "Auth Service Client ./auth/mocks/auth_client.go"
|
||||
check_mock_changes ./auth/mocks/policy_client.go "Policy Service Client ./auth/mocks/policy_client.go"
|
||||
check_mock_changes ./things/mocks/authz_client.go "Authz Service Client things/mocks/authz_client.go"
|
||||
|
||||
@@ -160,9 +160,6 @@ jobs:
|
||||
- "logger/**"
|
||||
- "pkg/events/**"
|
||||
|
||||
pkg-auth:
|
||||
- "pkg/auth/**"
|
||||
|
||||
pkg-clients:
|
||||
- "pkg/clients/**"
|
||||
|
||||
@@ -173,6 +170,9 @@ jobs:
|
||||
- "pkg/events/**"
|
||||
- "pkg/messaging/**"
|
||||
|
||||
pkg-grpcclient:
|
||||
- "pkg/grpcclient/**"
|
||||
|
||||
pkg-messaging:
|
||||
- "pkg/messaging/**"
|
||||
|
||||
@@ -314,11 +314,6 @@ jobs:
|
||||
run: |
|
||||
go test --race -v -count=1 -coverprofile=coverage/mqtt.out ./mqtt/...
|
||||
|
||||
- name: Run pkg auth tests
|
||||
if: steps.changes.outputs.pkg-auth == 'true' || steps.changes.outputs.workflow == 'true'
|
||||
run: |
|
||||
go test --race -v -count=1 -coverprofile=coverage/pkg-auth.out ./pkg/auth/...
|
||||
|
||||
- name: Run pkg clients tests
|
||||
if: steps.changes.outputs.pkg-clients == 'true' || steps.changes.outputs.workflow == 'true'
|
||||
run: |
|
||||
@@ -334,6 +329,11 @@ jobs:
|
||||
run: |
|
||||
go test --race -v -count=1 -coverprofile=coverage/pkg-events.out ./pkg/events/...
|
||||
|
||||
- name: Run pkg grpcclient tests
|
||||
if: steps.changes.outputs.pkg-grpcclient == 'true' || steps.changes.outputs.workflow == 'true'
|
||||
run: |
|
||||
go test --race -v -count=1 -coverprofile=coverage/pkg-grpcclient.out ./pkg/grpcclient/...
|
||||
|
||||
- name: Run pkg messaging tests
|
||||
if: steps.changes.outputs.pkg-messaging == 'true' || steps.changes.outputs.workflow == 'true'
|
||||
run: |
|
||||
|
||||
@@ -466,6 +466,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -306,6 +306,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -131,6 +131,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -57,6 +57,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -171,6 +171,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -71,6 +71,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -131,6 +131,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -71,6 +71,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -75,6 +75,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -453,7 +453,7 @@ paths:
|
||||
"403":
|
||||
description: Failed to perform authorization over the entity.
|
||||
"404":
|
||||
descripttion: A non-existent entity request.
|
||||
description: A non-existent entity request.
|
||||
"409":
|
||||
description: Failed due to using an existing identity.
|
||||
"415":
|
||||
@@ -577,7 +577,7 @@ paths:
|
||||
"403":
|
||||
description: Unauthorized access to thing id.
|
||||
"404":
|
||||
descripttion: A non-existent entity request.
|
||||
description: A non-existent entity request.
|
||||
"500":
|
||||
$ref: "#/components/responses/ServiceError"
|
||||
|
||||
@@ -967,6 +967,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -180,6 +180,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
@@ -397,7 +397,7 @@ paths:
|
||||
"500":
|
||||
$ref: "#/components/responses/ServiceError"
|
||||
|
||||
/users/search:
|
||||
/users/search:
|
||||
get:
|
||||
operationId: searchUsers
|
||||
summary: Search users
|
||||
@@ -1062,6 +1062,7 @@ paths:
|
||||
summary: Retrieves service health check info.
|
||||
tags:
|
||||
- health
|
||||
security: []
|
||||
responses:
|
||||
"200":
|
||||
$ref: "#/components/responses/HealthRes"
|
||||
|
||||
+48
-53
@@ -2256,23 +2256,20 @@ var file_auth_proto_rawDesc = []byte{
|
||||
0x72, 0x69, 0x7a, 0x65, 0x12, 0x18, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c,
|
||||
0x61, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x18,
|
||||
0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x41, 0x75, 0x74, 0x68,
|
||||
0x6f, 0x72, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x22, 0x00, 0x32, 0xac, 0x09, 0x0a, 0x0b, 0x41,
|
||||
0x75, 0x74, 0x68, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x32, 0x0a, 0x05, 0x49, 0x73,
|
||||
0x73, 0x75, 0x65, 0x12, 0x14, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61,
|
||||
0x2e, 0x49, 0x73, 0x73, 0x75, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6d, 0x61, 0x67, 0x69,
|
||||
0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x00, 0x12, 0x36,
|
||||
0x0a, 0x07, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x12, 0x16, 0x2e, 0x6d, 0x61, 0x67, 0x69,
|
||||
0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x52, 0x65,
|
||||
0x71, 0x1a, 0x11, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x54,
|
||||
0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x08, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,
|
||||
0x66, 0x79, 0x12, 0x17, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e,
|
||||
0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x6d, 0x61,
|
||||
0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,
|
||||
0x79, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x41, 0x0a, 0x09, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72,
|
||||
0x69, 0x7a, 0x65, 0x12, 0x18, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61,
|
||||
0x2e, 0x41, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x18, 0x2e,
|
||||
0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x41, 0x75, 0x74, 0x68, 0x6f,
|
||||
0x72, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x22, 0x00, 0x12, 0x41, 0x0a, 0x09, 0x41, 0x64, 0x64,
|
||||
0x6f, 0x72, 0x69, 0x7a, 0x65, 0x52, 0x65, 0x73, 0x22, 0x00, 0x32, 0xba, 0x01, 0x0a, 0x0c, 0x41,
|
||||
0x75, 0x74, 0x68, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x32, 0x0a, 0x05, 0x49,
|
||||
0x73, 0x73, 0x75, 0x65, 0x12, 0x14, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c,
|
||||
0x61, 0x2e, 0x49, 0x73, 0x73, 0x75, 0x65, 0x52, 0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6d, 0x61, 0x67,
|
||||
0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x00, 0x12,
|
||||
0x36, 0x0a, 0x07, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x12, 0x16, 0x2e, 0x6d, 0x61, 0x67,
|
||||
0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x52, 0x65, 0x66, 0x72, 0x65, 0x73, 0x68, 0x52,
|
||||
0x65, 0x71, 0x1a, 0x11, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e,
|
||||
0x54, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x00, 0x12, 0x3e, 0x0a, 0x08, 0x49, 0x64, 0x65, 0x6e, 0x74,
|
||||
0x69, 0x66, 0x79, 0x12, 0x17, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61,
|
||||
0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x52, 0x65, 0x71, 0x1a, 0x17, 0x2e, 0x6d,
|
||||
0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69,
|
||||
0x74, 0x79, 0x52, 0x65, 0x73, 0x22, 0x00, 0x32, 0xbf, 0x07, 0x0a, 0x0d, 0x50, 0x6f, 0x6c, 0x69,
|
||||
0x63, 0x79, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x41, 0x0a, 0x09, 0x41, 0x64, 0x64,
|
||||
0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x12, 0x18, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72,
|
||||
0x61, 0x6c, 0x61, 0x2e, 0x41, 0x64, 0x64, 0x50, 0x6f, 0x6c, 0x69, 0x63, 0x79, 0x52, 0x65, 0x71,
|
||||
0x1a, 0x18, 0x2e, 0x6d, 0x61, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x6c, 0x61, 0x2e, 0x41, 0x64,
|
||||
@@ -2381,41 +2378,39 @@ var file_auth_proto_depIdxs = []int32{
|
||||
7, // 0: magistrala.AddPoliciesReq.addPoliciesReq:type_name -> magistrala.AddPolicyReq
|
||||
13, // 1: magistrala.DeletePoliciesReq.deletePoliciesReq:type_name -> magistrala.DeletePolicyReq
|
||||
5, // 2: magistrala.AuthzService.Authorize:input_type -> magistrala.AuthorizeReq
|
||||
3, // 3: magistrala.AuthService.Issue:input_type -> magistrala.IssueReq
|
||||
4, // 4: magistrala.AuthService.Refresh:input_type -> magistrala.RefreshReq
|
||||
1, // 5: magistrala.AuthService.Identify:input_type -> magistrala.IdentityReq
|
||||
5, // 6: magistrala.AuthService.Authorize:input_type -> magistrala.AuthorizeReq
|
||||
7, // 7: magistrala.AuthService.AddPolicy:input_type -> magistrala.AddPolicyReq
|
||||
8, // 8: magistrala.AuthService.AddPolicies:input_type -> magistrala.AddPoliciesReq
|
||||
11, // 9: magistrala.AuthService.DeletePolicyFilter:input_type -> magistrala.DeletePolicyFilterReq
|
||||
12, // 10: magistrala.AuthService.DeletePolicies:input_type -> magistrala.DeletePoliciesReq
|
||||
15, // 11: magistrala.AuthService.ListObjects:input_type -> magistrala.ListObjectsReq
|
||||
15, // 12: magistrala.AuthService.ListAllObjects:input_type -> magistrala.ListObjectsReq
|
||||
17, // 13: magistrala.AuthService.CountObjects:input_type -> magistrala.CountObjectsReq
|
||||
19, // 14: magistrala.AuthService.ListSubjects:input_type -> magistrala.ListSubjectsReq
|
||||
19, // 15: magistrala.AuthService.ListAllSubjects:input_type -> magistrala.ListSubjectsReq
|
||||
21, // 16: magistrala.AuthService.CountSubjects:input_type -> magistrala.CountSubjectsReq
|
||||
23, // 17: magistrala.AuthService.ListPermissions:input_type -> magistrala.ListPermissionsReq
|
||||
25, // 18: magistrala.AuthService.DeleteEntityPolicies:input_type -> magistrala.DeleteEntityPoliciesReq
|
||||
6, // 19: magistrala.AuthzService.Authorize:output_type -> magistrala.AuthorizeRes
|
||||
0, // 20: magistrala.AuthService.Issue:output_type -> magistrala.Token
|
||||
0, // 21: magistrala.AuthService.Refresh:output_type -> magistrala.Token
|
||||
2, // 22: magistrala.AuthService.Identify:output_type -> magistrala.IdentityRes
|
||||
6, // 23: magistrala.AuthService.Authorize:output_type -> magistrala.AuthorizeRes
|
||||
9, // 24: magistrala.AuthService.AddPolicy:output_type -> magistrala.AddPolicyRes
|
||||
10, // 25: magistrala.AuthService.AddPolicies:output_type -> magistrala.AddPoliciesRes
|
||||
14, // 26: magistrala.AuthService.DeletePolicyFilter:output_type -> magistrala.DeletePolicyRes
|
||||
14, // 27: magistrala.AuthService.DeletePolicies:output_type -> magistrala.DeletePolicyRes
|
||||
16, // 28: magistrala.AuthService.ListObjects:output_type -> magistrala.ListObjectsRes
|
||||
16, // 29: magistrala.AuthService.ListAllObjects:output_type -> magistrala.ListObjectsRes
|
||||
18, // 30: magistrala.AuthService.CountObjects:output_type -> magistrala.CountObjectsRes
|
||||
20, // 31: magistrala.AuthService.ListSubjects:output_type -> magistrala.ListSubjectsRes
|
||||
20, // 32: magistrala.AuthService.ListAllSubjects:output_type -> magistrala.ListSubjectsRes
|
||||
22, // 33: magistrala.AuthService.CountSubjects:output_type -> magistrala.CountSubjectsRes
|
||||
24, // 34: magistrala.AuthService.ListPermissions:output_type -> magistrala.ListPermissionsRes
|
||||
14, // 35: magistrala.AuthService.DeleteEntityPolicies:output_type -> magistrala.DeletePolicyRes
|
||||
19, // [19:36] is the sub-list for method output_type
|
||||
2, // [2:19] is the sub-list for method input_type
|
||||
3, // 3: magistrala.AuthnService.Issue:input_type -> magistrala.IssueReq
|
||||
4, // 4: magistrala.AuthnService.Refresh:input_type -> magistrala.RefreshReq
|
||||
1, // 5: magistrala.AuthnService.Identify:input_type -> magistrala.IdentityReq
|
||||
7, // 6: magistrala.PolicyService.AddPolicy:input_type -> magistrala.AddPolicyReq
|
||||
8, // 7: magistrala.PolicyService.AddPolicies:input_type -> magistrala.AddPoliciesReq
|
||||
11, // 8: magistrala.PolicyService.DeletePolicyFilter:input_type -> magistrala.DeletePolicyFilterReq
|
||||
12, // 9: magistrala.PolicyService.DeletePolicies:input_type -> magistrala.DeletePoliciesReq
|
||||
15, // 10: magistrala.PolicyService.ListObjects:input_type -> magistrala.ListObjectsReq
|
||||
15, // 11: magistrala.PolicyService.ListAllObjects:input_type -> magistrala.ListObjectsReq
|
||||
17, // 12: magistrala.PolicyService.CountObjects:input_type -> magistrala.CountObjectsReq
|
||||
19, // 13: magistrala.PolicyService.ListSubjects:input_type -> magistrala.ListSubjectsReq
|
||||
19, // 14: magistrala.PolicyService.ListAllSubjects:input_type -> magistrala.ListSubjectsReq
|
||||
21, // 15: magistrala.PolicyService.CountSubjects:input_type -> magistrala.CountSubjectsReq
|
||||
23, // 16: magistrala.PolicyService.ListPermissions:input_type -> magistrala.ListPermissionsReq
|
||||
25, // 17: magistrala.PolicyService.DeleteEntityPolicies:input_type -> magistrala.DeleteEntityPoliciesReq
|
||||
6, // 18: magistrala.AuthzService.Authorize:output_type -> magistrala.AuthorizeRes
|
||||
0, // 19: magistrala.AuthnService.Issue:output_type -> magistrala.Token
|
||||
0, // 20: magistrala.AuthnService.Refresh:output_type -> magistrala.Token
|
||||
2, // 21: magistrala.AuthnService.Identify:output_type -> magistrala.IdentityRes
|
||||
9, // 22: magistrala.PolicyService.AddPolicy:output_type -> magistrala.AddPolicyRes
|
||||
10, // 23: magistrala.PolicyService.AddPolicies:output_type -> magistrala.AddPoliciesRes
|
||||
14, // 24: magistrala.PolicyService.DeletePolicyFilter:output_type -> magistrala.DeletePolicyRes
|
||||
14, // 25: magistrala.PolicyService.DeletePolicies:output_type -> magistrala.DeletePolicyRes
|
||||
16, // 26: magistrala.PolicyService.ListObjects:output_type -> magistrala.ListObjectsRes
|
||||
16, // 27: magistrala.PolicyService.ListAllObjects:output_type -> magistrala.ListObjectsRes
|
||||
18, // 28: magistrala.PolicyService.CountObjects:output_type -> magistrala.CountObjectsRes
|
||||
20, // 29: magistrala.PolicyService.ListSubjects:output_type -> magistrala.ListSubjectsRes
|
||||
20, // 30: magistrala.PolicyService.ListAllSubjects:output_type -> magistrala.ListSubjectsRes
|
||||
22, // 31: magistrala.PolicyService.CountSubjects:output_type -> magistrala.CountSubjectsRes
|
||||
24, // 32: magistrala.PolicyService.ListPermissions:output_type -> magistrala.ListPermissionsRes
|
||||
14, // 33: magistrala.PolicyService.DeleteEntityPolicies:output_type -> magistrala.DeletePolicyRes
|
||||
18, // [18:34] is the sub-list for method output_type
|
||||
2, // [2:18] is the sub-list for method input_type
|
||||
2, // [2:2] is the sub-list for extension type_name
|
||||
2, // [2:2] is the sub-list for extension extendee
|
||||
0, // [0:2] is the sub-list for field type_name
|
||||
@@ -2751,7 +2746,7 @@ func file_auth_proto_init() {
|
||||
NumEnums: 0,
|
||||
NumMessages: 26,
|
||||
NumExtensions: 0,
|
||||
NumServices: 2,
|
||||
NumServices: 3,
|
||||
},
|
||||
GoTypes: file_auth_proto_goTypes,
|
||||
DependencyIndexes: file_auth_proto_depIdxs,
|
||||
|
||||
+10
-6
@@ -6,21 +6,25 @@ syntax = "proto3";
|
||||
package magistrala;
|
||||
option go_package = "./magistrala";
|
||||
|
||||
// AuthzService is a service that provides authentication and authorization
|
||||
// functionalities for the things service.
|
||||
// AuthzService is a service that provides authorization functionalities
|
||||
// for magistrala services.
|
||||
service AuthzService {
|
||||
// Authorize checks if the subject is authorized to perform
|
||||
// the action on the object.
|
||||
rpc Authorize(AuthorizeReq) returns (AuthorizeRes) {}
|
||||
}
|
||||
|
||||
// AuthService is a service that provides authentication and authorization
|
||||
// functionalities for the users service.
|
||||
service AuthService {
|
||||
// AuthnService is a service that provides authentication functionalities
|
||||
// for magistrala services.
|
||||
service AuthnService {
|
||||
rpc Issue(IssueReq) returns (Token) {}
|
||||
rpc Refresh(RefreshReq) returns (Token) {}
|
||||
rpc Identify(IdentityReq) returns (IdentityRes) {}
|
||||
rpc Authorize(AuthorizeReq) returns (AuthorizeRes) {}
|
||||
}
|
||||
|
||||
// PolicyService is a service that provides policy CRUD
|
||||
// functionalities for magistrala services.
|
||||
service PolicyService {
|
||||
rpc AddPolicy(AddPolicyReq) returns (AddPolicyRes) {}
|
||||
rpc AddPolicies(AddPoliciesReq) returns (AddPoliciesRes) {}
|
||||
rpc DeletePolicyFilter(DeletePolicyFilterReq) returns (DeletePolicyRes) {}
|
||||
|
||||
+164
-140
@@ -19,36 +19,37 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
const svcName = "magistrala.AuthService"
|
||||
const (
|
||||
authzSvcName = "magistrala.AuthzService"
|
||||
authnSvcName = "magistrala.AuthnService"
|
||||
policySvcName = "magistrala.PolicyService"
|
||||
)
|
||||
|
||||
var _ magistrala.AuthServiceClient = (*grpcClient)(nil)
|
||||
var (
|
||||
_ AuthServiceClient = (*authGrpcClient)(nil)
|
||||
_ magistrala.PolicyServiceClient = (*policyGrpcClient)(nil)
|
||||
)
|
||||
|
||||
type grpcClient struct {
|
||||
issue endpoint.Endpoint
|
||||
refresh endpoint.Endpoint
|
||||
identify endpoint.Endpoint
|
||||
authorize endpoint.Endpoint
|
||||
addPolicy endpoint.Endpoint
|
||||
addPolicies endpoint.Endpoint
|
||||
deletePolicyFilter endpoint.Endpoint
|
||||
deletePolicies endpoint.Endpoint
|
||||
listObjects endpoint.Endpoint
|
||||
listAllObjects endpoint.Endpoint
|
||||
countObjects endpoint.Endpoint
|
||||
listSubjects endpoint.Endpoint
|
||||
listAllSubjects endpoint.Endpoint
|
||||
countSubjects endpoint.Endpoint
|
||||
listPermissions endpoint.Endpoint
|
||||
deleteEntityPolicies endpoint.Endpoint
|
||||
timeout time.Duration
|
||||
//go:generate mockery --name AuthServiceClient --output=../../mocks --filename auth_client.go --quiet --note "Copyright (c) Abstract Machines"
|
||||
type AuthServiceClient interface {
|
||||
magistrala.AuthzServiceClient
|
||||
magistrala.AuthnServiceClient
|
||||
}
|
||||
|
||||
// NewClient returns new gRPC client instance.
|
||||
func NewClient(conn *grpc.ClientConn, timeout time.Duration) magistrala.AuthServiceClient {
|
||||
return &grpcClient{
|
||||
type authGrpcClient struct {
|
||||
issue endpoint.Endpoint
|
||||
refresh endpoint.Endpoint
|
||||
identify endpoint.Endpoint
|
||||
authorize endpoint.Endpoint
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// NewAuthClient returns new auth gRPC client instance.
|
||||
func NewAuthClient(conn *grpc.ClientConn, timeout time.Duration) AuthServiceClient {
|
||||
return &authGrpcClient{
|
||||
issue: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
authnSvcName,
|
||||
"Issue",
|
||||
encodeIssueRequest,
|
||||
decodeIssueResponse,
|
||||
@@ -56,7 +57,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) magistrala.AuthServ
|
||||
).Endpoint(),
|
||||
refresh: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
authnSvcName,
|
||||
"Refresh",
|
||||
encodeRefreshRequest,
|
||||
decodeRefreshResponse,
|
||||
@@ -64,7 +65,7 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) magistrala.AuthServ
|
||||
).Endpoint(),
|
||||
identify: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
authnSvcName,
|
||||
"Identify",
|
||||
encodeIdentifyRequest,
|
||||
decodeIdentifyResponse,
|
||||
@@ -72,114 +73,17 @@ func NewClient(conn *grpc.ClientConn, timeout time.Duration) magistrala.AuthServ
|
||||
).Endpoint(),
|
||||
authorize: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
authzSvcName,
|
||||
"Authorize",
|
||||
encodeAuthorizeRequest,
|
||||
decodeAuthorizeResponse,
|
||||
magistrala.AuthorizeRes{},
|
||||
).Endpoint(),
|
||||
addPolicy: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"AddPolicy",
|
||||
encodeAddPolicyRequest,
|
||||
decodeAddPolicyResponse,
|
||||
magistrala.AddPolicyRes{},
|
||||
).Endpoint(),
|
||||
addPolicies: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"AddPolicies",
|
||||
encodeAddPoliciesRequest,
|
||||
decodeAddPoliciesResponse,
|
||||
magistrala.AddPoliciesRes{},
|
||||
).Endpoint(),
|
||||
deletePolicyFilter: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"DeletePolicyFilter",
|
||||
encodeDeletePolicyFilterRequest,
|
||||
decodeDeletePolicyFilterResponse,
|
||||
magistrala.DeletePolicyRes{},
|
||||
).Endpoint(),
|
||||
deletePolicies: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"DeletePolicies",
|
||||
encodeDeletePoliciesRequest,
|
||||
decodeDeletePoliciesResponse,
|
||||
magistrala.DeletePolicyRes{},
|
||||
).Endpoint(),
|
||||
listObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"ListObjects",
|
||||
encodeListObjectsRequest,
|
||||
decodeListObjectsResponse,
|
||||
magistrala.ListObjectsRes{},
|
||||
).Endpoint(),
|
||||
listAllObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"ListAllObjects",
|
||||
encodeListObjectsRequest,
|
||||
decodeListObjectsResponse,
|
||||
magistrala.ListObjectsRes{},
|
||||
).Endpoint(),
|
||||
countObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"CountObjects",
|
||||
encodeCountObjectsRequest,
|
||||
decodeCountObjectsResponse,
|
||||
magistrala.CountObjectsRes{},
|
||||
).Endpoint(),
|
||||
listSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"ListSubjects",
|
||||
encodeListSubjectsRequest,
|
||||
decodeListSubjectsResponse,
|
||||
magistrala.ListSubjectsRes{},
|
||||
).Endpoint(),
|
||||
listAllSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"ListAllSubjects",
|
||||
encodeListSubjectsRequest,
|
||||
decodeListSubjectsResponse,
|
||||
magistrala.ListSubjectsRes{},
|
||||
).Endpoint(),
|
||||
countSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"CountSubjects",
|
||||
encodeCountSubjectsRequest,
|
||||
decodeCountSubjectsResponse,
|
||||
magistrala.CountSubjectsRes{},
|
||||
).Endpoint(),
|
||||
listPermissions: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"ListPermissions",
|
||||
encodeListPermissionsRequest,
|
||||
decodeListPermissionsResponse,
|
||||
magistrala.ListPermissionsRes{},
|
||||
).Endpoint(),
|
||||
deleteEntityPolicies: kitgrpc.NewClient(
|
||||
conn,
|
||||
svcName,
|
||||
"DeleteEntityPolicies",
|
||||
encodeDeleteEntityPoliciesRequest,
|
||||
decodeDeleteEntityPoliciesResponse,
|
||||
magistrala.DeletePolicyRes{},
|
||||
).Endpoint(),
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
func (client grpcClient) Issue(ctx context.Context, req *magistrala.IssueReq, _ ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
func (client authGrpcClient) Issue(ctx context.Context, req *magistrala.IssueReq, _ ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -207,7 +111,7 @@ func decodeIssueResponse(_ context.Context, grpcRes interface{}) (interface{}, e
|
||||
return grpcRes, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) Refresh(ctx context.Context, req *magistrala.RefreshReq, _ ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
func (client authGrpcClient) Refresh(ctx context.Context, req *magistrala.RefreshReq, _ ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -227,7 +131,7 @@ func decodeRefreshResponse(_ context.Context, grpcRes interface{}) (interface{},
|
||||
return grpcRes, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) Identify(ctx context.Context, token *magistrala.IdentityReq, _ ...grpc.CallOption) (*magistrala.IdentityRes, error) {
|
||||
func (client authGrpcClient) Identify(ctx context.Context, token *magistrala.IdentityReq, _ ...grpc.CallOption) (*magistrala.IdentityRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -249,7 +153,7 @@ func decodeIdentifyResponse(_ context.Context, grpcRes interface{}) (interface{}
|
||||
return identityRes{id: res.GetId(), userID: res.GetUserId(), domainID: res.GetDomainId()}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) Authorize(ctx context.Context, req *magistrala.AuthorizeReq, _ ...grpc.CallOption) (r *magistrala.AuthorizeRes, err error) {
|
||||
func (client authGrpcClient) Authorize(ctx context.Context, req *magistrala.AuthorizeReq, _ ...grpc.CallOption) (r *magistrala.AuthorizeRes, err error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -290,7 +194,127 @@ func encodeAuthorizeRequest(_ context.Context, grpcReq interface{}) (interface{}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
|
||||
type policyGrpcClient struct {
|
||||
addPolicy endpoint.Endpoint
|
||||
addPolicies endpoint.Endpoint
|
||||
deletePolicyFilter endpoint.Endpoint
|
||||
deletePolicies endpoint.Endpoint
|
||||
listObjects endpoint.Endpoint
|
||||
listAllObjects endpoint.Endpoint
|
||||
countObjects endpoint.Endpoint
|
||||
listSubjects endpoint.Endpoint
|
||||
listAllSubjects endpoint.Endpoint
|
||||
countSubjects endpoint.Endpoint
|
||||
listPermissions endpoint.Endpoint
|
||||
deleteEntityPolicies endpoint.Endpoint
|
||||
timeout time.Duration
|
||||
}
|
||||
|
||||
// NewPolicyClient returns new policy gRPC client instance.
|
||||
func NewPolicyClient(conn *grpc.ClientConn, timeout time.Duration) magistrala.PolicyServiceClient {
|
||||
return &policyGrpcClient{
|
||||
addPolicy: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"AddPolicy",
|
||||
encodeAddPolicyRequest,
|
||||
decodeAddPolicyResponse,
|
||||
magistrala.AddPolicyRes{},
|
||||
).Endpoint(),
|
||||
addPolicies: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"AddPolicies",
|
||||
encodeAddPoliciesRequest,
|
||||
decodeAddPoliciesResponse,
|
||||
magistrala.AddPoliciesRes{},
|
||||
).Endpoint(),
|
||||
deletePolicyFilter: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"DeletePolicyFilter",
|
||||
encodeDeletePolicyFilterRequest,
|
||||
decodeDeletePolicyFilterResponse,
|
||||
magistrala.DeletePolicyRes{},
|
||||
).Endpoint(),
|
||||
deletePolicies: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"DeletePolicies",
|
||||
encodeDeletePoliciesRequest,
|
||||
decodeDeletePoliciesResponse,
|
||||
magistrala.DeletePolicyRes{},
|
||||
).Endpoint(),
|
||||
listObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"ListObjects",
|
||||
encodeListObjectsRequest,
|
||||
decodeListObjectsResponse,
|
||||
magistrala.ListObjectsRes{},
|
||||
).Endpoint(),
|
||||
listAllObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"ListAllObjects",
|
||||
encodeListObjectsRequest,
|
||||
decodeListObjectsResponse,
|
||||
magistrala.ListObjectsRes{},
|
||||
).Endpoint(),
|
||||
countObjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"CountObjects",
|
||||
encodeCountObjectsRequest,
|
||||
decodeCountObjectsResponse,
|
||||
magistrala.CountObjectsRes{},
|
||||
).Endpoint(),
|
||||
listSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"ListSubjects",
|
||||
encodeListSubjectsRequest,
|
||||
decodeListSubjectsResponse,
|
||||
magistrala.ListSubjectsRes{},
|
||||
).Endpoint(),
|
||||
listAllSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"ListAllSubjects",
|
||||
encodeListSubjectsRequest,
|
||||
decodeListSubjectsResponse,
|
||||
magistrala.ListSubjectsRes{},
|
||||
).Endpoint(),
|
||||
countSubjects: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"CountSubjects",
|
||||
encodeCountSubjectsRequest,
|
||||
decodeCountSubjectsResponse,
|
||||
magistrala.CountSubjectsRes{},
|
||||
).Endpoint(),
|
||||
listPermissions: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"ListPermissions",
|
||||
encodeListPermissionsRequest,
|
||||
decodeListPermissionsResponse,
|
||||
magistrala.ListPermissionsRes{},
|
||||
).Endpoint(),
|
||||
deleteEntityPolicies: kitgrpc.NewClient(
|
||||
conn,
|
||||
policySvcName,
|
||||
"DeleteEntityPolicies",
|
||||
encodeDeleteEntityPoliciesRequest,
|
||||
decodeDeleteEntityPoliciesResponse,
|
||||
magistrala.DeletePolicyRes{},
|
||||
).Endpoint(),
|
||||
|
||||
timeout: timeout,
|
||||
}
|
||||
}
|
||||
|
||||
func (client policyGrpcClient) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -333,7 +357,7 @@ func encodeAddPolicyRequest(_ context.Context, grpcReq interface{}) (interface{}
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) AddPolicies(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption) (*magistrala.AddPoliciesRes, error) {
|
||||
func (client policyGrpcClient) AddPolicies(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption) (*magistrala.AddPoliciesRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
r := policiesReq{}
|
||||
@@ -388,7 +412,7 @@ func encodeAddPoliciesRequest(_ context.Context, grpcReq interface{}) (interface
|
||||
return &magistrala.AddPoliciesReq{AddPoliciesReq: addPolicies}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
func (client policyGrpcClient) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -431,7 +455,7 @@ func encodeDeletePolicyFilterRequest(_ context.Context, grpcReq interface{}) (in
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
func (client policyGrpcClient) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
r := policiesReq{}
|
||||
@@ -486,7 +510,7 @@ func encodeDeletePoliciesRequest(_ context.Context, grpcReq interface{}) (interf
|
||||
return &magistrala.DeletePoliciesReq{DeletePoliciesReq: deletePolicies}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
func (client policyGrpcClient) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -525,7 +549,7 @@ func encodeListObjectsRequest(_ context.Context, grpcReq interface{}) (interface
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
func (client policyGrpcClient) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -546,7 +570,7 @@ func (client grpcClient) ListAllObjects(ctx context.Context, in *magistrala.List
|
||||
return &magistrala.ListObjectsRes{Policies: lpr.policies}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) {
|
||||
func (client policyGrpcClient) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -585,7 +609,7 @@ func encodeCountObjectsRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
func (client policyGrpcClient) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -625,7 +649,7 @@ func encodeListSubjectsRequest(_ context.Context, grpcReq interface{}) (interfac
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
func (client policyGrpcClient) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -646,7 +670,7 @@ func (client grpcClient) ListAllSubjects(ctx context.Context, in *magistrala.Lis
|
||||
return &magistrala.ListSubjectsRes{Policies: lpr.policies}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) {
|
||||
func (client policyGrpcClient) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -685,7 +709,7 @@ func encodeCountSubjectsRequest(_ context.Context, grpcReq interface{}) (interfa
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) ListPermissions(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption) (*magistrala.ListPermissionsRes, error) {
|
||||
func (client policyGrpcClient) ListPermissions(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption) (*magistrala.ListPermissionsRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
@@ -739,7 +763,7 @@ func encodeListPermissionsRequest(_ context.Context, grpcReq interface{}) (inter
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (client grpcClient) DeleteEntityPolicies(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
func (client policyGrpcClient) DeleteEntityPolicies(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
ctx, cancel := context.WithTimeout(ctx, client.timeout)
|
||||
defer cancel()
|
||||
|
||||
|
||||
@@ -55,17 +55,19 @@ var (
|
||||
func startGRPCServer(svc auth.Service, port int) {
|
||||
listener, _ := net.Listen("tcp", fmt.Sprintf(":%d", port))
|
||||
server := grpc.NewServer()
|
||||
magistrala.RegisterAuthServiceServer(server, grpcapi.NewServer(svc))
|
||||
magistrala.RegisterAuthzServiceServer(server, grpcapi.NewAuthzServer(svc))
|
||||
magistrala.RegisterAuthnServiceServer(server, grpcapi.NewAuthnServer(svc))
|
||||
magistrala.RegisterPolicyServiceServer(server, grpcapi.NewPolicyServer(svc))
|
||||
go func() {
|
||||
err := server.Serve(listener)
|
||||
assert.Nil(&testing.T{}, err, fmt.Sprintf(`"Unexpected error creating server %s"`, err))
|
||||
assert.Nil(&testing.T{}, err, fmt.Sprintf(`"Unexpected error creating auth server %s"`, err))
|
||||
}()
|
||||
}
|
||||
|
||||
func TestIssue(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewAuthClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -134,7 +136,7 @@ func TestIssue(t *testing.T) {
|
||||
func TestRefresh(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewAuthClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -180,7 +182,7 @@ func TestRefresh(t *testing.T) {
|
||||
func TestIdentify(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewAuthClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -224,7 +226,7 @@ func TestIdentify(t *testing.T) {
|
||||
func TestAuthorize(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewAuthClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -346,7 +348,7 @@ func TestAuthorize(t *testing.T) {
|
||||
func TestAddPolicy(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
groupAdminObj := "groupadmin"
|
||||
|
||||
@@ -400,7 +402,7 @@ func TestAddPolicy(t *testing.T) {
|
||||
func TestAddPolicies(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
groupAdminObj := "groupadmin"
|
||||
|
||||
@@ -462,7 +464,7 @@ func TestAddPolicies(t *testing.T) {
|
||||
func TestDeletePolicyFilter(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
readRelation := "read"
|
||||
thingID := "thing"
|
||||
@@ -515,7 +517,7 @@ func TestDeletePolicyFilter(t *testing.T) {
|
||||
func TestDeletePolicies(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
readRelation := "read"
|
||||
thingID := "thing"
|
||||
@@ -578,7 +580,7 @@ func TestDeletePolicies(t *testing.T) {
|
||||
func TestListObjects(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -628,7 +630,7 @@ func TestListObjects(t *testing.T) {
|
||||
func TestListAllObjects(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -678,7 +680,7 @@ func TestListAllObjects(t *testing.T) {
|
||||
func TestCountObects(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -728,7 +730,7 @@ func TestCountObects(t *testing.T) {
|
||||
func TestListSubjects(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -778,7 +780,7 @@ func TestListSubjects(t *testing.T) {
|
||||
func TestListAllSubjects(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf(`"Unexpected error creating client connection %s"`, err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -828,7 +830,7 @@ func TestListAllSubjects(t *testing.T) {
|
||||
func TestCountSubjects(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -883,7 +885,7 @@ func TestCountSubjects(t *testing.T) {
|
||||
func TestListPermissions(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1014,7 +1016,7 @@ func TestListPermissions(t *testing.T) {
|
||||
func TestDeleteEntityPolicies(t *testing.T) {
|
||||
conn, err := grpc.NewClient(authAddr, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating client connection %s", err))
|
||||
client := grpcapi.NewClient(conn, time.Second)
|
||||
client := grpcapi.NewPolicyClient(conn, time.Second)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
|
||||
+94
-71
@@ -16,31 +16,46 @@ import (
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
||||
var _ magistrala.AuthServiceServer = (*grpcServer)(nil)
|
||||
var (
|
||||
_ magistrala.AuthzServiceServer = (*authzGrpcServer)(nil)
|
||||
_ magistrala.AuthnServiceServer = (*authnGrpcServer)(nil)
|
||||
_ magistrala.PolicyServiceServer = (*policyGrpcServer)(nil)
|
||||
)
|
||||
|
||||
type grpcServer struct {
|
||||
magistrala.UnimplementedAuthServiceServer
|
||||
issue kitgrpc.Handler
|
||||
refresh kitgrpc.Handler
|
||||
identify kitgrpc.Handler
|
||||
authorize kitgrpc.Handler
|
||||
addPolicy kitgrpc.Handler
|
||||
addPolicies kitgrpc.Handler
|
||||
deletePolicyFilter kitgrpc.Handler
|
||||
deletePolicies kitgrpc.Handler
|
||||
listObjects kitgrpc.Handler
|
||||
listAllObjects kitgrpc.Handler
|
||||
countObjects kitgrpc.Handler
|
||||
listSubjects kitgrpc.Handler
|
||||
listAllSubjects kitgrpc.Handler
|
||||
countSubjects kitgrpc.Handler
|
||||
listPermissions kitgrpc.Handler
|
||||
deleteEntityPolicies kitgrpc.Handler
|
||||
type authzGrpcServer struct {
|
||||
magistrala.UnimplementedAuthzServiceServer
|
||||
authorize kitgrpc.Handler
|
||||
}
|
||||
|
||||
// NewServer returns new AuthServiceServer instance.
|
||||
func NewServer(svc auth.Service) magistrala.AuthServiceServer {
|
||||
return &grpcServer{
|
||||
// NewAuthzServer returns new AuthzServiceServer instance.
|
||||
func NewAuthzServer(svc auth.Service) magistrala.AuthzServiceServer {
|
||||
return &authzGrpcServer{
|
||||
authorize: kitgrpc.NewServer(
|
||||
(authorizeEndpoint(svc)),
|
||||
decodeAuthorizeRequest,
|
||||
encodeAuthorizeResponse,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *authzGrpcServer) 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.(*magistrala.AuthorizeRes), nil
|
||||
}
|
||||
|
||||
type authnGrpcServer struct {
|
||||
magistrala.UnimplementedAuthnServiceServer
|
||||
issue kitgrpc.Handler
|
||||
refresh kitgrpc.Handler
|
||||
identify kitgrpc.Handler
|
||||
}
|
||||
|
||||
// NewAuthnServer returns new AuthnServiceServer instance.
|
||||
func NewAuthnServer(svc auth.Service) magistrala.AuthnServiceServer {
|
||||
return &authnGrpcServer{
|
||||
issue: kitgrpc.NewServer(
|
||||
(issueEndpoint(svc)),
|
||||
decodeIssueRequest,
|
||||
@@ -56,11 +71,51 @@ func NewServer(svc auth.Service) magistrala.AuthServiceServer {
|
||||
decodeIdentifyRequest,
|
||||
encodeIdentifyResponse,
|
||||
),
|
||||
authorize: kitgrpc.NewServer(
|
||||
(authorizeEndpoint(svc)),
|
||||
decodeAuthorizeRequest,
|
||||
encodeAuthorizeResponse,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *authnGrpcServer) 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.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func (s *authnGrpcServer) 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.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
func (s *authnGrpcServer) 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.(*magistrala.IdentityRes), nil
|
||||
}
|
||||
|
||||
type policyGrpcServer struct {
|
||||
magistrala.UnimplementedPolicyServiceServer
|
||||
addPolicy kitgrpc.Handler
|
||||
addPolicies kitgrpc.Handler
|
||||
deletePolicyFilter kitgrpc.Handler
|
||||
deletePolicies kitgrpc.Handler
|
||||
listObjects kitgrpc.Handler
|
||||
listAllObjects kitgrpc.Handler
|
||||
countObjects kitgrpc.Handler
|
||||
listSubjects kitgrpc.Handler
|
||||
listAllSubjects kitgrpc.Handler
|
||||
countSubjects kitgrpc.Handler
|
||||
listPermissions kitgrpc.Handler
|
||||
deleteEntityPolicies kitgrpc.Handler
|
||||
}
|
||||
|
||||
func NewPolicyServer(svc auth.Service) magistrala.PolicyServiceServer {
|
||||
return &policyGrpcServer{
|
||||
addPolicy: kitgrpc.NewServer(
|
||||
(addPolicyEndpoint(svc)),
|
||||
decodeAddPolicyRequest,
|
||||
@@ -124,39 +179,7 @@ func NewServer(svc auth.Service) magistrala.AuthServiceServer {
|
||||
}
|
||||
}
|
||||
|
||||
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.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
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.(*magistrala.Token), nil
|
||||
}
|
||||
|
||||
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.(*magistrala.IdentityRes), nil
|
||||
}
|
||||
|
||||
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.(*magistrala.AuthorizeRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) AddPolicy(ctx context.Context, req *magistrala.AddPolicyReq) (*magistrala.AddPolicyRes, error) {
|
||||
func (s *policyGrpcServer) AddPolicy(ctx context.Context, req *magistrala.AddPolicyReq) (*magistrala.AddPolicyRes, error) {
|
||||
_, res, err := s.addPolicy.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -164,7 +187,7 @@ func (s *grpcServer) AddPolicy(ctx context.Context, req *magistrala.AddPolicyReq
|
||||
return res.(*magistrala.AddPolicyRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) AddPolicies(ctx context.Context, req *magistrala.AddPoliciesReq) (*magistrala.AddPoliciesRes, error) {
|
||||
func (s *policyGrpcServer) AddPolicies(ctx context.Context, req *magistrala.AddPoliciesReq) (*magistrala.AddPoliciesRes, error) {
|
||||
_, res, err := s.addPolicies.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -172,7 +195,7 @@ func (s *grpcServer) AddPolicies(ctx context.Context, req *magistrala.AddPolicie
|
||||
return res.(*magistrala.AddPoliciesRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) DeletePolicyFilter(ctx context.Context, req *magistrala.DeletePolicyFilterReq) (*magistrala.DeletePolicyRes, error) {
|
||||
func (s *policyGrpcServer) DeletePolicyFilter(ctx context.Context, req *magistrala.DeletePolicyFilterReq) (*magistrala.DeletePolicyRes, error) {
|
||||
_, res, err := s.deletePolicyFilter.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -180,7 +203,7 @@ func (s *grpcServer) DeletePolicyFilter(ctx context.Context, req *magistrala.Del
|
||||
return res.(*magistrala.DeletePolicyRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) DeletePolicies(ctx context.Context, req *magistrala.DeletePoliciesReq) (*magistrala.DeletePolicyRes, error) {
|
||||
func (s *policyGrpcServer) DeletePolicies(ctx context.Context, req *magistrala.DeletePoliciesReq) (*magistrala.DeletePolicyRes, error) {
|
||||
_, res, err := s.deletePolicies.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -188,7 +211,7 @@ func (s *grpcServer) DeletePolicies(ctx context.Context, req *magistrala.DeleteP
|
||||
return res.(*magistrala.DeletePolicyRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListObjects(ctx context.Context, req *magistrala.ListObjectsReq) (*magistrala.ListObjectsRes, error) {
|
||||
func (s *policyGrpcServer) ListObjects(ctx context.Context, req *magistrala.ListObjectsReq) (*magistrala.ListObjectsRes, error) {
|
||||
_, res, err := s.listObjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -196,7 +219,7 @@ func (s *grpcServer) ListObjects(ctx context.Context, req *magistrala.ListObject
|
||||
return res.(*magistrala.ListObjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListAllObjects(ctx context.Context, req *magistrala.ListObjectsReq) (*magistrala.ListObjectsRes, error) {
|
||||
func (s *policyGrpcServer) ListAllObjects(ctx context.Context, req *magistrala.ListObjectsReq) (*magistrala.ListObjectsRes, error) {
|
||||
_, res, err := s.listAllObjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -204,7 +227,7 @@ func (s *grpcServer) ListAllObjects(ctx context.Context, req *magistrala.ListObj
|
||||
return res.(*magistrala.ListObjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) CountObjects(ctx context.Context, req *magistrala.CountObjectsReq) (*magistrala.CountObjectsRes, error) {
|
||||
func (s *policyGrpcServer) CountObjects(ctx context.Context, req *magistrala.CountObjectsReq) (*magistrala.CountObjectsRes, error) {
|
||||
_, res, err := s.countObjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -212,7 +235,7 @@ func (s *grpcServer) CountObjects(ctx context.Context, req *magistrala.CountObje
|
||||
return res.(*magistrala.CountObjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListSubjects(ctx context.Context, req *magistrala.ListSubjectsReq) (*magistrala.ListSubjectsRes, error) {
|
||||
func (s *policyGrpcServer) ListSubjects(ctx context.Context, req *magistrala.ListSubjectsReq) (*magistrala.ListSubjectsRes, error) {
|
||||
_, res, err := s.listSubjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -220,7 +243,7 @@ func (s *grpcServer) ListSubjects(ctx context.Context, req *magistrala.ListSubje
|
||||
return res.(*magistrala.ListSubjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListAllSubjects(ctx context.Context, req *magistrala.ListSubjectsReq) (*magistrala.ListSubjectsRes, error) {
|
||||
func (s *policyGrpcServer) ListAllSubjects(ctx context.Context, req *magistrala.ListSubjectsReq) (*magistrala.ListSubjectsRes, error) {
|
||||
_, res, err := s.listAllSubjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -228,7 +251,7 @@ func (s *grpcServer) ListAllSubjects(ctx context.Context, req *magistrala.ListSu
|
||||
return res.(*magistrala.ListSubjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) CountSubjects(ctx context.Context, req *magistrala.CountSubjectsReq) (*magistrala.CountSubjectsRes, error) {
|
||||
func (s *policyGrpcServer) CountSubjects(ctx context.Context, req *magistrala.CountSubjectsReq) (*magistrala.CountSubjectsRes, error) {
|
||||
_, res, err := s.countSubjects.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -236,7 +259,7 @@ func (s *grpcServer) CountSubjects(ctx context.Context, req *magistrala.CountSub
|
||||
return res.(*magistrala.CountSubjectsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) ListPermissions(ctx context.Context, req *magistrala.ListPermissionsReq) (*magistrala.ListPermissionsRes, error) {
|
||||
func (s *policyGrpcServer) ListPermissions(ctx context.Context, req *magistrala.ListPermissionsReq) (*magistrala.ListPermissionsRes, error) {
|
||||
_, res, err := s.listPermissions.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
@@ -244,7 +267,7 @@ func (s *grpcServer) ListPermissions(ctx context.Context, req *magistrala.ListPe
|
||||
return res.(*magistrala.ListPermissionsRes), nil
|
||||
}
|
||||
|
||||
func (s *grpcServer) DeleteEntityPolicies(ctx context.Context, req *magistrala.DeleteEntityPoliciesReq) (*magistrala.DeletePolicyRes, error) {
|
||||
func (s *policyGrpcServer) DeleteEntityPolicies(ctx context.Context, req *magistrala.DeleteEntityPoliciesReq) (*magistrala.DeletePolicyRes, error) {
|
||||
_, res, err := s.deleteEntityPolicies.ServeGRPC(ctx, req)
|
||||
if err != nil {
|
||||
return nil, encodeError(err)
|
||||
|
||||
+12
-1058
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,932 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
|
||||
magistrala "github.com/absmach/magistrala"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// PolicyServiceClient is an autogenerated mock type for the PolicyServiceClient type
|
||||
type PolicyServiceClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type PolicyServiceClient_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *PolicyServiceClient) EXPECT() *PolicyServiceClient_Expecter {
|
||||
return &PolicyServiceClient_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// AddPolicies provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) AddPolicies(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption) (*magistrala.AddPoliciesRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for AddPolicies")
|
||||
}
|
||||
|
||||
var r0 *magistrala.AddPoliciesRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) (*magistrala.AddPoliciesRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) *magistrala.AddPoliciesRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.AddPoliciesRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_AddPolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddPolicies'
|
||||
type PolicyServiceClient_AddPolicies_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// AddPolicies is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.AddPoliciesReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) AddPolicies(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_AddPolicies_Call {
|
||||
return &PolicyServiceClient_AddPolicies_Call{Call: _e.mock.On("AddPolicies",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_AddPolicies_Call) Run(run func(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption)) *PolicyServiceClient_AddPolicies_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.AddPoliciesReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_AddPolicies_Call) Return(_a0 *magistrala.AddPoliciesRes, _a1 error) *PolicyServiceClient_AddPolicies_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_AddPolicies_Call) RunAndReturn(run func(context.Context, *magistrala.AddPoliciesReq, ...grpc.CallOption) (*magistrala.AddPoliciesRes, error)) *PolicyServiceClient_AddPolicies_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// AddPolicy provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for AddPolicy")
|
||||
}
|
||||
|
||||
var r0 *magistrala.AddPolicyRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) (*magistrala.AddPolicyRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) *magistrala.AddPolicyRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.AddPolicyRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_AddPolicy_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'AddPolicy'
|
||||
type PolicyServiceClient_AddPolicy_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// AddPolicy is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.AddPolicyReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) AddPolicy(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_AddPolicy_Call {
|
||||
return &PolicyServiceClient_AddPolicy_Call{Call: _e.mock.On("AddPolicy",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_AddPolicy_Call) Run(run func(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption)) *PolicyServiceClient_AddPolicy_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.AddPolicyReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_AddPolicy_Call) Return(_a0 *magistrala.AddPolicyRes, _a1 error) *PolicyServiceClient_AddPolicy_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_AddPolicy_Call) RunAndReturn(run func(context.Context, *magistrala.AddPolicyReq, ...grpc.CallOption) (*magistrala.AddPolicyRes, error)) *PolicyServiceClient_AddPolicy_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// CountObjects provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) CountObjects(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption) (*magistrala.CountObjectsRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CountObjects")
|
||||
}
|
||||
|
||||
var r0 *magistrala.CountObjectsRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) (*magistrala.CountObjectsRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) *magistrala.CountObjectsRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.CountObjectsRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_CountObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountObjects'
|
||||
type PolicyServiceClient_CountObjects_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// CountObjects is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.CountObjectsReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) CountObjects(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_CountObjects_Call {
|
||||
return &PolicyServiceClient_CountObjects_Call{Call: _e.mock.On("CountObjects",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_CountObjects_Call) Run(run func(ctx context.Context, in *magistrala.CountObjectsReq, opts ...grpc.CallOption)) *PolicyServiceClient_CountObjects_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.CountObjectsReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_CountObjects_Call) Return(_a0 *magistrala.CountObjectsRes, _a1 error) *PolicyServiceClient_CountObjects_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_CountObjects_Call) RunAndReturn(run func(context.Context, *magistrala.CountObjectsReq, ...grpc.CallOption) (*magistrala.CountObjectsRes, error)) *PolicyServiceClient_CountObjects_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// CountSubjects provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) CountSubjects(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption) (*magistrala.CountSubjectsRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for CountSubjects")
|
||||
}
|
||||
|
||||
var r0 *magistrala.CountSubjectsRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) (*magistrala.CountSubjectsRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) *magistrala.CountSubjectsRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.CountSubjectsRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_CountSubjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'CountSubjects'
|
||||
type PolicyServiceClient_CountSubjects_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// CountSubjects is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.CountSubjectsReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) CountSubjects(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_CountSubjects_Call {
|
||||
return &PolicyServiceClient_CountSubjects_Call{Call: _e.mock.On("CountSubjects",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_CountSubjects_Call) Run(run func(ctx context.Context, in *magistrala.CountSubjectsReq, opts ...grpc.CallOption)) *PolicyServiceClient_CountSubjects_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.CountSubjectsReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_CountSubjects_Call) Return(_a0 *magistrala.CountSubjectsRes, _a1 error) *PolicyServiceClient_CountSubjects_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_CountSubjects_Call) RunAndReturn(run func(context.Context, *magistrala.CountSubjectsReq, ...grpc.CallOption) (*magistrala.CountSubjectsRes, error)) *PolicyServiceClient_CountSubjects_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// DeleteEntityPolicies provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) DeleteEntityPolicies(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for DeleteEntityPolicies")
|
||||
}
|
||||
|
||||
var r0 *magistrala.DeletePolicyRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) *magistrala.DeletePolicyRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.DeletePolicyRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_DeleteEntityPolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeleteEntityPolicies'
|
||||
type PolicyServiceClient_DeleteEntityPolicies_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// DeleteEntityPolicies is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.DeleteEntityPoliciesReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) DeleteEntityPolicies(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_DeleteEntityPolicies_Call {
|
||||
return &PolicyServiceClient_DeleteEntityPolicies_Call{Call: _e.mock.On("DeleteEntityPolicies",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeleteEntityPolicies_Call) Run(run func(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption)) *PolicyServiceClient_DeleteEntityPolicies_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.DeleteEntityPoliciesReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeleteEntityPolicies_Call) Return(_a0 *magistrala.DeletePolicyRes, _a1 error) *PolicyServiceClient_DeleteEntityPolicies_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeleteEntityPolicies_Call) RunAndReturn(run func(context.Context, *magistrala.DeleteEntityPoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)) *PolicyServiceClient_DeleteEntityPolicies_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// DeletePolicies provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for DeletePolicies")
|
||||
}
|
||||
|
||||
var r0 *magistrala.DeletePolicyRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) *magistrala.DeletePolicyRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.DeletePolicyRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_DeletePolicies_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeletePolicies'
|
||||
type PolicyServiceClient_DeletePolicies_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// DeletePolicies is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.DeletePoliciesReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) DeletePolicies(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_DeletePolicies_Call {
|
||||
return &PolicyServiceClient_DeletePolicies_Call{Call: _e.mock.On("DeletePolicies",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeletePolicies_Call) Run(run func(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption)) *PolicyServiceClient_DeletePolicies_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.DeletePoliciesReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeletePolicies_Call) Return(_a0 *magistrala.DeletePolicyRes, _a1 error) *PolicyServiceClient_DeletePolicies_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeletePolicies_Call) RunAndReturn(run func(context.Context, *magistrala.DeletePoliciesReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)) *PolicyServiceClient_DeletePolicies_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// DeletePolicyFilter provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for DeletePolicyFilter")
|
||||
}
|
||||
|
||||
var r0 *magistrala.DeletePolicyRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) *magistrala.DeletePolicyRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.DeletePolicyRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_DeletePolicyFilter_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'DeletePolicyFilter'
|
||||
type PolicyServiceClient_DeletePolicyFilter_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// DeletePolicyFilter is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.DeletePolicyFilterReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) DeletePolicyFilter(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_DeletePolicyFilter_Call {
|
||||
return &PolicyServiceClient_DeletePolicyFilter_Call{Call: _e.mock.On("DeletePolicyFilter",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeletePolicyFilter_Call) Run(run func(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption)) *PolicyServiceClient_DeletePolicyFilter_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.DeletePolicyFilterReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeletePolicyFilter_Call) Return(_a0 *magistrala.DeletePolicyRes, _a1 error) *PolicyServiceClient_DeletePolicyFilter_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_DeletePolicyFilter_Call) RunAndReturn(run func(context.Context, *magistrala.DeletePolicyFilterReq, ...grpc.CallOption) (*magistrala.DeletePolicyRes, error)) *PolicyServiceClient_DeletePolicyFilter_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// ListAllObjects provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) ListAllObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ListAllObjects")
|
||||
}
|
||||
|
||||
var r0 *magistrala.ListObjectsRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) *magistrala.ListObjectsRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.ListObjectsRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_ListAllObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllObjects'
|
||||
type PolicyServiceClient_ListAllObjects_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// ListAllObjects is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.ListObjectsReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) ListAllObjects(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_ListAllObjects_Call {
|
||||
return &PolicyServiceClient_ListAllObjects_Call{Call: _e.mock.On("ListAllObjects",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListAllObjects_Call) Run(run func(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption)) *PolicyServiceClient_ListAllObjects_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.ListObjectsReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListAllObjects_Call) Return(_a0 *magistrala.ListObjectsRes, _a1 error) *PolicyServiceClient_ListAllObjects_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListAllObjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)) *PolicyServiceClient_ListAllObjects_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// ListAllSubjects provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) ListAllSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ListAllSubjects")
|
||||
}
|
||||
|
||||
var r0 *magistrala.ListSubjectsRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) *magistrala.ListSubjectsRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.ListSubjectsRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_ListAllSubjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListAllSubjects'
|
||||
type PolicyServiceClient_ListAllSubjects_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// ListAllSubjects is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.ListSubjectsReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) ListAllSubjects(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_ListAllSubjects_Call {
|
||||
return &PolicyServiceClient_ListAllSubjects_Call{Call: _e.mock.On("ListAllSubjects",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListAllSubjects_Call) Run(run func(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption)) *PolicyServiceClient_ListAllSubjects_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.ListSubjectsReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListAllSubjects_Call) Return(_a0 *magistrala.ListSubjectsRes, _a1 error) *PolicyServiceClient_ListAllSubjects_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListAllSubjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)) *PolicyServiceClient_ListAllSubjects_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// ListObjects provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ListObjects")
|
||||
}
|
||||
|
||||
var r0 *magistrala.ListObjectsRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) *magistrala.ListObjectsRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.ListObjectsRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_ListObjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListObjects'
|
||||
type PolicyServiceClient_ListObjects_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// ListObjects is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.ListObjectsReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) ListObjects(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_ListObjects_Call {
|
||||
return &PolicyServiceClient_ListObjects_Call{Call: _e.mock.On("ListObjects",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListObjects_Call) Run(run func(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption)) *PolicyServiceClient_ListObjects_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.ListObjectsReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListObjects_Call) Return(_a0 *magistrala.ListObjectsRes, _a1 error) *PolicyServiceClient_ListObjects_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListObjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListObjectsReq, ...grpc.CallOption) (*magistrala.ListObjectsRes, error)) *PolicyServiceClient_ListObjects_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// ListPermissions provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) ListPermissions(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption) (*magistrala.ListPermissionsRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ListPermissions")
|
||||
}
|
||||
|
||||
var r0 *magistrala.ListPermissionsRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) (*magistrala.ListPermissionsRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) *magistrala.ListPermissionsRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.ListPermissionsRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_ListPermissions_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListPermissions'
|
||||
type PolicyServiceClient_ListPermissions_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// ListPermissions is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.ListPermissionsReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) ListPermissions(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_ListPermissions_Call {
|
||||
return &PolicyServiceClient_ListPermissions_Call{Call: _e.mock.On("ListPermissions",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListPermissions_Call) Run(run func(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption)) *PolicyServiceClient_ListPermissions_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.ListPermissionsReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListPermissions_Call) Return(_a0 *magistrala.ListPermissionsRes, _a1 error) *PolicyServiceClient_ListPermissions_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListPermissions_Call) RunAndReturn(run func(context.Context, *magistrala.ListPermissionsReq, ...grpc.CallOption) (*magistrala.ListPermissionsRes, error)) *PolicyServiceClient_ListPermissions_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// ListSubjects provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *PolicyServiceClient) ListSubjects(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption) (*magistrala.ListSubjectsRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for ListSubjects")
|
||||
}
|
||||
|
||||
var r0 *magistrala.ListSubjectsRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) *magistrala.ListSubjectsRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.ListSubjectsRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// PolicyServiceClient_ListSubjects_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'ListSubjects'
|
||||
type PolicyServiceClient_ListSubjects_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// ListSubjects is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.ListSubjectsReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *PolicyServiceClient_Expecter) ListSubjects(ctx interface{}, in interface{}, opts ...interface{}) *PolicyServiceClient_ListSubjects_Call {
|
||||
return &PolicyServiceClient_ListSubjects_Call{Call: _e.mock.On("ListSubjects",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListSubjects_Call) Run(run func(ctx context.Context, in *magistrala.ListSubjectsReq, opts ...grpc.CallOption)) *PolicyServiceClient_ListSubjects_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.ListSubjectsReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListSubjects_Call) Return(_a0 *magistrala.ListSubjectsRes, _a1 error) *PolicyServiceClient_ListSubjects_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *PolicyServiceClient_ListSubjects_Call) RunAndReturn(run func(context.Context, *magistrala.ListSubjectsReq, ...grpc.CallOption) (*magistrala.ListSubjectsRes, error)) *PolicyServiceClient_ListSubjects_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewPolicyServiceClient creates a new instance of PolicyServiceClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewPolicyServiceClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *PolicyServiceClient {
|
||||
mock := &PolicyServiceClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
+308
-287
@@ -29,8 +29,8 @@ const (
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
//
|
||||
// AuthzService is a service that provides authentication and authorization
|
||||
// functionalities for the things service.
|
||||
// AuthzService is a service that provides authorization functionalities
|
||||
// for magistrala services.
|
||||
type AuthzServiceClient interface {
|
||||
// Authorize checks if the subject is authorized to perform
|
||||
// the action on the object.
|
||||
@@ -59,8 +59,8 @@ func (c *authzServiceClient) Authorize(ctx context.Context, in *AuthorizeReq, op
|
||||
// All implementations must embed UnimplementedAuthzServiceServer
|
||||
// for forward compatibility
|
||||
//
|
||||
// AuthzService is a service that provides authentication and authorization
|
||||
// functionalities for the things service.
|
||||
// AuthzService is a service that provides authorization functionalities
|
||||
// for magistrala services.
|
||||
type AuthzServiceServer interface {
|
||||
// Authorize checks if the subject is authorized to perform
|
||||
// the action on the object.
|
||||
@@ -123,35 +123,200 @@ var AuthzService_ServiceDesc = grpc.ServiceDesc{
|
||||
}
|
||||
|
||||
const (
|
||||
AuthService_Issue_FullMethodName = "/magistrala.AuthService/Issue"
|
||||
AuthService_Refresh_FullMethodName = "/magistrala.AuthService/Refresh"
|
||||
AuthService_Identify_FullMethodName = "/magistrala.AuthService/Identify"
|
||||
AuthService_Authorize_FullMethodName = "/magistrala.AuthService/Authorize"
|
||||
AuthService_AddPolicy_FullMethodName = "/magistrala.AuthService/AddPolicy"
|
||||
AuthService_AddPolicies_FullMethodName = "/magistrala.AuthService/AddPolicies"
|
||||
AuthService_DeletePolicyFilter_FullMethodName = "/magistrala.AuthService/DeletePolicyFilter"
|
||||
AuthService_DeletePolicies_FullMethodName = "/magistrala.AuthService/DeletePolicies"
|
||||
AuthService_ListObjects_FullMethodName = "/magistrala.AuthService/ListObjects"
|
||||
AuthService_ListAllObjects_FullMethodName = "/magistrala.AuthService/ListAllObjects"
|
||||
AuthService_CountObjects_FullMethodName = "/magistrala.AuthService/CountObjects"
|
||||
AuthService_ListSubjects_FullMethodName = "/magistrala.AuthService/ListSubjects"
|
||||
AuthService_ListAllSubjects_FullMethodName = "/magistrala.AuthService/ListAllSubjects"
|
||||
AuthService_CountSubjects_FullMethodName = "/magistrala.AuthService/CountSubjects"
|
||||
AuthService_ListPermissions_FullMethodName = "/magistrala.AuthService/ListPermissions"
|
||||
AuthService_DeleteEntityPolicies_FullMethodName = "/magistrala.AuthService/DeleteEntityPolicies"
|
||||
AuthnService_Issue_FullMethodName = "/magistrala.AuthnService/Issue"
|
||||
AuthnService_Refresh_FullMethodName = "/magistrala.AuthnService/Refresh"
|
||||
AuthnService_Identify_FullMethodName = "/magistrala.AuthnService/Identify"
|
||||
)
|
||||
|
||||
// AuthServiceClient is the client API for AuthService service.
|
||||
// AuthnServiceClient is the client API for AuthnService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
//
|
||||
// AuthService is a service that provides authentication and authorization
|
||||
// functionalities for the users service.
|
||||
type AuthServiceClient interface {
|
||||
// AuthnService is a service that provides authentication functionalities
|
||||
// for magistrala services.
|
||||
type AuthnServiceClient interface {
|
||||
Issue(ctx context.Context, in *IssueReq, opts ...grpc.CallOption) (*Token, error)
|
||||
Refresh(ctx context.Context, in *RefreshReq, opts ...grpc.CallOption) (*Token, error)
|
||||
Identify(ctx context.Context, in *IdentityReq, opts ...grpc.CallOption) (*IdentityRes, error)
|
||||
Authorize(ctx context.Context, in *AuthorizeReq, opts ...grpc.CallOption) (*AuthorizeRes, error)
|
||||
}
|
||||
|
||||
type authnServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewAuthnServiceClient(cc grpc.ClientConnInterface) AuthnServiceClient {
|
||||
return &authnServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *authnServiceClient) Issue(ctx context.Context, in *IssueReq, opts ...grpc.CallOption) (*Token, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Token)
|
||||
err := c.cc.Invoke(ctx, AuthnService_Issue_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authnServiceClient) Refresh(ctx context.Context, in *RefreshReq, opts ...grpc.CallOption) (*Token, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Token)
|
||||
err := c.cc.Invoke(ctx, AuthnService_Refresh_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authnServiceClient) Identify(ctx context.Context, in *IdentityReq, opts ...grpc.CallOption) (*IdentityRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(IdentityRes)
|
||||
err := c.cc.Invoke(ctx, AuthnService_Identify_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AuthnServiceServer is the server API for AuthnService service.
|
||||
// All implementations must embed UnimplementedAuthnServiceServer
|
||||
// for forward compatibility
|
||||
//
|
||||
// AuthnService is a service that provides authentication functionalities
|
||||
// for magistrala services.
|
||||
type AuthnServiceServer interface {
|
||||
Issue(context.Context, *IssueReq) (*Token, error)
|
||||
Refresh(context.Context, *RefreshReq) (*Token, error)
|
||||
Identify(context.Context, *IdentityReq) (*IdentityRes, error)
|
||||
mustEmbedUnimplementedAuthnServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedAuthnServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedAuthnServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedAuthnServiceServer) Issue(context.Context, *IssueReq) (*Token, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Issue not implemented")
|
||||
}
|
||||
func (UnimplementedAuthnServiceServer) Refresh(context.Context, *RefreshReq) (*Token, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Refresh not implemented")
|
||||
}
|
||||
func (UnimplementedAuthnServiceServer) Identify(context.Context, *IdentityReq) (*IdentityRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Identify not implemented")
|
||||
}
|
||||
func (UnimplementedAuthnServiceServer) mustEmbedUnimplementedAuthnServiceServer() {}
|
||||
|
||||
// UnsafeAuthnServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to AuthnServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeAuthnServiceServer interface {
|
||||
mustEmbedUnimplementedAuthnServiceServer()
|
||||
}
|
||||
|
||||
func RegisterAuthnServiceServer(s grpc.ServiceRegistrar, srv AuthnServiceServer) {
|
||||
s.RegisterService(&AuthnService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _AuthnService_Issue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(IssueReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthnServiceServer).Issue(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthnService_Issue_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthnServiceServer).Issue(ctx, req.(*IssueReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthnService_Refresh_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RefreshReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthnServiceServer).Refresh(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthnService_Refresh_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthnServiceServer).Refresh(ctx, req.(*RefreshReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthnService_Identify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(IdentityReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthnServiceServer).Identify(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthnService_Identify_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthnServiceServer).Identify(ctx, req.(*IdentityReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// AuthnService_ServiceDesc is the grpc.ServiceDesc for AuthnService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var AuthnService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "magistrala.AuthnService",
|
||||
HandlerType: (*AuthnServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Issue",
|
||||
Handler: _AuthnService_Issue_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Refresh",
|
||||
Handler: _AuthnService_Refresh_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Identify",
|
||||
Handler: _AuthnService_Identify_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
Metadata: "auth.proto",
|
||||
}
|
||||
|
||||
const (
|
||||
PolicyService_AddPolicy_FullMethodName = "/magistrala.PolicyService/AddPolicy"
|
||||
PolicyService_AddPolicies_FullMethodName = "/magistrala.PolicyService/AddPolicies"
|
||||
PolicyService_DeletePolicyFilter_FullMethodName = "/magistrala.PolicyService/DeletePolicyFilter"
|
||||
PolicyService_DeletePolicies_FullMethodName = "/magistrala.PolicyService/DeletePolicies"
|
||||
PolicyService_ListObjects_FullMethodName = "/magistrala.PolicyService/ListObjects"
|
||||
PolicyService_ListAllObjects_FullMethodName = "/magistrala.PolicyService/ListAllObjects"
|
||||
PolicyService_CountObjects_FullMethodName = "/magistrala.PolicyService/CountObjects"
|
||||
PolicyService_ListSubjects_FullMethodName = "/magistrala.PolicyService/ListSubjects"
|
||||
PolicyService_ListAllSubjects_FullMethodName = "/magistrala.PolicyService/ListAllSubjects"
|
||||
PolicyService_CountSubjects_FullMethodName = "/magistrala.PolicyService/CountSubjects"
|
||||
PolicyService_ListPermissions_FullMethodName = "/magistrala.PolicyService/ListPermissions"
|
||||
PolicyService_DeleteEntityPolicies_FullMethodName = "/magistrala.PolicyService/DeleteEntityPolicies"
|
||||
)
|
||||
|
||||
// PolicyServiceClient is the client API for PolicyService service.
|
||||
//
|
||||
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
|
||||
//
|
||||
// PolicyService is a service that provides policy CRUD
|
||||
// functionalities for magistrala services.
|
||||
type PolicyServiceClient interface {
|
||||
AddPolicy(ctx context.Context, in *AddPolicyReq, opts ...grpc.CallOption) (*AddPolicyRes, error)
|
||||
AddPolicies(ctx context.Context, in *AddPoliciesReq, opts ...grpc.CallOption) (*AddPoliciesRes, error)
|
||||
DeletePolicyFilter(ctx context.Context, in *DeletePolicyFilterReq, opts ...grpc.CallOption) (*DeletePolicyRes, error)
|
||||
@@ -166,185 +331,141 @@ type AuthServiceClient interface {
|
||||
DeleteEntityPolicies(ctx context.Context, in *DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*DeletePolicyRes, error)
|
||||
}
|
||||
|
||||
type authServiceClient struct {
|
||||
type policyServiceClient struct {
|
||||
cc grpc.ClientConnInterface
|
||||
}
|
||||
|
||||
func NewAuthServiceClient(cc grpc.ClientConnInterface) AuthServiceClient {
|
||||
return &authServiceClient{cc}
|
||||
func NewPolicyServiceClient(cc grpc.ClientConnInterface) PolicyServiceClient {
|
||||
return &policyServiceClient{cc}
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Issue(ctx context.Context, in *IssueReq, opts ...grpc.CallOption) (*Token, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Token)
|
||||
err := c.cc.Invoke(ctx, AuthService_Issue_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Refresh(ctx context.Context, in *RefreshReq, opts ...grpc.CallOption) (*Token, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(Token)
|
||||
err := c.cc.Invoke(ctx, AuthService_Refresh_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Identify(ctx context.Context, in *IdentityReq, opts ...grpc.CallOption) (*IdentityRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(IdentityRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_Identify_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) Authorize(ctx context.Context, in *AuthorizeReq, opts ...grpc.CallOption) (*AuthorizeRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AuthorizeRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_Authorize_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) AddPolicy(ctx context.Context, in *AddPolicyReq, opts ...grpc.CallOption) (*AddPolicyRes, error) {
|
||||
func (c *policyServiceClient) AddPolicy(ctx context.Context, in *AddPolicyReq, opts ...grpc.CallOption) (*AddPolicyRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AddPolicyRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_AddPolicy_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_AddPolicy_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) AddPolicies(ctx context.Context, in *AddPoliciesReq, opts ...grpc.CallOption) (*AddPoliciesRes, error) {
|
||||
func (c *policyServiceClient) AddPolicies(ctx context.Context, in *AddPoliciesReq, opts ...grpc.CallOption) (*AddPoliciesRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(AddPoliciesRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_AddPolicies_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_AddPolicies_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) DeletePolicyFilter(ctx context.Context, in *DeletePolicyFilterReq, opts ...grpc.CallOption) (*DeletePolicyRes, error) {
|
||||
func (c *policyServiceClient) DeletePolicyFilter(ctx context.Context, in *DeletePolicyFilterReq, opts ...grpc.CallOption) (*DeletePolicyRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DeletePolicyRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_DeletePolicyFilter_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_DeletePolicyFilter_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) DeletePolicies(ctx context.Context, in *DeletePoliciesReq, opts ...grpc.CallOption) (*DeletePolicyRes, error) {
|
||||
func (c *policyServiceClient) DeletePolicies(ctx context.Context, in *DeletePoliciesReq, opts ...grpc.CallOption) (*DeletePolicyRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DeletePolicyRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_DeletePolicies_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_DeletePolicies_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) ListObjects(ctx context.Context, in *ListObjectsReq, opts ...grpc.CallOption) (*ListObjectsRes, error) {
|
||||
func (c *policyServiceClient) ListObjects(ctx context.Context, in *ListObjectsReq, opts ...grpc.CallOption) (*ListObjectsRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListObjectsRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_ListObjects_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_ListObjects_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) ListAllObjects(ctx context.Context, in *ListObjectsReq, opts ...grpc.CallOption) (*ListObjectsRes, error) {
|
||||
func (c *policyServiceClient) ListAllObjects(ctx context.Context, in *ListObjectsReq, opts ...grpc.CallOption) (*ListObjectsRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListObjectsRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_ListAllObjects_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_ListAllObjects_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) CountObjects(ctx context.Context, in *CountObjectsReq, opts ...grpc.CallOption) (*CountObjectsRes, error) {
|
||||
func (c *policyServiceClient) CountObjects(ctx context.Context, in *CountObjectsReq, opts ...grpc.CallOption) (*CountObjectsRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CountObjectsRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_CountObjects_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_CountObjects_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) ListSubjects(ctx context.Context, in *ListSubjectsReq, opts ...grpc.CallOption) (*ListSubjectsRes, error) {
|
||||
func (c *policyServiceClient) ListSubjects(ctx context.Context, in *ListSubjectsReq, opts ...grpc.CallOption) (*ListSubjectsRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListSubjectsRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_ListSubjects_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_ListSubjects_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) ListAllSubjects(ctx context.Context, in *ListSubjectsReq, opts ...grpc.CallOption) (*ListSubjectsRes, error) {
|
||||
func (c *policyServiceClient) ListAllSubjects(ctx context.Context, in *ListSubjectsReq, opts ...grpc.CallOption) (*ListSubjectsRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListSubjectsRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_ListAllSubjects_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_ListAllSubjects_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) CountSubjects(ctx context.Context, in *CountSubjectsReq, opts ...grpc.CallOption) (*CountSubjectsRes, error) {
|
||||
func (c *policyServiceClient) CountSubjects(ctx context.Context, in *CountSubjectsReq, opts ...grpc.CallOption) (*CountSubjectsRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(CountSubjectsRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_CountSubjects_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_CountSubjects_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) ListPermissions(ctx context.Context, in *ListPermissionsReq, opts ...grpc.CallOption) (*ListPermissionsRes, error) {
|
||||
func (c *policyServiceClient) ListPermissions(ctx context.Context, in *ListPermissionsReq, opts ...grpc.CallOption) (*ListPermissionsRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(ListPermissionsRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_ListPermissions_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_ListPermissions_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *authServiceClient) DeleteEntityPolicies(ctx context.Context, in *DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*DeletePolicyRes, error) {
|
||||
func (c *policyServiceClient) DeleteEntityPolicies(ctx context.Context, in *DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*DeletePolicyRes, error) {
|
||||
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
|
||||
out := new(DeletePolicyRes)
|
||||
err := c.cc.Invoke(ctx, AuthService_DeleteEntityPolicies_FullMethodName, in, out, cOpts...)
|
||||
err := c.cc.Invoke(ctx, PolicyService_DeleteEntityPolicies_FullMethodName, in, out, cOpts...)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
// AuthServiceServer is the server API for AuthService service.
|
||||
// All implementations must embed UnimplementedAuthServiceServer
|
||||
// PolicyServiceServer is the server API for PolicyService service.
|
||||
// All implementations must embed UnimplementedPolicyServiceServer
|
||||
// for forward compatibility
|
||||
//
|
||||
// AuthService is a service that provides authentication and authorization
|
||||
// functionalities for the users service.
|
||||
type AuthServiceServer interface {
|
||||
Issue(context.Context, *IssueReq) (*Token, error)
|
||||
Refresh(context.Context, *RefreshReq) (*Token, error)
|
||||
Identify(context.Context, *IdentityReq) (*IdentityRes, error)
|
||||
Authorize(context.Context, *AuthorizeReq) (*AuthorizeRes, error)
|
||||
// PolicyService is a service that provides policy CRUD
|
||||
// functionalities for magistrala services.
|
||||
type PolicyServiceServer interface {
|
||||
AddPolicy(context.Context, *AddPolicyReq) (*AddPolicyRes, error)
|
||||
AddPolicies(context.Context, *AddPoliciesReq) (*AddPoliciesRes, error)
|
||||
DeletePolicyFilter(context.Context, *DeletePolicyFilterReq) (*DeletePolicyRes, error)
|
||||
@@ -357,432 +478,332 @@ type AuthServiceServer interface {
|
||||
CountSubjects(context.Context, *CountSubjectsReq) (*CountSubjectsRes, error)
|
||||
ListPermissions(context.Context, *ListPermissionsReq) (*ListPermissionsRes, error)
|
||||
DeleteEntityPolicies(context.Context, *DeleteEntityPoliciesReq) (*DeletePolicyRes, error)
|
||||
mustEmbedUnimplementedAuthServiceServer()
|
||||
mustEmbedUnimplementedPolicyServiceServer()
|
||||
}
|
||||
|
||||
// UnimplementedAuthServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedAuthServiceServer struct {
|
||||
// UnimplementedPolicyServiceServer must be embedded to have forward compatible implementations.
|
||||
type UnimplementedPolicyServiceServer struct {
|
||||
}
|
||||
|
||||
func (UnimplementedAuthServiceServer) Issue(context.Context, *IssueReq) (*Token, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Issue not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) Refresh(context.Context, *RefreshReq) (*Token, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Refresh not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) Identify(context.Context, *IdentityReq) (*IdentityRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Identify not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) Authorize(context.Context, *AuthorizeReq) (*AuthorizeRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method Authorize not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) AddPolicy(context.Context, *AddPolicyReq) (*AddPolicyRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) AddPolicy(context.Context, *AddPolicyReq) (*AddPolicyRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method AddPolicy not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) AddPolicies(context.Context, *AddPoliciesReq) (*AddPoliciesRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) AddPolicies(context.Context, *AddPoliciesReq) (*AddPoliciesRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method AddPolicies not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) DeletePolicyFilter(context.Context, *DeletePolicyFilterReq) (*DeletePolicyRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) DeletePolicyFilter(context.Context, *DeletePolicyFilterReq) (*DeletePolicyRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeletePolicyFilter not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) DeletePolicies(context.Context, *DeletePoliciesReq) (*DeletePolicyRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) DeletePolicies(context.Context, *DeletePoliciesReq) (*DeletePolicyRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeletePolicies not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) ListObjects(context.Context, *ListObjectsReq) (*ListObjectsRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) ListObjects(context.Context, *ListObjectsReq) (*ListObjectsRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListObjects not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) ListAllObjects(context.Context, *ListObjectsReq) (*ListObjectsRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) ListAllObjects(context.Context, *ListObjectsReq) (*ListObjectsRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListAllObjects not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) CountObjects(context.Context, *CountObjectsReq) (*CountObjectsRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) CountObjects(context.Context, *CountObjectsReq) (*CountObjectsRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CountObjects not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) ListSubjects(context.Context, *ListSubjectsReq) (*ListSubjectsRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) ListSubjects(context.Context, *ListSubjectsReq) (*ListSubjectsRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListSubjects not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) ListAllSubjects(context.Context, *ListSubjectsReq) (*ListSubjectsRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) ListAllSubjects(context.Context, *ListSubjectsReq) (*ListSubjectsRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListAllSubjects not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) CountSubjects(context.Context, *CountSubjectsReq) (*CountSubjectsRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) CountSubjects(context.Context, *CountSubjectsReq) (*CountSubjectsRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method CountSubjects not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) ListPermissions(context.Context, *ListPermissionsReq) (*ListPermissionsRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) ListPermissions(context.Context, *ListPermissionsReq) (*ListPermissionsRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method ListPermissions not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) DeleteEntityPolicies(context.Context, *DeleteEntityPoliciesReq) (*DeletePolicyRes, error) {
|
||||
func (UnimplementedPolicyServiceServer) DeleteEntityPolicies(context.Context, *DeleteEntityPoliciesReq) (*DeletePolicyRes, error) {
|
||||
return nil, status.Errorf(codes.Unimplemented, "method DeleteEntityPolicies not implemented")
|
||||
}
|
||||
func (UnimplementedAuthServiceServer) mustEmbedUnimplementedAuthServiceServer() {}
|
||||
func (UnimplementedPolicyServiceServer) mustEmbedUnimplementedPolicyServiceServer() {}
|
||||
|
||||
// UnsafeAuthServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to AuthServiceServer will
|
||||
// UnsafePolicyServiceServer may be embedded to opt out of forward compatibility for this service.
|
||||
// Use of this interface is not recommended, as added methods to PolicyServiceServer will
|
||||
// result in compilation errors.
|
||||
type UnsafeAuthServiceServer interface {
|
||||
mustEmbedUnimplementedAuthServiceServer()
|
||||
type UnsafePolicyServiceServer interface {
|
||||
mustEmbedUnimplementedPolicyServiceServer()
|
||||
}
|
||||
|
||||
func RegisterAuthServiceServer(s grpc.ServiceRegistrar, srv AuthServiceServer) {
|
||||
s.RegisterService(&AuthService_ServiceDesc, srv)
|
||||
func RegisterPolicyServiceServer(s grpc.ServiceRegistrar, srv PolicyServiceServer) {
|
||||
s.RegisterService(&PolicyService_ServiceDesc, srv)
|
||||
}
|
||||
|
||||
func _AuthService_Issue_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(IssueReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Issue(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_Issue_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Issue(ctx, req.(*IssueReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_Refresh_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(RefreshReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Refresh(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_Refresh_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Refresh(ctx, req.(*RefreshReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_Identify_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(IdentityReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Identify(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_Identify_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Identify(ctx, req.(*IdentityReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_Authorize_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AuthorizeReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).Authorize(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_Authorize_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).Authorize(ctx, req.(*AuthorizeReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_AddPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_AddPolicy_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddPolicyReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).AddPolicy(ctx, in)
|
||||
return srv.(PolicyServiceServer).AddPolicy(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_AddPolicy_FullMethodName,
|
||||
FullMethod: PolicyService_AddPolicy_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).AddPolicy(ctx, req.(*AddPolicyReq))
|
||||
return srv.(PolicyServiceServer).AddPolicy(ctx, req.(*AddPolicyReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_AddPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_AddPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(AddPoliciesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).AddPolicies(ctx, in)
|
||||
return srv.(PolicyServiceServer).AddPolicies(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_AddPolicies_FullMethodName,
|
||||
FullMethod: PolicyService_AddPolicies_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).AddPolicies(ctx, req.(*AddPoliciesReq))
|
||||
return srv.(PolicyServiceServer).AddPolicies(ctx, req.(*AddPoliciesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_DeletePolicyFilter_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_DeletePolicyFilter_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeletePolicyFilterReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).DeletePolicyFilter(ctx, in)
|
||||
return srv.(PolicyServiceServer).DeletePolicyFilter(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_DeletePolicyFilter_FullMethodName,
|
||||
FullMethod: PolicyService_DeletePolicyFilter_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).DeletePolicyFilter(ctx, req.(*DeletePolicyFilterReq))
|
||||
return srv.(PolicyServiceServer).DeletePolicyFilter(ctx, req.(*DeletePolicyFilterReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_DeletePolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_DeletePolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeletePoliciesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).DeletePolicies(ctx, in)
|
||||
return srv.(PolicyServiceServer).DeletePolicies(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_DeletePolicies_FullMethodName,
|
||||
FullMethod: PolicyService_DeletePolicies_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).DeletePolicies(ctx, req.(*DeletePoliciesReq))
|
||||
return srv.(PolicyServiceServer).DeletePolicies(ctx, req.(*DeletePoliciesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_ListObjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_ListObjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListObjectsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).ListObjects(ctx, in)
|
||||
return srv.(PolicyServiceServer).ListObjects(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_ListObjects_FullMethodName,
|
||||
FullMethod: PolicyService_ListObjects_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).ListObjects(ctx, req.(*ListObjectsReq))
|
||||
return srv.(PolicyServiceServer).ListObjects(ctx, req.(*ListObjectsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_ListAllObjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_ListAllObjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListObjectsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).ListAllObjects(ctx, in)
|
||||
return srv.(PolicyServiceServer).ListAllObjects(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_ListAllObjects_FullMethodName,
|
||||
FullMethod: PolicyService_ListAllObjects_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).ListAllObjects(ctx, req.(*ListObjectsReq))
|
||||
return srv.(PolicyServiceServer).ListAllObjects(ctx, req.(*ListObjectsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_CountObjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_CountObjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CountObjectsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).CountObjects(ctx, in)
|
||||
return srv.(PolicyServiceServer).CountObjects(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_CountObjects_FullMethodName,
|
||||
FullMethod: PolicyService_CountObjects_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).CountObjects(ctx, req.(*CountObjectsReq))
|
||||
return srv.(PolicyServiceServer).CountObjects(ctx, req.(*CountObjectsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_ListSubjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_ListSubjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListSubjectsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).ListSubjects(ctx, in)
|
||||
return srv.(PolicyServiceServer).ListSubjects(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_ListSubjects_FullMethodName,
|
||||
FullMethod: PolicyService_ListSubjects_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).ListSubjects(ctx, req.(*ListSubjectsReq))
|
||||
return srv.(PolicyServiceServer).ListSubjects(ctx, req.(*ListSubjectsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_ListAllSubjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_ListAllSubjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListSubjectsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).ListAllSubjects(ctx, in)
|
||||
return srv.(PolicyServiceServer).ListAllSubjects(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_ListAllSubjects_FullMethodName,
|
||||
FullMethod: PolicyService_ListAllSubjects_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).ListAllSubjects(ctx, req.(*ListSubjectsReq))
|
||||
return srv.(PolicyServiceServer).ListAllSubjects(ctx, req.(*ListSubjectsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_CountSubjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_CountSubjects_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(CountSubjectsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).CountSubjects(ctx, in)
|
||||
return srv.(PolicyServiceServer).CountSubjects(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_CountSubjects_FullMethodName,
|
||||
FullMethod: PolicyService_CountSubjects_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).CountSubjects(ctx, req.(*CountSubjectsReq))
|
||||
return srv.(PolicyServiceServer).CountSubjects(ctx, req.(*CountSubjectsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_ListPermissions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_ListPermissions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(ListPermissionsReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).ListPermissions(ctx, in)
|
||||
return srv.(PolicyServiceServer).ListPermissions(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_ListPermissions_FullMethodName,
|
||||
FullMethod: PolicyService_ListPermissions_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).ListPermissions(ctx, req.(*ListPermissionsReq))
|
||||
return srv.(PolicyServiceServer).ListPermissions(ctx, req.(*ListPermissionsReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
func _AuthService_DeleteEntityPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
func _PolicyService_DeleteEntityPolicies_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
|
||||
in := new(DeleteEntityPoliciesReq)
|
||||
if err := dec(in); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if interceptor == nil {
|
||||
return srv.(AuthServiceServer).DeleteEntityPolicies(ctx, in)
|
||||
return srv.(PolicyServiceServer).DeleteEntityPolicies(ctx, in)
|
||||
}
|
||||
info := &grpc.UnaryServerInfo{
|
||||
Server: srv,
|
||||
FullMethod: AuthService_DeleteEntityPolicies_FullMethodName,
|
||||
FullMethod: PolicyService_DeleteEntityPolicies_FullMethodName,
|
||||
}
|
||||
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
|
||||
return srv.(AuthServiceServer).DeleteEntityPolicies(ctx, req.(*DeleteEntityPoliciesReq))
|
||||
return srv.(PolicyServiceServer).DeleteEntityPolicies(ctx, req.(*DeleteEntityPoliciesReq))
|
||||
}
|
||||
return interceptor(ctx, in, info, handler)
|
||||
}
|
||||
|
||||
// AuthService_ServiceDesc is the grpc.ServiceDesc for AuthService service.
|
||||
// PolicyService_ServiceDesc is the grpc.ServiceDesc for PolicyService service.
|
||||
// It's only intended for direct use with grpc.RegisterService,
|
||||
// and not to be introspected or modified (even as a copy)
|
||||
var AuthService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "magistrala.AuthService",
|
||||
HandlerType: (*AuthServiceServer)(nil),
|
||||
var PolicyService_ServiceDesc = grpc.ServiceDesc{
|
||||
ServiceName: "magistrala.PolicyService",
|
||||
HandlerType: (*PolicyServiceServer)(nil),
|
||||
Methods: []grpc.MethodDesc{
|
||||
{
|
||||
MethodName: "Issue",
|
||||
Handler: _AuthService_Issue_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Refresh",
|
||||
Handler: _AuthService_Refresh_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Identify",
|
||||
Handler: _AuthService_Identify_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "Authorize",
|
||||
Handler: _AuthService_Authorize_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "AddPolicy",
|
||||
Handler: _AuthService_AddPolicy_Handler,
|
||||
Handler: _PolicyService_AddPolicy_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "AddPolicies",
|
||||
Handler: _AuthService_AddPolicies_Handler,
|
||||
Handler: _PolicyService_AddPolicies_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeletePolicyFilter",
|
||||
Handler: _AuthService_DeletePolicyFilter_Handler,
|
||||
Handler: _PolicyService_DeletePolicyFilter_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeletePolicies",
|
||||
Handler: _AuthService_DeletePolicies_Handler,
|
||||
Handler: _PolicyService_DeletePolicies_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListObjects",
|
||||
Handler: _AuthService_ListObjects_Handler,
|
||||
Handler: _PolicyService_ListObjects_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListAllObjects",
|
||||
Handler: _AuthService_ListAllObjects_Handler,
|
||||
Handler: _PolicyService_ListAllObjects_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CountObjects",
|
||||
Handler: _AuthService_CountObjects_Handler,
|
||||
Handler: _PolicyService_CountObjects_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListSubjects",
|
||||
Handler: _AuthService_ListSubjects_Handler,
|
||||
Handler: _PolicyService_ListSubjects_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListAllSubjects",
|
||||
Handler: _AuthService_ListAllSubjects_Handler,
|
||||
Handler: _PolicyService_ListAllSubjects_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "CountSubjects",
|
||||
Handler: _AuthService_CountSubjects_Handler,
|
||||
Handler: _PolicyService_CountSubjects_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "ListPermissions",
|
||||
Handler: _AuthService_ListPermissions_Handler,
|
||||
Handler: _PolicyService_ListPermissions_Handler,
|
||||
},
|
||||
{
|
||||
MethodName: "DeleteEntityPolicies",
|
||||
Handler: _AuthService_DeleteEntityPolicies_Handler,
|
||||
Handler: _PolicyService_DeleteEntityPolicies_Handler,
|
||||
},
|
||||
},
|
||||
Streams: []grpc.StreamDesc{},
|
||||
|
||||
@@ -84,24 +84,38 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func newService(t *testing.T, url string) (bootstrap.Service, *mocks.ConfigRepository, *authmocks.AuthClient, *sdkmocks.SDK) {
|
||||
type testVariable struct {
|
||||
svc bootstrap.Service
|
||||
boot *mocks.ConfigRepository
|
||||
auth *authmocks.AuthServiceClient
|
||||
policy *authmocks.PolicyServiceClient
|
||||
sdk *sdkmocks.SDK
|
||||
}
|
||||
|
||||
func newTestVariable(t *testing.T, redisURL string) testVariable {
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthClient)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, boot, sdk, encKey, idp)
|
||||
publisher, err := store.NewPublisher(context.Background(), url, streamID)
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
publisher, err := store.NewPublisher(context.Background(), redisURL, streamID)
|
||||
require.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
svc = producer.NewEventStoreMiddleware(svc, publisher)
|
||||
|
||||
return svc, boot, auth, sdk
|
||||
return testVariable{
|
||||
svc: svc,
|
||||
boot: boot,
|
||||
auth: auth,
|
||||
policy: policy,
|
||||
sdk: sdk,
|
||||
}
|
||||
}
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, auth, sdk := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
var channels []string
|
||||
for _, ch := range config.Channels {
|
||||
@@ -204,13 +218,13 @@ func TestAdd(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
sdkCall := sdk.On("Thing", tc.config.ThingID, tc.token).Return(mgsdk.Thing{ID: tc.config.ThingID, Credentials: mgsdk.Credentials{Secret: tc.config.ThingKey}}, errors.NewSDKError(tc.thingErr))
|
||||
repoCall := boot.On("ListExisting", context.Background(), domainID, mock.Anything).Return(tc.config.Channels, tc.listErr)
|
||||
repoCall1 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, tc.saveErr)
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := tv.auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
sdkCall := tv.sdk.On("Thing", tc.config.ThingID, tc.token).Return(mgsdk.Thing{ID: tc.config.ThingID, Credentials: mgsdk.Credentials{Secret: tc.config.ThingKey}}, errors.NewSDKError(tc.thingErr))
|
||||
repoCall := tv.boot.On("ListExisting", context.Background(), domainID, mock.Anything).Return(tc.config.Channels, tc.listErr)
|
||||
repoCall1 := tv.boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, tc.saveErr)
|
||||
|
||||
_, err := svc.Add(context.Background(), tc.token, tc.config)
|
||||
_, err := tv.svc.Add(context.Background(), tc.token, tc.config)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -239,7 +253,7 @@ func TestView(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, auth, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
nonExisting := config
|
||||
nonExisting.ThingID = unknownThingID
|
||||
@@ -310,11 +324,11 @@ func TestView(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := boot.On("RetrieveByID", context.Background(), tc.domainID, tc.config.ThingID).Return(config, tc.retrieveErr)
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := tv.auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := tv.boot.On("RetrieveByID", context.Background(), tc.domainID, tc.config.ThingID).Return(config, tc.retrieveErr)
|
||||
|
||||
_, err := svc.View(context.Background(), tc.token, tc.config.ThingID)
|
||||
_, err := tv.svc.View(context.Background(), tc.token, tc.config.ThingID)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -342,7 +356,7 @@ func TestUpdate(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, auth, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
c := config
|
||||
|
||||
@@ -431,10 +445,10 @@ func TestUpdate(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := boot.On("Update", context.Background(), mock.Anything).Return(tc.updateErr)
|
||||
err := svc.Update(context.Background(), tc.token, tc.config)
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := tv.auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := tv.boot.On("Update", context.Background(), mock.Anything).Return(tc.updateErr)
|
||||
err := tv.svc.Update(context.Background(), tc.token, tc.config)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -462,7 +476,7 @@ func TestUpdateConnections(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, auth, sdk := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -570,13 +584,13 @@ func TestUpdateConnections(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
sdkCall := sdk.On("Channel", mock.Anything, tc.token).Return(mgsdk.Channel{}, tc.channelErr)
|
||||
repoCall := boot.On("RetrieveByID", context.Background(), tc.domainID, tc.configID).Return(config, tc.retrieveErr)
|
||||
repoCall1 := boot.On("ListExisting", context.Background(), domainID, mock.Anything, mock.Anything).Return(config.Channels, tc.listErr)
|
||||
repoCall2 := boot.On("UpdateConnections", context.Background(), tc.domainID, tc.configID, mock.Anything, tc.connections).Return(tc.updateErr)
|
||||
err := svc.UpdateConnections(context.Background(), tc.token, tc.configID, tc.connections)
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.id, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := tv.auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
sdkCall := tv.sdk.On("Channel", mock.Anything, tc.token).Return(mgsdk.Channel{}, tc.channelErr)
|
||||
repoCall := tv.boot.On("RetrieveByID", context.Background(), tc.domainID, tc.configID).Return(config, tc.retrieveErr)
|
||||
repoCall1 := tv.boot.On("ListExisting", context.Background(), domainID, mock.Anything, mock.Anything).Return(config.Channels, tc.listErr)
|
||||
repoCall2 := tv.boot.On("UpdateConnections", context.Background(), tc.domainID, tc.configID, mock.Anything, tc.connections).Return(tc.updateErr)
|
||||
err := tv.svc.UpdateConnections(context.Background(), tc.token, tc.configID, tc.connections)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -605,7 +619,7 @@ func TestUpdateCert(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, auth, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -744,10 +758,10 @@ func TestUpdateCert(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := boot.On("UpdateCert", context.Background(), tc.domainID, tc.configID, tc.clientCert, tc.clientKey, tc.caCert).Return(config, tc.updateErr)
|
||||
_, err := svc.UpdateCert(context.Background(), tc.token, tc.configID, tc.clientCert, tc.clientKey, tc.caCert)
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := tv.auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := tv.boot.On("UpdateCert", context.Background(), tc.domainID, tc.configID, tc.clientCert, tc.clientKey, tc.caCert).Return(config, tc.updateErr)
|
||||
_, err := tv.svc.UpdateCert(context.Background(), tc.token, tc.configID, tc.clientCert, tc.clientKey, tc.caCert)
|
||||
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
@@ -772,7 +786,8 @@ func TestUpdateCert(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
svc, boot, auth, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
numThings := 101
|
||||
var c bootstrap.Config
|
||||
saved := make([]bootstrap.Config, 0)
|
||||
@@ -997,15 +1012,15 @@ func TestList(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := tv.auth.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: authsvc.UserType,
|
||||
Subject: tc.userID,
|
||||
Permission: authsvc.AdminPermission,
|
||||
ObjectType: authsvc.PlatformType,
|
||||
Object: authsvc.MagistralaObject,
|
||||
}).Return(tc.superAdminAuthRes, tc.superAdmiAuthErr)
|
||||
authCall2 := auth.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall2 := tv.auth.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: authsvc.UserType,
|
||||
SubjectKind: authsvc.UsersKind,
|
||||
Subject: tc.userID,
|
||||
@@ -1013,15 +1028,15 @@ func TestList(t *testing.T) {
|
||||
ObjectType: authsvc.DomainType,
|
||||
Object: tc.domainID,
|
||||
}).Return(tc.domainAdminAuthRes, tc.domainAdmiAuthErr)
|
||||
authCall3 := auth.On("ListAllObjects", mock.Anything, &magistrala.ListObjectsReq{
|
||||
authCall3 := tv.policy.On("ListAllObjects", mock.Anything, &magistrala.ListObjectsReq{
|
||||
SubjectType: authsvc.UserType,
|
||||
Subject: tc.userID,
|
||||
Permission: authsvc.ViewPermission,
|
||||
ObjectType: authsvc.ThingType,
|
||||
}).Return(tc.listObjectsResponse, tc.listObjectsErr)
|
||||
repoCall := boot.On("RetrieveAll", context.Background(), mock.Anything, mock.Anything, tc.filter, tc.offset, tc.limit).Return(tc.config, tc.retrieveErr)
|
||||
repoCall := tv.boot.On("RetrieveAll", context.Background(), mock.Anything, mock.Anything, tc.filter, tc.offset, tc.limit).Return(tc.config, tc.retrieveErr)
|
||||
|
||||
_, err := svc.List(context.Background(), tc.token, tc.filter, tc.offset, tc.limit)
|
||||
_, err := tv.svc.List(context.Background(), tc.token, tc.filter, tc.offset, tc.limit)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1050,7 +1065,7 @@ func TestRemove(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, auth, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
nonExisting := config
|
||||
nonExisting.ThingID = unknownThingID
|
||||
@@ -1116,10 +1131,10 @@ func TestRemove(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := boot.On("Remove", context.Background(), mock.Anything, mock.Anything).Return(tc.removeErr)
|
||||
err := svc.Remove(context.Background(), tc.token, tc.configID)
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
authCall1 := tv.auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall := tv.boot.On("Remove", context.Background(), mock.Anything, mock.Anything).Return(tc.removeErr)
|
||||
err := tv.svc.Remove(context.Background(), tc.token, tc.configID)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1145,7 +1160,7 @@ func TestBootstrap(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, _, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1184,8 +1199,8 @@ func TestBootstrap(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
repoCall := boot.On("RetrieveByExternalID", context.Background(), mock.Anything).Return(config, tc.retrieveErr)
|
||||
_, err = svc.Bootstrap(context.Background(), tc.externalKey, tc.externalID, false)
|
||||
repoCall := tv.boot.On("RetrieveByExternalID", context.Background(), mock.Anything).Return(config, tc.retrieveErr)
|
||||
_, err = tv.svc.Bootstrap(context.Background(), tc.externalKey, tc.externalID, false)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1208,7 +1223,7 @@ func TestChangeState(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, auth, sdk := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1288,11 +1303,11 @@ func TestChangeState(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
repoCall := boot.On("RetrieveByID", context.Background(), tc.domainID, tc.id).Return(config, tc.retrieveErr)
|
||||
sdkCall1 := sdk.On("Connect", mock.Anything, mock.Anything).Return(errors.NewSDKError(tc.connectErr))
|
||||
repoCall1 := boot.On("ChangeState", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(tc.stateErr)
|
||||
err := svc.ChangeState(context.Background(), tc.token, tc.id, tc.state)
|
||||
authCall := tv.auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: tc.userID, DomainId: tc.domainID}, tc.identifyErr)
|
||||
repoCall := tv.boot.On("RetrieveByID", context.Background(), tc.domainID, tc.id).Return(config, tc.retrieveErr)
|
||||
sdkCall1 := tv.sdk.On("Connect", mock.Anything, mock.Anything).Return(errors.NewSDKError(tc.connectErr))
|
||||
repoCall1 := tv.boot.On("ChangeState", context.Background(), mock.Anything, mock.Anything, mock.Anything).Return(tc.stateErr)
|
||||
err := tv.svc.ChangeState(context.Background(), tc.token, tc.id, tc.state)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1319,7 +1334,7 @@ func TestUpdateChannelHandler(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, _, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1375,8 +1390,8 @@ func TestUpdateChannelHandler(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
repoCall := boot.On("UpdateChannel", context.Background(), mock.Anything).Return(tc.err)
|
||||
err := svc.UpdateChannelHandler(context.Background(), tc.channel)
|
||||
repoCall := tv.boot.On("UpdateChannel", context.Background(), mock.Anything).Return(tc.err)
|
||||
err := tv.svc.UpdateChannelHandler(context.Background(), tc.channel)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1401,7 +1416,7 @@ func TestRemoveChannelHandler(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, _, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1436,8 +1451,8 @@ func TestRemoveChannelHandler(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
repoCall := boot.On("RemoveChannel", context.Background(), mock.Anything).Return(tc.err)
|
||||
err := svc.RemoveChannelHandler(context.Background(), tc.channelID)
|
||||
repoCall := tv.boot.On("RemoveChannel", context.Background(), mock.Anything).Return(tc.err)
|
||||
err := tv.svc.RemoveChannelHandler(context.Background(), tc.channelID)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1463,7 +1478,7 @@ func TestRemoveConfigHandler(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, _, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1498,8 +1513,8 @@ func TestRemoveConfigHandler(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
repoCall := boot.On("RemoveThing", context.Background(), mock.Anything).Return(tc.err)
|
||||
err := svc.RemoveConfigHandler(context.Background(), tc.configID)
|
||||
repoCall := tv.boot.On("RemoveThing", context.Background(), mock.Anything).Return(tc.err)
|
||||
err := tv.svc.RemoveConfigHandler(context.Background(), tc.configID)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1525,7 +1540,7 @@ func TestConnectThingHandler(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, _, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1572,8 +1587,8 @@ func TestConnectThingHandler(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
repoCall := boot.On("ConnectThing", context.Background(), mock.Anything, mock.Anything).Return(tc.err)
|
||||
err := svc.ConnectThingHandler(context.Background(), tc.channelID, tc.thingID)
|
||||
repoCall := tv.boot.On("ConnectThing", context.Background(), mock.Anything, mock.Anything).Return(tc.err)
|
||||
err := tv.svc.ConnectThingHandler(context.Background(), tc.channelID, tc.thingID)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
@@ -1599,7 +1614,7 @@ func TestDisconnectThingHandler(t *testing.T) {
|
||||
err := redisClient.FlushAll(context.Background()).Err()
|
||||
assert.Nil(t, err, fmt.Sprintf("got unexpected error: %s", err))
|
||||
|
||||
svc, boot, _, _ := newService(t, redisURL)
|
||||
tv := newTestVariable(t, redisURL)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1656,8 +1671,8 @@ func TestDisconnectThingHandler(t *testing.T) {
|
||||
|
||||
lastID := "0"
|
||||
for _, tc := range cases {
|
||||
repoCall := boot.On("DisconnectThing", context.Background(), tc.channelID, tc.thingID).Return(tc.err)
|
||||
err := svc.DisconnectThingHandler(context.Background(), tc.channelID, tc.thingID)
|
||||
repoCall := tv.boot.On("DisconnectThing", context.Background(), tc.channelID, tc.thingID).Return(tc.err)
|
||||
err := tv.svc.DisconnectThingHandler(context.Background(), tc.channelID, tc.thingID)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
streams := redisClient.XRead(context.Background(), &redis.XReadArgs{
|
||||
|
||||
@@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
grpcclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
@@ -119,7 +120,8 @@ type ConfigReader interface {
|
||||
}
|
||||
|
||||
type bootstrapService struct {
|
||||
auth magistrala.AuthServiceClient
|
||||
auth grpcclient.AuthServiceClient
|
||||
policy magistrala.PolicyServiceClient
|
||||
configs ConfigRepository
|
||||
sdk mgsdk.SDK
|
||||
encKey []byte
|
||||
@@ -127,11 +129,12 @@ type bootstrapService struct {
|
||||
}
|
||||
|
||||
// New returns new Bootstrap service.
|
||||
func New(uauth magistrala.AuthServiceClient, configs ConfigRepository, sdk mgsdk.SDK, encKey []byte, idp magistrala.IDProvider) Service {
|
||||
func New(auth grpcclient.AuthServiceClient, policy magistrala.PolicyServiceClient, configs ConfigRepository, sdk mgsdk.SDK, encKey []byte, idp magistrala.IDProvider) Service {
|
||||
return &bootstrapService{
|
||||
configs: configs,
|
||||
sdk: sdk,
|
||||
auth: uauth,
|
||||
auth: auth,
|
||||
policy: policy,
|
||||
encKey: encKey,
|
||||
idProvider: idp,
|
||||
}
|
||||
@@ -302,7 +305,7 @@ func (bs bootstrapService) UpdateConnections(ctx context.Context, token, id stri
|
||||
}
|
||||
|
||||
func (bs bootstrapService) listClientIDs(ctx context.Context, userID string) ([]string, error) {
|
||||
tids, err := bs.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
tids, err := bs.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Permission: auth.ViewPermission,
|
||||
|
||||
+96
-27
@@ -59,15 +59,6 @@ var (
|
||||
}
|
||||
)
|
||||
|
||||
func newService() (bootstrap.Service, *mocks.ConfigRepository, *authmocks.AuthClient, *sdkmocks.SDK) {
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
|
||||
return bootstrap.New(auth, boot, sdk, encKey, idp), boot, auth, sdk
|
||||
}
|
||||
|
||||
func enc(in []byte) ([]byte, error) {
|
||||
block, err := aes.NewCipher(encKey)
|
||||
if err != nil {
|
||||
@@ -84,7 +75,13 @@ func enc(in []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func TestAdd(t *testing.T) {
|
||||
c, boot, auth, sdk := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
neID := config
|
||||
neID.ThingID = "non-existent"
|
||||
|
||||
@@ -200,7 +197,7 @@ func TestAdd(t *testing.T) {
|
||||
repoCall3 := boot.On("ListExisting", context.Background(), tc.domainID, mock.Anything).Return(tc.config.Channels, tc.listExistingErr)
|
||||
repoCall4 := boot.On("Save", context.Background(), mock.Anything, mock.Anything).Return(mock.Anything, tc.saveErr)
|
||||
|
||||
_, err := c.Add(context.Background(), tc.token, tc.config)
|
||||
_, err := svc.Add(context.Background(), tc.token, tc.config)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
|
||||
authCall.Unset()
|
||||
@@ -214,7 +211,12 @@ func TestAdd(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestView(t *testing.T) {
|
||||
svc, boot, auth, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -308,9 +310,14 @@ func TestView(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdate(t *testing.T) {
|
||||
svc, boot, auth, _ := newService()
|
||||
c := config
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
c := config
|
||||
ch := channel
|
||||
ch.ID = "2"
|
||||
c.Channels = append(c.Channels, ch)
|
||||
@@ -395,9 +402,14 @@ func TestUpdate(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateCert(t *testing.T) {
|
||||
svc, boot, auth, _ := newService()
|
||||
c := config
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
c := config
|
||||
ch := channel
|
||||
ch.ID = "2"
|
||||
c.Channels = append(c.Channels, ch)
|
||||
@@ -506,7 +518,13 @@ func TestUpdateCert(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateConnections(t *testing.T) {
|
||||
svc, boot, auth, sdk := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
c := config
|
||||
c.State = bootstrap.Inactive
|
||||
|
||||
@@ -620,7 +638,13 @@ func TestUpdateConnections(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestList(t *testing.T) {
|
||||
svc, boot, auth, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
numThings := 101
|
||||
var saved []bootstrap.Config
|
||||
for i := 0; i < numThings; i++ {
|
||||
@@ -960,7 +984,7 @@ func TestList(t *testing.T) {
|
||||
ObjectType: authsvc.DomainType,
|
||||
Object: tc.domainID,
|
||||
}).Return(tc.domainAdminAuthRes, tc.domainAdmiAuthErr)
|
||||
authCall3 := auth.On("ListAllObjects", mock.Anything, &magistrala.ListObjectsReq{
|
||||
authCall3 := policy.On("ListAllObjects", mock.Anything, &magistrala.ListObjectsReq{
|
||||
SubjectType: authsvc.UserType,
|
||||
Subject: tc.userID,
|
||||
Permission: authsvc.ViewPermission,
|
||||
@@ -981,7 +1005,13 @@ func TestList(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
svc, boot, auth, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
c := config
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1064,7 +1094,13 @@ func TestRemove(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestBootstrap(t *testing.T) {
|
||||
svc, boot, _, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
c := config
|
||||
e, err := enc([]byte(c.ExternalKey))
|
||||
assert.Nil(t, err, fmt.Sprintf("Encrypting external key expected to succeed: %s.\n", err))
|
||||
@@ -1131,7 +1167,12 @@ func TestBootstrap(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChangeState(t *testing.T) {
|
||||
svc, boot, auth, sdk := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
c := config
|
||||
cases := []struct {
|
||||
@@ -1232,7 +1273,13 @@ func TestChangeState(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateChannelHandler(t *testing.T) {
|
||||
svc, boot, _, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
ch := bootstrap.Channel{
|
||||
ID: channel.ID,
|
||||
Name: "new name",
|
||||
@@ -1265,7 +1312,12 @@ func TestUpdateChannelHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemoveChannelHandler(t *testing.T) {
|
||||
svc, boot, _, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1293,7 +1345,12 @@ func TestRemoveChannelHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemoveConfigHandler(t *testing.T) {
|
||||
svc, boot, _, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1321,7 +1378,13 @@ func TestRemoveConfigHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestConnectThingsHandler(t *testing.T) {
|
||||
svc, boot, _, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
thingID string
|
||||
@@ -1351,7 +1414,13 @@ func TestConnectThingsHandler(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDisconnectThingsHandler(t *testing.T) {
|
||||
svc, boot, _, _ := newService()
|
||||
boot := new(mocks.ConfigRepository)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
idp := uuid.NewMock()
|
||||
svc := bootstrap.New(auth, policy, boot, sdk, encKey, idp)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
thingID string
|
||||
|
||||
+2
-2
@@ -50,14 +50,14 @@ type Service interface {
|
||||
}
|
||||
|
||||
type certsService struct {
|
||||
auth magistrala.AuthServiceClient
|
||||
auth magistrala.AuthnServiceClient
|
||||
certsRepo Repository
|
||||
sdk mgsdk.SDK
|
||||
pki pki.Agent
|
||||
}
|
||||
|
||||
// New returns new Certs service.
|
||||
func New(auth magistrala.AuthServiceClient, certs Repository, sdk mgsdk.SDK, pkiAgent pki.Agent) Service {
|
||||
func New(auth magistrala.AuthnServiceClient, certs Repository, sdk mgsdk.SDK, pkiAgent pki.Agent) Service {
|
||||
return &certsService{
|
||||
certsRepo: certs,
|
||||
sdk: sdk,
|
||||
|
||||
@@ -37,10 +37,10 @@ const (
|
||||
validID = "d4ebb847-5d0e-4e46-bdd9-b6aceaaa3a22"
|
||||
)
|
||||
|
||||
func newService(_ *testing.T) (certs.Service, *mocks.Repository, *mocks.Agent, *authmocks.AuthClient, *sdkmocks.SDK) {
|
||||
func newService(_ *testing.T) (certs.Service, *mocks.Repository, *mocks.Agent, *authmocks.AuthServiceClient, *sdkmocks.SDK) {
|
||||
repo := new(mocks.Repository)
|
||||
agent := new(mocks.Agent)
|
||||
auth := new(authmocks.AuthClient)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
sdk := new(sdkmocks.SDK)
|
||||
|
||||
return certs.New(auth, repo, sdk, agent), repo, agent, auth, sdk
|
||||
|
||||
+3
-1
@@ -147,7 +147,9 @@ func main() {
|
||||
}
|
||||
registerAuthServiceServer := func(srv *grpc.Server) {
|
||||
reflection.Register(srv)
|
||||
magistrala.RegisterAuthServiceServer(srv, grpcapi.NewServer(svc))
|
||||
magistrala.RegisterAuthzServiceServer(srv, grpcapi.NewAuthzServer(svc))
|
||||
magistrala.RegisterAuthnServiceServer(srv, grpcapi.NewAuthnServer(svc))
|
||||
magistrala.RegisterPolicyServiceServer(srv, grpcapi.NewPolicyServer(svc))
|
||||
}
|
||||
|
||||
gs := grpcserver.NewServer(ctx, cancel, svcName, grpcServerConfig, registerAuthServiceServer, logger)
|
||||
|
||||
+19
-9
@@ -14,6 +14,7 @@ import (
|
||||
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
authclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/bootstrap"
|
||||
"github.com/absmach/magistrala/bootstrap/api"
|
||||
"github.com/absmach/magistrala/bootstrap/events/consumer"
|
||||
@@ -21,9 +22,9 @@ import (
|
||||
bootstrappg "github.com/absmach/magistrala/bootstrap/postgres"
|
||||
"github.com/absmach/magistrala/bootstrap/tracing"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/events"
|
||||
"github.com/absmach/magistrala/pkg/events/store"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
"github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/postgres"
|
||||
pgclient "github.com/absmach/magistrala/pkg/postgres"
|
||||
@@ -55,7 +56,7 @@ type config struct {
|
||||
EncKey string `env:"MG_BOOTSTRAP_ENCRYPT_KEY" envDefault:"12345678910111213141516171819202"`
|
||||
ESConsumerName string `env:"MG_BOOTSTRAP_EVENT_CONSUMER" envDefault:"bootstrap"`
|
||||
ThingsURL string `env:"MG_THINGS_URL" envDefault:"http://localhost:9000"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_BOOTSTRAP_INSTANCE_ID" envDefault:""`
|
||||
ESURL string `env:"MG_ES_URL" envDefault:"nats://localhost:4222"`
|
||||
@@ -100,21 +101,30 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
clientConfig := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&clientConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authClient, authHandler, err := auth.Setup(ctx, authConfig)
|
||||
authClient, authHandler, err := grpcclient.SetupAuthClient(ctx, clientConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer authHandler.Close()
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
policyClient, policyHandler, err := grpcclient.SetupPolicyClient(ctx, clientConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer policyHandler.Close()
|
||||
logger.Info("PolicyService gRPC client successfully connected to auth gRPC server " + policyHandler.Secure())
|
||||
|
||||
tp, err := jaeger.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio)
|
||||
if err != nil {
|
||||
@@ -130,7 +140,7 @@ func main() {
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
// Create new service
|
||||
svc, err := newService(ctx, authClient, db, tracer, logger, cfg, dbConfig)
|
||||
svc, err := newService(ctx, authClient, policyClient, db, tracer, logger, cfg, dbConfig)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to create %s service: %s", svcName, err))
|
||||
exitCode = 1
|
||||
@@ -171,7 +181,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, authClient magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger *slog.Logger, cfg config, dbConfig pgclient.Config) (bootstrap.Service, error) {
|
||||
func newService(ctx context.Context, authClient authclient.AuthServiceClient, policyClient magistrala.PolicyServiceClient, db *sqlx.DB, tracer trace.Tracer, logger *slog.Logger, cfg config, dbConfig pgclient.Config) (bootstrap.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
|
||||
repoConfig := bootstrappg.NewConfigRepository(database, logger)
|
||||
@@ -183,7 +193,7 @@ func newService(ctx context.Context, authClient magistrala.AuthServiceClient, db
|
||||
sdk := mgsdk.NewSDK(config)
|
||||
idp := uuid.New()
|
||||
|
||||
svc := bootstrap.New(authClient, repoConfig, sdk, []byte(cfg.EncKey), idp)
|
||||
svc := bootstrap.New(authClient, policyClient, repoConfig, sdk, []byte(cfg.EncKey), idp)
|
||||
|
||||
publisher, err := store.NewPublisher(ctx, cfg.ESURL, streamID)
|
||||
if err != nil {
|
||||
|
||||
+7
-7
@@ -20,7 +20,7 @@ import (
|
||||
certspg "github.com/absmach/magistrala/certs/postgres"
|
||||
"github.com/absmach/magistrala/certs/tracing"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/postgres"
|
||||
pgclient "github.com/absmach/magistrala/pkg/postgres"
|
||||
@@ -47,7 +47,7 @@ const (
|
||||
type config struct {
|
||||
LogLevel string `env:"MG_CERTS_LOG_LEVEL" envDefault:"info"`
|
||||
ThingsURL string `env:"MG_THINGS_URL" envDefault:"http://localhost:9000"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_CERTS_INSTANCE_ID" envDefault:""`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
@@ -119,14 +119,14 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
authClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&authClientCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authClient, authHandler, err := auth.Setup(ctx, authConfig)
|
||||
authClient, authHandler, err := grpcclient.SetupAuthClient(ctx, authClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -134,7 +134,7 @@ func main() {
|
||||
}
|
||||
defer authHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio)
|
||||
if err != nil {
|
||||
@@ -177,7 +177,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(authClient magistrala.AuthServiceClient, db *sqlx.DB, tracer trace.Tracer, logger *slog.Logger, cfg config, dbConfig pgclient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
func newService(authClient magistrala.AuthnServiceClient, db *sqlx.DB, tracer trace.Tracer, logger *slog.Logger, cfg config, dbConfig pgclient.Config, pkiAgent vault.Agent) certs.Service {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
certsRepo := certspg.NewRepository(database, logger)
|
||||
config := mgsdk.Config{
|
||||
|
||||
+14
-14
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/absmach/magistrala/coap/api"
|
||||
"github.com/absmach/magistrala/coap/tracing"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
@@ -31,18 +31,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
svcName = "coap_adapter"
|
||||
envPrefix = "MG_COAP_ADAPTER_"
|
||||
envPrefixHTTP = "MG_COAP_ADAPTER_HTTP_"
|
||||
envPrefixAuthz = "MG_THINGS_AUTH_GRPC_"
|
||||
defSvcHTTPPort = "5683"
|
||||
defSvcCoAPPort = "5683"
|
||||
svcName = "coap_adapter"
|
||||
envPrefix = "MG_COAP_ADAPTER_"
|
||||
envPrefixHTTP = "MG_COAP_ADAPTER_HTTP_"
|
||||
envPrefixThings = "MG_THINGS_AUTH_GRPC_"
|
||||
defSvcHTTPPort = "5683"
|
||||
defSvcCoAPPort = "5683"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
LogLevel string `env:"MG_COAP_ADAPTER_LOG_LEVEL" envDefault:"info"`
|
||||
BrokerURL string `env:"MG_MESSAGE_BROKER_URL" envDefault:"nats://localhost:4222"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_COAP_ADAPTER_INSTANCE_ID" envDefault:""`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
@@ -87,22 +87,22 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuthz}); err != nil {
|
||||
thingsClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&thingsClientCfg, env.Options{Prefix: envPrefixThings}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authClient, authHandler, err := auth.SetupAuthz(ctx, authConfig)
|
||||
thingsClient, thingsHandler, err := grpcclient.SetupThingsClient(ctx, thingsClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer authHandler.Close()
|
||||
defer thingsHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + authHandler.Secure())
|
||||
logger.Info("Things service gRPC client successfully connected to things gRPC server " + thingsHandler.Secure())
|
||||
|
||||
tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio)
|
||||
if err != nil {
|
||||
@@ -126,7 +126,7 @@ func main() {
|
||||
defer nps.Close()
|
||||
nps = brokerstracing.NewPubSub(coapServerConfig, tracer, nps)
|
||||
|
||||
svc := coap.New(authClient, nps)
|
||||
svc := coap.New(thingsClient, nps)
|
||||
|
||||
svc = tracing.New(tracer, svc)
|
||||
|
||||
|
||||
+14
-14
@@ -19,7 +19,7 @@ import (
|
||||
adapter "github.com/absmach/magistrala/http"
|
||||
"github.com/absmach/magistrala/http/api"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
@@ -38,18 +38,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
svcName = "http_adapter"
|
||||
envPrefix = "MG_HTTP_ADAPTER_"
|
||||
envPrefixAuthz = "MG_THINGS_AUTH_GRPC_"
|
||||
defSvcHTTPPort = "80"
|
||||
targetHTTPPort = "81"
|
||||
targetHTTPHost = "http://localhost"
|
||||
svcName = "http_adapter"
|
||||
envPrefix = "MG_HTTP_ADAPTER_"
|
||||
envPrefixThings = "MG_THINGS_AUTH_GRPC_"
|
||||
defSvcHTTPPort = "80"
|
||||
targetHTTPPort = "81"
|
||||
targetHTTPHost = "http://localhost"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
LogLevel string `env:"MG_HTTP_ADAPTER_LOG_LEVEL" envDefault:"info"`
|
||||
BrokerURL string `env:"MG_MESSAGE_BROKER_URL" envDefault:"nats://localhost:4222"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_HTTP_ADAPTER_INSTANCE_ID" envDefault:""`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
@@ -87,22 +87,22 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuthz}); err != nil {
|
||||
thingsClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&thingsClientCfg, env.Options{Prefix: envPrefixThings}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authClient, authHandler, err := auth.SetupAuthz(ctx, authConfig)
|
||||
thingsClient, thingsHandler, err := grpcclient.SetupThingsClient(ctx, thingsClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer authHandler.Close()
|
||||
defer thingsHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + authHandler.Secure())
|
||||
logger.Info("Things service gRPC client successfully connected to things gRPC server " + thingsHandler.Secure())
|
||||
|
||||
tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio)
|
||||
if err != nil {
|
||||
@@ -126,7 +126,7 @@ func main() {
|
||||
defer pub.Close()
|
||||
pub = brokerstracing.NewPublisher(httpServerConfig, tracer, pub)
|
||||
|
||||
svc := newService(pub, authClient, logger, tracer)
|
||||
svc := newService(pub, thingsClient, logger, tracer)
|
||||
targetServerCfg := server.Config{Port: targetHTTPPort}
|
||||
|
||||
hs := httpserver.NewServer(ctx, cancel, svcName, targetServerCfg, api.MakeHandler(logger, cfg.InstanceID), logger)
|
||||
|
||||
@@ -14,12 +14,13 @@ import (
|
||||
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
authclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/invitations"
|
||||
"github.com/absmach/magistrala/invitations/api"
|
||||
"github.com/absmach/magistrala/invitations/middleware"
|
||||
invitationspg "github.com/absmach/magistrala/invitations/postgres"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
"github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/postgres"
|
||||
clientspg "github.com/absmach/magistrala/pkg/postgres"
|
||||
@@ -48,7 +49,7 @@ type config struct {
|
||||
UsersURL string `env:"MG_USERS_URL" envDefault:"http://localhost:9002"`
|
||||
DomainsURL string `env:"MG_DOMAINS_URL" envDefault:"http://localhost:8189"`
|
||||
InstanceID string `env:"MG_INVITATIONS_INSTANCE_ID" envDefault:""`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
}
|
||||
@@ -92,20 +93,20 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
authClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&authClientCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load auth configuration : %s", err.Error()))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
authClient, authHandler, err := auth.Setup(ctx, authConfig)
|
||||
authClient, authHandler, err := grpcclient.SetupAuthClient(ctx, authClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer authHandler.Close()
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
tp, err := jaeger.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio)
|
||||
if err != nil {
|
||||
@@ -154,7 +155,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, dbConfig clientspg.Config, authClient magistrala.AuthServiceClient, tracer trace.Tracer, conf config, logger *slog.Logger) (invitations.Service, error) {
|
||||
func newService(db *sqlx.DB, dbConfig clientspg.Config, authClient authclient.AuthServiceClient, tracer trace.Tracer, conf config, logger *slog.Logger) (invitations.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
repo := invitationspg.NewRepository(database)
|
||||
|
||||
|
||||
+10
-9
@@ -14,14 +14,15 @@ import (
|
||||
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
authclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/journal"
|
||||
"github.com/absmach/magistrala/journal/api"
|
||||
"github.com/absmach/magistrala/journal/events"
|
||||
"github.com/absmach/magistrala/journal/middleware"
|
||||
journalpg "github.com/absmach/magistrala/journal/postgres"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/events/store"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/postgres"
|
||||
pgclient "github.com/absmach/magistrala/pkg/postgres"
|
||||
@@ -47,7 +48,7 @@ const (
|
||||
type config struct {
|
||||
LogLevel string `env:"MG_JOURNAL_LOG_LEVEL" envDefault:"info"`
|
||||
ESURL string `env:"MG_ES_URL" envDefault:"nats://localhost:4222"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_JOURNAL_INSTANCE_ID" envDefault:""`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
@@ -92,22 +93,22 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
authClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&authClientCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
ac, acHandler, err := auth.Setup(ctx, authConfig)
|
||||
authClient, authHandler, err := grpcclient.SetupAuthClient(ctx, authClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer acHandler.Close()
|
||||
defer authHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to auth grpc server " + acHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio)
|
||||
if err != nil {
|
||||
@@ -122,7 +123,7 @@ func main() {
|
||||
}()
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
svc := newService(db, dbConfig, ac, logger, tracer)
|
||||
svc := newService(db, dbConfig, authClient, logger, tracer)
|
||||
|
||||
subscriber, err := store.NewSubscriber(ctx, cfg.ESURL, logger)
|
||||
if err != nil {
|
||||
@@ -166,7 +167,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(db *sqlx.DB, dbConfig pgclient.Config, authClient magistrala.AuthServiceClient, logger *slog.Logger, tracer trace.Tracer) journal.Service {
|
||||
func newService(db *sqlx.DB, dbConfig pgclient.Config, authClient authclient.AuthServiceClient, logger *slog.Logger, tracer trace.Tracer) journal.Service {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
repo := journalpg.NewRepository(database)
|
||||
idp := uuid.New()
|
||||
|
||||
+11
-11
@@ -23,8 +23,8 @@ import (
|
||||
"github.com/absmach/magistrala/mqtt"
|
||||
"github.com/absmach/magistrala/mqtt/events"
|
||||
mqtttracing "github.com/absmach/magistrala/mqtt/tracing"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
brokerstracing "github.com/absmach/magistrala/pkg/messaging/brokers/tracing"
|
||||
@@ -42,9 +42,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
svcName = "mqtt"
|
||||
envPrefixAuthz = "MG_THINGS_AUTH_GRPC_"
|
||||
wsPathPrefix = "/mqtt"
|
||||
svcName = "mqtt"
|
||||
envPrefixThings = "MG_THINGS_AUTH_GRPC_"
|
||||
wsPathPrefix = "/mqtt"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -60,7 +60,7 @@ type config struct {
|
||||
HTTPTargetPort string `env:"MG_MQTT_ADAPTER_WS_TARGET_PORT" envDefault:"8080"`
|
||||
HTTPTargetPath string `env:"MG_MQTT_ADAPTER_WS_TARGET_PATH" envDefault:"/mqtt"`
|
||||
Instance string `env:"MG_MQTT_ADAPTER_INSTANCE" envDefault:""`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
BrokerURL string `env:"MG_MESSAGE_BROKER_URL" envDefault:"nats://localhost:4222"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_MQTT_ADAPTER_INSTANCE_ID" envDefault:""`
|
||||
@@ -165,24 +165,24 @@ func main() {
|
||||
return
|
||||
}
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuthz}); err != nil {
|
||||
thingsClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&thingsClientCfg, env.Options{Prefix: envPrefixThings}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authClient, authHandler, err := auth.SetupAuthz(ctx, authConfig)
|
||||
thingsClient, thingsHandler, err := grpcclient.SetupThingsClient(ctx, thingsClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer authHandler.Close()
|
||||
defer thingsHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + authHandler.Secure())
|
||||
logger.Info("Things service gRPC client successfully connected to things gRPC server " + thingsHandler.Secure())
|
||||
|
||||
h := mqtt.NewHandler(np, es, logger, authClient)
|
||||
h := mqtt.NewHandler(np, es, logger, thingsClient)
|
||||
h = handler.NewTracing(tracer, h)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
|
||||
+19
-19
@@ -14,7 +14,7 @@ import (
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
pgclient "github.com/absmach/magistrala/pkg/postgres"
|
||||
"github.com/absmach/magistrala/pkg/prometheus"
|
||||
"github.com/absmach/magistrala/pkg/server"
|
||||
@@ -29,13 +29,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
svcName = "postgres-reader"
|
||||
envPrefixDB = "MG_POSTGRES_"
|
||||
envPrefixHTTP = "MG_POSTGRES_READER_HTTP_"
|
||||
envPrefixAuth = "MG_AUTH_GRPC_"
|
||||
envPrefixAuthz = "MG_THINGS_AUTH_GRPC_"
|
||||
defDB = "magistrala"
|
||||
defSvcHTTPPort = "9009"
|
||||
svcName = "postgres-reader"
|
||||
envPrefixDB = "MG_POSTGRES_"
|
||||
envPrefixHTTP = "MG_POSTGRES_READER_HTTP_"
|
||||
envPrefixAuth = "MG_AUTH_GRPC_"
|
||||
envPrefixThings = "MG_THINGS_AUTH_GRPC_"
|
||||
defDB = "magistrala"
|
||||
defSvcHTTPPort = "9009"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -83,39 +83,39 @@ func main() {
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
authClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&authClientCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
ac, acHandler, err := auth.Setup(ctx, authConfig)
|
||||
authClient, authHandler, err := grpcclient.SetupAuthClient(ctx, authClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer acHandler.Close()
|
||||
defer authHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to auth grpc server " + acHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
authConfig = auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuthz}); err != nil {
|
||||
thingsClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&thingsClientCfg, env.Options{Prefix: envPrefixThings}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
tc, tcHandler, err := auth.SetupAuthz(ctx, authConfig)
|
||||
thingsClient, thingsHandler, err := grpcclient.SetupThingsClient(ctx, thingsClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer tcHandler.Close()
|
||||
defer thingsHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
logger.Info("Things service gRPC client successfully connected to things gRPC server " + thingsHandler.Secure())
|
||||
|
||||
repo := newService(db, logger)
|
||||
|
||||
@@ -125,7 +125,7 @@ func main() {
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, ac, tc, svcName, cfg.InstanceID), logger)
|
||||
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, authClient, thingsClient, svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
|
||||
@@ -44,7 +44,7 @@ type config struct {
|
||||
LogLevel string `env:"MG_POSTGRES_WRITER_LOG_LEVEL" envDefault:"info"`
|
||||
ConfigPath string `env:"MG_POSTGRES_WRITER_CONFIG_PATH" envDefault:"/config.toml"`
|
||||
BrokerURL string `env:"MG_MESSAGE_BROKER_URL" envDefault:"nats://localhost:4222"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_POSTGRES_WRITER_INSTANCE_ID" envDefault:""`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
|
||||
+28
-14
@@ -15,6 +15,7 @@ import (
|
||||
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
authclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
redisclient "github.com/absmach/magistrala/internal/clients/redis"
|
||||
mggroups "github.com/absmach/magistrala/internal/groups"
|
||||
gapi "github.com/absmach/magistrala/internal/groups/api"
|
||||
@@ -22,8 +23,8 @@ import (
|
||||
gpostgres "github.com/absmach/magistrala/internal/groups/postgres"
|
||||
gtracing "github.com/absmach/magistrala/internal/groups/tracing"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/groups"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/postgres"
|
||||
pgclient "github.com/absmach/magistrala/pkg/postgres"
|
||||
@@ -68,7 +69,7 @@ type config struct {
|
||||
LogLevel string `env:"MG_THINGS_LOG_LEVEL" envDefault:"info"`
|
||||
StandaloneID string `env:"MG_THINGS_STANDALONE_ID" envDefault:""`
|
||||
StandaloneToken string `env:"MG_THINGS_STANDALONE_TOKEN" envDefault:""`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
CacheKeyDuration time.Duration `env:"MG_THINGS_CACHE_KEY_DURATION" envDefault:"10m"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_THINGS_INSTANCE_ID" envDefault:""`
|
||||
@@ -144,21 +145,24 @@ func main() {
|
||||
}
|
||||
defer cacheclient.Close()
|
||||
|
||||
var authClient magistrala.AuthServiceClient
|
||||
|
||||
var (
|
||||
authClient authclient.AuthServiceClient
|
||||
policyClient magistrala.PolicyServiceClient
|
||||
)
|
||||
switch cfg.StandaloneID != "" && cfg.StandaloneToken != "" {
|
||||
case true:
|
||||
authClient = localusers.NewAuthService(cfg.StandaloneID, cfg.StandaloneToken)
|
||||
policyClient = localusers.NewPolicyService(cfg.StandaloneID, cfg.StandaloneToken)
|
||||
logger.Info("Using standalone auth service")
|
||||
default:
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
clientConfig := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&clientConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authServiceClient, authHandler, err := auth.Setup(ctx, authConfig)
|
||||
authServiceClient, authHandler, err := grpcclient.SetupAuthClient(ctx, clientConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
@@ -166,10 +170,20 @@ func main() {
|
||||
}
|
||||
defer authHandler.Close()
|
||||
authClient = authServiceClient
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
policyServiceClient, policyHandler, err := grpcclient.SetupPolicyClient(ctx, clientConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer policyHandler.Close()
|
||||
policyClient = policyServiceClient
|
||||
logger.Info("PolicyService gRPC client successfully connected to auth gRPC server " + policyHandler.Secure())
|
||||
}
|
||||
|
||||
csvc, gsvc, err := newService(ctx, db, dbConfig, authClient, cacheclient, cfg.CacheKeyDuration, cfg.ESURL, tracer, logger)
|
||||
csvc, gsvc, err := newService(ctx, db, dbConfig, authClient, policyClient, cacheclient, cfg.CacheKeyDuration, cfg.ESURL, tracer, logger)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to create services: %s", err))
|
||||
exitCode = 1
|
||||
@@ -191,11 +205,11 @@ func main() {
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
regiterAuthzServer := func(srv *grpc.Server) {
|
||||
registerThingsServer := func(srv *grpc.Server) {
|
||||
reflection.Register(srv)
|
||||
magistrala.RegisterAuthzServiceServer(srv, grpcapi.NewServer(csvc))
|
||||
}
|
||||
gs := grpcserver.NewServer(ctx, cancel, svcName, grpcServerConfig, regiterAuthzServer, logger)
|
||||
gs := grpcserver.NewServer(ctx, cancel, svcName, grpcServerConfig, registerThingsServer, logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
@@ -220,7 +234,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, authClient magistrala.AuthServiceClient, cacheClient *redis.Client, keyDuration time.Duration, esURL string, tracer trace.Tracer, logger *slog.Logger) (things.Service, groups.Service, error) {
|
||||
func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, authClient authclient.AuthServiceClient, policyClient magistrala.PolicyServiceClient, cacheClient *redis.Client, keyDuration time.Duration, esURL string, tracer trace.Tracer, logger *slog.Logger) (things.Service, groups.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := thingspg.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
@@ -229,8 +243,8 @@ func newService(ctx context.Context, db *sqlx.DB, dbConfig pgclient.Config, auth
|
||||
|
||||
thingCache := thcache.NewCache(cacheClient, keyDuration)
|
||||
|
||||
csvc := things.NewService(authClient, cRepo, gRepo, thingCache, idp)
|
||||
gsvc := mggroups.NewService(gRepo, idp, authClient)
|
||||
csvc := things.NewService(authClient, policyClient, cRepo, gRepo, thingCache, idp)
|
||||
gsvc := mggroups.NewService(gRepo, idp, authClient, policyClient)
|
||||
|
||||
csvc, err := thevents.NewEventStoreMiddleware(ctx, csvc, esURL)
|
||||
if err != nil {
|
||||
|
||||
@@ -14,7 +14,7 @@ import (
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
pgclient "github.com/absmach/magistrala/pkg/postgres"
|
||||
"github.com/absmach/magistrala/pkg/prometheus"
|
||||
"github.com/absmach/magistrala/pkg/server"
|
||||
@@ -29,13 +29,13 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
svcName = "timescaledb-reader"
|
||||
envPrefixDB = "MG_TIMESCALE_"
|
||||
envPrefixHTTP = "MG_TIMESCALE_READER_HTTP_"
|
||||
envPrefixAuth = "MG_AUTH_GRPC_"
|
||||
envPrefixAuthz = "MG_THINGS_AUTH_GRPC_"
|
||||
defDB = "messages"
|
||||
defSvcHTTPPort = "9011"
|
||||
svcName = "timescaledb-reader"
|
||||
envPrefixDB = "MG_TIMESCALE_"
|
||||
envPrefixHTTP = "MG_TIMESCALE_READER_HTTP_"
|
||||
envPrefixAuth = "MG_AUTH_GRPC_"
|
||||
envPrefixThings = "MG_THINGS_AUTH_GRPC_"
|
||||
defDB = "messages"
|
||||
defSvcHTTPPort = "9011"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
@@ -83,39 +83,39 @@ func main() {
|
||||
|
||||
repo := newService(db, logger)
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
authClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&authClientCfg, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
ac, acHandler, err := auth.Setup(ctx, authConfig)
|
||||
authClient, authHandler, err := grpcclient.SetupAuthClient(ctx, authClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer acHandler.Close()
|
||||
defer authHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to auth grpc server " + acHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
authConfig = auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuthz}); err != nil {
|
||||
thingsClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&thingsClientCfg, env.Options{Prefix: envPrefixThings}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
tc, tcHandler, err := auth.SetupAuthz(ctx, authConfig)
|
||||
thingsClient, thingsHandler, err := grpcclient.SetupThingsClient(ctx, thingsClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer tcHandler.Close()
|
||||
defer thingsHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + tcHandler.Secure())
|
||||
logger.Info("ThingsService gRPC client successfully connected to things gRPC server " + thingsHandler.Secure())
|
||||
|
||||
httpServerConfig := server.Config{Port: defSvcHTTPPort}
|
||||
if err := env.ParseWithOptions(&httpServerConfig, env.Options{Prefix: envPrefixHTTP}); err != nil {
|
||||
@@ -123,7 +123,7 @@ func main() {
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, ac, tc, svcName, cfg.InstanceID), logger)
|
||||
hs := httpserver.NewServer(ctx, cancel, svcName, httpServerConfig, api.MakeHandler(repo, authClient, thingsClient, svcName, cfg.InstanceID), logger)
|
||||
|
||||
if cfg.SendTelemetry {
|
||||
chc := chclient.New(svcName, magistrala.Version, logger, cancel)
|
||||
|
||||
@@ -44,7 +44,7 @@ type config struct {
|
||||
LogLevel string `env:"MG_TIMESCALE_WRITER_LOG_LEVEL" envDefault:"info"`
|
||||
ConfigPath string `env:"MG_TIMESCALE_WRITER_CONFIG_PATH" envDefault:"/config.toml"`
|
||||
BrokerURL string `env:"MG_MESSAGE_BROKER_URL" envDefault:"nats://localhost:4222"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_TIMESCALE_WRITER_INSTANCE_ID" envDefault:""`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
|
||||
+24
-14
@@ -17,6 +17,7 @@ import (
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
authSvc "github.com/absmach/magistrala/auth"
|
||||
authclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/internal/email"
|
||||
mggroups "github.com/absmach/magistrala/internal/groups"
|
||||
gapi "github.com/absmach/magistrala/internal/groups/api"
|
||||
@@ -24,10 +25,10 @@ import (
|
||||
gpostgres "github.com/absmach/magistrala/internal/groups/postgres"
|
||||
gtracing "github.com/absmach/magistrala/internal/groups/tracing"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
"github.com/absmach/magistrala/pkg/groups"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/oauth2"
|
||||
googleoauth "github.com/absmach/magistrala/pkg/oauth2/google"
|
||||
@@ -69,7 +70,7 @@ type config struct {
|
||||
AdminPassword string `env:"MG_USERS_ADMIN_PASSWORD" envDefault:"12345678"`
|
||||
PassRegexText string `env:"MG_USERS_PASS_REGEX" envDefault:"^.{8,}$"`
|
||||
ResetURL string `env:"MG_TOKEN_RESET_ENDPOINT" envDefault:"/reset-request"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_USERS_INSTANCE_ID" envDefault:""`
|
||||
ESURL string `env:"MG_ES_URL" envDefault:"nats://localhost:4222"`
|
||||
@@ -149,23 +150,32 @@ func main() {
|
||||
}()
|
||||
tracer := tp.Tracer(svcName)
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
clientConfig := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&clientConfig, env.Options{Prefix: envPrefixAuth}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authClient, authHandler, err := auth.Setup(ctx, authConfig)
|
||||
authClient, authHandler, err := grpcclient.SetupAuthClient(ctx, clientConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer authHandler.Close()
|
||||
logger.Info("Successfully connected to auth grpc server " + authHandler.Secure())
|
||||
logger.Info("AuthService gRPC client successfully connected to auth gRPC server " + authHandler.Secure())
|
||||
|
||||
csvc, gsvc, err := newService(ctx, authClient, db, dbConfig, tracer, cfg, ec, logger)
|
||||
policyClient, policyHandler, err := grpcclient.SetupPolicyClient(ctx, clientConfig)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer policyHandler.Close()
|
||||
logger.Info("PolicyService gRPC client successfully connected to auth gRPC server " + policyHandler.Secure())
|
||||
|
||||
csvc, gsvc, err := newService(ctx, authClient, policyClient, db, dbConfig, tracer, cfg, ec, logger)
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to setup service: %s", err))
|
||||
exitCode = 1
|
||||
@@ -208,7 +218,7 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(ctx context.Context, authClient magistrala.AuthServiceClient, db *sqlx.DB, dbConfig pgclient.Config, tracer trace.Tracer, c config, ec email.Config, logger *slog.Logger) (users.Service, groups.Service, error) {
|
||||
func newService(ctx context.Context, authClient authclient.AuthServiceClient, policyClient magistrala.PolicyServiceClient, db *sqlx.DB, dbConfig pgclient.Config, tracer trace.Tracer, c config, ec email.Config, logger *slog.Logger) (users.Service, groups.Service, error) {
|
||||
database := postgres.NewDatabase(db, dbConfig, tracer)
|
||||
cRepo := clientspg.NewRepository(database)
|
||||
gRepo := gpostgres.New(database)
|
||||
@@ -221,8 +231,8 @@ func newService(ctx context.Context, authClient magistrala.AuthServiceClient, db
|
||||
logger.Error(fmt.Sprintf("failed to configure e-mailing util: %s", err.Error()))
|
||||
}
|
||||
|
||||
csvc := users.NewService(cRepo, authClient, emailerClient, hsr, idp, c.SelfRegister)
|
||||
gsvc := mggroups.NewService(gRepo, idp, authClient)
|
||||
csvc := users.NewService(cRepo, authClient, policyClient, emailerClient, hsr, idp, c.SelfRegister)
|
||||
gsvc := mggroups.NewService(gRepo, idp, authClient, policyClient)
|
||||
|
||||
csvc, err = uevents.NewEventStoreMiddleware(ctx, csvc, c.ESURL)
|
||||
if err != nil {
|
||||
@@ -247,11 +257,11 @@ func newService(ctx context.Context, authClient magistrala.AuthServiceClient, db
|
||||
if err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to create admin client: %s", err))
|
||||
}
|
||||
if err := createAdminPolicy(ctx, clientID, authClient); err != nil {
|
||||
if err := createAdminPolicy(ctx, clientID, authClient, policyClient); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
users.NewDeleteHandler(ctx, cRepo, authClient, c.DeleteInterval, c.DeleteAfter, logger)
|
||||
users.NewDeleteHandler(ctx, cRepo, policyClient, c.DeleteInterval, c.DeleteAfter, logger)
|
||||
|
||||
return csvc, gsvc, err
|
||||
}
|
||||
@@ -296,7 +306,7 @@ func createAdmin(ctx context.Context, c config, crepo clientspg.Repository, hsr
|
||||
return client.ID, nil
|
||||
}
|
||||
|
||||
func createAdminPolicy(ctx context.Context, clientID string, authClient magistrala.AuthServiceClient) error {
|
||||
func createAdminPolicy(ctx context.Context, clientID string, authClient authclient.AuthServiceClient, policyClient magistrala.PolicyServiceClient) error {
|
||||
res, err := authClient.Authorize(ctx, &magistrala.AuthorizeReq{
|
||||
SubjectType: authSvc.UserType,
|
||||
Subject: clientID,
|
||||
@@ -305,7 +315,7 @@ func createAdminPolicy(ctx context.Context, clientID string, authClient magistra
|
||||
ObjectType: authSvc.PlatformType,
|
||||
})
|
||||
if err != nil || !res.Authorized {
|
||||
addPolicyRes, err := authClient.AddPolicy(ctx, &magistrala.AddPolicyReq{
|
||||
addPolicyRes, err := policyClient.AddPolicy(ctx, &magistrala.AddPolicyReq{
|
||||
SubjectType: authSvc.UserType,
|
||||
Subject: clientID,
|
||||
Relation: authSvc.AdministratorRelation,
|
||||
|
||||
+17
-17
@@ -15,7 +15,7 @@ import (
|
||||
chclient "github.com/absmach/callhome/pkg/client"
|
||||
"github.com/absmach/magistrala"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
jaegerclient "github.com/absmach/magistrala/pkg/jaeger"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
"github.com/absmach/magistrala/pkg/messaging/brokers"
|
||||
@@ -35,18 +35,18 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
svcName = "ws-adapter"
|
||||
envPrefixHTTP = "MG_WS_ADAPTER_HTTP_"
|
||||
envPrefixAuthz = "MG_THINGS_AUTH_GRPC_"
|
||||
defSvcHTTPPort = "8190"
|
||||
targetWSPort = "8191"
|
||||
targetWSHost = "localhost"
|
||||
svcName = "ws-adapter"
|
||||
envPrefixHTTP = "MG_WS_ADAPTER_HTTP_"
|
||||
envPrefixThings = "MG_THINGS_AUTH_GRPC_"
|
||||
defSvcHTTPPort = "8190"
|
||||
targetWSPort = "8191"
|
||||
targetWSHost = "localhost"
|
||||
)
|
||||
|
||||
type config struct {
|
||||
LogLevel string `env:"MG_WS_ADAPTER_LOG_LEVEL" envDefault:"info"`
|
||||
BrokerURL string `env:"MG_MESSAGE_BROKER_URL" envDefault:"nats://localhost:4222"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
JaegerURL url.URL `env:"MG_JAEGER_URL" envDefault:"http://localhost:4318/v1/traces"`
|
||||
SendTelemetry bool `env:"MG_SEND_TELEMETRY" envDefault:"true"`
|
||||
InstanceID string `env:"MG_WS_ADAPTER_INSTANCE_ID" envDefault:""`
|
||||
TraceRatio float64 `env:"MG_JAEGER_TRACE_RATIO" envDefault:"1.0"`
|
||||
@@ -89,22 +89,22 @@ func main() {
|
||||
Host: targetWSHost,
|
||||
}
|
||||
|
||||
authConfig := auth.Config{}
|
||||
if err := env.ParseWithOptions(&authConfig, env.Options{Prefix: envPrefixAuthz}); err != nil {
|
||||
thingsClientCfg := grpcclient.Config{}
|
||||
if err := env.ParseWithOptions(&thingsClientCfg, env.Options{Prefix: envPrefixThings}); err != nil {
|
||||
logger.Error(fmt.Sprintf("failed to load %s auth configuration : %s", svcName, err))
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
|
||||
authClient, authHandler, err := auth.SetupAuthz(ctx, authConfig)
|
||||
thingsClient, thingsHandler, err := grpcclient.SetupThingsClient(ctx, thingsClientCfg)
|
||||
if err != nil {
|
||||
logger.Error(err.Error())
|
||||
exitCode = 1
|
||||
return
|
||||
}
|
||||
defer authHandler.Close()
|
||||
defer thingsHandler.Close()
|
||||
|
||||
logger.Info("Successfully connected to things grpc server " + authHandler.Secure())
|
||||
logger.Info("Things service gRPC client successfully connected to things gRPC server " + thingsHandler.Secure())
|
||||
|
||||
tp, err := jaegerclient.NewProvider(ctx, svcName, cfg.JaegerURL, cfg.InstanceID, cfg.TraceRatio)
|
||||
if err != nil {
|
||||
@@ -128,7 +128,7 @@ func main() {
|
||||
defer nps.Close()
|
||||
nps = brokerstracing.NewPubSub(targetServerConfig, tracer, nps)
|
||||
|
||||
svc := newService(authClient, nps, logger, tracer)
|
||||
svc := newService(thingsClient, nps, logger, tracer)
|
||||
|
||||
hs := httpserver.NewServer(ctx, cancel, svcName, targetServerConfig, api.MakeHandler(ctx, svc, logger, cfg.InstanceID), logger)
|
||||
|
||||
@@ -141,7 +141,7 @@ func main() {
|
||||
g.Go(func() error {
|
||||
return hs.Start()
|
||||
})
|
||||
handler := ws.NewHandler(nps, logger, authClient)
|
||||
handler := ws.NewHandler(nps, logger, thingsClient)
|
||||
return proxyWS(ctx, httpServerConfig, targetServerConfig, logger, handler)
|
||||
})
|
||||
|
||||
@@ -154,8 +154,8 @@ func main() {
|
||||
}
|
||||
}
|
||||
|
||||
func newService(tc magistrala.AuthzServiceClient, nps messaging.PubSub, logger *slog.Logger, tracer trace.Tracer) ws.Service {
|
||||
svc := ws.New(tc, nps)
|
||||
func newService(thingsClient magistrala.AuthzServiceClient, nps messaging.PubSub, logger *slog.Logger, tracer trace.Tracer) ws.Service {
|
||||
svc := ws.New(thingsClient, nps)
|
||||
svc = tracing.New(tracer, svc)
|
||||
svc = api.LoggingMiddleware(svc, logger)
|
||||
counter, latency := prometheus.MakeMetrics("ws_adapter", "api")
|
||||
|
||||
+6
-6
@@ -37,14 +37,14 @@ var _ Service = (*adapterService)(nil)
|
||||
|
||||
// Observers is a map of maps,.
|
||||
type adapterService struct {
|
||||
auth magistrala.AuthzServiceClient
|
||||
things magistrala.AuthzServiceClient
|
||||
pubsub messaging.PubSub
|
||||
}
|
||||
|
||||
// New instantiates the CoAP adapter implementation.
|
||||
func New(authClient magistrala.AuthzServiceClient, pubsub messaging.PubSub) Service {
|
||||
func New(thingsClient magistrala.AuthzServiceClient, pubsub messaging.PubSub) Service {
|
||||
as := &adapterService{
|
||||
auth: authClient,
|
||||
things: thingsClient,
|
||||
pubsub: pubsub,
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ func (svc *adapterService) Publish(ctx context.Context, key string, msg *messagi
|
||||
Object: msg.GetChannel(),
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := svc.auth.Authorize(ctx, ar)
|
||||
res, err := svc.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrAuthorization, err)
|
||||
}
|
||||
@@ -79,7 +79,7 @@ func (svc *adapterService) Subscribe(ctx context.Context, key, chanID, subtopic
|
||||
Object: chanID,
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := svc.auth.Authorize(ctx, ar)
|
||||
res, err := svc.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrAuthorization, err)
|
||||
}
|
||||
@@ -107,7 +107,7 @@ func (svc *adapterService) Unsubscribe(ctx context.Context, key, chanID, subtopi
|
||||
Object: chanID,
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := svc.auth.Authorize(ctx, ar)
|
||||
res, err := svc.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrAuthorization, err)
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ type Service interface {
|
||||
var _ Service = (*notifierService)(nil)
|
||||
|
||||
type notifierService struct {
|
||||
auth magistrala.AuthServiceClient
|
||||
auth magistrala.AuthnServiceClient
|
||||
subs SubscriptionsRepository
|
||||
idp magistrala.IDProvider
|
||||
notifier Notifier
|
||||
@@ -51,7 +51,7 @@ type notifierService struct {
|
||||
}
|
||||
|
||||
// New instantiates the subscriptions service implementation.
|
||||
func New(auth magistrala.AuthServiceClient, subs SubscriptionsRepository, idp magistrala.IDProvider, notifier Notifier, from string) Service {
|
||||
func New(auth magistrala.AuthnServiceClient, subs SubscriptionsRepository, idp magistrala.IDProvider, notifier Notifier, from string) Service {
|
||||
return ¬ifierService{
|
||||
auth: auth,
|
||||
subs: subs,
|
||||
|
||||
@@ -29,9 +29,9 @@ const (
|
||||
validID = "d4ebb847-5d0e-4e46-bdd9-b6aceaaa3a22"
|
||||
)
|
||||
|
||||
func newService() (notifiers.Service, *authmocks.AuthClient, *mocks.SubscriptionsRepository) {
|
||||
func newService() (notifiers.Service, *authmocks.AuthServiceClient, *mocks.SubscriptionsRepository) {
|
||||
repo := new(mocks.SubscriptionsRepository)
|
||||
auth := new(authmocks.AuthClient)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
notifier := new(mocks.Notifier)
|
||||
idp := uuid.NewMock()
|
||||
from := "exampleFrom"
|
||||
@@ -276,10 +276,7 @@ func TestListSubscriptions(t *testing.T) {
|
||||
func TestRemoveSubscription(t *testing.T) {
|
||||
svc, auth, repo := newService()
|
||||
sub := notifiers.Subscription{
|
||||
Contact: exampleUser1,
|
||||
Topic: "valid.topic",
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
OwnerID: validID,
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
@@ -327,21 +324,6 @@ func TestRemoveSubscription(t *testing.T) {
|
||||
|
||||
func TestConsume(t *testing.T) {
|
||||
svc, _, repo := newService()
|
||||
sub := notifiers.Subscription{
|
||||
Contact: exampleUser1,
|
||||
OwnerID: validID,
|
||||
Topic: "topic.subtopic",
|
||||
}
|
||||
for i := 0; i < total; i++ {
|
||||
tmp := sub
|
||||
tmp.Contact = fmt.Sprintf("contact%d@example.com", i)
|
||||
if i%2 == 0 {
|
||||
tmp.Topic = fmt.Sprintf("%s-2", sub.Topic)
|
||||
}
|
||||
}
|
||||
sub.Contact = "invalid@example.com"
|
||||
sub.Topic = fmt.Sprintf("%s-2", sub.Topic)
|
||||
|
||||
msg := messaging.Message{
|
||||
Channel: "topic",
|
||||
Subtopic: "subtopic",
|
||||
|
||||
@@ -12,12 +12,12 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
authmocks "github.com/absmach/magistrala/auth/mocks"
|
||||
server "github.com/absmach/magistrala/http"
|
||||
"github.com/absmach/magistrala/http/api"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/apiutil"
|
||||
pubsub "github.com/absmach/magistrala/pkg/messaging/mocks"
|
||||
thmocks "github.com/absmach/magistrala/things/mocks"
|
||||
"github.com/absmach/mproxy"
|
||||
mproxyhttp "github.com/absmach/mproxy/pkg/http"
|
||||
"github.com/absmach/mproxy/pkg/session"
|
||||
@@ -30,9 +30,9 @@ const (
|
||||
invalidValue = "invalid"
|
||||
)
|
||||
|
||||
func newService(auth magistrala.AuthzServiceClient) (session.Handler, *pubsub.PubSub) {
|
||||
func newService(things magistrala.AuthzServiceClient) (session.Handler, *pubsub.PubSub) {
|
||||
pub := new(pubsub.PubSub)
|
||||
return server.NewHandler(pub, mglog.NewMock(), auth), pub
|
||||
return server.NewHandler(pub, mglog.NewMock(), things), pub
|
||||
}
|
||||
|
||||
func newTargetHTTPServer() *httptest.Server {
|
||||
@@ -81,7 +81,7 @@ func (tr testRequest) make() (*http.Response, error) {
|
||||
}
|
||||
|
||||
func TestPublish(t *testing.T) {
|
||||
auth := new(authmocks.AuthClient)
|
||||
things := new(thmocks.AuthzServiceClient)
|
||||
chanID := "1"
|
||||
ctSenmlJSON := "application/senml+json"
|
||||
ctSenmlCBOR := "application/senml+cbor"
|
||||
@@ -91,7 +91,7 @@ func TestPublish(t *testing.T) {
|
||||
msg := `[{"n":"current","t":-1,"v":1.6}]`
|
||||
msgJSON := `{"field1":"val1","field2":"val2"}`
|
||||
msgCBOR := `81A3616E6763757272656E746174206176FB3FF999999999999A`
|
||||
svc, pub := newService(auth)
|
||||
svc, pub := newService(things)
|
||||
target := newTargetHTTPServer()
|
||||
defer target.Close()
|
||||
ts, err := newProxyHTPPServer(svc, target)
|
||||
@@ -99,8 +99,8 @@ func TestPublish(t *testing.T) {
|
||||
|
||||
defer ts.Close()
|
||||
|
||||
auth.On("Authorize", mock.Anything, &magistrala.AuthorizeReq{Subject: thingKey, Object: chanID, Domain: "", SubjectType: "thing", Permission: "publish", ObjectType: "group"}).Return(&magistrala.AuthorizeRes{Authorized: true, Id: ""}, nil)
|
||||
auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: false, Id: ""}, nil)
|
||||
things.On("Authorize", mock.Anything, &magistrala.AuthorizeReq{Subject: thingKey, Object: chanID, Domain: "", SubjectType: "thing", Permission: "publish", ObjectType: "group"}).Return(&magistrala.AuthorizeRes{Authorized: true, Id: ""}, nil)
|
||||
things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: false, Id: ""}, nil)
|
||||
|
||||
cases := map[string]struct {
|
||||
chanID string
|
||||
|
||||
+4
-4
@@ -47,16 +47,16 @@ var channelRegExp = regexp.MustCompile(`^\/?channels\/([\w\-]+)\/messages(\/[^?]
|
||||
// Event implements events.Event interface.
|
||||
type handler struct {
|
||||
publisher messaging.Publisher
|
||||
auth magistrala.AuthzServiceClient
|
||||
things magistrala.AuthzServiceClient
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
// NewHandler creates new Handler entity.
|
||||
func NewHandler(publisher messaging.Publisher, logger *slog.Logger, authClient magistrala.AuthzServiceClient) session.Handler {
|
||||
func NewHandler(publisher messaging.Publisher, logger *slog.Logger, thingsClient magistrala.AuthzServiceClient) session.Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
publisher: publisher,
|
||||
auth: authClient,
|
||||
things: thingsClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) e
|
||||
Permission: auth.PublishPermission,
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := h.auth.Authorize(ctx, ar)
|
||||
res, err := h.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+22
-19
@@ -10,6 +10,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
grpcclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/pkg/apiutil"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
@@ -26,16 +27,18 @@ var (
|
||||
|
||||
type service struct {
|
||||
groups groups.Repository
|
||||
auth magistrala.AuthServiceClient
|
||||
auth grpcclient.AuthServiceClient
|
||||
policy magistrala.PolicyServiceClient
|
||||
idProvider magistrala.IDProvider
|
||||
}
|
||||
|
||||
// NewService returns a new Clients service implementation.
|
||||
func NewService(g groups.Repository, idp magistrala.IDProvider, authClient magistrala.AuthServiceClient) groups.Service {
|
||||
func NewService(g groups.Repository, idp magistrala.IDProvider, authClient grpcclient.AuthServiceClient, policyClient magistrala.PolicyServiceClient) groups.Service {
|
||||
return service{
|
||||
groups: g,
|
||||
idProvider: idp,
|
||||
auth: authClient,
|
||||
policy: policyClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +122,7 @@ func (svc service) ListGroups(ctx context.Context, token, memberKind, memberID s
|
||||
if _, err := svc.authorizeKind(ctx, res.GetDomainId(), auth.UserType, auth.UsersKind, res.GetId(), auth.ViewPermission, auth.ThingType, memberID); err != nil {
|
||||
return groups.Page{}, err
|
||||
}
|
||||
cids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
cids, err := svc.policy.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Permission: auth.GroupRelation,
|
||||
ObjectType: auth.ThingType,
|
||||
@@ -137,7 +140,7 @@ func (svc service) ListGroups(ctx context.Context, token, memberKind, memberID s
|
||||
return groups.Page{}, err
|
||||
}
|
||||
|
||||
gids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
gids, err := svc.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Subject: memberID,
|
||||
Permission: auth.ParentGroupRelation,
|
||||
@@ -154,7 +157,7 @@ func (svc service) ListGroups(ctx context.Context, token, memberKind, memberID s
|
||||
if _, err := svc.authorizeKind(ctx, res.GetDomainId(), auth.UserType, auth.UsersKind, res.GetId(), auth.ViewPermission, auth.GroupType, memberID); err != nil {
|
||||
return groups.Page{}, err
|
||||
}
|
||||
gids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
gids, err := svc.policy.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Permission: auth.ParentGroupRelation,
|
||||
ObjectType: auth.GroupType,
|
||||
@@ -174,7 +177,7 @@ func (svc service) ListGroups(ctx context.Context, token, memberKind, memberID s
|
||||
if _, err := svc.authorizeKind(ctx, res.GetDomainId(), auth.UserType, auth.UsersKind, res.GetId(), auth.AdminPermission, auth.DomainType, res.GetDomainId()); err != nil {
|
||||
return groups.Page{}, err
|
||||
}
|
||||
gids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
gids, err := svc.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: auth.EncodeDomainUserID(res.GetDomainId(), memberID),
|
||||
Permission: gm.Permission,
|
||||
@@ -239,7 +242,7 @@ func (svc service) retrievePermissions(ctx context.Context, userID string, group
|
||||
}
|
||||
|
||||
func (svc service) listUserGroupPermission(ctx context.Context, userID, groupID string) ([]string, error) {
|
||||
lp, err := svc.auth.ListPermissions(ctx, &magistrala.ListPermissionsReq{
|
||||
lp, err := svc.policy.ListPermissions(ctx, &magistrala.ListPermissionsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Object: groupID,
|
||||
@@ -279,7 +282,7 @@ func (svc service) ListMembers(ctx context.Context, token, groupID, permission,
|
||||
}
|
||||
switch memberKind {
|
||||
case auth.ThingsKind:
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
tids, err := svc.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Subject: groupID,
|
||||
Relation: auth.GroupRelation,
|
||||
@@ -304,7 +307,7 @@ func (svc service) ListMembers(ctx context.Context, token, groupID, permission,
|
||||
Members: members,
|
||||
}, nil
|
||||
case auth.UsersKind:
|
||||
uids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
uids, err := svc.policy.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Permission: permission,
|
||||
Object: groupID,
|
||||
@@ -423,7 +426,7 @@ func (svc service) Assign(ctx context.Context, token, groupID, relation, memberK
|
||||
return errMemberKind
|
||||
}
|
||||
|
||||
if _, err := svc.auth.AddPolicies(ctx, &policies); err != nil {
|
||||
if _, err := svc.policy.AddPolicies(ctx, &policies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrAddPolicies, err)
|
||||
}
|
||||
|
||||
@@ -462,12 +465,12 @@ func (svc service) assignParentGroup(ctx context.Context, domain, parentGroupID
|
||||
})
|
||||
}
|
||||
|
||||
if _, err := svc.auth.AddPolicies(ctx, &addPolicies); err != nil {
|
||||
if _, err := svc.policy.AddPolicies(ctx, &addPolicies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrAddPolicies, err)
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if _, errRollback := svc.auth.DeletePolicies(ctx, &deletePolicies); errRollback != nil {
|
||||
if _, errRollback := svc.policy.DeletePolicies(ctx, &deletePolicies); errRollback != nil {
|
||||
err = errors.Wrap(err, errors.Wrap(apiutil.ErrRollbackTx, errRollback))
|
||||
}
|
||||
}
|
||||
@@ -508,12 +511,12 @@ func (svc service) unassignParentGroup(ctx context.Context, domain, parentGroupI
|
||||
})
|
||||
}
|
||||
|
||||
if _, err := svc.auth.DeletePolicies(ctx, &deletePolicies); err != nil {
|
||||
if _, err := svc.policy.DeletePolicies(ctx, &deletePolicies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
defer func() {
|
||||
if err != nil {
|
||||
if _, errRollback := svc.auth.AddPolicies(ctx, &addPolicies); errRollback != nil {
|
||||
if _, errRollback := svc.policy.AddPolicies(ctx, &addPolicies); errRollback != nil {
|
||||
err = errors.Wrap(err, errors.Wrap(apiutil.ErrRollbackTx, errRollback))
|
||||
}
|
||||
}
|
||||
@@ -574,7 +577,7 @@ func (svc service) Unassign(ctx context.Context, token, groupID, relation, membe
|
||||
return errMemberKind
|
||||
}
|
||||
|
||||
if _, err := svc.auth.DeletePolicies(ctx, &policies); err != nil {
|
||||
if _, err := svc.policy.DeletePolicies(ctx, &policies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
return nil
|
||||
@@ -589,7 +592,7 @@ func (svc service) DeleteGroup(ctx context.Context, token, id string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
deleteRes, err := svc.auth.DeleteEntityPolicies(ctx, &magistrala.DeleteEntityPoliciesReq{
|
||||
deleteRes, err := svc.policy.DeleteEntityPolicies(ctx, &magistrala.DeleteEntityPoliciesReq{
|
||||
EntityType: auth.GroupType,
|
||||
Id: id,
|
||||
})
|
||||
@@ -625,7 +628,7 @@ func (svc service) filterAllowedGroupIDsOfUserID(ctx context.Context, userID, pe
|
||||
}
|
||||
|
||||
func (svc service) listAllGroupsOfUserID(ctx context.Context, userID, permission string) ([]string, error) {
|
||||
allowedIDs, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
allowedIDs, err := svc.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Permission: permission,
|
||||
@@ -734,7 +737,7 @@ func (svc service) addGroupPolicy(ctx context.Context, userID, domainID, id, par
|
||||
Object: id,
|
||||
})
|
||||
}
|
||||
if _, err := svc.auth.AddPolicies(ctx, &policies); err != nil {
|
||||
if _, err := svc.policy.AddPolicies(ctx, &policies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrAddPolicies, err)
|
||||
}
|
||||
|
||||
@@ -771,7 +774,7 @@ func (svc service) addGroupPolicyRollback(ctx context.Context, userID, domainID,
|
||||
Object: id,
|
||||
})
|
||||
}
|
||||
if _, err := svc.auth.DeletePolicies(ctx, &policies); err != nil {
|
||||
if _, err := svc.policy.DeletePolicies(ctx, &policies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
|
||||
|
||||
+121
-106
@@ -48,8 +48,9 @@ var (
|
||||
|
||||
func TestCreateGroup(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -287,8 +288,8 @@ func TestCreateGroup(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authcall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authCall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.UsersKind,
|
||||
Subject: tc.idResp.GetId(),
|
||||
@@ -296,7 +297,7 @@ func TestCreateGroup(t *testing.T) {
|
||||
Object: tc.idResp.GetDomainId(),
|
||||
ObjectType: auth.DomainType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
authcall2 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall2 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.TokenKind,
|
||||
Subject: tc.token,
|
||||
@@ -304,9 +305,9 @@ func TestCreateGroup(t *testing.T) {
|
||||
Object: tc.group.Parent,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzTknResp, tc.authzTknErr)
|
||||
repocall := repo.On("Save", context.Background(), mock.Anything).Return(tc.repoResp, tc.repoErr)
|
||||
authcall3 := authsvc.On("AddPolicies", context.Background(), mock.Anything).Return(tc.addPolResp, tc.addPolErr)
|
||||
authCall4 := authsvc.On("DeletePolicies", mock.Anything, mock.Anything).Return(tc.deletePolResp, tc.deletePolErr)
|
||||
repoCall := repo.On("Save", context.Background(), mock.Anything).Return(tc.repoResp, tc.repoErr)
|
||||
authCall3 := policy.On("AddPolicies", context.Background(), mock.Anything).Return(tc.addPolResp, tc.addPolErr)
|
||||
authCall4 := policy.On("DeletePolicies", mock.Anything, mock.Anything).Return(tc.deletePolResp, tc.deletePolErr)
|
||||
got, err := svc.CreateGroup(context.Background(), tc.token, tc.kind, tc.group)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
if err == nil {
|
||||
@@ -314,14 +315,14 @@ func TestCreateGroup(t *testing.T) {
|
||||
assert.NotEmpty(t, got.CreatedAt)
|
||||
assert.NotEmpty(t, got.Domain)
|
||||
assert.WithinDuration(t, time.Now(), got.CreatedAt, 2*time.Second)
|
||||
ok := repocall.Parent.AssertCalled(t, "Save", context.Background(), mock.Anything)
|
||||
ok := repoCall.Parent.AssertCalled(t, "Save", context.Background(), mock.Anything)
|
||||
assert.True(t, ok, fmt.Sprintf("Save was not called on %s", tc.desc))
|
||||
}
|
||||
authcall.Unset()
|
||||
authcall1.Unset()
|
||||
authcall2.Unset()
|
||||
repocall.Unset()
|
||||
authcall3.Unset()
|
||||
authCall.Unset()
|
||||
authCall1.Unset()
|
||||
authCall2.Unset()
|
||||
repoCall.Unset()
|
||||
authCall3.Unset()
|
||||
authCall4.Unset()
|
||||
})
|
||||
}
|
||||
@@ -329,8 +330,9 @@ func TestCreateGroup(t *testing.T) {
|
||||
|
||||
func TestViewGroup(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -375,7 +377,7 @@ func TestViewGroup(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.TokenKind,
|
||||
Subject: tc.token,
|
||||
@@ -383,7 +385,7 @@ func TestViewGroup(t *testing.T) {
|
||||
Object: tc.id,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
repo.On("RetrieveByID", context.Background(), tc.id).Return(tc.repoResp, tc.repoErr)
|
||||
repoCall := repo.On("RetrieveByID", context.Background(), tc.id).Return(tc.repoResp, tc.repoErr)
|
||||
got, err := svc.ViewGroup(context.Background(), tc.token, tc.id)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
if err == nil {
|
||||
@@ -391,14 +393,17 @@ func TestViewGroup(t *testing.T) {
|
||||
ok := repo.AssertCalled(t, "RetrieveByID", context.Background(), tc.id)
|
||||
assert.True(t, ok, fmt.Sprintf("RetrieveByID was not called on %s", tc.desc))
|
||||
}
|
||||
authCall.Unset()
|
||||
repoCall.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestViewGroupPerms(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -461,8 +466,8 @@ func TestViewGroupPerms(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authcall1 := authsvc.On("ListPermissions", context.Background(), &magistrala.ListPermissionsReq{
|
||||
authCall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authCall1 := policy.On("ListPermissions", context.Background(), &magistrala.ListPermissionsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: tc.idResp.GetId(),
|
||||
Object: tc.id,
|
||||
@@ -473,16 +478,17 @@ func TestViewGroupPerms(t *testing.T) {
|
||||
if err == nil {
|
||||
assert.Equal(t, tc.listResp.Permissions, got)
|
||||
}
|
||||
authcall.Unset()
|
||||
authcall1.Unset()
|
||||
authCall.Unset()
|
||||
authCall1.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdateGroup(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -536,7 +542,7 @@ func TestUpdateGroup(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.TokenKind,
|
||||
Subject: tc.token,
|
||||
@@ -544,7 +550,7 @@ func TestUpdateGroup(t *testing.T) {
|
||||
Object: tc.group.ID,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
repo.On("Update", context.Background(), mock.Anything).Return(tc.repoResp, tc.repoErr)
|
||||
repoCall := repo.On("Update", context.Background(), mock.Anything).Return(tc.repoResp, tc.repoErr)
|
||||
got, err := svc.UpdateGroup(context.Background(), tc.token, tc.group)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
if err == nil {
|
||||
@@ -552,14 +558,17 @@ func TestUpdateGroup(t *testing.T) {
|
||||
ok := repo.AssertCalled(t, "Update", context.Background(), mock.Anything)
|
||||
assert.True(t, ok, fmt.Sprintf("Update was not called on %s", tc.desc))
|
||||
}
|
||||
authCall.Unset()
|
||||
repoCall.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestEnableGroup(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -632,7 +641,7 @@ func TestEnableGroup(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.TokenKind,
|
||||
Subject: tc.token,
|
||||
@@ -640,8 +649,8 @@ func TestEnableGroup(t *testing.T) {
|
||||
Object: tc.id,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
repocall := repo.On("RetrieveByID", context.Background(), tc.id).Return(tc.retrieveResp, tc.retrieveErr)
|
||||
repocall1 := repo.On("ChangeStatus", context.Background(), mock.Anything).Return(tc.changeResp, tc.changeErr)
|
||||
repoCall := repo.On("RetrieveByID", context.Background(), tc.id).Return(tc.retrieveResp, tc.retrieveErr)
|
||||
repoCall1 := repo.On("ChangeStatus", context.Background(), mock.Anything).Return(tc.changeResp, tc.changeErr)
|
||||
got, err := svc.EnableGroup(context.Background(), tc.token, tc.id)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
if err == nil {
|
||||
@@ -649,17 +658,18 @@ func TestEnableGroup(t *testing.T) {
|
||||
ok := repo.AssertCalled(t, "RetrieveByID", context.Background(), tc.id)
|
||||
assert.True(t, ok, fmt.Sprintf("RetrieveByID was not called on %s", tc.desc))
|
||||
}
|
||||
authcall.Unset()
|
||||
repocall.Unset()
|
||||
repocall1.Unset()
|
||||
authCall.Unset()
|
||||
repoCall.Unset()
|
||||
repoCall1.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestDisableGroup(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -732,7 +742,7 @@ func TestDisableGroup(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.TokenKind,
|
||||
Subject: tc.token,
|
||||
@@ -740,8 +750,8 @@ func TestDisableGroup(t *testing.T) {
|
||||
Object: tc.id,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
repocall := repo.On("RetrieveByID", context.Background(), tc.id).Return(tc.retrieveResp, tc.retrieveErr)
|
||||
repocall1 := repo.On("ChangeStatus", context.Background(), mock.Anything).Return(tc.changeResp, tc.changeErr)
|
||||
repoCall := repo.On("RetrieveByID", context.Background(), tc.id).Return(tc.retrieveResp, tc.retrieveErr)
|
||||
repoCall1 := repo.On("ChangeStatus", context.Background(), mock.Anything).Return(tc.changeResp, tc.changeErr)
|
||||
got, err := svc.DisableGroup(context.Background(), tc.token, tc.id)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
if err == nil {
|
||||
@@ -749,17 +759,18 @@ func TestDisableGroup(t *testing.T) {
|
||||
ok := repo.AssertCalled(t, "RetrieveByID", context.Background(), tc.id)
|
||||
assert.True(t, ok, fmt.Sprintf("RetrieveByID was not called on %s", tc.desc))
|
||||
}
|
||||
authcall.Unset()
|
||||
repocall.Unset()
|
||||
repocall1.Unset()
|
||||
authCall.Unset()
|
||||
repoCall.Unset()
|
||||
repoCall1.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestListMembers(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -860,7 +871,7 @@ func TestListMembers(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.TokenKind,
|
||||
Subject: tc.token,
|
||||
@@ -868,13 +879,13 @@ func TestListMembers(t *testing.T) {
|
||||
Object: tc.groupID,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
authcall1 := authsvc.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
authCall1 := policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Subject: tc.groupID,
|
||||
Relation: auth.GroupRelation,
|
||||
ObjectType: auth.ThingType,
|
||||
}).Return(tc.listObjectResp, tc.listObjectErr)
|
||||
authcall2 := authsvc.On("ListAllSubjects", context.Background(), &magistrala.ListSubjectsReq{
|
||||
authCall2 := policy.On("ListAllSubjects", context.Background(), &magistrala.ListSubjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Permission: tc.permission,
|
||||
Object: tc.groupID,
|
||||
@@ -885,17 +896,18 @@ func TestListMembers(t *testing.T) {
|
||||
if err == nil {
|
||||
assert.NotEmpty(t, got)
|
||||
}
|
||||
authcall.Unset()
|
||||
authcall1.Unset()
|
||||
authcall2.Unset()
|
||||
authCall.Unset()
|
||||
authCall1.Unset()
|
||||
authCall2.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestListGroups(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1513,14 +1525,14 @@ func TestListGroups(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authcall1 := &mock.Call{}
|
||||
authcall2 := &mock.Call{}
|
||||
authcall3 := &mock.Call{}
|
||||
authCall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authCall1 := &mock.Call{}
|
||||
authCall2 := &mock.Call{}
|
||||
authCall3 := &mock.Call{}
|
||||
adminCheck := &mock.Call{}
|
||||
switch tc.memberKind {
|
||||
case auth.ThingsKind:
|
||||
authcall1 = authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall1 = authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
Domain: tc.idResp.GetDomainId(),
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.UsersKind,
|
||||
@@ -1529,20 +1541,20 @@ func TestListGroups(t *testing.T) {
|
||||
Object: tc.memberID,
|
||||
ObjectType: auth.ThingType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
authcall2 = authsvc.On("ListAllSubjects", context.Background(), &magistrala.ListSubjectsReq{
|
||||
authCall2 = policy.On("ListAllSubjects", context.Background(), &magistrala.ListSubjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Permission: auth.GroupRelation,
|
||||
ObjectType: auth.ThingType,
|
||||
Object: tc.memberID,
|
||||
}).Return(tc.listSubjectResp, tc.listSubjectErr)
|
||||
authcall3 = authsvc.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
authCall3 = policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: tc.idResp.GetId(),
|
||||
Permission: tc.page.Permission,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.listObjectFilterResp, tc.listObjectFilterErr)
|
||||
case auth.GroupsKind:
|
||||
authcall1 = authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall1 = authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
Domain: tc.idResp.GetDomainId(),
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.UsersKind,
|
||||
@@ -1551,20 +1563,20 @@ func TestListGroups(t *testing.T) {
|
||||
Object: tc.memberID,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
authcall2 = authsvc.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
authCall2 = policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Subject: tc.memberID,
|
||||
Permission: auth.ParentGroupRelation,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.listObjectResp, tc.listObjectErr)
|
||||
authcall3 = authsvc.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
authCall3 = policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: tc.idResp.GetId(),
|
||||
Permission: tc.page.Permission,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.listObjectFilterResp, tc.listObjectFilterErr)
|
||||
case auth.ChannelsKind:
|
||||
authcall1 = authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall1 = authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
Domain: tc.idResp.GetDomainId(),
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.UsersKind,
|
||||
@@ -1573,13 +1585,13 @@ func TestListGroups(t *testing.T) {
|
||||
Object: tc.memberID,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
authcall2 = authsvc.On("ListAllSubjects", context.Background(), &magistrala.ListSubjectsReq{
|
||||
authCall2 = policy.On("ListAllSubjects", context.Background(), &magistrala.ListSubjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Permission: auth.ParentGroupRelation,
|
||||
ObjectType: auth.GroupType,
|
||||
Object: tc.memberID,
|
||||
}).Return(tc.listSubjectResp, tc.listSubjectErr)
|
||||
authcall3 = authsvc.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
authCall3 = policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: tc.idResp.GetId(),
|
||||
Permission: tc.page.Permission,
|
||||
@@ -1607,35 +1619,35 @@ func TestListGroups(t *testing.T) {
|
||||
authReq.Domain = ""
|
||||
authReq.Permission = auth.MembershipPermission
|
||||
}
|
||||
authcall1 = authsvc.On("Authorize", context.Background(), authReq).Return(tc.authzResp, tc.authzErr)
|
||||
authcall2 = authsvc.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
authCall1 = authsvc.On("Authorize", context.Background(), authReq).Return(tc.authzResp, tc.authzErr)
|
||||
authCall2 = policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: auth.EncodeDomainUserID(tc.idResp.GetDomainId(), tc.memberID),
|
||||
Permission: tc.page.Permission,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.listObjectResp, tc.listObjectErr)
|
||||
authcall3 = authsvc.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
authCall3 = policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: tc.idResp.GetId(),
|
||||
Permission: tc.page.Permission,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.listObjectFilterResp, tc.listObjectFilterErr)
|
||||
}
|
||||
repocall := repo.On("RetrieveByIDs", context.Background(), mock.Anything, mock.Anything).Return(tc.repoResp, tc.repoErr)
|
||||
authcall4 := authsvc.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermResp, tc.listPermErr)
|
||||
repoCall := repo.On("RetrieveByIDs", context.Background(), mock.Anything, mock.Anything).Return(tc.repoResp, tc.repoErr)
|
||||
authCall4 := policy.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermResp, tc.listPermErr)
|
||||
got, err := svc.ListGroups(context.Background(), tc.token, tc.memberKind, tc.memberID, tc.page)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
if err == nil {
|
||||
assert.NotEmpty(t, got)
|
||||
}
|
||||
authcall.Unset()
|
||||
repocall.Unset()
|
||||
authCall.Unset()
|
||||
repoCall.Unset()
|
||||
switch tc.memberKind {
|
||||
case auth.ThingsKind, auth.GroupsKind, auth.ChannelsKind, auth.UsersKind:
|
||||
authcall1.Unset()
|
||||
authcall2.Unset()
|
||||
authcall3.Unset()
|
||||
authcall4.Unset()
|
||||
authCall1.Unset()
|
||||
authCall2.Unset()
|
||||
authCall3.Unset()
|
||||
authCall4.Unset()
|
||||
if tc.memberID == "" {
|
||||
adminCheck.Unset()
|
||||
}
|
||||
@@ -1646,8 +1658,9 @@ func TestListGroups(t *testing.T) {
|
||||
|
||||
func TestAssign(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1965,8 +1978,8 @@ func TestAssign(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authcall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authCall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
Domain: tc.idResp.GetDomainId(),
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.UsersKind,
|
||||
@@ -2013,7 +2026,7 @@ func TestAssign(t *testing.T) {
|
||||
Object: group.ID,
|
||||
})
|
||||
}
|
||||
deletePoliciesCall = authsvc.On("DeletePolicies", context.Background(), &deletePolicies).Return(tc.deleteParentPoliciesRes, tc.deleteParentPoliciesErr)
|
||||
deletePoliciesCall = policy.On("DeletePolicies", context.Background(), &deletePolicies).Return(tc.deleteParentPoliciesRes, tc.deleteParentPoliciesErr)
|
||||
assignParentCall = repo.On("AssignParentGroup", context.Background(), tc.groupID, tc.memberIDs).Return(tc.repoParentGroupErr)
|
||||
case auth.ChannelsKind:
|
||||
for _, memberID := range tc.memberIDs {
|
||||
@@ -2038,12 +2051,12 @@ func TestAssign(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
authcall2 := authsvc.On("AddPolicies", context.Background(), &policies).Return(tc.addPoliciesRes, tc.addPoliciesErr)
|
||||
authCall2 := policy.On("AddPolicies", context.Background(), &policies).Return(tc.addPoliciesRes, tc.addPoliciesErr)
|
||||
err := svc.Assign(context.Background(), tc.token, tc.groupID, tc.relation, tc.memberKind, tc.memberIDs...)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
authcall.Unset()
|
||||
authcall1.Unset()
|
||||
authcall2.Unset()
|
||||
authCall.Unset()
|
||||
authCall1.Unset()
|
||||
authCall2.Unset()
|
||||
if tc.memberKind == auth.GroupsKind {
|
||||
retrieveByIDsCall.Unset()
|
||||
deletePoliciesCall.Unset()
|
||||
@@ -2055,8 +2068,9 @@ func TestAssign(t *testing.T) {
|
||||
|
||||
func TestUnassign(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -2374,8 +2388,8 @@ func TestUnassign(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authcall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authCall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
Domain: tc.idResp.GetDomainId(),
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.UsersKind,
|
||||
@@ -2422,7 +2436,7 @@ func TestUnassign(t *testing.T) {
|
||||
Object: group.ID,
|
||||
})
|
||||
}
|
||||
addPoliciesCall = authsvc.On("AddPolicies", context.Background(), &addPolicies).Return(tc.addParentPoliciesRes, tc.addParentPoliciesErr)
|
||||
addPoliciesCall = policy.On("AddPolicies", context.Background(), &addPolicies).Return(tc.addParentPoliciesRes, tc.addParentPoliciesErr)
|
||||
assignParentCall = repo.On("UnassignParentGroup", context.Background(), tc.groupID, tc.memberIDs).Return(tc.repoParentGroupErr)
|
||||
case auth.ChannelsKind:
|
||||
for _, memberID := range tc.memberIDs {
|
||||
@@ -2447,12 +2461,12 @@ func TestUnassign(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
authcall2 := authsvc.On("DeletePolicies", context.Background(), &policies).Return(tc.deletePoliciesRes, tc.deletePoliciesErr)
|
||||
authCall2 := policy.On("DeletePolicies", context.Background(), &policies).Return(tc.deletePoliciesRes, tc.deletePoliciesErr)
|
||||
err := svc.Unassign(context.Background(), tc.token, tc.groupID, tc.relation, tc.memberKind, tc.memberIDs...)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
authcall.Unset()
|
||||
authcall1.Unset()
|
||||
authcall2.Unset()
|
||||
authCall.Unset()
|
||||
authCall1.Unset()
|
||||
authCall2.Unset()
|
||||
if tc.memberKind == auth.GroupsKind {
|
||||
retrieveByIDsCall.Unset()
|
||||
addPoliciesCall.Unset()
|
||||
@@ -2464,8 +2478,9 @@ func TestUnassign(t *testing.T) {
|
||||
|
||||
func TestDeleteGroup(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
svc := groups.NewService(repo, idProvider, authsvc, policy)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -2557,8 +2572,8 @@ func TestDeleteGroup(t *testing.T) {
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.desc, func(t *testing.T) {
|
||||
authcall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authcall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
authCall := authsvc.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.idResp, tc.idErr)
|
||||
authCall1 := authsvc.On("Authorize", context.Background(), &magistrala.AuthorizeReq{
|
||||
Domain: tc.idResp.GetDomainId(),
|
||||
SubjectType: auth.UserType,
|
||||
SubjectKind: auth.UsersKind,
|
||||
@@ -2567,17 +2582,17 @@ func TestDeleteGroup(t *testing.T) {
|
||||
Object: tc.groupID,
|
||||
ObjectType: auth.GroupType,
|
||||
}).Return(tc.authzResp, tc.authzErr)
|
||||
authcall2 := authsvc.On("DeleteEntityPolicies", context.Background(), &magistrala.DeleteEntityPoliciesReq{
|
||||
authCall2 := policy.On("DeleteEntityPolicies", context.Background(), &magistrala.DeleteEntityPoliciesReq{
|
||||
EntityType: auth.GroupType,
|
||||
Id: tc.groupID,
|
||||
}).Return(tc.deletePoliciesRes, tc.deletePoliciesErr)
|
||||
repocall := repo.On("Delete", context.Background(), tc.groupID).Return(tc.repoErr)
|
||||
repoCall := repo.On("Delete", context.Background(), tc.groupID).Return(tc.repoErr)
|
||||
err := svc.DeleteGroup(context.Background(), tc.token, tc.groupID)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("expected error %v to contain %v", err, tc.err))
|
||||
authcall.Unset()
|
||||
authcall1.Unset()
|
||||
authcall2.Unset()
|
||||
repocall.Unset()
|
||||
authCall.Unset()
|
||||
authCall1.Unset()
|
||||
authCall2.Unset()
|
||||
repoCall.Unset()
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
grpcclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
mgsdk "github.com/absmach/magistrala/pkg/sdk/go"
|
||||
@@ -16,14 +17,14 @@ import (
|
||||
|
||||
type service struct {
|
||||
repo Repository
|
||||
auth magistrala.AuthServiceClient
|
||||
auth grpcclient.AuthServiceClient
|
||||
sdk mgsdk.SDK
|
||||
}
|
||||
|
||||
// ErrMemberExist indicates that the user is already a member of the domain.
|
||||
var ErrMemberExist = errors.New("user is already a member of the domain")
|
||||
|
||||
func NewService(repo Repository, authClient magistrala.AuthServiceClient, sdk mgsdk.SDK) Service {
|
||||
func NewService(repo Repository, authClient grpcclient.AuthServiceClient, sdk mgsdk.SDK) Service {
|
||||
return &service{
|
||||
repo: repo,
|
||||
auth: authClient,
|
||||
|
||||
@@ -34,7 +34,7 @@ var (
|
||||
|
||||
func TestSendInvitation(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
svc := invitations.NewService(repo, authsvc, nil)
|
||||
|
||||
cases := []struct {
|
||||
@@ -221,7 +221,7 @@ func TestSendInvitation(t *testing.T) {
|
||||
|
||||
func TestViewInvitation(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
svc := invitations.NewService(repo, authsvc, nil)
|
||||
|
||||
validInvitation := invitations.Invitation{
|
||||
@@ -398,7 +398,7 @@ func TestViewInvitation(t *testing.T) {
|
||||
|
||||
func TestListInvitations(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
svc := invitations.NewService(repo, authsvc, nil)
|
||||
|
||||
validPage := invitations.Page{
|
||||
@@ -576,7 +576,7 @@ func TestListInvitations(t *testing.T) {
|
||||
|
||||
func TestAcceptInvitation(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
svc := invitations.NewService(repo, authsvc, nil)
|
||||
|
||||
userID := testsutil.GenerateUUID(t)
|
||||
@@ -649,7 +649,7 @@ func TestAcceptInvitation(t *testing.T) {
|
||||
|
||||
func TestDeleteInvitation(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
svc := invitations.NewService(repo, authsvc, nil)
|
||||
|
||||
cases := []struct {
|
||||
|
||||
+3
-2
@@ -8,17 +8,18 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
grpcclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
)
|
||||
|
||||
type service struct {
|
||||
idProvider magistrala.IDProvider
|
||||
auth magistrala.AuthServiceClient
|
||||
auth grpcclient.AuthServiceClient
|
||||
repository Repository
|
||||
}
|
||||
|
||||
func NewService(idp magistrala.IDProvider, repository Repository, authClient magistrala.AuthServiceClient) Service {
|
||||
func NewService(idp magistrala.IDProvider, repository Repository, authClient grpcclient.AuthServiceClient) Service {
|
||||
return &service{
|
||||
idProvider: idp,
|
||||
auth: authClient,
|
||||
|
||||
@@ -41,7 +41,7 @@ var (
|
||||
|
||||
func TestSave(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
svc := journal.NewService(idProvider, repo, authsvc)
|
||||
|
||||
cases := []struct {
|
||||
@@ -75,7 +75,7 @@ func TestSave(t *testing.T) {
|
||||
|
||||
func TestReadAll(t *testing.T) {
|
||||
repo := new(mocks.Repository)
|
||||
authsvc := new(authmocks.AuthClient)
|
||||
authsvc := new(authmocks.AuthServiceClient)
|
||||
svc := journal.NewService(idProvider, repo, authsvc)
|
||||
|
||||
validToken := "token"
|
||||
|
||||
+4
-4
@@ -58,18 +58,18 @@ var channelRegExp = regexp.MustCompile(`^\/?channels\/([\w\-]+)\/messages(\/[^?]
|
||||
// Event implements events.Event interface.
|
||||
type handler struct {
|
||||
publisher messaging.Publisher
|
||||
auth magistrala.AuthzServiceClient
|
||||
things magistrala.AuthzServiceClient
|
||||
logger *slog.Logger
|
||||
es events.EventStore
|
||||
}
|
||||
|
||||
// NewHandler creates new Handler entity.
|
||||
func NewHandler(publisher messaging.Publisher, es events.EventStore, logger *slog.Logger, authClient magistrala.AuthzServiceClient) session.Handler {
|
||||
func NewHandler(publisher messaging.Publisher, es events.EventStore, logger *slog.Logger, thingsClient magistrala.AuthzServiceClient) session.Handler {
|
||||
return &handler{
|
||||
es: es,
|
||||
logger: logger,
|
||||
publisher: publisher,
|
||||
auth: authClient,
|
||||
things: thingsClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ func (h *handler) authAccess(ctx context.Context, password, topic, action string
|
||||
Object: chanID,
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := h.auth.Authorize(ctx, ar)
|
||||
res, err := h.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -11,13 +11,13 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
authmocks "github.com/absmach/magistrala/auth/mocks"
|
||||
"github.com/absmach/magistrala/internal/testsutil"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/mqtt"
|
||||
"github.com/absmach/magistrala/mqtt/mocks"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
thmocks "github.com/absmach/magistrala/things/mocks"
|
||||
"github.com/absmach/mproxy/pkg/session"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -121,7 +121,7 @@ func TestAuthConnect(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthPublish(t *testing.T) {
|
||||
handler, auth, _ := newHandler()
|
||||
handler, things, _ := newHandler()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -161,7 +161,7 @@ func TestAuthPublish(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
repocall := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true, Id: testsutil.GenerateUUID(t)}, tc.err)
|
||||
repocall := things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true, Id: testsutil.GenerateUUID(t)}, tc.err)
|
||||
ctx := context.TODO()
|
||||
if tc.session != nil {
|
||||
ctx = session.NewContext(ctx, tc.session)
|
||||
@@ -173,7 +173,7 @@ func TestAuthPublish(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthSubscribe(t *testing.T) {
|
||||
handler, auth, _ := newHandler()
|
||||
handler, things, _ := newHandler()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -214,7 +214,7 @@ func TestAuthSubscribe(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
repocall := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true, Id: testsutil.GenerateUUID(t)}, tc.err)
|
||||
repocall := things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true, Id: testsutil.GenerateUUID(t)}, tc.err)
|
||||
ctx := context.TODO()
|
||||
if tc.session != nil {
|
||||
ctx = session.NewContext(ctx, tc.session)
|
||||
@@ -450,12 +450,12 @@ func TestDisconnect(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func newHandler() (session.Handler, *authmocks.AuthClient, *mocks.EventStore) {
|
||||
func newHandler() (session.Handler, *thmocks.AuthzServiceClient, *mocks.EventStore) {
|
||||
logger, err := mglog.New(&logBuffer, "debug")
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create logger: %s", err)
|
||||
}
|
||||
auth := new(authmocks.AuthClient)
|
||||
things := new(thmocks.AuthzServiceClient)
|
||||
eventStore := new(mocks.EventStore)
|
||||
return mqtt.NewHandler(mocks.NewPublisher(), eventStore, logger, auth), auth, eventStore
|
||||
return mqtt.NewHandler(mocks.NewPublisher(), eventStore, logger, things), things, eventStore
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package auth
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
authgrpc "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
thingsauth "github.com/absmach/magistrala/things/api/grpc"
|
||||
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
|
||||
)
|
||||
|
||||
var errSvcNotServing = errors.New("service is not serving")
|
||||
|
||||
// Setup loads Auth gRPC configuration and creates new Auth gRPC client.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// authClient, authHandler, err := auth.Setup(ctx, auth.Config{})
|
||||
func Setup(ctx context.Context, cfg Config) (magistrala.AuthServiceClient, Handler, error) {
|
||||
client, err := newHandler(cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
health := grpchealth.NewHealthClient(client.Connection())
|
||||
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
|
||||
Service: "auth",
|
||||
})
|
||||
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
|
||||
return nil, nil, errSvcNotServing
|
||||
}
|
||||
|
||||
return authgrpc.NewClient(client.Connection(), cfg.Timeout), client, nil
|
||||
}
|
||||
|
||||
// Setup loads Authz gRPC configuration and creates new Authz gRPC client.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// authzClient, authzHandler, err := auth.Setup(ctx, auth.Config{})
|
||||
func SetupAuthz(ctx context.Context, cfg Config) (magistrala.AuthzServiceClient, Handler, error) {
|
||||
client, err := newHandler(cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
health := grpchealth.NewHealthClient(client.Connection())
|
||||
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
|
||||
Service: "things",
|
||||
})
|
||||
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
|
||||
return nil, nil, errSvcNotServing
|
||||
}
|
||||
|
||||
return thingsauth.NewClient(client.Connection(), cfg.Timeout), client, nil
|
||||
}
|
||||
@@ -0,0 +1,82 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
authgrpc "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
thingsauth "github.com/absmach/magistrala/things/api/grpc"
|
||||
grpchealth "google.golang.org/grpc/health/grpc_health_v1"
|
||||
)
|
||||
|
||||
var errSvcNotServing = errors.New("service is not serving")
|
||||
|
||||
// SetupAuthClient loads Auth gRPC configuration and creates new Auth gRPC client.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// authClient, authHandler, err := auth.SetupAuth(ctx, auth.Config{}).
|
||||
func SetupAuthClient(ctx context.Context, cfg Config) (authgrpc.AuthServiceClient, Handler, error) {
|
||||
client, err := newHandler(cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
health := grpchealth.NewHealthClient(client.Connection())
|
||||
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
|
||||
Service: "auth",
|
||||
})
|
||||
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
|
||||
return nil, nil, errSvcNotServing
|
||||
}
|
||||
|
||||
return authgrpc.NewAuthClient(client.Connection(), cfg.Timeout), client, nil
|
||||
}
|
||||
|
||||
// SetupPolicyClient loads Policy gRPC configuration and creates a new Policy gRPC client.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// policyClient, policyHandler, err := auth.SetupPolicyClient(ctx, auth.Config{}).
|
||||
func SetupPolicyClient(ctx context.Context, cfg Config) (magistrala.PolicyServiceClient, Handler, error) {
|
||||
client, err := newHandler(cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
health := grpchealth.NewHealthClient(client.Connection())
|
||||
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
|
||||
Service: "auth",
|
||||
})
|
||||
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
|
||||
return nil, nil, errSvcNotServing
|
||||
}
|
||||
|
||||
return authgrpc.NewPolicyClient(client.Connection(), cfg.Timeout), client, nil
|
||||
}
|
||||
|
||||
// SetupThingsClient loads things gRPC configuration and creates new things gRPC client.
|
||||
//
|
||||
// For example:
|
||||
//
|
||||
// thingClient, thingHandler, err := auth.SetupThings(ctx, auth.Config{}).
|
||||
func SetupThingsClient(ctx context.Context, cfg Config) (magistrala.AuthzServiceClient, Handler, error) {
|
||||
client, err := newHandler(cfg)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
health := grpchealth.NewHealthClient(client.Connection())
|
||||
resp, err := health.Check(ctx, &grpchealth.HealthCheckRequest{
|
||||
Service: "things",
|
||||
})
|
||||
if err != nil || resp.GetStatus() != grpchealth.HealthCheckResponse_SERVING {
|
||||
return nil, nil, errSvcNotServing
|
||||
}
|
||||
|
||||
return thingsauth.NewClient(client.Connection(), cfg.Timeout), client, nil
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package auth_test
|
||||
package grpcclient_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
@@ -13,8 +13,8 @@ import (
|
||||
authgrpcapi "github.com/absmach/magistrala/auth/api/grpc"
|
||||
"github.com/absmach/magistrala/auth/mocks"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/auth"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
"github.com/absmach/magistrala/pkg/grpcclient"
|
||||
"github.com/absmach/magistrala/pkg/server"
|
||||
grpcserver "github.com/absmach/magistrala/pkg/server/grpc"
|
||||
thingsgrpcapi "github.com/absmach/magistrala/things/api/grpc"
|
||||
@@ -27,7 +27,8 @@ func TestSetupAuth(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
registerAuthServiceServer := func(srv *grpc.Server) {
|
||||
magistrala.RegisterAuthServiceServer(srv, authgrpcapi.NewServer(new(mocks.Service)))
|
||||
magistrala.RegisterAuthzServiceServer(srv, authgrpcapi.NewAuthzServer(new(mocks.Service)))
|
||||
magistrala.RegisterAuthnServiceServer(srv, authgrpcapi.NewAuthnServer(new(mocks.Service)))
|
||||
}
|
||||
gs := grpcserver.NewServer(ctx, cancel, "auth", server.Config{Port: "12345"}, registerAuthServiceServer, mglog.NewMock())
|
||||
go func() {
|
||||
@@ -41,12 +42,12 @@ func TestSetupAuth(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
config auth.Config
|
||||
config grpcclient.Config
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "successful",
|
||||
config: auth.Config{
|
||||
config: grpcclient.Config{
|
||||
URL: "localhost:12345",
|
||||
Timeout: time.Second,
|
||||
},
|
||||
@@ -54,7 +55,7 @@ func TestSetupAuth(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "failed with empty URL",
|
||||
config: auth.Config{
|
||||
config: grpcclient.Config{
|
||||
URL: "",
|
||||
Timeout: time.Second,
|
||||
},
|
||||
@@ -64,7 +65,7 @@ func TestSetupAuth(t *testing.T) {
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
client, handler, err := auth.Setup(context.Background(), c.config)
|
||||
client, handler, err := grpcclient.SetupAuthClient(context.Background(), c.config)
|
||||
assert.True(t, errors.Contains(err, c.err), fmt.Sprintf("expected %s to contain %s", err, c.err))
|
||||
if err == nil {
|
||||
assert.NotNil(t, client)
|
||||
@@ -74,13 +75,13 @@ func TestSetupAuth(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupAuthz(t *testing.T) {
|
||||
func TestSetupThingsClient(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
registerAuthaServiceServer := func(srv *grpc.Server) {
|
||||
registerThingsServiceServer := func(srv *grpc.Server) {
|
||||
magistrala.RegisterAuthzServiceServer(srv, thingsgrpcapi.NewServer(new(thmocks.Service)))
|
||||
}
|
||||
gs := grpcserver.NewServer(ctx, cancel, "things", server.Config{Port: "12345"}, registerAuthaServiceServer, mglog.NewMock())
|
||||
gs := grpcserver.NewServer(ctx, cancel, "things", server.Config{Port: "12345"}, registerThingsServiceServer, mglog.NewMock())
|
||||
go func() {
|
||||
err := gs.Start()
|
||||
assert.Nil(t, err, fmt.Sprintf(`"Unexpected error creating server %s"`, err))
|
||||
@@ -92,12 +93,12 @@ func TestSetupAuthz(t *testing.T) {
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
config auth.Config
|
||||
config grpcclient.Config
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "successful",
|
||||
config: auth.Config{
|
||||
config: grpcclient.Config{
|
||||
URL: "localhost:12345",
|
||||
Timeout: time.Second,
|
||||
},
|
||||
@@ -105,7 +106,7 @@ func TestSetupAuthz(t *testing.T) {
|
||||
},
|
||||
{
|
||||
desc: "failed with empty URL",
|
||||
config: auth.Config{
|
||||
config: grpcclient.Config{
|
||||
URL: "",
|
||||
Timeout: time.Second,
|
||||
},
|
||||
@@ -115,7 +116,58 @@ func TestSetupAuthz(t *testing.T) {
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
client, handler, err := auth.SetupAuthz(context.Background(), c.config)
|
||||
client, handler, err := grpcclient.SetupThingsClient(context.Background(), c.config)
|
||||
assert.True(t, errors.Contains(err, c.err), fmt.Sprintf("expected %s to contain %s", err, c.err))
|
||||
if err == nil {
|
||||
assert.NotNil(t, client)
|
||||
assert.NotNil(t, handler)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestSetupPolicyClient(t *testing.T) {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
registerPolicyServiceServer := func(srv *grpc.Server) {
|
||||
magistrala.RegisterPolicyServiceServer(srv, authgrpcapi.NewPolicyServer(new(mocks.Service)))
|
||||
}
|
||||
gs := grpcserver.NewServer(ctx, cancel, "auth", server.Config{Port: "12345"}, registerPolicyServiceServer, mglog.NewMock())
|
||||
go func() {
|
||||
err := gs.Start()
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error creating server %s", err))
|
||||
}()
|
||||
defer func() {
|
||||
err := gs.Stop()
|
||||
assert.Nil(t, err, fmt.Sprintf("Unexpected error stopping server %s", err))
|
||||
}()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
config grpcclient.Config
|
||||
err error
|
||||
}{
|
||||
{
|
||||
desc: "successfully",
|
||||
config: grpcclient.Config{
|
||||
URL: "localhost:12345",
|
||||
Timeout: time.Second,
|
||||
},
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
desc: "failed with empty URL",
|
||||
config: grpcclient.Config{
|
||||
URL: "",
|
||||
Timeout: time.Second,
|
||||
},
|
||||
err: errors.New("service is not serving"),
|
||||
},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
t.Run(c.desc, func(t *testing.T) {
|
||||
client, handler, err := grpcclient.SetupPolicyClient(context.Background(), c.config)
|
||||
assert.True(t, errors.Contains(err, c.err), fmt.Sprintf("expected %s to contain %s", err, c.err))
|
||||
if err == nil {
|
||||
assert.NotNil(t, client)
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package auth
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
@@ -1,7 +1,7 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package auth
|
||||
package grpcclient
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@@ -3,4 +3,4 @@
|
||||
|
||||
// Package auth contains the domain concept definitions needed to support
|
||||
// Magistrala auth functionality.
|
||||
package auth
|
||||
package grpcclient
|
||||
@@ -30,8 +30,8 @@ import (
|
||||
"github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
func setupMessages() (*httptest.Server, *authmocks.AuthClient, *pubsub.PubSub) {
|
||||
auth := new(authmocks.AuthClient)
|
||||
func setupMessages() (*httptest.Server, *authmocks.AuthServiceClient, *pubsub.PubSub) {
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
pub := new(pubsub.PubSub)
|
||||
handler := adapter.NewHandler(pub, mglog.NewMock(), auth)
|
||||
|
||||
@@ -50,10 +50,10 @@ func setupMessages() (*httptest.Server, *authmocks.AuthClient, *pubsub.PubSub) {
|
||||
return httptest.NewServer(http.HandlerFunc(mp.ServeHTTP)), auth, pub
|
||||
}
|
||||
|
||||
func setupReader() (*httptest.Server, *authmocks.AuthClient, *readersmocks.MessageRepository) {
|
||||
func setupReader() (*httptest.Server, *authmocks.AuthServiceClient, *readersmocks.MessageRepository) {
|
||||
repo := new(readersmocks.MessageRepository)
|
||||
auth := new(authmocks.AuthClient)
|
||||
tauth := new(thmocks.ThingAuthzService)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
tauth := new(thmocks.AuthzServiceClient)
|
||||
|
||||
mux := readersapi.MakeHandler(repo, auth, tauth, "test", "")
|
||||
return httptest.NewServer(mux), auth, repo
|
||||
|
||||
@@ -14,14 +14,14 @@ import (
|
||||
"github.com/go-kit/kit/endpoint"
|
||||
)
|
||||
|
||||
func listMessagesEndpoint(svc readers.MessageRepository, uauth magistrala.AuthServiceClient, taauth magistrala.AuthzServiceClient) endpoint.Endpoint {
|
||||
func listMessagesEndpoint(svc readers.MessageRepository, authClient magistrala.AuthzServiceClient, thingsClient magistrala.AuthzServiceClient) endpoint.Endpoint {
|
||||
return func(ctx context.Context, request interface{}) (interface{}, error) {
|
||||
req := request.(listMessagesReq)
|
||||
if err := req.validate(); err != nil {
|
||||
return nil, errors.Wrap(apiutil.ErrValidation, err)
|
||||
}
|
||||
|
||||
if err := authorize(ctx, req, uauth, taauth); err != nil {
|
||||
if err := authorize(ctx, req, authClient, thingsClient); err != nil {
|
||||
return nil, errors.Wrap(svcerr.ErrAuthorization, err)
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ var (
|
||||
sum float64 = 42
|
||||
)
|
||||
|
||||
func newServer(repo *mocks.MessageRepository, ac *authmocks.AuthClient, tc *thmocks.ThingAuthzService) *httptest.Server {
|
||||
mux := api.MakeHandler(repo, ac, tc, svcName, instanceID)
|
||||
func newServer(repo *mocks.MessageRepository, authClient *authmocks.AuthServiceClient, thingsAuthzClient *thmocks.AuthzServiceClient) *httptest.Server {
|
||||
mux := api.MakeHandler(repo, authClient, thingsAuthzClient, svcName, instanceID)
|
||||
return httptest.NewServer(mux)
|
||||
}
|
||||
|
||||
@@ -129,9 +129,9 @@ func TestReadAll(t *testing.T) {
|
||||
}
|
||||
|
||||
repo := new(mocks.MessageRepository)
|
||||
auth := new(authmocks.AuthClient)
|
||||
tauth := new(thmocks.ThingAuthzService)
|
||||
ts := newServer(repo, auth, tauth)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
things := new(thmocks.AuthzServiceClient)
|
||||
ts := newServer(repo, auth, things)
|
||||
defer ts.Close()
|
||||
|
||||
cases := []struct {
|
||||
@@ -981,7 +981,7 @@ func TestReadAll(t *testing.T) {
|
||||
authCall := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: tc.authResponse}, tc.err)
|
||||
repo.On("ReadAll", chanID, tc.res.PageMetadata).Return(readers.MessagesPage{Total: tc.res.Total, Messages: fromSenml(tc.res.Messages)}, nil)
|
||||
if tc.key != "" {
|
||||
repoCall = tauth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: tc.authResponse}, tc.err)
|
||||
repoCall = things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: tc.authResponse}, tc.err)
|
||||
}
|
||||
req := testRequest{
|
||||
client: ts.Client(),
|
||||
|
||||
@@ -54,14 +54,14 @@ const (
|
||||
var errUserAccess = errors.New("user has no permission")
|
||||
|
||||
// MakeHandler returns a HTTP handler for API endpoints.
|
||||
func MakeHandler(svc readers.MessageRepository, uauth magistrala.AuthServiceClient, taauth magistrala.AuthzServiceClient, svcName, instanceID string) http.Handler {
|
||||
func MakeHandler(svc readers.MessageRepository, auth magistrala.AuthzServiceClient, things magistrala.AuthzServiceClient, svcName, instanceID string) http.Handler {
|
||||
opts := []kithttp.ServerOption{
|
||||
kithttp.ServerErrorEncoder(encodeError),
|
||||
}
|
||||
|
||||
mux := chi.NewRouter()
|
||||
mux.Get("/channels/{chanID}/messages", kithttp.NewServer(
|
||||
listMessagesEndpoint(svc, uauth, taauth),
|
||||
listMessagesEndpoint(svc, auth, things),
|
||||
decodeList,
|
||||
encodeResponse,
|
||||
opts...,
|
||||
@@ -241,10 +241,10 @@ func encodeError(_ context.Context, err error, w http.ResponseWriter) {
|
||||
}
|
||||
}
|
||||
|
||||
func authorize(ctx context.Context, req listMessagesReq, uauth magistrala.AuthServiceClient, taauth magistrala.AuthzServiceClient) (err error) {
|
||||
func authorize(ctx context.Context, req listMessagesReq, auth magistrala.AuthzServiceClient, things magistrala.AuthzServiceClient) (err error) {
|
||||
switch {
|
||||
case req.token != "":
|
||||
if _, err = uauth.Authorize(ctx, &magistrala.AuthorizeReq{
|
||||
if _, err = auth.Authorize(ctx, &magistrala.AuthorizeReq{
|
||||
SubjectType: userType,
|
||||
SubjectKind: tokenKind,
|
||||
Subject: req.token,
|
||||
@@ -260,7 +260,7 @@ func authorize(ctx context.Context, req listMessagesReq, uauth magistrala.AuthSe
|
||||
}
|
||||
return nil
|
||||
case req.key != "":
|
||||
if _, err = taauth.Authorize(ctx, &magistrala.AuthorizeReq{
|
||||
if _, err = things.Authorize(ctx, &magistrala.AuthorizeReq{
|
||||
SubjectType: groupType,
|
||||
Subject: req.key,
|
||||
ObjectType: thingType,
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
const WrongID = "wrongID"
|
||||
|
||||
var _ magistrala.AuthzServiceClient = (*ThingAuthzService)(nil)
|
||||
|
||||
type ThingAuthzService struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
func (m *ThingAuthzService) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) {
|
||||
ret := m.Called(ctx, in)
|
||||
if in.GetSubject() == WrongID || in.GetSubject() == "" {
|
||||
return &magistrala.AuthorizeRes{}, svcerr.ErrAuthorization
|
||||
}
|
||||
if in.GetObject() == WrongID || in.GetObject() == "" {
|
||||
return &magistrala.AuthorizeRes{}, svcerr.ErrAuthorization
|
||||
}
|
||||
|
||||
return ret.Get(0).(*magistrala.AuthorizeRes), ret.Error(1)
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
// Copyright (c) Abstract Machines
|
||||
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// Code generated by mockery v2.43.2. DO NOT EDIT.
|
||||
|
||||
package mocks
|
||||
|
||||
import (
|
||||
context "context"
|
||||
|
||||
grpc "google.golang.org/grpc"
|
||||
|
||||
magistrala "github.com/absmach/magistrala"
|
||||
|
||||
mock "github.com/stretchr/testify/mock"
|
||||
)
|
||||
|
||||
// AuthzServiceClient is an autogenerated mock type for the AuthzServiceClient type
|
||||
type AuthzServiceClient struct {
|
||||
mock.Mock
|
||||
}
|
||||
|
||||
type AuthzServiceClient_Expecter struct {
|
||||
mock *mock.Mock
|
||||
}
|
||||
|
||||
func (_m *AuthzServiceClient) EXPECT() *AuthzServiceClient_Expecter {
|
||||
return &AuthzServiceClient_Expecter{mock: &_m.Mock}
|
||||
}
|
||||
|
||||
// Authorize provides a mock function with given fields: ctx, in, opts
|
||||
func (_m *AuthzServiceClient) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) {
|
||||
_va := make([]interface{}, len(opts))
|
||||
for _i := range opts {
|
||||
_va[_i] = opts[_i]
|
||||
}
|
||||
var _ca []interface{}
|
||||
_ca = append(_ca, ctx, in)
|
||||
_ca = append(_ca, _va...)
|
||||
ret := _m.Called(_ca...)
|
||||
|
||||
if len(ret) == 0 {
|
||||
panic("no return value specified for Authorize")
|
||||
}
|
||||
|
||||
var r0 *magistrala.AuthorizeRes
|
||||
var r1 error
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) (*magistrala.AuthorizeRes, error)); ok {
|
||||
return rf(ctx, in, opts...)
|
||||
}
|
||||
if rf, ok := ret.Get(0).(func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) *magistrala.AuthorizeRes); ok {
|
||||
r0 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
if ret.Get(0) != nil {
|
||||
r0 = ret.Get(0).(*magistrala.AuthorizeRes)
|
||||
}
|
||||
}
|
||||
|
||||
if rf, ok := ret.Get(1).(func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) error); ok {
|
||||
r1 = rf(ctx, in, opts...)
|
||||
} else {
|
||||
r1 = ret.Error(1)
|
||||
}
|
||||
|
||||
return r0, r1
|
||||
}
|
||||
|
||||
// AuthzServiceClient_Authorize_Call is a *mock.Call that shadows Run/Return methods with type explicit version for method 'Authorize'
|
||||
type AuthzServiceClient_Authorize_Call struct {
|
||||
*mock.Call
|
||||
}
|
||||
|
||||
// Authorize is a helper method to define mock.On call
|
||||
// - ctx context.Context
|
||||
// - in *magistrala.AuthorizeReq
|
||||
// - opts ...grpc.CallOption
|
||||
func (_e *AuthzServiceClient_Expecter) Authorize(ctx interface{}, in interface{}, opts ...interface{}) *AuthzServiceClient_Authorize_Call {
|
||||
return &AuthzServiceClient_Authorize_Call{Call: _e.mock.On("Authorize",
|
||||
append([]interface{}{ctx, in}, opts...)...)}
|
||||
}
|
||||
|
||||
func (_c *AuthzServiceClient_Authorize_Call) Run(run func(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption)) *AuthzServiceClient_Authorize_Call {
|
||||
_c.Call.Run(func(args mock.Arguments) {
|
||||
variadicArgs := make([]grpc.CallOption, len(args)-2)
|
||||
for i, a := range args[2:] {
|
||||
if a != nil {
|
||||
variadicArgs[i] = a.(grpc.CallOption)
|
||||
}
|
||||
}
|
||||
run(args[0].(context.Context), args[1].(*magistrala.AuthorizeReq), variadicArgs...)
|
||||
})
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *AuthzServiceClient_Authorize_Call) Return(_a0 *magistrala.AuthorizeRes, _a1 error) *AuthzServiceClient_Authorize_Call {
|
||||
_c.Call.Return(_a0, _a1)
|
||||
return _c
|
||||
}
|
||||
|
||||
func (_c *AuthzServiceClient_Authorize_Call) RunAndReturn(run func(context.Context, *magistrala.AuthorizeReq, ...grpc.CallOption) (*magistrala.AuthorizeRes, error)) *AuthzServiceClient_Authorize_Call {
|
||||
_c.Call.Return(run)
|
||||
return _c
|
||||
}
|
||||
|
||||
// NewAuthzServiceClient creates a new instance of AuthzServiceClient. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations.
|
||||
// The first argument is typically a *testing.T value.
|
||||
func NewAuthzServiceClient(t interface {
|
||||
mock.TestingT
|
||||
Cleanup(func())
|
||||
}) *AuthzServiceClient {
|
||||
mock := &AuthzServiceClient{}
|
||||
mock.Mock.Test(t)
|
||||
|
||||
t.Cleanup(func() { mock.AssertExpectations(t) })
|
||||
|
||||
return mock
|
||||
}
|
||||
+15
-12
@@ -8,6 +8,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
grpcclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
@@ -17,7 +18,8 @@ import (
|
||||
)
|
||||
|
||||
type service struct {
|
||||
auth magistrala.AuthServiceClient
|
||||
auth grpcclient.AuthServiceClient
|
||||
policy magistrala.PolicyServiceClient
|
||||
clients postgres.Repository
|
||||
clientCache Cache
|
||||
idProvider magistrala.IDProvider
|
||||
@@ -25,9 +27,10 @@ type service struct {
|
||||
}
|
||||
|
||||
// NewService returns a new Clients service implementation.
|
||||
func NewService(uauth magistrala.AuthServiceClient, c postgres.Repository, grepo mggroups.Repository, tcache Cache, idp magistrala.IDProvider) Service {
|
||||
func NewService(auth grpcclient.AuthServiceClient, policy magistrala.PolicyServiceClient, c postgres.Repository, grepo mggroups.Repository, tcache Cache, idp magistrala.IDProvider) Service {
|
||||
return service{
|
||||
auth: uauth,
|
||||
auth: auth,
|
||||
policy: policy,
|
||||
clients: c,
|
||||
grepo: grepo,
|
||||
clientCache: tcache,
|
||||
@@ -217,7 +220,7 @@ func (svc service) retrievePermissions(ctx context.Context, userID string, clien
|
||||
}
|
||||
|
||||
func (svc service) listUserThingPermission(ctx context.Context, userID, thingID string) ([]string, error) {
|
||||
lp, err := svc.auth.ListPermissions(ctx, &magistrala.ListPermissionsReq{
|
||||
lp, err := svc.policy.ListPermissions(ctx, &magistrala.ListPermissionsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Object: thingID,
|
||||
@@ -230,7 +233,7 @@ func (svc service) listUserThingPermission(ctx context.Context, userID, thingID
|
||||
}
|
||||
|
||||
func (svc service) listClientIDs(ctx context.Context, userID, permission string) ([]string, error) {
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
tids, err := svc.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Permission: permission,
|
||||
@@ -244,7 +247,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, &magistrala.ListObjectsReq{
|
||||
tids, err := svc.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Permission: permission,
|
||||
@@ -392,7 +395,7 @@ func (svc service) Share(ctx context.Context, token, id, relation string, userid
|
||||
Object: id,
|
||||
})
|
||||
}
|
||||
res, err := svc.auth.AddPolicies(ctx, &policies)
|
||||
res, err := svc.policy.AddPolicies(ctx, &policies)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
}
|
||||
@@ -421,7 +424,7 @@ func (svc service) Unshare(ctx context.Context, token, id, relation string, user
|
||||
Object: id,
|
||||
})
|
||||
}
|
||||
res, err := svc.auth.DeletePolicies(ctx, &policies)
|
||||
res, err := svc.policy.DeletePolicies(ctx, &policies)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrUpdateEntity, err)
|
||||
}
|
||||
@@ -444,7 +447,7 @@ func (svc service) DeleteClient(ctx context.Context, token, id string) error {
|
||||
return errors.Wrap(svcerr.ErrRemoveEntity, err)
|
||||
}
|
||||
|
||||
deleteRes, err := svc.auth.DeleteEntityPolicies(ctx, &magistrala.DeleteEntityPoliciesReq{
|
||||
deleteRes, err := svc.policy.DeleteEntityPolicies(ctx, &magistrala.DeleteEntityPoliciesReq{
|
||||
EntityType: auth.ThingType,
|
||||
Id: id,
|
||||
})
|
||||
@@ -493,7 +496,7 @@ func (svc service) ListClientsByGroup(ctx context.Context, token, groupID string
|
||||
return mgclients.MembersPage{}, err
|
||||
}
|
||||
|
||||
tids, err := svc.auth.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
tids, err := svc.policy.ListAllObjects(ctx, &magistrala.ListObjectsReq{
|
||||
SubjectType: auth.GroupType,
|
||||
Subject: groupID,
|
||||
Permission: auth.GroupRelation,
|
||||
@@ -603,7 +606,7 @@ func (svc service) addThingPolicies(ctx context.Context, userID, domainID string
|
||||
})
|
||||
}
|
||||
|
||||
if _, err := svc.auth.AddPolicies(ctx, &policies); err != nil {
|
||||
if _, err := svc.policy.AddPolicies(ctx, &policies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrCreateEntity, err)
|
||||
}
|
||||
|
||||
@@ -632,7 +635,7 @@ func (svc service) addThingPoliciesRollback(ctx context.Context, userID, domainI
|
||||
})
|
||||
}
|
||||
|
||||
if _, err := svc.auth.DeletePolicies(ctx, &policies); err != nil {
|
||||
if _, err := svc.policy.DeletePolicies(ctx, &policies); err != nil {
|
||||
return errors.Wrap(svcerr.ErrRemoveEntity, err)
|
||||
}
|
||||
|
||||
|
||||
+36
-43
@@ -46,18 +46,19 @@ var (
|
||||
errRemovePolicies = errors.New("failed to delete policies")
|
||||
)
|
||||
|
||||
func newService() (things.Service, *mocks.Repository, *authmocks.AuthClient, *mocks.Cache) {
|
||||
auth := new(authmocks.AuthClient)
|
||||
func newService() (things.Service, *mocks.Repository, *authmocks.AuthServiceClient, *authmocks.PolicyServiceClient, *mocks.Cache) {
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policyClient := new(authmocks.PolicyServiceClient)
|
||||
thingCache := new(mocks.Cache)
|
||||
idProvider := uuid.NewMock()
|
||||
cRepo := new(mocks.Repository)
|
||||
gRepo := new(gmocks.Repository)
|
||||
|
||||
return things.NewService(auth, cRepo, gRepo, thingCache, idProvider), cRepo, auth, thingCache
|
||||
return things.NewService(auth, policyClient, cRepo, gRepo, thingCache, idProvider), cRepo, auth, policyClient, thingCache
|
||||
}
|
||||
|
||||
func TestCreateThings(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, policy, _ := newService()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -330,8 +331,8 @@ func TestCreateThings(t *testing.T) {
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(&magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, tc.identifyErr)
|
||||
authcall := auth.On("Authorize", mock.Anything, mock.Anything).Return(tc.authResponse, tc.authorizeErr)
|
||||
repoCall1 := cRepo.On("Save", context.Background(), mock.Anything).Return([]mgclients.Client{tc.thing}, tc.saveErr)
|
||||
authCall1 := auth.On("AddPolicies", mock.Anything, mock.Anything).Return(tc.addPolicyResponse, tc.addPolicyErr)
|
||||
authCall2 := auth.On("DeletePolicies", mock.Anything, mock.Anything).Return(tc.deletePolicyRes, tc.deletePolicyErr)
|
||||
authCall1 := policy.On("AddPolicies", mock.Anything, mock.Anything).Return(tc.addPolicyResponse, tc.addPolicyErr)
|
||||
authCall2 := policy.On("DeletePolicies", mock.Anything, mock.Anything).Return(tc.deletePolicyRes, tc.deletePolicyErr)
|
||||
expected, err := svc.CreateThings(context.Background(), tc.token, tc.thing)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
if err == nil {
|
||||
@@ -352,7 +353,7 @@ func TestCreateThings(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestViewClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, _, _ := newService()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -413,7 +414,7 @@ func TestViewClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListClients(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, policy, _ := newService()
|
||||
|
||||
adminID := testsutil.GenerateUUID(t)
|
||||
domainID := testsutil.GenerateUUID(t)
|
||||
@@ -622,9 +623,9 @@ func TestListClients(t *testing.T) {
|
||||
ObjectType: "domain",
|
||||
Object: tc.identifyResponse.DomainId,
|
||||
}).Return(tc.authorizeResponse1, tc.authorizeErr1)
|
||||
listAllObjectsCall := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(tc.listObjectsResponse, tc.listObjectsErr)
|
||||
listAllObjectsCall := policy.On("ListAllObjects", mock.Anything, mock.Anything).Return(tc.listObjectsResponse, tc.listObjectsErr)
|
||||
retrieveAllCall := cRepo.On("SearchClients", mock.Anything, mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
|
||||
listPermissionsCall := auth.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)
|
||||
listPermissionsCall := policy.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)
|
||||
|
||||
page, err := svc.ListClients(context.Background(), tc.token, tc.id, tc.page)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
@@ -797,20 +798,20 @@ func TestListClients(t *testing.T) {
|
||||
for _, tc := range cases2 {
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
authorizeCall := auth.On("Authorize", mock.Anything, mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
listAllObjectsCall := auth.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
listAllObjectsCall := policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: authsvc.UserType,
|
||||
Subject: tc.identifyResponse.DomainId + "_" + adminID,
|
||||
Permission: "",
|
||||
ObjectType: authsvc.ThingType,
|
||||
}).Return(tc.listObjectsResponse, tc.listObjectsErr)
|
||||
listAllObjectsCall2 := auth.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
listAllObjectsCall2 := policy.On("ListAllObjects", context.Background(), &magistrala.ListObjectsReq{
|
||||
SubjectType: authsvc.UserType,
|
||||
Subject: tc.identifyResponse.Id,
|
||||
Permission: "",
|
||||
ObjectType: authsvc.ThingType,
|
||||
}).Return(tc.listObjectsResponse1, tc.listObjectsErr1)
|
||||
retrieveAllCall := cRepo.On("SearchClients", mock.Anything, mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
|
||||
listPermissionsCall := auth.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)
|
||||
listPermissionsCall := policy.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)
|
||||
|
||||
page, err := svc.ListClients(context.Background(), tc.token, tc.id, tc.page)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
@@ -825,7 +826,7 @@ func TestListClients(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, _, _ := newService()
|
||||
|
||||
client1 := client
|
||||
client2 := client
|
||||
@@ -920,7 +921,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClientTags(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, _, _ := newService()
|
||||
|
||||
client.Tags = []string{"updated"}
|
||||
|
||||
@@ -986,7 +987,7 @@ func TestUpdateClientTags(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClientSecret(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, _, _ := newService()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -1060,7 +1061,7 @@ func TestUpdateClientSecret(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnableClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, policy, _ := newService()
|
||||
|
||||
enabledClient1 := mgclients.Client{ID: ID, Credentials: mgclients.Credentials{Identity: "client1@example.com", Secret: "password"}, Status: mgclients.EnabledStatus}
|
||||
disabledClient1 := mgclients.Client{ID: ID, Credentials: mgclients.Credentials{Identity: "client3@example.com", Secret: "password"}, Status: mgclients.DisabledStatus}
|
||||
@@ -1202,7 +1203,7 @@ func TestEnableClient(t *testing.T) {
|
||||
}
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: validToken}).Return(&magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, nil)
|
||||
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true}, nil)
|
||||
repoCall2 := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: getIDs(tc.response.Clients)}, nil)
|
||||
repoCall2 := policy.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: getIDs(tc.response.Clients)}, nil)
|
||||
repoCall3 := cRepo.On("SearchClients", context.Background(), mock.Anything).Return(tc.response, nil)
|
||||
page, err := svc.ListClients(context.Background(), validToken, "", pm)
|
||||
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
|
||||
@@ -1216,7 +1217,7 @@ func TestEnableClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDisableClient(t *testing.T) {
|
||||
svc, cRepo, auth, cache := newService()
|
||||
svc, cRepo, auth, policy, cache := newService()
|
||||
|
||||
enabledClient1 := mgclients.Client{ID: ID, Credentials: mgclients.Credentials{Identity: "client1@example.com", Secret: "password"}, Status: mgclients.EnabledStatus}
|
||||
disabledClient1 := mgclients.Client{ID: ID, Credentials: mgclients.Credentials{Identity: "client3@example.com", Secret: "password"}, Status: mgclients.DisabledStatus}
|
||||
@@ -1372,7 +1373,7 @@ func TestDisableClient(t *testing.T) {
|
||||
}
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: validToken}).Return(&magistrala.IdentityRes{Id: validID, DomainId: testsutil.GenerateUUID(t)}, nil)
|
||||
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true}, nil)
|
||||
repoCall2 := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: getIDs(tc.response.Clients)}, nil)
|
||||
repoCall2 := policy.On("ListAllObjects", mock.Anything, mock.Anything).Return(&magistrala.ListObjectsRes{Policies: getIDs(tc.response.Clients)}, nil)
|
||||
repoCall3 := cRepo.On("SearchClients", context.Background(), mock.Anything).Return(tc.response, nil)
|
||||
page, err := svc.ListClients(context.Background(), validToken, "", pm)
|
||||
require.Nil(t, err, fmt.Sprintf("unexpected error: %s", err))
|
||||
@@ -1386,7 +1387,7 @@ func TestDisableClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListMembers(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService()
|
||||
svc, cRepo, auth, policy, _ := newService()
|
||||
|
||||
nClients := uint64(10)
|
||||
aClients := []mgclients.Client{}
|
||||
@@ -1589,9 +1590,9 @@ func TestListMembers(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
repoCall2 := auth.On("ListAllObjects", mock.Anything, mock.Anything).Return(tc.listObjectsResponse, tc.listObjectsErr)
|
||||
repoCall2 := policy.On("ListAllObjects", mock.Anything, mock.Anything).Return(tc.listObjectsResponse, tc.listObjectsErr)
|
||||
repoCall3 := cRepo.On("RetrieveAllByIDs", context.Background(), tc.page).Return(tc.retreiveAllByIDsResponse, tc.retreiveAllByIDsErr)
|
||||
repoCall4 := auth.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)
|
||||
repoCall4 := policy.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionsErr)
|
||||
page, err := svc.ListClientsByGroup(context.Background(), tc.token, tc.groupID, tc.page)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
assert.Equal(t, tc.response, page, fmt.Sprintf("%s: expected %v got %v\n", tc.desc, tc.response, page))
|
||||
@@ -1604,20 +1605,12 @@ func TestListMembers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteClient(t *testing.T) {
|
||||
svc, cRepo, auth, cache := newService()
|
||||
svc, cRepo, auth, policy, cache := newService()
|
||||
|
||||
client := mgclients.Client{
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
Name: "TestClient",
|
||||
Credentials: mgclients.Credentials{
|
||||
Identity: "TestClient@example.com",
|
||||
Secret: "password",
|
||||
},
|
||||
Tags: []string{"tag1", "tag2"},
|
||||
Metadata: mgclients.Metadata{"role": "client"},
|
||||
ID: testsutil.GenerateUUID(t),
|
||||
}
|
||||
invalidClientID := "invalidClientID"
|
||||
_ = invalidClientID
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
token string
|
||||
@@ -1693,7 +1686,7 @@ func TestDeleteClient(t *testing.T) {
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
repoCall2 := cache.On("Remove", mock.Anything, tc.clientID).Return(tc.removeErr)
|
||||
repoCall3 := auth.On("DeleteEntityPolicies", context.Background(), &magistrala.DeleteEntityPoliciesReq{
|
||||
repoCall3 := policy.On("DeleteEntityPolicies", context.Background(), &magistrala.DeleteEntityPoliciesReq{
|
||||
EntityType: authsvc.ThingType,
|
||||
Id: tc.clientID,
|
||||
}).Return(tc.deletePolicyResponse, tc.deletePolicyErr)
|
||||
@@ -1709,7 +1702,7 @@ func TestDeleteClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestShare(t *testing.T) {
|
||||
svc, _, auth, _ := newService()
|
||||
svc, _, auth, policy, _ := newService()
|
||||
|
||||
clientID := "clientID"
|
||||
|
||||
@@ -1777,7 +1770,7 @@ func TestShare(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
repoCall2 := auth.On("AddPolicies", mock.Anything, mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesErr)
|
||||
repoCall2 := policy.On("AddPolicies", mock.Anything, mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesErr)
|
||||
err := svc.Share(context.Background(), tc.token, tc.clientID, tc.relation, tc.userID)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
repoCall.Unset()
|
||||
@@ -1787,7 +1780,7 @@ func TestShare(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUnShare(t *testing.T) {
|
||||
svc, _, auth, _ := newService()
|
||||
svc, _, auth, policy, _ := newService()
|
||||
|
||||
clientID := "clientID"
|
||||
|
||||
@@ -1855,7 +1848,7 @@ func TestUnShare(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
repoCall2 := auth.On("DeletePolicies", mock.Anything, mock.Anything).Return(tc.deletePoliciesResponse, tc.deletePoliciesErr)
|
||||
repoCall2 := policy.On("DeletePolicies", mock.Anything, mock.Anything).Return(tc.deletePoliciesResponse, tc.deletePoliciesErr)
|
||||
err := svc.Unshare(context.Background(), tc.token, tc.clientID, tc.relation, tc.userID)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
repoCall.Unset()
|
||||
@@ -1865,7 +1858,7 @@ func TestUnShare(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestViewClientPerms(t *testing.T) {
|
||||
svc, _, auth, _ := newService()
|
||||
svc, _, auth, policy, _ := newService()
|
||||
|
||||
validID := valid
|
||||
|
||||
@@ -1927,7 +1920,7 @@ func TestViewClientPerms(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
repoCall := auth.On("Identify", mock.Anything, &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
repoCall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
repoCall2 := auth.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermResponse, tc.listPermErr)
|
||||
repoCall2 := policy.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermResponse, tc.listPermErr)
|
||||
_, err := svc.ViewClientPerms(context.Background(), tc.token, tc.thingID)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
repoCall.Unset()
|
||||
@@ -1937,7 +1930,7 @@ func TestViewClientPerms(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIdentify(t *testing.T) {
|
||||
svc, cRepo, _, cache := newService()
|
||||
svc, cRepo, _, _, cache := newService()
|
||||
|
||||
valid := valid
|
||||
|
||||
@@ -1998,7 +1991,7 @@ func TestIdentify(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestAuthorize(t *testing.T) {
|
||||
svc, cRepo, auth, cache := newService()
|
||||
svc, cRepo, auth, _, cache := newService()
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
|
||||
@@ -7,38 +7,42 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
grpcclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
var _ magistrala.AuthServiceClient = (*singleUserRepo)(nil)
|
||||
var (
|
||||
_ grpcclient.AuthServiceClient = (*singleUserAuth)(nil)
|
||||
_ magistrala.PolicyServiceClient = (*singleUserPolicyClient)(nil)
|
||||
)
|
||||
|
||||
type singleUserRepo struct {
|
||||
type singleUserAuth struct {
|
||||
id string
|
||||
token string
|
||||
}
|
||||
|
||||
// NewAuthService creates single user repository for constrained environments.
|
||||
func NewAuthService(id, token string) magistrala.AuthServiceClient {
|
||||
return singleUserRepo{
|
||||
func NewAuthService(id, token string) grpcclient.AuthServiceClient {
|
||||
return singleUserAuth{
|
||||
id: id,
|
||||
token: token,
|
||||
}
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) Login(ctx context.Context, in *magistrala.IssueReq, opts ...grpc.CallOption) (*magistrala.Token, error) {
|
||||
func (repo singleUserAuth) 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) {
|
||||
func (repo singleUserAuth) 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) {
|
||||
func (repo singleUserAuth) 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) {
|
||||
func (repo singleUserAuth) Identify(ctx context.Context, in *magistrala.IdentityReq, opts ...grpc.CallOption) (*magistrala.IdentityRes, error) {
|
||||
if repo.token != in.GetToken() {
|
||||
return nil, svcerr.ErrAuthentication
|
||||
}
|
||||
@@ -46,7 +50,7 @@ func (repo singleUserRepo) Identify(ctx context.Context, in *magistrala.Identity
|
||||
return &magistrala.IdentityRes{Id: repo.id}, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) Authorize(ctx context.Context, in *magistrala.AuthorizeReq, opts ...grpc.CallOption) (*magistrala.AuthorizeRes, error) {
|
||||
func (repo singleUserAuth) 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
|
||||
}
|
||||
@@ -54,50 +58,63 @@ func (repo singleUserRepo) Authorize(ctx context.Context, in *magistrala.Authori
|
||||
return &magistrala.AuthorizeRes{Authorized: true}, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) AddPolicy(ctx context.Context, in *magistrala.AddPolicyReq, opts ...grpc.CallOption) (*magistrala.AddPolicyRes, error) {
|
||||
type singleUserPolicyClient struct {
|
||||
id string
|
||||
token string
|
||||
}
|
||||
|
||||
// NewPolicyService creates single user policy service for constrained environments.
|
||||
func NewPolicyService(id, token string) magistrala.PolicyServiceClient {
|
||||
return singleUserPolicyClient{
|
||||
id: id,
|
||||
token: token,
|
||||
}
|
||||
}
|
||||
|
||||
func (repo singleUserPolicyClient) 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) {
|
||||
func (repo singleUserPolicyClient) AddPolicies(ctx context.Context, in *magistrala.AddPoliciesReq, opts ...grpc.CallOption) (*magistrala.AddPoliciesRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
func (repo singleUserPolicyClient) DeletePolicyFilter(ctx context.Context, in *magistrala.DeletePolicyFilterReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
func (repo singleUserPolicyClient) DeletePolicies(ctx context.Context, in *magistrala.DeletePoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) ListObjects(ctx context.Context, in *magistrala.ListObjectsReq, opts ...grpc.CallOption) (*magistrala.ListObjectsRes, error) {
|
||||
func (repo singleUserPolicyClient) 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) {
|
||||
func (repo singleUserPolicyClient) 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) {
|
||||
func (repo singleUserPolicyClient) 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) {
|
||||
func (repo singleUserPolicyClient) 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) {
|
||||
func (repo singleUserPolicyClient) 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) {
|
||||
func (repo singleUserPolicyClient) 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) {
|
||||
func (repo singleUserPolicyClient) ListPermissions(ctx context.Context, in *magistrala.ListPermissionsReq, opts ...grpc.CallOption) (*magistrala.ListPermissionsRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (repo singleUserRepo) DeleteEntityPolicies(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
func (repo singleUserPolicyClient) DeleteEntityPolicies(ctx context.Context, in *magistrala.DeleteEntityPoliciesReq, opts ...grpc.CallOption) (*magistrala.DeletePolicyRes, error) {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
@@ -8,8 +8,13 @@ boilerplate-file: "./tools/config/boilerplate.txt"
|
||||
packages:
|
||||
github.com/absmach/magistrala:
|
||||
interfaces:
|
||||
AuthServiceClient:
|
||||
AuthzServiceClient:
|
||||
config:
|
||||
dir: "./things/mocks"
|
||||
mockname: "AuthzServiceClient"
|
||||
filename: "authz_client.go"
|
||||
PolicyServiceClient:
|
||||
config:
|
||||
dir: "./auth/mocks"
|
||||
mockname: "AuthClient"
|
||||
filename: "auth_client.go"
|
||||
mockname: "PolicyServiceClient"
|
||||
filename: "policy_client.go"
|
||||
|
||||
@@ -25,16 +25,16 @@ const defLimit = uint64(100)
|
||||
|
||||
type handler struct {
|
||||
clients postgres.Repository
|
||||
auth magistrala.AuthServiceClient
|
||||
policy magistrala.PolicyServiceClient
|
||||
checkInterval time.Duration
|
||||
deleteAfter time.Duration
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
func NewDeleteHandler(ctx context.Context, clients postgres.Repository, auth magistrala.AuthServiceClient, defCheckInterval, deleteAfter time.Duration, logger *slog.Logger) {
|
||||
func NewDeleteHandler(ctx context.Context, clients postgres.Repository, policyClient magistrala.PolicyServiceClient, defCheckInterval, deleteAfter time.Duration, logger *slog.Logger) {
|
||||
handler := &handler{
|
||||
clients: clients,
|
||||
auth: auth,
|
||||
policy: policyClient,
|
||||
checkInterval: defCheckInterval,
|
||||
deleteAfter: deleteAfter,
|
||||
logger: logger,
|
||||
@@ -73,7 +73,7 @@ func (h *handler) handle(ctx context.Context) {
|
||||
continue
|
||||
}
|
||||
|
||||
deleteRes, err := h.auth.DeleteEntityPolicies(ctx, &magistrala.DeleteEntityPoliciesReq{
|
||||
deleteRes, err := h.policy.DeleteEntityPolicies(ctx, &magistrala.DeleteEntityPoliciesReq{
|
||||
Id: u.ID,
|
||||
EntityType: auth.UserType,
|
||||
})
|
||||
|
||||
+11
-8
@@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
"github.com/absmach/magistrala/auth"
|
||||
grpcclient "github.com/absmach/magistrala/auth/api/grpc"
|
||||
mgclients "github.com/absmach/magistrala/pkg/clients"
|
||||
"github.com/absmach/magistrala/pkg/errors"
|
||||
repoerr "github.com/absmach/magistrala/pkg/errors/repository"
|
||||
@@ -27,17 +28,19 @@ var (
|
||||
type service struct {
|
||||
clients postgres.Repository
|
||||
idProvider magistrala.IDProvider
|
||||
auth magistrala.AuthServiceClient
|
||||
auth grpcclient.AuthServiceClient
|
||||
policy magistrala.PolicyServiceClient
|
||||
hasher Hasher
|
||||
email Emailer
|
||||
selfRegister bool
|
||||
}
|
||||
|
||||
// NewService returns a new Users service implementation.
|
||||
func NewService(crepo postgres.Repository, authClient magistrala.AuthServiceClient, emailer Emailer, hasher Hasher, idp magistrala.IDProvider, selfRegister bool) Service {
|
||||
func NewService(crepo postgres.Repository, authClient grpcclient.AuthServiceClient, policyClient magistrala.PolicyServiceClient, emailer Emailer, hasher Hasher, idp magistrala.IDProvider, selfRegister bool) Service {
|
||||
return service{
|
||||
clients: crepo,
|
||||
auth: authClient,
|
||||
policy: policyClient,
|
||||
hasher: hasher,
|
||||
email: emailer,
|
||||
idProvider: idp,
|
||||
@@ -500,7 +503,7 @@ func (svc service) ListMembers(ctx context.Context, token, objectKind, objectID
|
||||
if _, err := svc.authorize(ctx, auth.UserType, auth.TokenKind, token, authzPerm, objectType, objectID); err != nil {
|
||||
return mgclients.MembersPage{}, errors.Wrap(svcerr.ErrAuthorization, err)
|
||||
}
|
||||
duids, err := svc.auth.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
duids, err := svc.policy.ListAllSubjects(ctx, &magistrala.ListSubjectsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Permission: pm.Permission,
|
||||
Object: objectID,
|
||||
@@ -571,7 +574,7 @@ func (svc service) retrieveObjectUsersPermissions(ctx context.Context, domainID,
|
||||
}
|
||||
|
||||
func (svc service) listObjectUserPermission(ctx context.Context, userID, objectType, objectID string) ([]string, error) {
|
||||
lp, err := svc.auth.ListPermissions(ctx, &magistrala.ListPermissionsReq{
|
||||
lp, err := svc.policy.ListPermissions(ctx, &magistrala.ListPermissionsReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Object: objectID,
|
||||
@@ -678,7 +681,7 @@ func (svc service) addClientPolicy(ctx context.Context, userID string, role mgcl
|
||||
Object: auth.MagistralaObject,
|
||||
})
|
||||
}
|
||||
resp, err := svc.auth.AddPolicies(ctx, &policies)
|
||||
resp, err := svc.policy.AddPolicies(ctx, &policies)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrAddPolicies, err)
|
||||
}
|
||||
@@ -708,7 +711,7 @@ func (svc service) addClientPolicyRollback(ctx context.Context, userID string, r
|
||||
Object: auth.MagistralaObject,
|
||||
})
|
||||
}
|
||||
resp, err := svc.auth.DeletePolicies(ctx, &policies)
|
||||
resp, err := svc.policy.DeletePolicies(ctx, &policies)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrDeletePolicies, err)
|
||||
}
|
||||
@@ -721,7 +724,7 @@ func (svc service) addClientPolicyRollback(ctx context.Context, userID string, r
|
||||
func (svc service) updateClientPolicy(ctx context.Context, userID string, role mgclients.Role) error {
|
||||
switch role {
|
||||
case mgclients.AdminRole:
|
||||
resp, err := svc.auth.AddPolicy(ctx, &magistrala.AddPolicyReq{
|
||||
resp, err := svc.policy.AddPolicy(ctx, &magistrala.AddPolicyReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Relation: auth.AdministratorRelation,
|
||||
@@ -738,7 +741,7 @@ func (svc service) updateClientPolicy(ctx context.Context, userID string, role m
|
||||
case mgclients.UserRole:
|
||||
fallthrough
|
||||
default:
|
||||
resp, err := svc.auth.DeletePolicyFilter(ctx, &magistrala.DeletePolicyFilterReq{
|
||||
resp, err := svc.policy.DeletePolicyFilter(ctx, &magistrala.DeletePolicyFilterReq{
|
||||
SubjectType: auth.UserType,
|
||||
Subject: userID,
|
||||
Relation: auth.AdministratorRelation,
|
||||
|
||||
+33
-32
@@ -50,15 +50,16 @@ var (
|
||||
errHashPassword = errors.New("generate hash from password failed")
|
||||
)
|
||||
|
||||
func newService(selfRegister bool) (users.Service, *mocks.Repository, *authmocks.AuthClient, *mocks.Emailer) {
|
||||
func newService(selfRegister bool) (users.Service, *mocks.Repository, *authmocks.AuthServiceClient, *authmocks.PolicyServiceClient, *mocks.Emailer) {
|
||||
cRepo := new(mocks.Repository)
|
||||
auth := new(authmocks.AuthClient)
|
||||
auth := new(authmocks.AuthServiceClient)
|
||||
policy := new(authmocks.PolicyServiceClient)
|
||||
e := new(mocks.Emailer)
|
||||
return users.NewService(cRepo, auth, e, phasher, idProvider, selfRegister), cRepo, auth, e
|
||||
return users.NewService(cRepo, auth, policy, e, phasher, idProvider, selfRegister), cRepo, auth, policy, e
|
||||
}
|
||||
|
||||
func TestRegisterClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, _, policy, _ := newService(true)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -263,8 +264,8 @@ func TestRegisterClient(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("AddPolicies", context.Background(), mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesResponseErr)
|
||||
authCall1 := auth.On("DeletePolicies", context.Background(), mock.Anything).Return(tc.deletePoliciesResponse, tc.deletePoliciesResponseErr)
|
||||
authCall := policy.On("AddPolicies", context.Background(), mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesResponseErr)
|
||||
authCall1 := policy.On("DeletePolicies", context.Background(), mock.Anything).Return(tc.deletePoliciesResponse, tc.deletePoliciesResponseErr)
|
||||
repoCall := cRepo.On("Save", context.Background(), mock.Anything).Return(tc.client, tc.saveErr)
|
||||
expected, err := svc.RegisterClient(context.Background(), tc.token, tc.client)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
@@ -283,7 +284,7 @@ func TestRegisterClient(t *testing.T) {
|
||||
authCall.Unset()
|
||||
}
|
||||
|
||||
svc, cRepo, auth, _ = newService(false)
|
||||
svc, cRepo, auth, policy, _ := newService(false)
|
||||
|
||||
cases2 := []struct {
|
||||
desc string
|
||||
@@ -340,8 +341,8 @@ func TestRegisterClient(t *testing.T) {
|
||||
authCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), mock.Anything).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
repoCall := cRepo.On("CheckSuperAdmin", context.Background(), mock.Anything).Return(tc.checkSuperAdminErr)
|
||||
authCall2 := auth.On("AddPolicies", context.Background(), mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesResponseErr)
|
||||
authCall3 := auth.On("DeletePolicies", context.Background(), mock.Anything).Return(tc.deletePoliciesResponse, tc.deletePoliciesResponseErr)
|
||||
authCall2 := policy.On("AddPolicies", context.Background(), mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesResponseErr)
|
||||
authCall3 := policy.On("DeletePolicies", context.Background(), mock.Anything).Return(tc.deletePoliciesResponse, tc.deletePoliciesResponseErr)
|
||||
repoCall1 := cRepo.On("Save", context.Background(), mock.Anything).Return(tc.client, tc.saveErr)
|
||||
expected, err := svc.RegisterClient(context.Background(), tc.token, tc.client)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
@@ -366,7 +367,7 @@ func TestRegisterClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestViewClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
adminID := testsutil.GenerateUUID(t)
|
||||
cases := []struct {
|
||||
@@ -477,7 +478,7 @@ func TestViewClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListClients(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -593,7 +594,7 @@ func TestListClients(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestSearchUsers(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
cases := []struct {
|
||||
desc string
|
||||
token string
|
||||
@@ -675,7 +676,7 @@ func TestSearchUsers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
client1 := client
|
||||
client2 := client
|
||||
@@ -805,7 +806,7 @@ func TestUpdateClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClientTags(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
client.Tags = []string{"updated"}
|
||||
adminID := testsutil.GenerateUUID(t)
|
||||
@@ -915,7 +916,7 @@ func TestUpdateClientTags(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClientIdentity(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
client2 := client
|
||||
client2.Credentials.Identity = "updated@example.com"
|
||||
@@ -1035,7 +1036,7 @@ func TestUpdateClientIdentity(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClientRole(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, policy, _ := newService(true)
|
||||
|
||||
client2 := client
|
||||
client.Role = mgclients.AdminRole
|
||||
@@ -1239,8 +1240,8 @@ func TestUpdateClientRole(t *testing.T) {
|
||||
authCall1 := auth.On("Authorize", context.Background(), tc.superAdminAuthReq).Return(tc.superAdminAuthRes, tc.authorizeErr)
|
||||
repoCall := cRepo.On("CheckSuperAdmin", context.Background(), mock.Anything).Return(tc.checkSuperAdminErr)
|
||||
authCall2 := auth.On("Authorize", context.Background(), tc.membershipAuthReq).Return(tc.membershipAuthRes, tc.membershipAuthErr)
|
||||
authCall3 := auth.On("AddPolicy", context.Background(), mock.Anything).Return(tc.addPolicyResponse, tc.addPolicyErr)
|
||||
authCall4 := auth.On("DeletePolicyFilter", context.Background(), mock.Anything).Return(tc.deletePolicyFilterResponse, tc.deletePolicyErr)
|
||||
authCall3 := policy.On("AddPolicy", context.Background(), mock.Anything).Return(tc.addPolicyResponse, tc.addPolicyErr)
|
||||
authCall4 := policy.On("DeletePolicyFilter", context.Background(), mock.Anything).Return(tc.deletePolicyFilterResponse, tc.deletePolicyErr)
|
||||
repoCall1 := cRepo.On("UpdateRole", context.Background(), mock.Anything).Return(tc.updateRoleResponse, tc.updateRoleErr)
|
||||
|
||||
updatedClient, err := svc.UpdateClientRole(context.Background(), tc.token, tc.client)
|
||||
@@ -1261,7 +1262,7 @@ func TestUpdateClientRole(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestUpdateClientSecret(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
newSecret := "newstrongSecret"
|
||||
rClient := client
|
||||
@@ -1391,7 +1392,7 @@ func TestUpdateClientSecret(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEnableClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
enabledClient1 := mgclients.Client{ID: testsutil.GenerateUUID(t), Credentials: mgclients.Credentials{Identity: "client1@example.com", Secret: "password"}, Status: mgclients.EnabledStatus}
|
||||
disabledClient1 := mgclients.Client{ID: testsutil.GenerateUUID(t), Credentials: mgclients.Credentials{Identity: "client3@example.com", Secret: "password"}, Status: mgclients.DisabledStatus}
|
||||
@@ -1515,7 +1516,7 @@ func TestEnableClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDisableClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
enabledClient1 := mgclients.Client{ID: testsutil.GenerateUUID(t), Credentials: mgclients.Credentials{Identity: "client1@example.com", Secret: "password"}, Status: mgclients.EnabledStatus}
|
||||
disabledClient1 := mgclients.Client{ID: testsutil.GenerateUUID(t), Credentials: mgclients.Credentials{Identity: "client3@example.com", Secret: "password"}, Status: mgclients.DisabledStatus}
|
||||
@@ -1639,7 +1640,7 @@ func TestDisableClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestDeleteClient(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
enabledClient1 := mgclients.Client{ID: testsutil.GenerateUUID(t), Credentials: mgclients.Credentials{Identity: "client1@example.com", Secret: "password"}, Status: mgclients.EnabledStatus}
|
||||
deletedClient1 := mgclients.Client{ID: testsutil.GenerateUUID(t), Credentials: mgclients.Credentials{Identity: "client3@example.com", Secret: "password"}, Status: mgclients.DeletedStatus}
|
||||
@@ -1762,7 +1763,7 @@ func TestDeleteClient(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListMembers(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, policy, _ := newService(true)
|
||||
|
||||
validPolicy := fmt.Sprintf("%s_%s", validID, client.ID)
|
||||
permissionsClient := basicClient
|
||||
@@ -2214,9 +2215,9 @@ func TestListMembers(t *testing.T) {
|
||||
for _, tc := range cases {
|
||||
authCall := auth.On("Identify", context.Background(), &magistrala.IdentityReq{Token: tc.token}).Return(tc.identifyResponse, tc.identifyErr)
|
||||
authCall1 := auth.On("Authorize", context.Background(), tc.authorizeReq).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
authCall2 := auth.On("ListAllSubjects", context.Background(), tc.listAllSubjectsReq).Return(tc.listAllSubjectsResponse, tc.listAllSubjectsErr)
|
||||
authCall2 := policy.On("ListAllSubjects", context.Background(), tc.listAllSubjectsReq).Return(tc.listAllSubjectsResponse, tc.listAllSubjectsErr)
|
||||
repoCall := cRepo.On("RetrieveAll", context.Background(), mock.Anything).Return(tc.retrieveAllResponse, tc.retrieveAllErr)
|
||||
authCall3 := auth.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionErr)
|
||||
authCall3 := policy.On("ListPermissions", mock.Anything, mock.Anything).Return(tc.listPermissionsResponse, tc.listPermissionErr)
|
||||
|
||||
page, err := svc.ListMembers(context.Background(), tc.token, tc.objectKind, tc.objectID, tc.page)
|
||||
assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
@@ -2231,7 +2232,7 @@ func TestListMembers(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIssueToken(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
rClient := client
|
||||
rClient2 := client
|
||||
@@ -2315,7 +2316,7 @@ func TestIssueToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRefreshToken(t *testing.T) {
|
||||
svc, crepo, auth, _ := newService(true)
|
||||
svc, crepo, auth, _, _ := newService(true)
|
||||
|
||||
rClient := client
|
||||
rClient.Credentials.Secret, _ = phasher.Hash(client.Credentials.Secret)
|
||||
@@ -2417,7 +2418,7 @@ func TestRefreshToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestGenerateResetToken(t *testing.T) {
|
||||
svc, cRepo, auth, e := newService(true)
|
||||
svc, cRepo, auth, _, e := newService(true)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -2476,7 +2477,7 @@ func TestGenerateResetToken(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetSecret(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
client := mgclients.Client{
|
||||
ID: "clientID",
|
||||
@@ -2581,7 +2582,7 @@ func TestResetSecret(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestViewProfile(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, _, _ := newService(true)
|
||||
|
||||
client := mgclients.Client{
|
||||
ID: "clientID",
|
||||
@@ -2642,7 +2643,7 @@ func TestViewProfile(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestOAuthCallback(t *testing.T) {
|
||||
svc, cRepo, auth, _ := newService(true)
|
||||
svc, cRepo, auth, policy, _ := newService(true)
|
||||
|
||||
cases := []struct {
|
||||
desc string
|
||||
@@ -2794,7 +2795,7 @@ func TestOAuthCallback(t *testing.T) {
|
||||
repoCall := cRepo.On("RetrieveByIdentity", context.Background(), tc.client.Credentials.Identity).Return(tc.retrieveByIdentityResponse, tc.retrieveByIdentityErr)
|
||||
repoCall1 := cRepo.On("Save", context.Background(), mock.Anything).Return(tc.saveResponse, tc.saveErr)
|
||||
authCall := auth.On("Issue", mock.Anything, mock.Anything).Return(tc.issueResponse, tc.issueErr)
|
||||
authCall1 := auth.On("AddPolicies", mock.Anything, mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesErr)
|
||||
authCall1 := policy.On("AddPolicies", mock.Anything, mock.Anything).Return(tc.addPoliciesResponse, tc.addPoliciesErr)
|
||||
authCall2 := auth.On("Authorize", mock.Anything, authReq).Return(tc.authorizeResponse, tc.authorizeErr)
|
||||
token, err := svc.OAuthCallback(context.Background(), tc.client)
|
||||
if err == nil {
|
||||
|
||||
+4
-4
@@ -41,14 +41,14 @@ type Service interface {
|
||||
var _ Service = (*adapterService)(nil)
|
||||
|
||||
type adapterService struct {
|
||||
auth magistrala.AuthzServiceClient
|
||||
things magistrala.AuthzServiceClient
|
||||
pubsub messaging.PubSub
|
||||
}
|
||||
|
||||
// New instantiates the WS adapter implementation.
|
||||
func New(authClient magistrala.AuthzServiceClient, pubsub messaging.PubSub) Service {
|
||||
func New(thingsClient magistrala.AuthzServiceClient, pubsub messaging.PubSub) Service {
|
||||
return &adapterService{
|
||||
auth: authClient,
|
||||
things: thingsClient,
|
||||
pubsub: pubsub,
|
||||
}
|
||||
}
|
||||
@@ -92,7 +92,7 @@ func (svc *adapterService) authorize(ctx context.Context, thingKey, chanID, acti
|
||||
Object: chanID,
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := svc.auth.Authorize(ctx, ar)
|
||||
res, err := svc.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return "", errors.Wrap(svcerr.ErrAuthorization, err)
|
||||
}
|
||||
|
||||
+6
-6
@@ -9,11 +9,11 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
authmocks "github.com/absmach/magistrala/auth/mocks"
|
||||
"github.com/absmach/magistrala/internal/testsutil"
|
||||
svcerr "github.com/absmach/magistrala/pkg/errors/service"
|
||||
"github.com/absmach/magistrala/pkg/messaging"
|
||||
"github.com/absmach/magistrala/pkg/messaging/mocks"
|
||||
thmocks "github.com/absmach/magistrala/things/mocks"
|
||||
"github.com/absmach/magistrala/ws"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/mock"
|
||||
@@ -37,15 +37,15 @@ var msg = messaging.Message{
|
||||
Payload: []byte(`[{"n":"current","t":-5,"v":1.2}]`),
|
||||
}
|
||||
|
||||
func newService() (ws.Service, *mocks.PubSub, *authmocks.AuthClient) {
|
||||
func newService() (ws.Service, *mocks.PubSub, *thmocks.AuthzServiceClient) {
|
||||
pubsub := new(mocks.PubSub)
|
||||
auth := new(authmocks.AuthClient)
|
||||
things := new(thmocks.AuthzServiceClient)
|
||||
|
||||
return ws.New(auth, pubsub), pubsub, auth
|
||||
return ws.New(things, pubsub), pubsub, things
|
||||
}
|
||||
|
||||
func TestSubscribe(t *testing.T) {
|
||||
svc, pubsub, auth := newService()
|
||||
svc, pubsub, things := newService()
|
||||
|
||||
c := ws.NewClient(nil)
|
||||
|
||||
@@ -115,7 +115,7 @@ func TestSubscribe(t *testing.T) {
|
||||
Handler: c,
|
||||
}
|
||||
repocall := pubsub.On("Subscribe", mock.Anything, subConfig).Return(tc.err)
|
||||
repocall1 := auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true, Id: thingID}, nil)
|
||||
repocall1 := things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: true, Id: thingID}, nil)
|
||||
err := svc.Subscribe(context.Background(), tc.thingKey, tc.chanID, tc.subtopic, c)
|
||||
assert.Equal(t, tc.err, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
|
||||
repocall1.Parent.AssertCalled(t, "Authorize", mock.Anything, mock.Anything)
|
||||
|
||||
@@ -13,9 +13,9 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/absmach/magistrala"
|
||||
authmocks "github.com/absmach/magistrala/auth/mocks"
|
||||
mglog "github.com/absmach/magistrala/logger"
|
||||
"github.com/absmach/magistrala/pkg/messaging/mocks"
|
||||
thmocks "github.com/absmach/magistrala/things/mocks"
|
||||
"github.com/absmach/magistrala/ws"
|
||||
"github.com/absmach/magistrala/ws/api"
|
||||
"github.com/absmach/mproxy/pkg/session"
|
||||
@@ -36,9 +36,9 @@ const (
|
||||
|
||||
var msg = []byte(`[{"n":"current","t":-1,"v":1.6}]`)
|
||||
|
||||
func newService(auth magistrala.AuthzServiceClient) (ws.Service, *mocks.PubSub) {
|
||||
func newService(things magistrala.AuthzServiceClient) (ws.Service, *mocks.PubSub) {
|
||||
pubsub := new(mocks.PubSub)
|
||||
return ws.New(auth, pubsub), pubsub
|
||||
return ws.New(things, pubsub), pubsub
|
||||
}
|
||||
|
||||
func newHTTPServer(svc ws.Service) *httptest.Server {
|
||||
@@ -90,17 +90,17 @@ func handshake(tsURL, chanID, subtopic, thingKey string, addHeader bool) (*webso
|
||||
}
|
||||
|
||||
func TestHandshake(t *testing.T) {
|
||||
auth := new(authmocks.AuthClient)
|
||||
svc, pubsub := newService(auth)
|
||||
things := new(thmocks.AuthzServiceClient)
|
||||
svc, pubsub := newService(things)
|
||||
target := newHTTPServer(svc)
|
||||
defer target.Close()
|
||||
handler := ws.NewHandler(pubsub, mglog.NewMock(), auth)
|
||||
handler := ws.NewHandler(pubsub, mglog.NewMock(), things)
|
||||
ts, err := newProxyHTPPServer(handler, target)
|
||||
require.Nil(t, err)
|
||||
defer ts.Close()
|
||||
auth.On("Authorize", mock.Anything, &magistrala.AuthorizeReq{Subject: thingKey, Object: id, Domain: "", SubjectType: "thing", Permission: "publish", ObjectType: "group"}).Return(&magistrala.AuthorizeRes{Authorized: true, Id: "1"}, nil)
|
||||
auth.On("Authorize", mock.Anything, &magistrala.AuthorizeReq{Subject: thingKey, Object: id, Domain: "", SubjectType: "thing", Permission: "subscribe", ObjectType: "group"}).Return(&magistrala.AuthorizeRes{Authorized: true, Id: "2"}, nil)
|
||||
auth.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: false, Id: "3"}, nil)
|
||||
things.On("Authorize", mock.Anything, &magistrala.AuthorizeReq{Subject: thingKey, Object: id, Domain: "", SubjectType: "thing", Permission: "publish", ObjectType: "group"}).Return(&magistrala.AuthorizeRes{Authorized: true, Id: "1"}, nil)
|
||||
things.On("Authorize", mock.Anything, &magistrala.AuthorizeReq{Subject: thingKey, Object: id, Domain: "", SubjectType: "thing", Permission: "subscribe", ObjectType: "group"}).Return(&magistrala.AuthorizeRes{Authorized: true, Id: "2"}, nil)
|
||||
things.On("Authorize", mock.Anything, mock.Anything).Return(&magistrala.AuthorizeRes{Authorized: false, Id: "3"}, nil)
|
||||
pubsub.On("Subscribe", mock.Anything, mock.Anything).Return(nil)
|
||||
pubsub.On("Publish", mock.Anything, mock.Anything, mock.Anything).Return(nil)
|
||||
|
||||
|
||||
+5
-5
@@ -51,16 +51,16 @@ var channelRegExp = regexp.MustCompile(`^\/?channels\/([\w\-]+)\/messages(\/[^?]
|
||||
// Event implements events.Event interface.
|
||||
type handler struct {
|
||||
pubsub messaging.PubSub
|
||||
auth magistrala.AuthzServiceClient
|
||||
things magistrala.AuthzServiceClient
|
||||
logger *slog.Logger
|
||||
}
|
||||
|
||||
// NewHandler creates new Handler entity.
|
||||
func NewHandler(pubsub messaging.PubSub, logger *slog.Logger, authClient magistrala.AuthzServiceClient) session.Handler {
|
||||
func NewHandler(pubsub messaging.PubSub, logger *slog.Logger, thingsClient magistrala.AuthzServiceClient) session.Handler {
|
||||
return &handler{
|
||||
logger: logger,
|
||||
pubsub: pubsub,
|
||||
auth: authClient,
|
||||
things: thingsClient,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ func (h *handler) Publish(ctx context.Context, topic *string, payload *[]byte) e
|
||||
Object: chanID,
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := h.auth.Authorize(ctx, ar)
|
||||
res, err := h.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -238,7 +238,7 @@ func (h *handler) authAccess(ctx context.Context, password, topic, action string
|
||||
Object: chanID,
|
||||
ObjectType: auth.GroupType,
|
||||
}
|
||||
res, err := h.auth.Authorize(ctx, ar)
|
||||
res, err := h.things.Authorize(ctx, ar)
|
||||
if err != nil {
|
||||
return errors.Wrap(svcerr.ErrAuthorization, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user