refactor: use singular as the tag for user APIs (#14654)

Use singular as the tag for user APIs to align with other APIs.

Signed-off-by: He Weiwei <hweiwei@vmware.com>
This commit is contained in:
He Weiwei 2021-04-15 10:52:48 +08:00 committed by GitHub
parent e6b2abfebb
commit dc37c83e11
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 60 additions and 60 deletions

View File

@ -297,7 +297,7 @@ endif
SWAGGER_IMAGENAME=goharbor/swagger SWAGGER_IMAGENAME=goharbor/swagger
SWAGGER_VERSION=v0.21.0 SWAGGER_VERSION=v0.21.0
SWAGGER=$(DOCKERCMD) run --rm -u $(shell id -u):$(shell id -g) -v $(BUILDPATH):$(BUILDPATH) -w $(BUILDPATH) ${SWAGGER_IMAGENAME}:${SWAGGER_VERSION} SWAGGER=$(DOCKERCMD) run --rm -u $(shell id -u):$(shell id -g) -v $(BUILDPATH):$(BUILDPATH) -w $(BUILDPATH) ${SWAGGER_IMAGENAME}:${SWAGGER_VERSION}
SWAGGER_GENERATE_SERVER=${SWAGGER} generate server --template-dir=$(TOOLSPATH)/swagger/templates --exclude-main --additional-initialism=CVE --additional-initialism=GC SWAGGER_GENERATE_SERVER=${SWAGGER} generate server --template-dir=$(TOOLSPATH)/swagger/templates --exclude-main --additional-initialism=CVE --additional-initialism=GC --additional-initialism=OIDC
SWAGGER_IMAGE_BUILD_CMD=${DOCKERBUILD} -f ${TOOLSPATH}/swagger/Dockerfile --build-arg SWAGGER_VERSION=${SWAGGER_VERSION} -t ${SWAGGER_IMAGENAME}:$(SWAGGER_VERSION) . SWAGGER_IMAGE_BUILD_CMD=${DOCKERBUILD} -f ${TOOLSPATH}/swagger/Dockerfile --build-arg SWAGGER_VERSION=${SWAGGER_VERSION} -t ${SWAGGER_IMAGENAME}:$(SWAGGER_VERSION) .
SWAGGER_IMAGENAME: SWAGGER_IMAGENAME:

View File

@ -182,7 +182,7 @@ paths:
'403': '403':
description: User does not have permission of admin role. description: User does not have permission of admin role.
'500': '500':
description: Unexpected internal errors. description: Unexpected internal errors.
/configurations: /configurations:
get: get:
summary: Get system configurations. summary: Get system configurations.
@ -191,7 +191,7 @@ paths:
tags: tags:
- configure - configure
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
responses: responses:
'200': '200':
description: Get system configurations successfully. The response body is a map. description: Get system configurations successfully. The response body is a map.
@ -455,7 +455,7 @@ paths:
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName' - $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId' - $ref: '#/parameters/projectNameOrId'
- $ref: '#/parameters/page' - $ref: '#/parameters/page'
- $ref: '#/parameters/pageSize' - $ref: '#/parameters/pageSize'
- name: entityname - name: entityname
@ -473,12 +473,12 @@ paths:
type: integer type: integer
Link: Link:
description: Link refers to the previous page and next page description: Link refers to the previous page and next page
type: string type: string
schema: schema:
type: array type: array
items: items:
$ref: '#/definitions/ProjectMemberEntity' $ref: '#/definitions/ProjectMemberEntity'
'400': '400':
$ref: '#/responses/400' $ref: '#/responses/400'
'401': '401':
@ -498,7 +498,7 @@ paths:
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName' - $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId' - $ref: '#/parameters/projectNameOrId'
- name: project_member - name: project_member
in: body in: body
schema: schema:
@ -530,7 +530,7 @@ paths:
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName' - $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId' - $ref: '#/parameters/projectNameOrId'
- name: mid - name: mid
in: path in: path
type: integer type: integer
@ -561,7 +561,7 @@ paths:
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName' - $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId' - $ref: '#/parameters/projectNameOrId'
- name: mid - name: mid
in: path in: path
type: integer type: integer
@ -593,7 +593,7 @@ paths:
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
- $ref: '#/parameters/isResourceName' - $ref: '#/parameters/isResourceName'
- $ref: '#/parameters/projectNameOrId' - $ref: '#/parameters/projectNameOrId'
- name: mid - name: mid
in: path in: path
type: integer type: integer
@ -610,7 +610,7 @@ paths:
'403': '403':
$ref: '#/responses/403' $ref: '#/responses/403'
'500': '500':
$ref: '#/responses/500' $ref: '#/responses/500'
/repositories: /repositories:
get: get:
summary: List all authorized repositories summary: List all authorized repositories
@ -4485,7 +4485,7 @@ paths:
get: get:
summary: List users summary: List users
tags: tags:
- users - user
operationId: listUsers operationId: listUsers
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
@ -4517,7 +4517,7 @@ paths:
summary: Create a local user. summary: Create a local user.
description: This API can be used only when the authentication mode is for local DB. When self registration is disabled. description: This API can be used only when the authentication mode is for local DB. When self registration is disabled.
tags: tags:
- users - user
operationId: createUser operationId: createUser
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
@ -4544,7 +4544,7 @@ paths:
get: get:
summary: Get current user info. summary: Get current user info.
tags: tags:
- users - user
operationId: getCurrentUserInfo operationId: getCurrentUserInfo
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
@ -4563,7 +4563,7 @@ paths:
description: | description: |
This endpoint is to search the users by username. It's open for all authenticated requests. This endpoint is to search the users by username. It's open for all authenticated requests.
tags: tags:
- users - user
operationId: searchUsers operationId: searchUsers
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
@ -4603,7 +4603,7 @@ paths:
format: int format: int
required: true required: true
tags: tags:
- users - user
operationId: getUser operationId: getUser
responses: responses:
'200': '200':
@ -4635,7 +4635,7 @@ paths:
schema: schema:
$ref: '#/definitions/UserProfile' $ref: '#/definitions/UserProfile'
tags: tags:
- users - user
operationId: updateUserProfile operationId: updateUserProfile
responses: responses:
'200': '200':
@ -4660,7 +4660,7 @@ paths:
required: true required: true
description: User ID for marking as to be removed. description: User ID for marking as to be removed.
tags: tags:
- users - user
operationId: deleteUser operationId: deleteUser
responses: responses:
'200': '200':
@ -4677,7 +4677,7 @@ paths:
put: put:
summary: Update a registered user to change to be an administrator of Harbor. summary: Update a registered user to change to be an administrator of Harbor.
tags: tags:
- users - user
operationId: setUserSysAdmin operationId: setUserSysAdmin
parameters: parameters:
- name: user_id - name: user_id
@ -4708,7 +4708,7 @@ paths:
description: | description: |
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. 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.
tags: tags:
- users - user
operationId: updateUserPassword operationId: updateUserPassword
parameters: parameters:
- name: user_id - name: user_id
@ -4737,7 +4737,7 @@ paths:
get: get:
summary: Get current user permissions. summary: Get current user permissions.
tags: tags:
- users - user
operationId: getCurrentUserPermissions operationId: getCurrentUserPermissions
parameters: parameters:
- name: scope - name: scope
@ -4771,7 +4771,7 @@ paths:
Once this API returns with successful status, the old secret will be invalid, as there will be only one CLI secret Once this API returns with successful status, the old secret will be invalid, as there will be only one CLI secret
for a user. for a user.
tags: tags:
- users - user
operationId: setCliSecret operationId: setCliSecret
parameters: parameters:
- $ref: '#/parameters/requestId' - $ref: '#/parameters/requestId'
@ -7528,7 +7528,7 @@ definitions:
description: 'The parameters of the policy, the values are dependant on the type of the policy.' description: 'The parameters of the policy, the values are dependant on the type of the policy.'
Configurations: Configurations:
type: object type: object
additionalProperties: additionalProperties:
type: object type: object
StringConfigItem: StringConfigItem:
type: object type: object

View File

@ -55,11 +55,11 @@ func New() http.Handler {
WebhookAPI: newNotificationPolicyAPI(), WebhookAPI: newNotificationPolicyAPI(),
WebhookjobAPI: newNotificationJobAPI(), WebhookjobAPI: newNotificationJobAPI(),
ImmutableAPI: newImmutableAPI(), ImmutableAPI: newImmutableAPI(),
OidcAPI: newOIDCAPI(), OIDCAPI: newOIDCAPI(),
SystemCVEAllowlistAPI: newSystemCVEAllowListAPI(), SystemCVEAllowlistAPI: newSystemCVEAllowListAPI(),
ConfigureAPI: newConfigAPI(), ConfigureAPI: newConfigAPI(),
UsergroupAPI: newUserGroupAPI(), UsergroupAPI: newUserGroupAPI(),
UsersAPI: newUsersAPI(), UserAPI: newUsersAPI(),
}) })
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View File

@ -42,7 +42,7 @@ func (u *User) ToUserResp() *svrmodels.UserResp {
UpdateTime: strfmt.DateTime(u.UpdateTime), UpdateTime: strfmt.DateTime(u.UpdateTime),
} }
if u.OIDCUserMeta != nil { if u.OIDCUserMeta != nil {
res.OidcUserMeta = &svrmodels.OIDCUserInfo{ res.OIDCUserMeta = &svrmodels.OIDCUserInfo{
ID: u.OIDCUserMeta.ID, ID: u.OIDCUserMeta.ID,
UserID: int64(u.OIDCUserMeta.UserID), UserID: int64(u.OIDCUserMeta.UserID),
Subiss: u.OIDCUserMeta.SubIss, Subiss: u.OIDCUserMeta.SubIss,

View File

@ -37,8 +37,7 @@ import (
usermodels "github.com/goharbor/harbor/src/pkg/user/models" usermodels "github.com/goharbor/harbor/src/pkg/user/models"
"github.com/goharbor/harbor/src/server/v2.0/handler/model" "github.com/goharbor/harbor/src/server/v2.0/handler/model"
"github.com/goharbor/harbor/src/server/v2.0/models" "github.com/goharbor/harbor/src/server/v2.0/models"
"github.com/goharbor/harbor/src/server/v2.0/restapi" operation "github.com/goharbor/harbor/src/server/v2.0/restapi/operations/user"
"github.com/goharbor/harbor/src/server/v2.0/restapi/operations/users"
) )
var userResource = system.NewNamespace().Resource(rbac.ResourceUser) var userResource = system.NewNamespace().Resource(rbac.ResourceUser)
@ -49,14 +48,14 @@ type usersAPI struct {
getAuth func(ctx context.Context) (string, error) // For testing getAuth func(ctx context.Context) (string, error) // For testing
} }
func newUsersAPI() restapi.UsersAPI { func newUsersAPI() *usersAPI {
return &usersAPI{ return &usersAPI{
ctl: user.Ctl, ctl: user.Ctl,
getAuth: config.AuthMode, getAuth: config.AuthMode,
} }
} }
func (u *usersAPI) SetCliSecret(ctx context.Context, params users.SetCliSecretParams) middleware.Responder { func (u *usersAPI) SetCliSecret(ctx context.Context, params operation.SetCliSecretParams) middleware.Responder {
uid := int(params.UserID) uid := int(params.UserID)
if err := u.requireForCLISecret(ctx, uid); err != nil { if err := u.requireForCLISecret(ctx, uid); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
@ -68,10 +67,10 @@ func (u *usersAPI) SetCliSecret(ctx context.Context, params users.SetCliSecretPa
log.G(ctx).Errorf("Failed to set CLI secret, error: %v", err) log.G(ctx).Errorf("Failed to set CLI secret, error: %v", err)
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
return users.NewSetCliSecretOK() return operation.NewSetCliSecretOK()
} }
func (u *usersAPI) CreateUser(ctx context.Context, params users.CreateUserParams) middleware.Responder { func (u *usersAPI) CreateUser(ctx context.Context, params operation.CreateUserParams) middleware.Responder {
if err := u.requireCreatable(ctx); err != nil { if err := u.requireCreatable(ctx); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
@ -94,11 +93,11 @@ func (u *usersAPI) CreateUser(ctx context.Context, params users.CreateUserParams
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
location := fmt.Sprintf("%s/%d", strings.TrimSuffix(params.HTTPRequest.URL.Path, "/"), uid) location := fmt.Sprintf("%s/%d", strings.TrimSuffix(params.HTTPRequest.URL.Path, "/"), uid)
return users.NewCreateUserCreated().WithLocation(location) return operation.NewCreateUserCreated().WithLocation(location)
} }
func (u *usersAPI) ListUsers(ctx context.Context, params users.ListUsersParams) middleware.Responder { func (u *usersAPI) ListUsers(ctx context.Context, params operation.ListUsersParams) middleware.Responder {
if err := u.RequireSystemAccess(ctx, rbac.ActionList, userResource); err != nil { if err := u.RequireSystemAccess(ctx, rbac.ActionList, userResource); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
@ -118,25 +117,25 @@ func (u *usersAPI) ListUsers(ctx context.Context, params users.ListUsersParams)
} }
payload := make([]*models.UserResp, 0) payload := make([]*models.UserResp, 0)
if total > 0 { if total > 0 {
ul, err := u.ctl.List(ctx, query) users, err := u.ctl.List(ctx, query)
if err != nil { if err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
payload = make([]*models.UserResp, len(ul)) payload = make([]*models.UserResp, len(users))
for i, u := range ul { for i, u := range users {
m := &model.User{ m := &model.User{
User: u, User: u,
} }
payload[i] = m.ToUserResp() payload[i] = m.ToUserResp()
} }
} }
return users.NewListUsersOK(). return operation.NewListUsersOK().
WithPayload(payload). WithPayload(payload).
WithLink(u.Links(ctx, params.HTTPRequest.URL, total, query.PageNumber, query.PageSize).String()). WithLink(u.Links(ctx, params.HTTPRequest.URL, total, query.PageNumber, query.PageSize).String()).
WithXTotalCount(total) WithXTotalCount(total)
} }
func (u *usersAPI) GetCurrentUserPermissions(ctx context.Context, params users.GetCurrentUserPermissionsParams) middleware.Responder { func (u *usersAPI) GetCurrentUserPermissions(ctx context.Context, params operation.GetCurrentUserPermissionsParams) middleware.Responder {
if err := u.RequireAuthenticated(ctx); err != nil { if err := u.RequireAuthenticated(ctx); err != nil {
u.SendError(ctx, err) u.SendError(ctx, err)
} }
@ -172,10 +171,10 @@ func (u *usersAPI) GetCurrentUserPermissions(ctx context.Context, params users.G
Action: policy.Action.String(), Action: policy.Action.String(),
}) })
} }
return users.NewGetCurrentUserPermissionsOK().WithPayload(res) return operation.NewGetCurrentUserPermissionsOK().WithPayload(res)
} }
func (u *usersAPI) DeleteUser(ctx context.Context, params users.DeleteUserParams) middleware.Responder { func (u *usersAPI) DeleteUser(ctx context.Context, params operation.DeleteUserParams) middleware.Responder {
uid := int(params.UserID) uid := int(params.UserID)
if err := u.requireDeletable(ctx, uid); err != nil { if err := u.requireDeletable(ctx, uid); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
@ -184,10 +183,10 @@ func (u *usersAPI) DeleteUser(ctx context.Context, params users.DeleteUserParams
log.G(ctx).Errorf("Failed to delete user %d, error: %v", uid, err) log.G(ctx).Errorf("Failed to delete user %d, error: %v", uid, err)
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
return users.NewDeleteUserOK() return operation.NewDeleteUserOK()
} }
func (u *usersAPI) GetCurrentUserInfo(ctx context.Context, params users.GetCurrentUserInfoParams) middleware.Responder { func (u *usersAPI) GetCurrentUserInfo(ctx context.Context, params operation.GetCurrentUserInfoParams) middleware.Responder {
if err := u.RequireAuthenticated(ctx); err != nil { if err := u.RequireAuthenticated(ctx); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
@ -201,10 +200,10 @@ func (u *usersAPI) GetCurrentUserInfo(ctx context.Context, params users.GetCurre
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
return users.NewGetCurrentUserInfoOK().WithPayload(resp) return operation.NewGetCurrentUserInfoOK().WithPayload(resp)
} }
func (u *usersAPI) GetUser(ctx context.Context, params users.GetUserParams) middleware.Responder { func (u *usersAPI) GetUser(ctx context.Context, params operation.GetUserParams) middleware.Responder {
uid := int(params.UserID) uid := int(params.UserID)
if err := u.requireReadable(ctx, uid); err != nil { if err := u.requireReadable(ctx, uid); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
@ -214,7 +213,7 @@ func (u *usersAPI) GetUser(ctx context.Context, params users.GetUserParams) midd
log.G(ctx).Errorf("Failed to get user info for ID %d, error: %v", uid, err) log.G(ctx).Errorf("Failed to get user info for ID %d, error: %v", uid, err)
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
return users.NewGetUserOK().WithPayload(resp) return operation.NewGetUserOK().WithPayload(resp)
} }
func (u *usersAPI) getUserByID(ctx context.Context, id int) (*models.UserResp, error) { func (u *usersAPI) getUserByID(ctx context.Context, id int) (*models.UserResp, error) {
@ -237,7 +236,7 @@ func (u *usersAPI) getUserByID(ctx context.Context, id int) (*models.UserResp, e
return m.ToUserResp(), nil return m.ToUserResp(), nil
} }
func (u *usersAPI) UpdateUserProfile(ctx context.Context, params users.UpdateUserProfileParams) middleware.Responder { func (u *usersAPI) UpdateUserProfile(ctx context.Context, params operation.UpdateUserProfileParams) middleware.Responder {
uid := int(params.UserID) uid := int(params.UserID)
if err := u.requireModifiable(ctx, uid); err != nil { if err := u.requireModifiable(ctx, uid); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
@ -255,10 +254,10 @@ func (u *usersAPI) UpdateUserProfile(ctx context.Context, params users.UpdateUse
log.G(ctx).Errorf("Failed to update user profile, error: %v", err) log.G(ctx).Errorf("Failed to update user profile, error: %v", err)
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
return users.NewUpdateUserProfileOK() return operation.NewUpdateUserProfileOK()
} }
func (u *usersAPI) SearchUsers(ctx context.Context, params users.SearchUsersParams) middleware.Responder { func (u *usersAPI) SearchUsers(ctx context.Context, params operation.SearchUsersParams) middleware.Responder {
if err := u.RequireAuthenticated(ctx); err != nil { if err := u.RequireAuthenticated(ctx); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
@ -272,7 +271,7 @@ func (u *usersAPI) SearchUsers(ctx context.Context, params users.SearchUsersPara
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
if total == 0 { if total == 0 {
return users.NewSearchUsersOK().WithXTotalCount(0).WithPayload([]*models.UserSearchRespItem{}) return operation.NewSearchUsersOK().WithXTotalCount(0).WithPayload([]*models.UserSearchRespItem{})
} }
l, err := u.ctl.List(ctx, query) l, err := u.ctl.List(ctx, query)
if err != nil { if err != nil {
@ -283,13 +282,13 @@ func (u *usersAPI) SearchUsers(ctx context.Context, params users.SearchUsersPara
m := &model.User{User: us} m := &model.User{User: us}
result = append(result, m.ToSearchRespItem()) result = append(result, m.ToSearchRespItem())
} }
return users.NewSearchUsersOK(). return operation.NewSearchUsersOK().
WithXTotalCount(total). WithXTotalCount(total).
WithPayload(result). WithPayload(result).
WithLink(u.Links(ctx, params.HTTPRequest.URL, total, query.PageNumber, query.PageSize).String()) WithLink(u.Links(ctx, params.HTTPRequest.URL, total, query.PageNumber, query.PageSize).String())
} }
func (u *usersAPI) UpdateUserPassword(ctx context.Context, params users.UpdateUserPasswordParams) middleware.Responder { func (u *usersAPI) UpdateUserPassword(ctx context.Context, params operation.UpdateUserPasswordParams) middleware.Responder {
uid := int(params.UserID) uid := int(params.UserID)
if err := u.requireModifiable(ctx, uid); err != nil { if err := u.requireModifiable(ctx, uid); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
@ -322,10 +321,10 @@ func (u *usersAPI) UpdateUserPassword(ctx context.Context, params users.UpdateUs
log.G(ctx).Errorf("Failed to update password, error: %v", err) log.G(ctx).Errorf("Failed to update password, error: %v", err)
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
return users.NewUpdateUserPasswordOK() return operation.NewUpdateUserPasswordOK()
} }
func (u *usersAPI) SetUserSysAdmin(ctx context.Context, params users.SetUserSysAdminParams) middleware.Responder { func (u *usersAPI) SetUserSysAdmin(ctx context.Context, params operation.SetUserSysAdminParams) middleware.Responder {
id := int(params.UserID) id := int(params.UserID)
if err := u.RequireSystemAccess(ctx, rbac.ActionUpdate, rbac.ResourceUser); err != nil { if err := u.RequireSystemAccess(ctx, rbac.ActionUpdate, rbac.ResourceUser); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
@ -333,7 +332,7 @@ func (u *usersAPI) SetUserSysAdmin(ctx context.Context, params users.SetUserSysA
if err := u.ctl.SetSysAdmin(ctx, id, params.SysadminFlag.SysadminFlag); err != nil { if err := u.ctl.SetSysAdmin(ctx, id, params.SysadminFlag.SysadminFlag); err != nil {
return u.SendError(ctx, err) return u.SendError(ctx, err)
} }
return users.NewSetUserSysAdminOK() return operation.NewSetUserSysAdminOK()
} }
func (u *usersAPI) requireForCLISecret(ctx context.Context, id int) error { func (u *usersAPI) requireForCLISecret(ctx context.Context, id int) error {
@ -471,9 +470,10 @@ func validateUserProfile(user *usermodels.User) error {
if utils.IsContainIllegalChar(user.Realname, []string{",", "~", "#", "$", "%"}) { if utils.IsContainIllegalChar(user.Realname, []string{",", "~", "#", "$", "%"}) {
return errors.BadRequestError(nil).WithMessage("realname contains illegal characters") return errors.BadRequestError(nil).WithMessage("realname contains illegal characters")
} }
if utils.IsIllegalLength(user.Comment, -1, 30) { if utils.IsIllegalLength(user.Comment, -1, 30) {
return errors.BadRequestError(nil).WithMessage("comment with illegal length") return errors.BadRequestError(nil).WithMessage("comment with illegal length")
} }
return nil
return nil
} }

View File

@ -41,7 +41,7 @@ type UserTestSuite struct {
func (uts *UserTestSuite) SetupSuite() { func (uts *UserTestSuite) SetupSuite() {
uts.uCtl = &usertesting.Controller{} uts.uCtl = &usertesting.Controller{}
uts.Config = &restapi.Config{ uts.Config = &restapi.Config{
UsersAPI: &usersAPI{ UserAPI: &usersAPI{
ctl: uts.uCtl, ctl: uts.uCtl,
getAuth: func(ctx context.Context) (string, error) { getAuth: func(ctx context.Context) (string, error) {
return common.DBAuth, nil return common.DBAuth, nil

View File

@ -31,7 +31,7 @@ def _create_client(server, credential, debug, api_type="products"):
cfg = None cfg = None
if api_type in ('projectv2', 'artifact', 'repository', 'scanner', 'scan', 'scanall', 'preheat', 'quota', if api_type in ('projectv2', 'artifact', 'repository', 'scanner', 'scan', 'scanall', 'preheat', 'quota',
'replication', 'registry', 'robot', 'gc', 'retention', 'immutable', 'system_cve_allowlist', 'replication', 'registry', 'robot', 'gc', 'retention', 'immutable', 'system_cve_allowlist',
'configure', 'users', 'member'): 'configure', 'user', 'member'):
cfg = v2_swagger_client.Configuration() cfg = v2_swagger_client.Configuration()
else: else:
cfg = swagger_client.Configuration() cfg = swagger_client.Configuration()
@ -72,7 +72,7 @@ def _create_client(server, credential, debug, api_type="products"):
"immutable": v2_swagger_client.ImmutableApi(v2_swagger_client.ApiClient(cfg)), "immutable": v2_swagger_client.ImmutableApi(v2_swagger_client.ApiClient(cfg)),
"system_cve_allowlist": v2_swagger_client.SystemCVEAllowlistApi(v2_swagger_client.ApiClient(cfg)), "system_cve_allowlist": v2_swagger_client.SystemCVEAllowlistApi(v2_swagger_client.ApiClient(cfg)),
"configure": v2_swagger_client.ConfigureApi(v2_swagger_client.ApiClient(cfg)), "configure": v2_swagger_client.ConfigureApi(v2_swagger_client.ApiClient(cfg)),
"users": v2_swagger_client.UsersApi(v2_swagger_client.ApiClient(cfg)), "user": v2_swagger_client.UserApi(v2_swagger_client.ApiClient(cfg)),
"member": v2_swagger_client.MemberApi(v2_swagger_client.ApiClient(cfg)), "member": v2_swagger_client.MemberApi(v2_swagger_client.ApiClient(cfg)),
}.get(api_type,'Error: Wrong API type') }.get(api_type,'Error: Wrong API type')

View File

@ -8,7 +8,7 @@ from v2_swagger_client.rest import ApiException
class User(base.Base, object): class User(base.Base, object):
def __init__(self): def __init__(self):
super(User, self).__init__(api_type = "users") super(User, self).__init__(api_type = "user")
def create_user(self, name=None, def create_user(self, name=None,
email=None, user_password=None, realname=None, expect_status_code=201, **kwargs): email=None, user_password=None, realname=None, expect_status_code=201, **kwargs):