harbor_client.UserApi

All URIs are relative to http://localhost/api/v2.0

MethodHTTP requestDescription
create_userPOST /usersCreate a local user.
delete_userDELETE /users/{user_id}Mark a registered user as be removed.
get_current_user_infoGET /users/currentGet current user info.
get_current_user_permissionsGET /users/current/permissionsGet current user permissions.
get_userGET /users/{user_id}Get a user's profile.
list_usersGET /usersList users
search_usersGET /users/searchSearch users by username
set_cli_secretPUT /users/{user_id}/cli_secretSet CLI secret for a user.
set_user_sys_adminPUT /users/{user_id}/sysadminUpdate a registered user to change to be an administrator of Harbor.
update_user_passwordPUT /users/{user_id}/passwordChange the password on a user that already exists.
update_user_profilePUT /users/{user_id}Update user's profile.

create_user

Signature

create_user(user_req: UserCreationReq, x_request_id: Optional[str])-> None

Create a local user.

This API can be used only when the authentication mode is for local DB. When self registration is disabled.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
user_req = harbor_client.UserCreationReq() # UserCreationReq | The new user
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Create a local user.
    api_instance.create_user(user_req, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling UserApi->create_user: %s\n" % e)

Parameters

NameTypeDescriptionNotes
user_reqUserCreationReqThe new user
x_request_idstrAn unique ID for the request[optional]

Return type

void (empty response body)

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

delete_user

Signature

delete_user(user_id: int, x_request_id: Optional[str])-> None

Mark a registered user as be removed.

This endpoint let administrator of Harbor mark a registered user as removed.It actually won’t be deleted from DB.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
user_id = 56 # int | User ID for marking as to be removed.
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Mark a registered user as be removed.
    api_instance.delete_user(user_id, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling UserApi->delete_user: %s\n" % e)

Parameters

NameTypeDescriptionNotes
user_idintUser ID for marking as to be removed.
x_request_idstrAn unique ID for the request[optional]

Return type

void (empty response body)

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

get_current_user_info

Signature

get_current_user_info(x_request_id: Optional[str])-> UserResp

Get current user info.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Get current user info.
    api_response = api_instance.get_current_user_info(x_request_id=x_request_id)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UserApi->get_current_user_info: %s\n" % e)

Parameters

NameTypeDescriptionNotes
x_request_idstrAn unique ID for the request[optional]

Return type

UserResp

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

get_current_user_permissions

Signature

get_current_user_permissions(x_request_id: Optional[str], scope: Optional[str], relative: Optional[bool])-> list[Permission]

Get current user permissions.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)
scope = 'scope_example' # str | The scope for the permission (optional)
relative = true # bool | If true, the resources in the response are relative to the scope, eg for resource '/project/1/repository' if relative is 'true' then the resource in response will be 'repository'.  (optional)

try:
    # Get current user permissions.
    api_response = api_instance.get_current_user_permissions(x_request_id=x_request_id, scope=scope, relative=relative)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UserApi->get_current_user_permissions: %s\n" % e)

Parameters

NameTypeDescriptionNotes
x_request_idstrAn unique ID for the request[optional]
scopestrThe scope for the permission[optional]
relativeboolIf true, the resources in the response are relative to the scope, eg for resource '/project/1/repository' if relative is 'true' then the resource in response will be 'repository'.[optional]

Return type

list[Permission]

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

get_user

Signature

get_user(user_id: int, x_request_id: Optional[str])-> UserResp

Get a user’s profile.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
user_id = 56 # int | 
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Get a user's profile.
    api_response = api_instance.get_user(user_id, x_request_id=x_request_id)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UserApi->get_user: %s\n" % e)

Parameters

NameTypeDescriptionNotes
user_idint
x_request_idstrAn unique ID for the request[optional]

Return type

UserResp

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

list_users

Signature

list_users(x_request_id: Optional[str], q: Optional[str], sort: Optional[str], page: Optional[int], page_size: Optional[int])-> list[UserResp]

List users

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)
q = 'q_example' # str | Query string to query resources. Supported query patterns are \"exact match(k=v)\", \"fuzzy match(k=~v)\", \"range(k=[min~max])\", \"list with union releationship(k={v1 v2 v3})\" and \"list with intersetion relationship(k=(v1 v2 v3))\". The value of range and list can be string(enclosed by \" or '), integer or time(in format \"2020-04-09 02:36:00\"). All of these query patterns should be put in the query string \"q=xxx\" and splitted by \",\". e.g. q=k1=v1,k2=~v2,k3=[min~max] (optional)
sort = 'sort_example' # str | Sort the resource list in ascending or descending order. e.g. sort by field1 in ascending orderr and field2 in descending order with \"sort=field1,-field2\" (optional)
page = 1 # int | The page number (optional) (default to 1)
page_size = 10 # int | The size of per page (optional) (default to 10)

try:
    # List users
    api_response = api_instance.list_users(x_request_id=x_request_id, q=q, sort=sort, page=page, page_size=page_size)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UserApi->list_users: %s\n" % e)

Parameters

NameTypeDescriptionNotes
x_request_idstrAn unique ID for the request[optional]
qstrQuery string to query resources. Supported query patterns are "exact match(k=v)", "fuzzy match(k=~v)", "range(k=[min~max])", "list with union releationship(k={v1 v2 v3})" and "list with intersetion relationship(k=(v1 v2 v3))". The value of range and list can be string(enclosed by " or '), integer or time(in format "2020-04-09 02:36:00"). All of these query patterns should be put in the query string "q=xxx" and splitted by ",". e.g. q=k1=v1,k2=~v2,k3=[min~max][optional]
sortstrSort the resource list in ascending or descending order. e.g. sort by field1 in ascending orderr and field2 in descending order with "sort=field1,-field2"[optional]
pageintThe page number[optional] [default to 1]
page_sizeintThe size of per page[optional] [default to 10]

Return type

list[UserResp]

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

search_users

Signature

search_users(username: str, x_request_id: Optional[str], page: Optional[int], page_size: Optional[int])-> list[UserSearchRespItem]

Search users by username

This endpoint is to search the users by username. It’s open for all authenticated requests.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
username = 'username_example' # str | Username for filtering results.
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)
page = 1 # int | The page number (optional) (default to 1)
page_size = 10 # int | The size of per page (optional) (default to 10)

try:
    # Search users by username
    api_response = api_instance.search_users(username, x_request_id=x_request_id, page=page, page_size=page_size)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling UserApi->search_users: %s\n" % e)

Parameters

NameTypeDescriptionNotes
usernamestrUsername for filtering results.
x_request_idstrAn unique ID for the request[optional]
pageintThe page number[optional] [default to 1]
page_sizeintThe size of per page[optional] [default to 10]

Return type

list[UserSearchRespItem]

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

set_cli_secret

Signature

set_cli_secret(user_id: int, secret: OIDCCliSecretReq, x_request_id: Optional[str])-> None

Set CLI secret for a user.

This endpoint let user generate a new CLI secret for himself. This API only works when auth mode is set to ‘OIDC’. Once this API returns with successful status, the old secret will be invalid, as there will be only one CLI secret for a user.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
user_id = 56 # int | User ID
secret = harbor_client.OIDCCliSecretReq() # OIDCCliSecretReq | 
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Set CLI secret for a user.
    api_instance.set_cli_secret(user_id, secret, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling UserApi->set_cli_secret: %s\n" % e)

Parameters

NameTypeDescriptionNotes
user_idintUser ID
secretOIDCCliSecretReq
x_request_idstrAn unique ID for the request[optional]

Return type

void (empty response body)

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

set_user_sys_admin

Signature

set_user_sys_admin(user_id: int, sysadmin_flag: UserSysAdminFlag, x_request_id: Optional[str])-> None

Update a registered user to change to be an administrator of Harbor.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
user_id = 56 # int | 
sysadmin_flag = harbor_client.UserSysAdminFlag() # UserSysAdminFlag | Toggle a user to admin or not.
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Update a registered user to change to be an administrator of Harbor.
    api_instance.set_user_sys_admin(user_id, sysadmin_flag, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling UserApi->set_user_sys_admin: %s\n" % e)

Parameters

NameTypeDescriptionNotes
user_idint
sysadmin_flagUserSysAdminFlagToggle a user to admin or not.
x_request_idstrAn unique ID for the request[optional]

Return type

void (empty response body)

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

update_user_password

Signature

update_user_password(user_id: int, password: PasswordReq, x_request_id: Optional[str])-> None

Change the password on a user that already exists.

This endpoint is for user to update password. Users with the admin role can change any user’s password. Regular users can change only their own password.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
user_id = 56 # int | 
password = harbor_client.PasswordReq() # PasswordReq | Password to be updated, the attribute 'old_password' is optional when the API is called by the system administrator.
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Change the password on a user that already exists.
    api_instance.update_user_password(user_id, password, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling UserApi->update_user_password: %s\n" % e)

Parameters

NameTypeDescriptionNotes
user_idint
passwordPasswordReqPassword to be updated, the attribute 'old_password' is optional when the API is called by the system administrator.
x_request_idstrAn unique ID for the request[optional]

Return type

void (empty response body)

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]

update_user_profile

Signature

update_user_profile(user_id: int, profile: UserProfile, x_request_id: Optional[str])-> None

Update user’s profile.

Example

from __future__ import print_function
import time
import harbor_client
from harbor_client.rest import ApiException
from pprint import pprint

# Configure HTTP basic authorization: basic
configuration = harbor_client.Configuration()
configuration.username = 'YOUR_USERNAME'
configuration.password = 'YOUR_PASSWORD'

# create an instance of the API class
api_instance = harbor_client.UserApi(harbor_client.ApiClient(configuration))
user_id = 56 # int | Registered user ID
profile = harbor_client.UserProfile() # UserProfile | Only email, realname and comment can be modified.
x_request_id = 'x_request_id_example' # str | An unique ID for the request (optional)

try:
    # Update user's profile.
    api_instance.update_user_profile(user_id, profile, x_request_id=x_request_id)
except ApiException as e:
    print("Exception when calling UserApi->update_user_profile: %s\n" % e)

Parameters

NameTypeDescriptionNotes
user_idintRegistered user ID
profileUserProfileOnly email, realname and comment can be modified.
x_request_idstrAn unique ID for the request[optional]

Return type

void (empty response body)

Authorization

basic

HTTP request headers

  • Content-Type: application/json
  • Accept: application/json

[Back to top]