@@ -301,24 +301,41 @@ created with a random display name and assigned to the workspace with the defaul
301301Use the ` account_groups ` argument to assign the service principal to account groups, which have the required
302302permissions to perform a specific action.
303303
304+ Example:
305+
306+ ``` python
307+ def test_run_as_lower_privilege_user (make_run_as , ws ):
308+ run_as = make_run_as(account_groups = [' account.group.name' ])
309+ through_query = next (run_as.sql_fetch_all(" SELECT CURRENT_USER() AS my_name" ))
310+ me = ws.current_user.me()
311+ assert me.user_name != through_query.my_name
312+ ```
313+
304314Returned object has the following properties:
305315* ` ws ` : Workspace client that is authenticated as the ephemeral service principal.
306316* ` sql_backend ` : SQL backend that is authenticated as the ephemeral service principal.
307317* ` sql_exec ` : Function to execute a SQL statement on behalf of the ephemeral service principal.
308318* ` sql_fetch_all ` : Function to fetch all rows from a SQL statement on behalf of the ephemeral service principal.
309319* ` display_name ` : Display name of the ephemeral service principal.
310320* ` application_id ` : Application ID of the ephemeral service principal.
311- * ... other fixtures are not currently available through the returned object yet, as it's quite complex to
312- implement, but there's a possibility to add generic support for them in the future.
321+ * if you want to have other fixtures available in the context of the ephemeral service principal, you can override
322+ the [ ` ws ` fixture] ( #ws-fixture ) on the file level, which would make all workspace fixtures provided by this
323+ plugin to run as lower privilege ephemeral service principal. You cannot combine it with the account-admin-level
324+ principal you're using to create the ephemeral principal.
313325
314326Example:
315327
316328``` python
317- def test_run_as_lower_privilege_user (make_run_as , ws ):
318- run_as = make_run_as(account_groups = [' account.group.name' ])
319- through_query = next (run_as.sql_fetch_all(" SELECT CURRENT_USER() AS my_name" ))
320- me = ws.current_user.me()
321- assert me.user_name != through_query.my_name
329+ from pytest import fixture
330+
331+ @fixture
332+ def ws (make_run_as ):
333+ run_as = make_run_as(account_groups = [' account.group.used.for.all.tests.in.this.file' ])
334+ return run_as.ws
335+
336+ def test_creating_notebook_on_behalf_of_ephemeral_principal (make_notebook ):
337+ notebook = make_notebook()
338+ assert notebook.exists()
322339```
323340
324341See also [ ` acc ` ] ( #acc-fixture ) , [ ` ws ` ] ( #ws-fixture ) , [ ` make_random ` ] ( #make_random-fixture ) , [ ` env_or_skip ` ] ( #env_or_skip-fixture ) , [ ` log_account_link ` ] ( #log_account_link-fixture ) .
0 commit comments