cf-perm 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2e0cc38271569c48c51a2c0877be866ef286a748
4
+ data.tar.gz: ba4b8ca77f6367b5688f82c50a6218d313fa40e1
5
+ SHA512:
6
+ metadata.gz: e4a985c559c37091598144ee9ac0dd044ba1b07b310184fe41024cde988d923a9dc921e7b25207b350908111ec923db3d2e4e20bf044ee7c8343ade9db64e68e
7
+ data.tar.gz: 9476625520fe357e4342e85fafb5abd0781c4d03c29b4ba191919708976a0106efd61817c8726d0d5d7038ec7252e8fc6617609cb6cbcd853ba0c9267420dbd5
data/LICENSE ADDED
@@ -0,0 +1,177 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
data/NOTICE ADDED
@@ -0,0 +1,15 @@
1
+ perm-rb
2
+
3
+ Copyright (c) 2017 CloudFoundry.org Foundation, Inc. All Rights Reserved.
4
+
5
+ Licensed under the Apache License, Version 2.0 (the "License");
6
+ you may not use this file except in compliance with the License.
7
+ You may obtain a copy of the License at
8
+
9
+ http://www.apache.org/licenses/LICENSE-2.0
10
+
11
+ Unless required by applicable law or agreed to in writing, software
12
+ distributed under the License is distributed on an "AS IS" BASIS,
13
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ See the License for the specific language governing permissions and
15
+ limitations under the License.
data/README.md ADDED
@@ -0,0 +1 @@
1
+ # Perm Gem
data/lib/perm.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'perm/version'
4
+ require 'perm/protos'
5
+ require 'perm/v1'
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'perm/protos/actor_pb'
4
+ require 'perm/protos/permission_pb'
5
+ require 'perm/protos/permission_service_pb'
6
+ require 'perm/protos/permission_service_services_pb'
7
+ require 'perm/protos/role_pb'
8
+ require 'perm/protos/role_service_pb'
9
+ require 'perm/protos/role_service_services_pb'
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: actor.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "cloud_foundry.perm.protos.Actor" do
8
+ optional :id, :string, 2
9
+ optional :issuer, :string, 3
10
+ end
11
+ end
12
+
13
+ module CloudFoundry
14
+ module Perm
15
+ module Protos
16
+ Actor = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.Actor").msgclass
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: permission.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "cloud_foundry.perm.protos.Permission" do
8
+ optional :name, :string, 1
9
+ optional :resource_pattern, :string, 2
10
+ end
11
+ end
12
+
13
+ module CloudFoundry
14
+ module Perm
15
+ module Protos
16
+ Permission = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.Permission").msgclass
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,34 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: permission_service.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'actor_pb'
7
+ Google::Protobuf::DescriptorPool.generated_pool.build do
8
+ add_message "cloud_foundry.perm.protos.HasPermissionRequest" do
9
+ optional :actor, :message, 1, "cloud_foundry.perm.protos.Actor"
10
+ optional :permission_name, :string, 2
11
+ optional :resource_id, :string, 3
12
+ end
13
+ add_message "cloud_foundry.perm.protos.HasPermissionResponse" do
14
+ optional :has_permission, :bool, 1
15
+ end
16
+ add_message "cloud_foundry.perm.protos.ListResourcePatternsRequest" do
17
+ optional :actor, :message, 1, "cloud_foundry.perm.protos.Actor"
18
+ optional :permission_name, :string, 2
19
+ end
20
+ add_message "cloud_foundry.perm.protos.ListResourcePatternsResponse" do
21
+ repeated :resource_patterns, :string, 1
22
+ end
23
+ end
24
+
25
+ module CloudFoundry
26
+ module Perm
27
+ module Protos
28
+ HasPermissionRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.HasPermissionRequest").msgclass
29
+ HasPermissionResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.HasPermissionResponse").msgclass
30
+ ListResourcePatternsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.ListResourcePatternsRequest").msgclass
31
+ ListResourcePatternsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.ListResourcePatternsResponse").msgclass
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: permission_service.proto for package 'cloud_foundry.perm.protos'
3
+
4
+ require 'grpc'
5
+ require 'permission_service_pb'
6
+
7
+ module CloudFoundry
8
+ module Perm
9
+ module Protos
10
+ module PermissionService
11
+ class Service
12
+
13
+ include GRPC::GenericService
14
+
15
+ self.marshal_class_method = :encode
16
+ self.unmarshal_class_method = :decode
17
+ self.service_name = 'cloud_foundry.perm.protos.PermissionService'
18
+
19
+ rpc :HasPermission, HasPermissionRequest, HasPermissionResponse
20
+ rpc :ListResourcePatterns, ListResourcePatternsRequest, ListResourcePatternsResponse
21
+ end
22
+
23
+ Stub = Service.rpc_stub_class
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: role.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ Google::Protobuf::DescriptorPool.generated_pool.build do
7
+ add_message "cloud_foundry.perm.protos.Role" do
8
+ optional :name, :string, 2
9
+ end
10
+ end
11
+
12
+ module CloudFoundry
13
+ module Perm
14
+ module Protos
15
+ Role = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.Role").msgclass
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,82 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # source: role_service.proto
3
+
4
+ require 'google/protobuf'
5
+
6
+ require 'actor_pb'
7
+ require 'permission_pb'
8
+ require 'role_pb'
9
+ Google::Protobuf::DescriptorPool.generated_pool.build do
10
+ add_message "cloud_foundry.perm.protos.CreateRoleRequest" do
11
+ optional :name, :string, 1
12
+ repeated :permissions, :message, 2, "cloud_foundry.perm.protos.Permission"
13
+ end
14
+ add_message "cloud_foundry.perm.protos.CreateRoleResponse" do
15
+ optional :role, :message, 1, "cloud_foundry.perm.protos.Role"
16
+ end
17
+ add_message "cloud_foundry.perm.protos.GetRoleRequest" do
18
+ optional :name, :string, 1
19
+ end
20
+ add_message "cloud_foundry.perm.protos.GetRoleResponse" do
21
+ optional :role, :message, 1, "cloud_foundry.perm.protos.Role"
22
+ end
23
+ add_message "cloud_foundry.perm.protos.DeleteRoleRequest" do
24
+ optional :name, :string, 1
25
+ end
26
+ add_message "cloud_foundry.perm.protos.DeleteRoleResponse" do
27
+ end
28
+ add_message "cloud_foundry.perm.protos.AssignRoleRequest" do
29
+ optional :actor, :message, 1, "cloud_foundry.perm.protos.Actor"
30
+ optional :role_name, :string, 2
31
+ end
32
+ add_message "cloud_foundry.perm.protos.AssignRoleResponse" do
33
+ end
34
+ add_message "cloud_foundry.perm.protos.UnassignRoleRequest" do
35
+ optional :actor, :message, 1, "cloud_foundry.perm.protos.Actor"
36
+ optional :role_name, :string, 2
37
+ end
38
+ add_message "cloud_foundry.perm.protos.UnassignRoleResponse" do
39
+ end
40
+ add_message "cloud_foundry.perm.protos.HasRoleRequest" do
41
+ optional :actor, :message, 1, "cloud_foundry.perm.protos.Actor"
42
+ optional :role_name, :string, 2
43
+ end
44
+ add_message "cloud_foundry.perm.protos.HasRoleResponse" do
45
+ optional :has_role, :bool, 1
46
+ end
47
+ add_message "cloud_foundry.perm.protos.ListActorRolesRequest" do
48
+ optional :actor, :message, 1, "cloud_foundry.perm.protos.Actor"
49
+ end
50
+ add_message "cloud_foundry.perm.protos.ListActorRolesResponse" do
51
+ repeated :roles, :message, 1, "cloud_foundry.perm.protos.Role"
52
+ end
53
+ add_message "cloud_foundry.perm.protos.ListRolePermissionsRequest" do
54
+ optional :role_name, :string, 1
55
+ end
56
+ add_message "cloud_foundry.perm.protos.ListRolePermissionsResponse" do
57
+ repeated :permissions, :message, 1, "cloud_foundry.perm.protos.Permission"
58
+ end
59
+ end
60
+
61
+ module CloudFoundry
62
+ module Perm
63
+ module Protos
64
+ CreateRoleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.CreateRoleRequest").msgclass
65
+ CreateRoleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.CreateRoleResponse").msgclass
66
+ GetRoleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.GetRoleRequest").msgclass
67
+ GetRoleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.GetRoleResponse").msgclass
68
+ DeleteRoleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.DeleteRoleRequest").msgclass
69
+ DeleteRoleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.DeleteRoleResponse").msgclass
70
+ AssignRoleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.AssignRoleRequest").msgclass
71
+ AssignRoleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.AssignRoleResponse").msgclass
72
+ UnassignRoleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.UnassignRoleRequest").msgclass
73
+ UnassignRoleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.UnassignRoleResponse").msgclass
74
+ HasRoleRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.HasRoleRequest").msgclass
75
+ HasRoleResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.HasRoleResponse").msgclass
76
+ ListActorRolesRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.ListActorRolesRequest").msgclass
77
+ ListActorRolesResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.ListActorRolesResponse").msgclass
78
+ ListRolePermissionsRequest = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.ListRolePermissionsRequest").msgclass
79
+ ListRolePermissionsResponse = Google::Protobuf::DescriptorPool.generated_pool.lookup("cloud_foundry.perm.protos.ListRolePermissionsResponse").msgclass
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,33 @@
1
+ # Generated by the protocol buffer compiler. DO NOT EDIT!
2
+ # Source: role_service.proto for package 'cloud_foundry.perm.protos'
3
+
4
+ require 'grpc'
5
+ require 'role_service_pb'
6
+
7
+ module CloudFoundry
8
+ module Perm
9
+ module Protos
10
+ module RoleService
11
+ class Service
12
+
13
+ include GRPC::GenericService
14
+
15
+ self.marshal_class_method = :encode
16
+ self.unmarshal_class_method = :decode
17
+ self.service_name = 'cloud_foundry.perm.protos.RoleService'
18
+
19
+ rpc :CreateRole, CreateRoleRequest, CreateRoleResponse
20
+ rpc :GetRole, GetRoleRequest, GetRoleResponse
21
+ rpc :DeleteRole, DeleteRoleRequest, DeleteRoleResponse
22
+ rpc :AssignRole, AssignRoleRequest, AssignRoleResponse
23
+ rpc :UnassignRole, UnassignRoleRequest, UnassignRoleResponse
24
+ rpc :HasRole, HasRoleRequest, HasRoleResponse
25
+ rpc :ListActorRoles, ListActorRolesRequest, ListActorRolesResponse
26
+ rpc :ListRolePermissions, ListRolePermissionsRequest, ListRolePermissionsResponse
27
+ end
28
+
29
+ Stub = Service.rpc_stub_class
30
+ end
31
+ end
32
+ end
33
+ end
data/lib/perm/v1.rb ADDED
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'perm/v1/client'
4
+ require 'perm/v1/errors'
5
+ require 'perm/v1/models'
@@ -0,0 +1,163 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'perm/protos'
4
+ require 'perm/v1/errors'
5
+
6
+ module CloudFoundry
7
+ module Perm
8
+ module V1
9
+ class Client
10
+ attr_reader :hostname, :port
11
+
12
+ def initialize(hostname:, port: 6283, trusted_cas:, timeout: 15)
13
+ raise ArgumentError, 'trusted_cas cannot be empty' if trusted_cas.empty?
14
+
15
+ @hostname = hostname
16
+ @port = port
17
+ @url = "#{hostname}:#{port}"
18
+ @trusted_cas = trusted_cas
19
+ @timeout = timeout
20
+ end
21
+
22
+ def create_role(role_name:, permissions: [])
23
+ permission_protos = permissions.map do |p|
24
+ Protos::Permission.new(name: p.name, resource_pattern: p.resource_pattern)
25
+ end
26
+ request = Protos::CreateRoleRequest.new(name: role_name, permissions: permission_protos)
27
+
28
+ response = grpc_role_service.create_role(request)
29
+ role = response.role
30
+
31
+ Models::Role.new(name: role.name)
32
+ rescue GRPC::BadStatus => e
33
+ raise Errors.from_grpc_error(e)
34
+ end
35
+
36
+ def get_role(name)
37
+ request = Protos::GetRoleRequest.new(name: name)
38
+
39
+ response = grpc_role_service.get_role(request)
40
+ role = response.role
41
+
42
+ Models::Role.new(name: role.name)
43
+ rescue GRPC::BadStatus => e
44
+ raise Errors.from_grpc_error(e)
45
+ end
46
+
47
+ def delete_role(name)
48
+ request = Protos::DeleteRoleRequest.new(name: name)
49
+
50
+ grpc_role_service.delete_role(request)
51
+
52
+ nil
53
+ rescue GRPC::BadStatus => e
54
+ raise Errors.from_grpc_error(e)
55
+ end
56
+
57
+ def assign_role(role_name:, actor_id:, issuer:)
58
+ actor = Protos::Actor.new(id: actor_id, issuer: issuer)
59
+ request = Protos::AssignRoleRequest.new(actor: actor, role_name: role_name)
60
+
61
+ grpc_role_service.assign_role(request)
62
+
63
+ nil
64
+ rescue GRPC::BadStatus => e
65
+ raise Errors.from_grpc_error(e)
66
+ end
67
+
68
+ def unassign_role(role_name:, actor_id:, issuer:)
69
+ actor = Protos::Actor.new(id: actor_id, issuer: issuer)
70
+ request = Protos::UnassignRoleRequest.new(actor: actor, role_name: role_name)
71
+
72
+ grpc_role_service.unassign_role(request)
73
+
74
+ nil
75
+ rescue GRPC::BadStatus => e
76
+ raise Errors.from_grpc_error(e)
77
+ end
78
+
79
+ # rubocop:disable Naming/PredicateName
80
+ def has_role?(role_name:, actor_id:, issuer:)
81
+ actor = Protos::Actor.new(id: actor_id, issuer: issuer)
82
+ request = Protos::HasRoleRequest.new(actor: actor, role_name: role_name)
83
+
84
+ response = grpc_role_service.has_role(request)
85
+ response.has_role
86
+ rescue GRPC::BadStatus => e
87
+ raise Errors.from_grpc_error(e)
88
+ end
89
+
90
+ def list_actor_roles(actor_id:, issuer:)
91
+ actor = Protos::Actor.new(id: actor_id, issuer: issuer)
92
+ request = Protos::ListActorRolesRequest.new(actor: actor)
93
+
94
+ response = grpc_role_service.list_actor_roles(request)
95
+ roles = response.roles
96
+
97
+ roles.map do |role|
98
+ Models::Role.new(name: role.name)
99
+ end
100
+ rescue GRPC::BadStatus => e
101
+ raise Errors.from_grpc_error(e)
102
+ end
103
+
104
+ def list_role_permissions(role_name:)
105
+ request = Protos::ListRolePermissionsRequest.new(role_name: role_name)
106
+
107
+ response = grpc_role_service.list_role_permissions(request)
108
+ permissions = response.permissions
109
+
110
+ permissions.map do |permission|
111
+ Models::Permission.new(name: permission.name, resource_pattern: permission.resource_pattern)
112
+ end
113
+ rescue GRPC::BadStatus => e
114
+ raise Errors.from_grpc_error(e)
115
+ end
116
+
117
+ def has_permission?(actor_id:, issuer:, permission_name:, resource_id:)
118
+ actor = Protos::Actor.new(id: actor_id, issuer: issuer)
119
+ request = Protos::HasPermissionRequest.new(
120
+ actor: actor,
121
+ permission_name: permission_name,
122
+ resource_id: resource_id
123
+ )
124
+
125
+ response = grpc_permission_service.has_permission(request)
126
+ response.has_permission
127
+ rescue GRPC::BadStatus => e
128
+ raise Errors.from_grpc_error(e)
129
+ end
130
+
131
+ def list_resource_patterns(actor_id:, issuer:, permission_name:)
132
+ actor = Protos::Actor.new(id: actor_id, issuer: issuer)
133
+ request = Protos::ListResourcePatternsRequest.new(
134
+ actor: actor,
135
+ permission_name: permission_name
136
+ )
137
+
138
+ response = grpc_permission_service.list_resource_patterns(request)
139
+
140
+ response.resource_patterns
141
+ rescue GRPC::BadStatus => e
142
+ raise Errors.from_grpc_error(e)
143
+ end
144
+
145
+ private
146
+
147
+ attr_reader :url, :trusted_cas, :timeout
148
+
149
+ def tls_credentials
150
+ @tls_credentials ||= GRPC::Core::ChannelCredentials.new(trusted_cas.join("\n"))
151
+ end
152
+
153
+ def grpc_role_service
154
+ @grpc_role_service ||= Protos::RoleService::Stub.new(url, tls_credentials, timeout: timeout)
155
+ end
156
+
157
+ def grpc_permission_service
158
+ @grpc_permission_service ||= Protos::PermissionService::Stub.new(url, tls_credentials, timeout: timeout)
159
+ end
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudFoundry
4
+ module Perm
5
+ module V1
6
+ module Errors
7
+ def self.from_grpc_error(e)
8
+ case e
9
+ when GRPC::AlreadyExists
10
+ AlreadyExists.new(e.code, e.details, e.metadata)
11
+ when GRPC::NotFound
12
+ NotFound.new(e.code, e.details, e.metadata)
13
+ when GRPC::BadStatus
14
+ BadStatus.new(e.code, e.details, e.metadata)
15
+ else
16
+ e
17
+ end
18
+ end
19
+
20
+ class StandardError < ::StandardError; end
21
+
22
+ class InvalidCertificateAuthorities < StandardError; end
23
+
24
+ class BadStatus < StandardError
25
+ attr_reader :code, :details, :metadata
26
+
27
+ def initialize(code, details = 'unknown cause', metadata = {})
28
+ super("#{code}:#{details}")
29
+ @code = code
30
+ @details = details
31
+ @metadata = metadata
32
+ end
33
+ end
34
+
35
+ class AlreadyExists < BadStatus; end
36
+ class NotFound < BadStatus; end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'perm/v1/models/base'
4
+ require 'perm/v1/models/role'
5
+ require 'perm/v1/models/permission'
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudFoundry
4
+ module Perm
5
+ module V1
6
+ module Models
7
+ class BaseModel
8
+ # Based on https://stackoverflow.com/a/25606643
9
+ def ==(other)
10
+ self.class == other.class && instance_variables.all? do |v|
11
+ instance_variable_get(v) == other.instance_variable_get(v)
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudFoundry
4
+ module Perm
5
+ module V1
6
+ module Models
7
+ class Permission < BaseModel
8
+ attr_reader :name, :resource_pattern
9
+
10
+ def initialize(name:, resource_pattern:)
11
+ @name = name
12
+ @resource_pattern = resource_pattern
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudFoundry
4
+ module Perm
5
+ module V1
6
+ module Models
7
+ class Role < BaseModel
8
+ attr_reader :name
9
+
10
+ def initialize(name:)
11
+ @name = name
12
+ end
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CloudFoundry
4
+ module Perm
5
+ VERSION = '0.0.0'
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cf-perm
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - CloudFoundry Permissions Team
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-04 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: grpc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 3.6.0
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 3.6.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: rubocop
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.50.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.50.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12'
69
+ - !ruby/object:Gem::Dependency
70
+ name: cf-perm-test-helpers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - LICENSE
90
+ - NOTICE
91
+ - README.md
92
+ - lib/perm.rb
93
+ - lib/perm/protos.rb
94
+ - lib/perm/protos/actor_pb.rb
95
+ - lib/perm/protos/permission_pb.rb
96
+ - lib/perm/protos/permission_service_pb.rb
97
+ - lib/perm/protos/permission_service_services_pb.rb
98
+ - lib/perm/protos/role_pb.rb
99
+ - lib/perm/protos/role_service_pb.rb
100
+ - lib/perm/protos/role_service_services_pb.rb
101
+ - lib/perm/v1.rb
102
+ - lib/perm/v1/client.rb
103
+ - lib/perm/v1/errors.rb
104
+ - lib/perm/v1/models.rb
105
+ - lib/perm/v1/models/base.rb
106
+ - lib/perm/v1/models/permission.rb
107
+ - lib/perm/v1/models/role.rb
108
+ - lib/perm/version.rb
109
+ homepage:
110
+ licenses:
111
+ - Apache-2.0
112
+ metadata: {}
113
+ post_install_message:
114
+ rdoc_options: []
115
+ require_paths:
116
+ - lib
117
+ - lib/perm/protos
118
+ required_ruby_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ required_rubygems_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ requirements: []
129
+ rubyforge_project:
130
+ rubygems_version: 2.6.13
131
+ signing_key:
132
+ specification_version: 4
133
+ summary: Ruby client for CloudFoundry Permissions
134
+ test_files: []