Skip to content

Users

get_user(user_id) async

Get information about a user.

Parameters:

Name Type Description Default
user_id int

The ID of the user to get information about

required

Returns:

Type Description
UserResp

Information about the user.

get_user_by_username(username) async

Get information about a user by username.

This is a convenience method for searching for a user by username and then getting the full user information with its ID.

See:

Parameters:

Name Type Description Default
username str

The username of the user to get information about

required

Returns:

Type Description
UserResp

Information about the user.

create_user(user) async

Create a new user. Can only be used when the authentication mode is for local DB, when self registration is disabled.

Parameters:

Name Type Description Default
user UserCreationReq

The user to create

required

Returns:

Type Description
str

The location of the created user

update_user(user_id, user) async

Update a user's profile.

Parameters:

Name Type Description Default
user_id int

The ID of the user to update

required
user UserProfile

The user profile to update

required

delete_user(user_id, missing_ok=None) async

Delete a user.

Parameters:

Name Type Description Default
user_id int

The ID of the user to delete

required
missing_ok Optional[bool]

DEPRECATED: Do not raise an error if the user does not exist.

None

get_users(query=None, sort=None, page=1, page_size=10, limit=None) async

Get all users.

Parameters:

Name Type Description Default
query Optional[str]

Query string to filter the users.

Supported query patterns are:

* exact match(`"k=v"`)
* fuzzy match(`"k=~v"`)
* range(`"k=[min~max]"`)
* list with union releationship(`"k={v1 v2 v3}"`)
* list with intersection relationship(`"k=(v1 v2 v3)"`).

The value of range and list can be:

* string(enclosed by `"` or `'`)
* integer
* time(in format `"2020-04-09 02:36:00"`)

All of these query patterns should be put in the query string and separated by ",". e.g. "k1=v1,k2=~v2,k3=[min~max]"

None
sort Optional[str]

Comma-separated string of fields to sort by. Prefix with - to sort descending. E.g. "username,-email"

None
page int

The page number to retrieve

1
page_size int

The number of users to retrieve per page

10
limit Optional[int]

The maximum number of users to retrieve.

None

Returns:

Type Description
List[UserResp]

A list of users.

search_users_by_username(username, page=1, page_size=100, limit=None, **kwargs) async

Search for users by username.

Parameters:

Name Type Description Default
username str

The username to search for

required
page int

The page of results to return

1
page_size int

The number of results to return per page

100
limit Optional[int]

The maximum number of results to return.

None

set_user_admin(user_id, is_admin) async

Set a user's admin status.

Parameters:

Name Type Description Default
user_id int

The ID of the user to set the admin status for

required
is_admin bool

Whether the user should be an admin or not

required

set_user_password(user_id, new_password, old_password=None) async

Set a user's password. Admin users can change any user's password. Non-admin users can only change their own password.

Parameters:

Name Type Description Default
user_id int

The ID of the user to set the password for

required
new_password str

The new password to set for the user

required
old_password str

The old password for the user, not required if API user is admin.

None

Raises:

Type Description
BadRequest

Raised for any of the following reasons:

* Invalid user ID
* Password does not meet requirement
* Old password is incorrect

set_user_cli_secret(user_id, secret) async

Set the CLI secret for a user.

Parameters:

Name Type Description Default
user_id int

The ID of the user to set the secret for

required
secret str

The secret to set for the user

required

Raises:

Type Description
BadRequest

Invalid user ID. Or user is not onboarded via OIDC authentication. Or the secret does not meet the standard. (This is a Harbor API implementation detail.)

get_current_user() async

Get information about the current user.

Returns:

Type Description
UserResp

Information about the current user.

get_current_user_permissions(scope=None, relative=False) async

Get current user permissions.

Parameters:

Name Type Description Default
scope Optional[str]

The scope for the permission

None
relative bool

Display resource paths relative to the scope. Has no effect if scope is not specified

False

Returns:

Type Description
List[Permission]

A list of Permission objects for the current user.