snowflake.core.user.UserResourceΒΆ
- class snowflake.core.user.UserResource(name: str, collection: UserCollection)ΒΆ
Bases:
ObjectReferenceMixin
[UserCollection
]Represents a reference to a Snowflake user.
With this user reference, you can create or alter, delete and fetch information about users, as well as perform certain actions on them.
Attributes
- rootΒΆ
Methods
- create_or_alter(user: UserModel) None ΒΆ
Create a user in Snowflake or alter one if it already exists.
- Parameters:
user (User) β The
User
object, together with theUser
βs properties: name; password, login_name, display_name, first_name, middle_name, last_name, email, must_change_password, disabled, days_to_expiry, mins_to_unlock, default_warehouse, default_namespace, default_role, default_secondary_roles, mins_to_bypass_mfa, rsa_public_key, rsa_public_key_fp, rsa_public_key_2, rsa_public_key_2_fp, comment, type, enable_unredacted_query_syntax_error, network_policy are optional
Examples
Creating a user or altering one if it already exists:
>>> user_parameters = User( ... name="User1", ... first_name="Snowy", ... last_name="User", ... must_change_password=False ...) >>> user_reference.create_or_alter(user_parameters)
- delete() None ΒΆ
The delete method is deprecated; use drop instead.
- drop(if_exists: bool | None = None) None ΒΆ
Drop this user.
- Parameters:
if_exists (bool, optional) β Check the existence of this user before dropping it. Default is
None
, which is equivalent toFalse
.
Examples
Deleting a user using its reference:
>>> user_ref.drop()
Deleting a user using its reference if it exists:
>>> user_ref.drop(if_exists=True)
- fetch() UserModel ΒΆ
Fetch the details of a user.
Examples
Fetching a reference to a user to print its informations:
>>> user_ref = root.users["test_user"].fetch() >>> print(user_ref.name, user_ref.first_name)
- grant_role(role_type: str, role: Securable) None ΒΆ
Grant a role to this user.
- Parameters:
role_type (str) β The type of role which would be granted.
role (Securable) β The role which would be granted.
Examples
Using a user reference to grant a role to it:
>>> user_reference.grant_role("role", Securable(name="test_role"))
- iter_grants_to() Iterator[Grant] ΒΆ
List grants to this user.
Lists all roles granted to the user.
Examples
Using a user reference to list grants to it:
>>> user_reference.iter_grants_to()
- revoke_role(role_type: str, role: Securable) None ΒΆ
Revoke a role from this user.
- Parameters:
role_type (str) β The type of role which would be revoked.
role (Securable) β The role which would be revoked.
Examples
Using a user reference to revoke a role from it:
>>> user_reference.revoke_role("role", Securable(name="test_role"))