|
26 | 26 | print(f"Created tenants: [{tenant1.id}, {tenant2.id}]") |
27 | 27 | tenant1.assign_user(user1.id) |
28 | 28 | print(f"Assigned user [{user1.id}] to tenant [{tenant1.id}]") |
29 | | -tenant2.assign_user(user2.id) |
30 | | -print(f"Assigned user [{user2.id}] to tenant [{tenant2.id}]") |
| 29 | +user2_subject = warrant.Subject("user", user2.id) |
| 30 | +warrant.Warrant.create("tenant", tenant1.id, "admin", user2_subject) |
| 31 | +print(f"Assigned user [{user2.id}] as admin to tenant [{tenant2.id}]") |
31 | 32 | tenant1_users = "" |
32 | 33 | for u in tenant1.list_users(): |
33 | 34 | tenant1_users += u.id + " " |
|
143 | 144 | """ |
144 | 145 | # Generate a self-service dashboard url for user2 |
145 | 146 | print("---------- FE & Self-service Authz Tokens ----------") |
146 | | -user2.assign_permission("view-self-service-dashboard") |
147 | | -print("Created self service dashboard url for user [" + user2.id + "]: " + warrant.Authz.create_self_service_url(tenant_id=tenant1.id, user_id=user2.id, redirect_url="http://example.com")) |
| 147 | +print("Created self service dashboard url for user [" + user2.id + "]: " + |
| 148 | + warrant.Authz.create_self_service_url(tenant_id=tenant1.id, user_id=user2.id, self_service_strategy="rbac", redirect_url="http://example.com")) |
148 | 149 |
|
149 | 150 | # Authz sessions |
150 | 151 | print("Created authorization session token for user [" + user1.id + "]: " + warrant.Authz.create_authorization_session(user_id=user1.id)) |
|
156 | 157 | Create and query your own warrants |
157 | 158 | """ |
158 | 159 | print("---------- Create & Query Warrants ----------") |
| 160 | +permission1 = warrant.Permission.create(id="permission1") |
159 | 161 | user1_subject = warrant.Subject("user", user1.id) |
160 | | -result = warrant.Authz.check("permission", "view-self-service-dashboard", "member", user1_subject) |
161 | | -print(f"Does [{user1.id}] have the [view-self-service-dashboard] permission? (should be false) -> {result}") |
162 | | -warrant.Warrant.create("permission", "view-self-service-dashboard", "member", user1_subject) |
163 | | -print("Manually assigned [view-self-service-dashboard] permission to [" + user1.id + "]") |
164 | | -result = warrant.Authz.check("permission", "view-self-service-dashboard", "member", user1_subject) |
165 | | -print(f"Does [{user1.id}] have the [view-self-service-dashboard] permission? (should be true) -> {result}") |
| 162 | +result = warrant.Authz.check("permission", "permission1", "member", user1_subject) |
| 163 | +print(f"Does [{user1.id}] have the [permission1] permission? (should be false) -> {result}") |
| 164 | +warrant.Warrant.create("permission", "permission1", "member", user1_subject) |
| 165 | +print("Manually assigned [permission1] permission to [" + user1.id + "]") |
| 166 | +result = warrant.Authz.check("permission", "permission1", "member", user1_subject) |
| 167 | +print(f"Does [{user1.id}] have the [permission1] permission? (should be true) -> {result}") |
166 | 168 |
|
167 | 169 | # Query warrants |
168 | | -warrants = warrant.Warrant.query(select="explicit warrants", for_clause="subject=user:"+user1.id, where="relation=member") |
169 | | -print("Query warrants results:") |
170 | | -for w in warrants: |
171 | | - print(f"[{w.object_type}:{w.object_id} {w.relation} {w.subject.object_type}:{w.subject.object_id}]") |
172 | | - |
173 | | -warrant.Warrant.delete("permission", "view-self-service-dashboard", "member", user1_subject) |
174 | | -print("Manually removed [view-self-service-dashboard] permission from [" + user1.id + "]") |
175 | | -result = warrant.Authz.check("permission", "view-self-service-dashboard", "member", user1_subject) |
176 | | -print(f"Does [{user1.id}] have the [view-self-service-dashboard] permission? (should be false) -> {result}") |
| 170 | +# warrants = warrant.Warrant.query(select="explicit warrants", for_clause="subject=user:"+user1.id, where="relation=member") |
| 171 | +# print("Query warrants results:") |
| 172 | +# for w in warrants: |
| 173 | +# print(f"[{w.object_type}:{w.object_id} {w.relation} {w.subject.object_type}:{w.subject.object_id}]") |
| 174 | + |
| 175 | +warrant.Warrant.delete("permission", "permission1", "member", user1_subject) |
| 176 | +print("Manually removed [permission1] permission from [" + user1.id + "]") |
| 177 | +result = warrant.Authz.check("permission", "permission1", "member", user1_subject) |
| 178 | +print(f"Does [{user1.id}] have the [permission1] permission? (should be false) -> {result}") |
177 | 179 | print("\n") |
178 | 180 |
|
179 | 181 |
|
|
185 | 187 | user1.remove_permission(special_perm.id) |
186 | 188 | user1.remove_role(admin_role.id) |
187 | 189 | user2.remove_role(viewer_role.id) |
188 | | -user2.remove_permission("view-self-service-dashboard") |
189 | 190 | admin_role.remove_permission(create_report_perm.id) |
190 | 191 | admin_role.remove_permission(delete_report_perm.id) |
191 | 192 | admin_role.remove_permission(view_report_perm.id) |
192 | 193 | viewer_role.remove_permission(view_report_perm.id) |
193 | 194 | tenant1.remove_user(user1.id) |
194 | | -tenant2.remove_user(user2.id) |
| 195 | +warrant.Warrant.delete("tenant", tenant1.id, "admin", user2_subject) |
195 | 196 | enterprise_tier.remove_feature(analytics_feature.id) |
196 | 197 | free_tier.remove_feature(dashboard_feature.id) |
197 | 198 |
|
|
205 | 206 | warrant.Permission.delete(delete_report_perm.id) |
206 | 207 | warrant.Permission.delete(view_report_perm.id) |
207 | 208 | warrant.Permission.delete(special_perm.id) |
| 209 | +warrant.Permission.delete(permission1.id) |
208 | 210 | warrant.Feature.delete(analytics_feature.id) |
209 | 211 | warrant.Feature.delete(dashboard_feature.id) |
210 | 212 | warrant.PricingTier.delete(enterprise_tier.id) |
|
0 commit comments