Make identity errors public. (#5353)
This makes the identity errors public so other packages can match on them. It also moves them to the same file as the interface, as that makes them more discoverable.
This commit is contained in:
@@ -6,6 +6,15 @@ import (
|
||||
|
||||
cs3 "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
libregraph "github.com/owncloud/libre-graph-api-go"
|
||||
"github.com/owncloud/ocis/v2/services/graph/pkg/service/v0/errorcode"
|
||||
)
|
||||
|
||||
// Errors used by the interfaces
|
||||
var (
|
||||
// ErrReadOnly signals that the backend is set to read only.
|
||||
ErrReadOnly = errorcode.New(errorcode.NotAllowed, "server is configured read-only")
|
||||
// ErrNotFound signals that the requested resource was not found.
|
||||
ErrNotFound = errorcode.New(errorcode.ItemNotFound, "not found")
|
||||
)
|
||||
|
||||
// Backend defines the Interface for an IdentityBackend implementation
|
||||
|
||||
@@ -18,11 +18,6 @@ import (
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
var (
|
||||
errReadOnly = errorcode.New(errorcode.NotAllowed, "server is configured read-only")
|
||||
errNotFound = errorcode.New(errorcode.ItemNotFound, "not found")
|
||||
)
|
||||
|
||||
type LDAP struct {
|
||||
useServerUUID bool
|
||||
writeEnabled bool
|
||||
@@ -126,7 +121,7 @@ func (i *LDAP) CreateUser(ctx context.Context, user libregraph.User) (*libregrap
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("CreateUser")
|
||||
if !i.writeEnabled {
|
||||
return nil, errReadOnly
|
||||
return nil, ErrReadOnly
|
||||
}
|
||||
|
||||
ar, err := i.userToAddRequest(user)
|
||||
@@ -165,7 +160,7 @@ func (i *LDAP) DeleteUser(ctx context.Context, nameOrID string) error {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("DeleteUser")
|
||||
if !i.writeEnabled {
|
||||
return errReadOnly
|
||||
return ErrReadOnly
|
||||
}
|
||||
e, err := i.getLDAPUserByNameOrID(nameOrID)
|
||||
if err != nil {
|
||||
@@ -200,7 +195,7 @@ func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("UpdateUser")
|
||||
if !i.writeEnabled {
|
||||
return nil, errReadOnly
|
||||
return nil, ErrReadOnly
|
||||
}
|
||||
e, err := i.getLDAPUserByNameOrID(nameOrID)
|
||||
if err != nil {
|
||||
@@ -315,13 +310,12 @@ func (i *LDAP) getEntryByDN(dn string, attrs []string, filter string) (*ldap.Ent
|
||||
Interface("attributes", searchRequest.Attributes).
|
||||
Msg("getEntryByDN")
|
||||
res, err := i.conn.Search(searchRequest)
|
||||
|
||||
if err != nil {
|
||||
i.logger.Error().Err(err).Str("backend", "ldap").Str("dn", dn).Msg("Search user by DN failed")
|
||||
return nil, errorcode.New(errorcode.ItemNotFound, err.Error())
|
||||
}
|
||||
if len(res.Entries) == 0 {
|
||||
return nil, errNotFound
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return res.Entries[0], nil
|
||||
@@ -349,13 +343,12 @@ func (i *LDAP) searchLDAPEntryByFilter(basedn string, attrs []string, filter str
|
||||
Interface("attributes", searchRequest.Attributes).
|
||||
Msg("getEntryByFilter")
|
||||
res, err := i.conn.Search(searchRequest)
|
||||
|
||||
if err != nil {
|
||||
i.logger.Error().Err(err).Str("backend", "ldap").Str("dn", basedn).Str("filter", filter).Msg("Search user by filter failed")
|
||||
return nil, errorcode.New(errorcode.ItemNotFound, err.Error())
|
||||
}
|
||||
if len(res.Entries) == 0 {
|
||||
return nil, errNotFound
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return res.Entries[0], nil
|
||||
@@ -393,7 +386,7 @@ func (i *LDAP) GetUser(ctx context.Context, nameOrID string, queryParam url.Valu
|
||||
}
|
||||
u := i.createUserModelFromLDAP(e)
|
||||
if u == nil {
|
||||
return nil, errNotFound
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
sel := strings.Split(queryParam.Get("$select"), ",")
|
||||
exp := strings.Split(queryParam.Get("$expand"), ",")
|
||||
@@ -579,7 +572,6 @@ func (i *LDAP) getLDAPGroupsByFilter(filter string, requestMembers, single bool)
|
||||
Interface("attributes", searchRequest.Attributes).
|
||||
Msg("getLDAPGroupsByFilter")
|
||||
res, err := i.conn.Search(searchRequest)
|
||||
|
||||
if err != nil {
|
||||
var errmsg string
|
||||
if lerr, ok := err.(*ldap.Error); ok {
|
||||
|
||||
@@ -29,7 +29,7 @@ func (i *LDAP) CreateEducationUser(ctx context.Context, user libregraph.Educatio
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("CreateEducationUser")
|
||||
if !i.writeEnabled {
|
||||
return nil, errReadOnly
|
||||
return nil, ErrReadOnly
|
||||
}
|
||||
|
||||
ar, err := i.educationUserToAddRequest(user)
|
||||
@@ -61,7 +61,7 @@ func (i *LDAP) DeleteEducationUser(ctx context.Context, nameOrID string) error {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("DeleteEducationUser")
|
||||
if !i.writeEnabled {
|
||||
return errReadOnly
|
||||
return ErrReadOnly
|
||||
}
|
||||
// TODO, implement a proper lookup for education Users here
|
||||
e, err := i.getEducationUserByNameOrID(nameOrID)
|
||||
@@ -91,7 +91,7 @@ func (i *LDAP) GetEducationUser(ctx context.Context, nameOrID string, queryParam
|
||||
}
|
||||
u := i.createEducationUserModelFromLDAP(e)
|
||||
if u == nil {
|
||||
return nil, errNotFound
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
return u, nil
|
||||
}
|
||||
@@ -165,6 +165,7 @@ func (i *LDAP) educationUserToUser(eduUser libregraph.EducationUser) *libregraph
|
||||
user.Mail = eduUser.Mail
|
||||
return user
|
||||
}
|
||||
|
||||
func (i *LDAP) userToEducationUser(user libregraph.User, e *ldap.Entry) *libregraph.EducationUser {
|
||||
eduUser := libregraph.NewEducationUser()
|
||||
eduUser.Id = user.Id
|
||||
|
||||
@@ -92,7 +92,7 @@ func (i *LDAP) CreateEducationSchool(ctx context.Context, school libregraph.Educ
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("CreateEducationSchool")
|
||||
if !i.writeEnabled {
|
||||
return nil, errReadOnly
|
||||
return nil, ErrReadOnly
|
||||
}
|
||||
|
||||
dn := fmt.Sprintf("%s=%s,%s",
|
||||
@@ -133,7 +133,7 @@ func (i *LDAP) DeleteEducationSchool(ctx context.Context, id string) error {
|
||||
logger := i.logger.SubloggerWithRequestID(ctx)
|
||||
logger.Debug().Str("backend", "ldap").Msg("DeleteEducationSchool")
|
||||
if !i.writeEnabled {
|
||||
return errReadOnly
|
||||
return ErrReadOnly
|
||||
}
|
||||
e, err := i.getSchoolByNumberOrID(id)
|
||||
if err != nil {
|
||||
@@ -217,7 +217,7 @@ func (i *LDAP) GetEducationSchoolUsers(ctx context.Context, id string) ([]*libre
|
||||
}
|
||||
|
||||
if schoolEntry == nil {
|
||||
return nil, errNotFound
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
id = ldap.EscapeFilter(id)
|
||||
idFilter := fmt.Sprintf("(%s=%s)", i.educationConfig.memberOfSchoolAttribute, id)
|
||||
@@ -267,7 +267,7 @@ func (i *LDAP) AddUsersToEducationSchool(ctx context.Context, schoolID string, m
|
||||
}
|
||||
|
||||
if schoolEntry == nil {
|
||||
return errNotFound
|
||||
return ErrNotFound
|
||||
}
|
||||
|
||||
userEntries := make([]*ldap.Entry, 0, len(memberIDs))
|
||||
@@ -312,7 +312,7 @@ func (i *LDAP) RemoveUserFromEducationSchool(ctx context.Context, schoolID strin
|
||||
}
|
||||
|
||||
if schoolEntry == nil {
|
||||
return errNotFound
|
||||
return ErrNotFound
|
||||
}
|
||||
user, err := i.getEducationUserByNameOrID(memberID)
|
||||
if err != nil {
|
||||
@@ -385,7 +385,6 @@ func (i *LDAP) getSchoolByFilter(filter string) (*ldap.Entry, error) {
|
||||
Interface("attributes", searchRequest.Attributes).
|
||||
Msg("getSchoolByFilter")
|
||||
res, err := i.conn.Search(searchRequest)
|
||||
|
||||
if err != nil {
|
||||
var errmsg string
|
||||
if lerr, ok := err.(*ldap.Error); ok {
|
||||
@@ -398,7 +397,7 @@ func (i *LDAP) getSchoolByFilter(filter string) (*ldap.Entry, error) {
|
||||
return nil, errorcode.New(errorcode.ItemNotFound, errmsg)
|
||||
}
|
||||
if len(res.Entries) == 0 {
|
||||
return nil, errNotFound
|
||||
return nil, ErrNotFound
|
||||
}
|
||||
|
||||
return res.Entries[0], nil
|
||||
|
||||
Reference in New Issue
Block a user