Replace some x-go-type in swagger

Related models:
    LdapFailedImportUser
    LdapUser
    UserGroup

Signed-off-by: stonezdj <stonezdj@gmail.com>
This commit is contained in:
stonezdj 2021-03-26 14:03:02 +08:00
parent e23b7eab21
commit 5bc1dc8e77
2 changed files with 70 additions and 15 deletions

View File

@ -6072,22 +6072,40 @@ definitions:
type: string
LdapFailedImportUser:
type: object
x-go-type:
type: FailedImportUser
import:
package: "github.com/goharbor/harbor/src/pkg/ldap/model"
properties:
uid:
type: string
description: the uid can't add to system.
error:
type: string
description: fail reason.
LdapUser:
type: object
x-go-type:
type: User
import:
package: "github.com/goharbor/harbor/src/pkg/ldap/model"
properties:
username:
type: string
description: ldap username.
realname:
type: string
description: The user realname from "uid" or "cn" attribute.
email:
type: string
description: The user email address from "mail" or "email" attribute.
UserGroup:
type: object
x-go-type:
type: Group
import:
package: "github.com/goharbor/harbor/src/pkg/ldap/model"
properties:
id:
type: integer
description: The ID of the user group
group_name:
type: string
description: The name of the user group
group_type:
type: integer
description: 'The group type, 1 for LDAP group, 2 for HTTP group.'
ldap_group_dn:
type: string
description: The DN of the LDAP group if group type is 1 (LDAP group).
SupportedWebhookEventTypes:
type: object
description: Supportted webhook event types and notify types.

View File

@ -56,7 +56,20 @@ func (l *ldapAPI) SearchLdapUser(ctx context.Context, params operation.SearchLda
if err != nil {
return l.SendError(ctx, err)
}
return operation.NewSearchLdapUserOK().WithPayload(ldapUsers)
return operation.NewSearchLdapUserOK().WithPayload(toLdapUsersResp(ldapUsers))
}
func toLdapUsersResp(users []ldapModel.User) []*models.LdapUser {
result := make([]*models.LdapUser, 0)
for _, u := range users {
user := &models.LdapUser{
Email: u.Email,
Realname: u.Realname,
Username: u.Username,
}
result = append(result, user)
}
return result
}
func (l *ldapAPI) ImportLdapUser(ctx context.Context, params operation.ImportLdapUserParams) middleware.Responder {
@ -70,7 +83,19 @@ func (l *ldapAPI) ImportLdapUser(ctx context.Context, params operation.ImportLda
if len(failedList) == 0 {
return operation.NewImportLdapUserOK()
}
return operation.NewImportLdapUserNotFound().WithPayload(failedList)
return operation.NewImportLdapUserNotFound().WithPayload(toFailedListResp(failedList))
}
func toFailedListResp(users []ldapModel.FailedImportUser) []*models.LdapFailedImportUser {
result := make([]*models.LdapFailedImportUser, 0)
for _, u := range users {
failed := &models.LdapFailedImportUser{
UID: u.UID,
Error: u.Error,
}
result = append(result, failed)
}
return result
}
func (l *ldapAPI) SearchLdapGroup(ctx context.Context, params operation.SearchLdapGroupParams) middleware.Responder {
@ -92,5 +117,17 @@ func (l *ldapAPI) SearchLdapGroup(ctx context.Context, params operation.SearchLd
if len(ug) == 0 {
return l.SendError(ctx, errors.NotFoundError(fmt.Errorf("group name:%v, group DN:%v", groupName, groupDN)))
}
return operation.NewSearchLdapGroupOK().WithPayload(ug)
return operation.NewSearchLdapGroupOK().WithPayload(toUserGroupResp(ug))
}
func toUserGroupResp(ugs []ldapModel.Group) []*models.UserGroup {
result := make([]*models.UserGroup, 0)
for _, g := range ugs {
ug := &models.UserGroup{
GroupName: g.Name,
LdapGroupDn: g.Dn,
}
result = append(result, ug)
}
return result
}