fix: typos, naming clashes, error messages and deprecations

This commit is contained in:
Thomas Müller
2024-04-03 15:34:36 +02:00
parent 48da9cfbee
commit 07f0cd5574
107 changed files with 298 additions and 310 deletions
+1 -1
View File
@@ -9,7 +9,7 @@ type Cache struct {
Database string `yaml:"database" env:"GRAPH_CACHE_STORE_DATABASE" desc:"The database name the configured store should use." introductionVersion:"pre5.0"`
Table string `yaml:"table" env:"GRAPH_CACHE_STORE_TABLE" desc:"The database table the store should use." introductionVersion:"pre5.0"`
TTL time.Duration `yaml:"ttl" env:"OCIS_CACHE_TTL;GRAPH_CACHE_TTL" desc:"Time to live for cache records in the graph. Defaults to '336h' (2 weeks). See the Environment Variable Types description for more details." introductionVersion:"pre5.0"`
Size int `yaml:"size" env:"OCIS_CACHE_SIZE;GRAPH_CACHE_SIZE" desc:"The maximum quantity of items in the store. Only applies when store type 'ocmem' is configured. Defaults to 512 which is derived from the ocmem package though not exclicitely set as default." introductionVersion:"pre5.0"`
Size int `yaml:"size" env:"OCIS_CACHE_SIZE;GRAPH_CACHE_SIZE" desc:"The maximum quantity of items in the store. Only applies when store type 'ocmem' is configured. Defaults to 512 which is derived from the ocmem package though not explicitly set as default." introductionVersion:"pre5.0"`
DisablePersistence bool `yaml:"disable_persistence" env:"OCIS_CACHE_DISABLE_PERSISTENCE;GRAPH_CACHE_DISABLE_PERSISTENCE" desc:"Disables persistence of the cache. Only applies when store type 'nats-js-kv' is configured. Defaults to false." introductionVersion:"5.0"`
AuthUsername string `yaml:"username" env:"OCIS_CACHE_AUTH_USERNAME;GRAPH_CACHE_AUTH_USERNAME" desc:"The username to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
AuthPassword string `yaml:"password" env:"OCIS_CACHE_AUTH_PASSWORD;GRAPH_CACHE_AUTH_PASSWORD" desc:"The password to authenticate with the cache. Only applies when store type 'nats-js-kv' is configured." introductionVersion:"5.0"`
+3 -3
View File
@@ -40,7 +40,7 @@ type Config struct {
type Spaces struct {
WebDavBase string `yaml:"webdav_base" env:"OCIS_URL;GRAPH_SPACES_WEBDAV_BASE" desc:"The public facing URL of WebDAV." introductionVersion:"pre5.0"`
WebDavPath string `yaml:"webdav_path" env:"GRAPH_SPACES_WEBDAV_PATH" desc:"The WebDAV subpath for spaces." introductionVersion:"pre5.0"`
WebDavPath string `yaml:"webdav_path" env:"GRAPH_SPACES_WEBDAV_PATH" desc:"The WebDAV sub-path for spaces." introductionVersion:"pre5.0"`
DefaultQuota string `yaml:"default_quota" env:"GRAPH_SPACES_DEFAULT_QUOTA" desc:"The default quota in bytes." introductionVersion:"pre5.0"`
ExtendedSpacePropertiesCacheTTL int `yaml:"extended_space_properties_cache_ttl" env:"GRAPH_SPACES_EXTENDED_SPACE_PROPERTIES_CACHE_TTL" desc:"Max TTL in seconds for the spaces property cache." introductionVersion:"pre5.0"`
UsersCacheTTL int `yaml:"users_cache_ttl" env:"GRAPH_SPACES_USERS_CACHE_TTL" desc:"Max TTL in seconds for the spaces users cache." introductionVersion:"pre5.0"`
@@ -65,7 +65,7 @@ type LDAP struct {
UserFilter string `yaml:"user_filter" env:"OCIS_LDAP_USER_FILTER;GRAPH_LDAP_USER_FILTER" desc:"LDAP filter to add to the default filters for user search like '(objectclass=ownCloud)'." introductionVersion:"pre5.0"`
UserObjectClass string `yaml:"user_objectclass" env:"OCIS_LDAP_USER_OBJECTCLASS;GRAPH_LDAP_USER_OBJECTCLASS" desc:"The object class to use for users in the default user search filter ('inetOrgPerson')." introductionVersion:"pre5.0"`
UserEmailAttribute string `yaml:"user_mail_attribute" env:"OCIS_LDAP_USER_SCHEMA_MAIL;GRAPH_LDAP_USER_EMAIL_ATTRIBUTE" desc:"LDAP Attribute to use for the email address of users." introductionVersion:"pre5.0"`
UserDisplayNameAttribute string `yaml:"user_displayname_attribute" env:"LDAP_USER_SCHEMA_DISPLAY_NAME;GRAPH_LDAP_USER_DISPLAYNAME_ATTRIBUTE" desc:"LDAP Attribute to use for the displayname of users." introductionVersion:"pre5.0"`
UserDisplayNameAttribute string `yaml:"user_displayname_attribute" env:"LDAP_USER_SCHEMA_DISPLAY_NAME;GRAPH_LDAP_USER_DISPLAYNAME_ATTRIBUTE" desc:"LDAP Attribute to use for the display name of users." introductionVersion:"pre5.0"`
UserNameAttribute string `yaml:"user_name_attribute" env:"OCIS_LDAP_USER_SCHEMA_USERNAME;GRAPH_LDAP_USER_NAME_ATTRIBUTE" desc:"LDAP Attribute to use for username of users." introductionVersion:"pre5.0"`
UserIDAttribute string `yaml:"user_id_attribute" env:"OCIS_LDAP_USER_SCHEMA_ID;GRAPH_LDAP_USER_UID_ATTRIBUTE" desc:"LDAP Attribute to use as the unique ID for users. This should be a stable globally unique ID like a UUID." introductionVersion:"pre5.0"`
UserIDIsOctetString bool `yaml:"user_id_is_octet_string" env:"OCIS_LDAP_USER_SCHEMA_ID_IS_OCTETSTRING;GRAPH_LDAP_USER_SCHEMA_ID_IS_OCTETSTRING" desc:"Set this to true if the defined 'ID' attribute for users is of the 'OCTETSTRING' syntax. This is required when using the 'objectGUID' attribute of Active Directory for the user ID's." introductionVersion:"pre5.0"`
@@ -154,5 +154,5 @@ type ServiceAccount struct {
// FilesSharing is the configuration for the files sharing
type FilesSharing struct {
EnableResharing bool `yaml:"enable_resharing" env:"OCIS_ENABLE_RESHARING;GRAPH_ENABLE_RESHARING" desc:"Changing this value is NOT supported. Enables the support for resharing." introductionVersion:"5.0" deprecationVersion:"5.0" deprecationInfo:"Resharing will be removed in the future."`
EnableResharing bool `yaml:"enable_resharing" env:"OCIS_ENABLE_RESHARING;GRAPH_ENABLE_RESHARING" desc:"Changing this value is NOT supported. Enables the support for re-sharing." introductionVersion:"5.0" deprecationVersion:"5.0" deprecationInfo:"Resharing will be removed in the future."`
}
+2 -2
View File
@@ -46,7 +46,7 @@ func TestFromCS3Status(t *testing.T) {
for _, test := range tests {
if output := errorcode.FromCS3Status(test.status, test.err, test.ignore...); !reflect.DeepEqual(output, test.result) {
t.Error("Test Failed: {} expected, recieved: {}", test.result, output)
t.Error("Test Failed: {} expected, received: {}", test.result, output)
}
}
}
@@ -63,7 +63,7 @@ func TestFromStat(t *testing.T) {
for _, test := range tests {
if output := errorcode.FromStat(test.stat, test.err); !reflect.DeepEqual(output, test.result) {
t.Error("Test Failed: {} expected, recieved: {}", test.result, output)
t.Error("Test Failed: {} expected, received: {}", test.result, output)
}
}
}
+5 -5
View File
@@ -15,7 +15,7 @@ import (
// ErrorCode defines code as used in MS Graph - see https://docs.microsoft.com/en-us/graph/errors?context=graph%2Fapi%2F1.0&view=graph-rest-1.0
type ErrorCode int
// Error defines a custom error struct, containing and MS Graph error code an a textual error message
// Error defines a custom error struct, containing and MS Graph error code and a textual error message
type Error struct {
errorCode ErrorCode
msg string
@@ -51,7 +51,7 @@ const (
ResyncRequired
// ServiceNotAvailable defines the error if the service is not available. Try the request again after a delay. There may be a Retry-After header.
ServiceNotAvailable
// The sync state generation is not found. The delta token is expired and data must be synchronized again.
// SyncStateNotFound defines the error when the sync state generation is not found. The delta token is expired and data must be synchronized again.
SyncStateNotFound
// QuotaLimitReached the user has reached their quota limit.
QuotaLimitReached
@@ -93,7 +93,7 @@ func New(e ErrorCode, msg string) Error {
}
}
// Render writes an Graph ErrorCode object to the response writer
// Render writes a Graph ErrorCode object to the response writer
func (e ErrorCode) Render(w http.ResponseWriter, r *http.Request, status int, msg string) {
render.Status(r, status)
render.JSON(w, r, e.CreateOdataError(r.Context(), msg))
@@ -115,7 +115,7 @@ func (e ErrorCode) CreateOdataError(ctx context.Context, msg string) *libregraph
}
}
// Render writes an Graph Error object to the response writer
// Render writes a Graph Error object to the response writer
func (e Error) Render(w http.ResponseWriter, r *http.Request) {
var status int
switch e.errorCode {
@@ -148,7 +148,7 @@ func (e ErrorCode) String() string {
return errorCodes[e]
}
// Error return the concatenation of the error string and optinal message
// Error return the concatenation of the error string and optional message
func (e Error) Error() string {
errString := errorCodes[e.errorCode]
if e.msg != "" {
+5 -5
View File
@@ -50,7 +50,7 @@ type Backend interface {
type EducationBackend interface {
// CreateEducationSchool creates the supplied school in the identity backend.
CreateEducationSchool(ctx context.Context, group libregraph.EducationSchool) (*libregraph.EducationSchool, error)
// DeleteSchool deletes a given school, identified by id
// DeleteEducationSchool deletes a given school, identified by id
DeleteEducationSchool(ctx context.Context, id string) error
// GetEducationSchool reads a given school by id
GetEducationSchool(ctx context.Context, nameOrID string) (*libregraph.EducationSchool, error)
@@ -65,7 +65,7 @@ type EducationBackend interface {
// RemoveUserFromEducationSchool removes a single member (by ID) from a school
RemoveUserFromEducationSchool(ctx context.Context, schoolID string, memberID string) error
// GetEducationSchoolClasses lists all classes in a chool
// GetEducationSchoolClasses lists all classes in a school
GetEducationSchoolClasses(ctx context.Context, schoolNumberOrID string) ([]*libregraph.EducationClass, error)
// AddClassesToEducationSchool adds new classes (referenced by a slice of IDs) to supplied school in the identity backend.
AddClassesToEducationSchool(ctx context.Context, schoolNumberOrID string, memberIDs []string) error
@@ -74,7 +74,7 @@ type EducationBackend interface {
// GetEducationClasses lists all classes
GetEducationClasses(ctx context.Context) ([]*libregraph.EducationClass, error)
// GetEducationClasses reads a given class by id
// GetEducationClass reads a given class by id
GetEducationClass(ctx context.Context, namedOrID string) (*libregraph.EducationClass, error)
// CreateEducationClass creates the supplied education class in the identity backend.
CreateEducationClass(ctx context.Context, class libregraph.EducationClass) (*libregraph.EducationClass, error)
@@ -87,7 +87,7 @@ type EducationBackend interface {
// CreateEducationUser creates a given education user in the identity backend.
CreateEducationUser(ctx context.Context, user libregraph.EducationUser) (*libregraph.EducationUser, error)
// DeleteEducationUser deletes a given educationuser, identified by username or id, from the backend
// DeleteEducationUser deletes a given education user, identified by username or id, from the backend
DeleteEducationUser(ctx context.Context, nameOrID string) error
// UpdateEducationUser applies changes to given education user, identified by username or id
UpdateEducationUser(ctx context.Context, nameOrID string, user libregraph.EducationUser) (*libregraph.EducationUser, error)
@@ -98,7 +98,7 @@ type EducationBackend interface {
// GetEducationClassTeachers returns the EducationUser teachers for an EducationClass
GetEducationClassTeachers(ctx context.Context, classID string) ([]*libregraph.EducationUser, error)
// AddTeacherToEducationclass adds a teacher (by ID) to class in the identity backend.
// AddTeacherToEducationClass adds a teacher (by ID) to class in the identity backend.
AddTeacherToEducationClass(ctx context.Context, classID string, teacherID string) error
// RemoveTeacherFromEducationClass removes teacher (by ID) from a class
RemoveTeacherFromEducationClass(ctx context.Context, classID string, teacherID string) error
+12 -12
View File
@@ -28,7 +28,7 @@ type identityCacheOptions struct {
groupsTTL time.Duration
}
// IdentityCacheOptiondefines a single option function.
// IdentityCacheOption defines a single option function.
type IdentityCacheOption func(o *identityCacheOptions)
// IdentityCacheWithGatewaySelector set the gatewaySelector for the Identity Cache
@@ -60,7 +60,7 @@ func newOptions(opts ...IdentityCacheOption) identityCacheOptions {
return opt
}
// NewIdentityCache instanciates a new IdentityCache and sets the supplied options
// NewIdentityCache instantiates a new IdentityCache and sets the supplied options
func NewIdentityCache(opts ...IdentityCacheOption) IdentityCache {
opt := newOptions(opts...)
@@ -83,7 +83,7 @@ func NewIdentityCache(opts ...IdentityCacheOption) IdentityCache {
return cache
}
// GetUser looks up a user by id, if the user is not cached yet it will do a lookup via the CS3 API
// GetUser looks up a user by id, if the user is not cached, yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetUser(ctx context.Context, userid string) (libregraph.User, error) {
var user libregraph.User
if item := cache.users.Get(userid); item == nil {
@@ -91,14 +91,14 @@ func (cache IdentityCache) GetUser(ctx context.Context, userid string) (libregra
cs3UserID := &cs3User.UserId{
OpaqueId: userid,
}
cs3User, err := revautils.GetUser(cs3UserID, gatewayClient)
u, err := revautils.GetUserWithContext(ctx, cs3UserID, gatewayClient)
if err != nil {
if revautils.IsErrNotFound(err) {
return libregraph.User{}, ErrNotFound
}
return libregraph.User{}, errorcode.New(errorcode.GeneralException, err.Error())
}
user = *CreateUserModelFromCS3(cs3User)
user = *CreateUserModelFromCS3(u)
cache.users.Set(userid, user, ttlcache.DefaultTTL)
} else {
@@ -107,13 +107,13 @@ func (cache IdentityCache) GetUser(ctx context.Context, userid string) (libregra
return user, nil
}
// GetUser looks up a group by id, if the group is not cached yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetGroup(ctx context.Context, groupid string) (libregraph.Group, error) {
// GetGroup looks up a group by id, if the group is not cached, yet it will do a lookup via the CS3 API
func (cache IdentityCache) GetGroup(ctx context.Context, groupID string) (libregraph.Group, error) {
var group libregraph.Group
if item := cache.groups.Get(groupid); item == nil {
if item := cache.groups.Get(groupID); item == nil {
gatewayClient, err := cache.gatewaySelector.Next()
cs3GroupID := &cs3Group.GroupId{
OpaqueId: groupid,
OpaqueId: groupID,
}
req := cs3Group.GetGroupRequest{
GroupId: cs3GroupID,
@@ -124,9 +124,9 @@ func (cache IdentityCache) GetGroup(ctx context.Context, groupid string) (libreg
}
switch res.Status.Code {
case rpc.Code_CODE_OK:
cs3Group := res.GetGroup()
group = *CreateGroupModelFromCS3(cs3Group)
cache.groups.Set(groupid, group, ttlcache.DefaultTTL)
g := res.GetGroup()
group = *CreateGroupModelFromCS3(g)
cache.groups.Set(groupID, group, ttlcache.DefaultTTL)
case rpc.Code_CODE_NOT_FOUND:
return group, ErrNotFound
default:
+1 -1
View File
@@ -36,7 +36,7 @@ func (i *CS3) DeleteUser(ctx context.Context, nameOrID string) error {
return errNotImplemented
}
// UpdateUser implements the Backend Interface. It's currently not suported for the CS3 backend
// UpdateUser implements the Backend Interface. It's currently not supported for the CS3 backend
func (i *CS3) UpdateUser(ctx context.Context, nameOrID string, user libregraph.User) (*libregraph.User, error) {
return nil, errNotImplemented
}
+2 -2
View File
@@ -89,7 +89,7 @@ func (i *ErrEducationBackend) GetEducationClassMembers(ctx context.Context, name
return nil, errNotImplemented
}
// UpdateEducationClass implments the EducationBackend interface
// UpdateEducationClass implements the EducationBackend interface
func (i *ErrEducationBackend) UpdateEducationClass(ctx context.Context, id string, class libregraph.EducationClass) (*libregraph.EducationClass, error) {
return nil, errNotImplemented
}
@@ -99,7 +99,7 @@ func (i *ErrEducationBackend) CreateEducationUser(ctx context.Context, user libr
return nil, errNotImplemented
}
// DeleteEducationUser deletes a given educationuser, identified by username or id, from the backend
// DeleteEducationUser deletes a given education user, identified by username or id, from the backend
func (i *ErrEducationBackend) DeleteEducationUser(ctx context.Context, nameOrID string) error {
return errNotImplemented
}
+11 -11
View File
@@ -203,7 +203,7 @@ func (i *LDAP) CreateUser(ctx context.Context, user libregraph.User) (*libregrap
}
if i.usePwModifyExOp && user.PasswordProfile != nil && user.PasswordProfile.Password != nil {
if err := i.updateUserPassowrd(ctx, ar.DN, user.PasswordProfile.GetPassword()); err != nil {
if err := i.updateUserPassword(ctx, ar.DN, user.PasswordProfile.GetPassword()); err != nil {
return nil, err
}
}
@@ -265,7 +265,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 {
// still allow eanble/disable User when using DisableMechanismGroup
// still allow to enable/disable user when using DisableMechanismGroup
if i.disableUserMechanism == DisableMechanismGroup && isUserEnabledUpdate(user) {
logger.Error().Str("backend", "ldap").Msg("Allowing accountEnabled Update on read-only backend")
} else {
@@ -319,7 +319,7 @@ func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.
if user.PasswordProfile != nil && user.PasswordProfile.GetPassword() != "" {
if i.usePwModifyExOp {
if err := i.updateUserPassowrd(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
if err := i.updateUserPassword(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
msg := "error updating user password"
logger.Error().Err(err).Msg(msg)
errMap := ldapResultToErrMap{
@@ -376,7 +376,7 @@ func (i *LDAP) UpdateUser(ctx context.Context, nameOrID string, user libregraph.
returnUser := i.createUserModelFromLDAP(e)
// To avoid an ldap lookup for group membership, set the enabled flag to same as input value
// To avoid a ldap lookup for group membership, set the enabled flag to same as input value
// since this would have been updated with group membership from the input anyway.
if user.AccountEnabled != nil && i.disableUserMechanism == DisableMechanismGroup {
returnUser.AccountEnabled = user.AccountEnabled
@@ -490,7 +490,7 @@ func filterEscapeUUID(binary bool, id string) (string, error) {
func (i *LDAP) getLDAPUserByID(id string) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.userIDisOctetString, id)
if err != nil {
return nil, fmt.Errorf("Invalid User id: %w", err)
return nil, fmt.Errorf("invalid User id: %w", err)
}
filter := fmt.Sprintf("(%s=%s)", i.userAttributeMap.id, idString)
return i.getLDAPUserByFilter(filter)
@@ -498,7 +498,7 @@ func (i *LDAP) getLDAPUserByID(id string) (*ldap.Entry, error) {
func (i *LDAP) getLDAPUserByNameOrID(nameOrID string) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.userIDisOctetString, nameOrID)
// err != nil just means that this is not a uuid so we can skip the uuid filterpart
// err != nil just means that this is not an uuid, so we can skip the uuid filter part
// and just filter by name
filter := ""
if err == nil {
@@ -738,9 +738,9 @@ func (i *LDAP) renameMemberInGroup(ctx context.Context, group *ldap.Entry, oldMe
return nil
}
func (i *LDAP) updateUserPassowrd(ctx context.Context, dn, password string) error {
func (i *LDAP) updateUserPassword(ctx context.Context, dn, password string) error {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("updateUserPassowrd")
logger.Debug().Str("backend", "ldap").Msg("updateUserPassword")
pwMod := ldap.PasswordModifyRequest{
UserIdentity: dn,
NewPassword: password,
@@ -915,7 +915,7 @@ func stringToScope(scope string) (int, error) {
return s, nil
}
// removeEntryByDNAndAttributeFromEntry creates a request to remove a single member entry by attribute and DN from an ldap entry
// removeEntryByDNAndAttributeFromEntry creates a request to remove a single member entry by attribute and DN from a ldap entry
func (i *LDAP) removeEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string, attribute string) error {
nOldDN, err := ldapdn.ParseNormalize(dn)
if err != nil {
@@ -982,7 +982,7 @@ func (i *LDAP) removeEntryByDNAndAttributeFromEntry(entry *ldap.Entry, dn string
return nil
}
// expandLDAPAttributeEntries reads an attribute from an ldap entry and expands to users
// expandLDAPAttributeEntries reads an attribute from a ldap entry and expands to users
func (i *LDAP) expandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, attribute string) ([]*ldap.Entry, error) {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("ExpandLDAPAttributeEntries")
@@ -1007,7 +1007,7 @@ func (i *LDAP) expandLDAPAttributeEntries(ctx context.Context, e *ldap.Entry, at
func replaceDN(fullDN *ldap.DN, newDN string) (string, error) {
if len(fullDN.RDNs) == 0 {
return "", fmt.Errorf("Can't operate on an empty dn")
return "", fmt.Errorf("can't operate on an empty dn")
}
if len(fullDN.RDNs) == 1 {
@@ -24,7 +24,7 @@ type ldapConnection struct {
Error error
}
// Implements the ldap.CLient interface
// ConnWithReconnect implements the ldap.Client interface
type ConnWithReconnect struct {
conn chan ldapConnection
reset chan *ldap.Conn
@@ -66,7 +66,7 @@ func (i *LDAP) GetEducationClasses(ctx context.Context) ([]*libregraph.Education
// CreateEducationClass implements the EducationBackend interface for the LDAP backend.
// An EducationClass is mapped to an LDAP entry of the "groupOfNames" structural ObjectClass.
// With a few additional Attributes added on top via the "ocEducationClass" auxiallary ObjectClass.
// With a few additional Attributes added on top via the "ocEducationClass" auxiliary ObjectClass.
func (i *LDAP) CreateEducationClass(ctx context.Context, class libregraph.EducationClass) (*libregraph.EducationClass, error) {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("create educationClass")
@@ -56,15 +56,15 @@ func TestCreateEducationClass(t *testing.T) {
class := libregraph.NewEducationClass("Math", "course")
class.SetExternalId("Math0123")
class.SetId("abcd-defg")
res_class, err := b.CreateEducationClass(context.Background(), *class)
resClass, err := b.CreateEducationClass(context.Background(), *class)
lm.AssertNumberOfCalls(t, "Add", 1)
lm.AssertNumberOfCalls(t, "Search", 1)
assert.Nil(t, err)
assert.NotNil(t, res_class)
assert.Equal(t, res_class.GetDisplayName(), class.GetDisplayName())
assert.Equal(t, res_class.GetId(), class.GetId())
assert.Equal(t, res_class.GetExternalId(), class.GetExternalId())
assert.Equal(t, res_class.GetClassification(), class.GetClassification())
assert.NotNil(t, resClass)
assert.Equal(t, resClass.GetDisplayName(), class.GetDisplayName())
assert.Equal(t, resClass.GetId(), class.GetId())
assert.Equal(t, resClass.GetExternalId(), class.GetExternalId())
assert.Equal(t, resClass.GetClassification(), class.GetClassification())
}
func TestGetEducationClasses(t *testing.T) {
@@ -268,7 +268,7 @@ func TestGetEducationClassMembers(t *testing.T) {
for _, tt := range tests {
lm := &mocks.Client{}
user_sr := &ldap.SearchRequest{
userSr := &ldap.SearchRequest{
BaseDN: "uid=user",
Scope: 0,
SizeLimit: 1,
@@ -276,7 +276,7 @@ func TestGetEducationClassMembers(t *testing.T) {
Attributes: []string{"displayname", "entryUUID", "mail", "uid", "sn", "givenname", "userEnabledAttribute", "userTypeAttribute"},
Controls: []ldap.Control(nil),
}
lm.On("Search", user_sr).Return(&ldap.SearchResult{Entries: []*ldap.Entry{userEntry}}, nil)
lm.On("Search", userSr).Return(&ldap.SearchResult{Entries: []*ldap.Entry{userEntry}}, nil)
sr := &ldap.SearchRequest{
BaseDN: "ou=groups,dc=test",
Scope: 2,
@@ -50,7 +50,7 @@ const (
const ldapDateFormat = "20060102150405Z0700"
var (
errNotSet = errors.New("Attribute not set")
errNotSet = errors.New("attribute not set")
errSchoolNameExists = errorcode.New(errorcode.NameAlreadyExists, "A school with that name is already present")
errSchoolNumberExists = errorcode.New(errorcode.NameAlreadyExists, "A school with that number is already present")
)
@@ -761,7 +761,7 @@ func (i *LDAP) getTerminationDate(e *ldap.Entry) (*time.Time, error) {
}
t, err := time.Parse(ldapDateFormat, dateString)
if err != nil {
err = fmt.Errorf("Error parsing LDAP date: '%s': %w", dateString, err)
err = fmt.Errorf("error parsing LDAP date: '%s': %w", dateString, err)
return nil, err
}
return &t, nil
@@ -184,18 +184,18 @@ func TestCreateEducationSchool(t *testing.T) {
school.SetDisplayName(tt.schoolName)
school.SetSchoolNumber(tt.schoolNumber)
school.SetId("abcd-defg")
res_school, err := b.CreateEducationSchool(context.Background(), *school)
resSchool, err := b.CreateEducationSchool(context.Background(), *school)
if tt.expectedError == nil {
assert.Nil(t, err)
lm.AssertNumberOfCalls(t, "Add", 1)
assert.NotNil(t, res_school)
assert.Equal(t, res_school.GetDisplayName(), school.GetDisplayName())
assert.Equal(t, res_school.GetId(), school.GetId())
assert.Equal(t, res_school.GetSchoolNumber(), school.GetSchoolNumber())
assert.False(t, res_school.HasTerminationDate())
assert.NotNil(t, resSchool)
assert.Equal(t, resSchool.GetDisplayName(), school.GetDisplayName())
assert.Equal(t, resSchool.GetId(), school.GetId())
assert.Equal(t, resSchool.GetSchoolNumber(), school.GetSchoolNumber())
assert.False(t, resSchool.HasTerminationDate())
} else {
assert.Equal(t, err, tt.expectedError)
assert.Nil(t, res_school)
assert.Nil(t, resSchool)
}
}
}
@@ -238,15 +238,15 @@ func TestUpdateEducationSchoolTerminationDate(t *testing.T) {
school := libregraph.NewEducationSchool()
terminationTime := time.Date(2042, time.January, 31, 12, 0, 0, 0, time.UTC)
school.SetTerminationDate(terminationTime)
res_school, err := b.UpdateEducationSchool(context.Background(), "abcd-defg", *school)
resSchool, err := b.UpdateEducationSchool(context.Background(), "abcd-defg", *school)
lm.AssertNumberOfCalls(t, "Search", 2)
assert.Nil(t, err)
assert.NotNil(t, res_school)
assert.Equal(t, "Test School", res_school.GetDisplayName())
assert.Equal(t, "abcd-defg", res_school.GetId())
assert.Equal(t, "0123", res_school.GetSchoolNumber())
assert.True(t, res_school.HasTerminationDate())
assert.True(t, terminationTime.Equal(res_school.GetTerminationDate()))
assert.NotNil(t, resSchool)
assert.Equal(t, "Test School", resSchool.GetDisplayName())
assert.Equal(t, "abcd-defg", resSchool.GetId())
assert.Equal(t, "0123", resSchool.GetSchoolNumber())
assert.True(t, resSchool.HasTerminationDate())
assert.True(t, terminationTime.Equal(resSchool.GetTerminationDate()))
}
func TestUpdateEducationSchoolOperation(t *testing.T) {
@@ -55,7 +55,7 @@ func (i *LDAP) CreateEducationUser(ctx context.Context, user libregraph.Educatio
return i.createEducationUserModelFromLDAP(e), nil
}
// DeleteEducationUser deletes a given educationuser, identified by username or id, from the backend
// DeleteEducationUser deletes a given education user, identified by username or id, from the backend
func (i *LDAP) DeleteEducationUser(ctx context.Context, nameOrID string) error {
logger := i.logger.SubloggerWithRequestID(ctx)
logger.Debug().Str("backend", "ldap").Msg("DeleteEducationUser")
@@ -145,7 +145,7 @@ func (i *LDAP) UpdateEducationUser(ctx context.Context, nameOrID string, user li
}
if user.PasswordProfile != nil && user.PasswordProfile.GetPassword() != "" {
if i.usePwModifyExOp {
if err := i.updateUserPassowrd(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
if err := i.updateUserPassword(ctx, e.DN, user.PasswordProfile.GetPassword()); err != nil {
return nil, err
}
} else {
@@ -182,7 +182,7 @@ func (i *LDAP) UpdateEducationUser(ctx context.Context, nameOrID string, user li
returnUser := i.createEducationUserModelFromLDAP(e)
// To avoid an ldap lookup for group membership, set the enabled flag to same as input value
// To avoid a ldap lookup for group membership, set the enabled flag to same as input value
// since this would have been updated with group membership from the input anyway.
if user.AccountEnabled != nil && i.disableUserMechanism == DisableMechanismGroup {
returnUser.AccountEnabled = user.AccountEnabled
+8 -8
View File
@@ -280,7 +280,7 @@ func (i *LDAP) UpdateGroupName(ctx context.Context, groupID string, groupName st
}
// AddMembersToGroup implements the Backend Interface for the LDAP backend.
// Currently it is limited to adding Users as Group members. Adding other groups
// Currently, it is limited to adding Users as Group members. Adding other groups
// as members is not yet implemented
func (i *LDAP) AddMembersToGroup(ctx context.Context, groupID string, memberIDs []string) error {
logger := i.logger.SubloggerWithRequestID(ctx)
@@ -340,17 +340,17 @@ func (i *LDAP) AddMembersToGroup(ctx context.Context, groupID string, memberIDs
if len(newMemberDN) > 0 {
// Small retry loop. It might be that, when reading the group we found the empty group member ("",
// line 289 above). Our modify operation tries to delete that value. However another go-routine
// line 289 above). Our modify operation tries to delete that value. However, another go-routine
// might have done that in parallel. In that case
// (LDAPResultNoSuchAttribute) we need to retry the modification
// without the delete.
// without to delete.
for j := 0; j < 2; j++ {
mr.Add(i.groupAttributeMap.member, newMemberDN)
if err := i.conn.Modify(&mr); err != nil {
if lerr, ok := err.(*ldap.Error); ok {
switch lerr.ResultCode {
case ldap.LDAPResultAttributeOrValueExists:
err = fmt.Errorf("Duplicate member entries in request")
err = fmt.Errorf("duplicate member entries in request")
case ldap.LDAPResultNoSuchAttribute:
if len(mr.Changes) == 2 {
// We tried the special case for adding the first group member, but some
@@ -363,7 +363,7 @@ func (i *LDAP) AddMembersToGroup(ctx context.Context, groupID string, memberIDs
}
default:
logger.Info().Err(err).Msg("Failed to modify group member entries on PATCH group")
err = fmt.Errorf("Unknown error when trying to modify group member entries")
err = fmt.Errorf("unknown error when trying to modify group member entries")
}
}
return err
@@ -437,7 +437,7 @@ func (i *LDAP) groupToLDAPAttrValues(group libregraph.Group) (map[string][]strin
// as required attribute for groupOfNames/groupOfUniqueNames. So we
// add an empty string (which is a valid DN) as the initial member.
// It will be replaced once real members are added.
// We might wanna use the newer, but not so broadly used "groupOfMembers"
// We might want to use the newer, but not so broadly used "groupOfMembers"
// objectclass (RFC2307bis-02) where "member" is optional.
i.groupAttributeMap.member: {""},
}
@@ -452,7 +452,7 @@ func (i *LDAP) groupToLDAPAttrValues(group libregraph.Group) (map[string][]strin
func (i *LDAP) getLDAPGroupByID(id string, requestMembers bool) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.groupIDisOctetString, id)
if err != nil {
return nil, fmt.Errorf("Invalid group id: %w", err)
return nil, fmt.Errorf("invalid group id: %w", err)
}
filter := fmt.Sprintf("(%s=%s)", i.groupAttributeMap.id, idString)
return i.getLDAPGroupByFilter(filter, requestMembers)
@@ -460,7 +460,7 @@ func (i *LDAP) getLDAPGroupByID(id string, requestMembers bool) (*ldap.Entry, er
func (i *LDAP) getLDAPGroupByNameOrID(nameOrID string, requestMembers bool) (*ldap.Entry, error) {
idString, err := filterEscapeUUID(i.groupIDisOctetString, nameOrID)
// err != nil just means that this is not a uuid so we can skip the uuid filterpart
// err != nil just means that this is not an uuid, so we can skip the uuid filter part
// and just filter by name
filter := ""
if err == nil {
@@ -45,7 +45,7 @@ var groupLookupSearchRequest = &ldap.SearchRequest{
Controls: []ldap.Control(nil),
}
var groupListSeachRequest = &ldap.SearchRequest{
var groupListSearchRequest = &ldap.SearchRequest{
BaseDN: "ou=groups,dc=test",
Scope: 2,
Filter: "(&(objectClass=groupOfNames))",
@@ -273,7 +273,7 @@ func TestGetGroups(t *testing.T) {
if err != nil {
t.Errorf("Expected success, got '%s'", err.Error())
}
lm.On("Search", groupListSeachRequest).Return(&ldap.SearchResult{Entries: []*ldap.Entry{groupEntry}}, nil)
lm.On("Search", groupListSearchRequest).Return(&ldap.SearchResult{Entries: []*ldap.Entry{groupEntry}}, nil)
lm.On("Search", sr2).Return(&ldap.SearchResult{Entries: []*ldap.Entry{userEntry}}, nil)
lm.On("Search", sr3).Return(&ldap.SearchResult{Entries: []*ldap.Entry{invalidUserEntry}}, nil)
b, _ = getMockedBackend(lm, lconfig, &logger)
@@ -439,8 +439,8 @@ func TestUpdateGroupName(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lm := &mocks.Client{}
for _, mock := range tt.ldapMocks {
lm.On(mock.funcName, mock.args...).Return(mock.returns...)
for _, ldapMock := range tt.ldapMocks {
lm.On(ldapMock.funcName, ldapMock.args...).Return(ldapMock.returns...)
}
ldapConfig := lconfig
+5 -5
View File
@@ -1431,8 +1431,8 @@ func TestUpdateUser(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lm := &mocks.Client{}
for _, mock := range tt.ldapMocks {
lm.On(mock.funcName, mock.args...).Return(mock.returns...)
for _, ldapMock := range tt.ldapMocks {
lm.On(ldapMock.funcName, ldapMock.args...).Return(ldapMock.returns...)
}
ldapConfig := lconfig
@@ -1659,7 +1659,7 @@ func TestUsersEnabledState(t *testing.T) {
returns: []interface{}{
nil,
&ldap.Error{
Err: fmt.Errorf("Very Problematic Problems"),
Err: fmt.Errorf("very problematic problems"),
},
},
},
@@ -1669,8 +1669,8 @@ func TestUsersEnabledState(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
lm := &mocks.Client{}
for _, mock := range tt.ldapMocks {
lm.On(mock.funcName, mock.args...).Return(mock.returns...)
for _, ldapMock := range tt.ldapMocks {
lm.On(ldapMock.funcName, ldapMock.args...).Return(ldapMock.returns...)
}
ldapConfig := lconfig
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"github.com/owncloud/ocis/v2/services/graph/pkg/config"
)
// LoggerFromConfig initializes a service-specific logger instance.
// Configure initializes a service-specific logger instance.
func Configure(name string, cfg *config.Log) log.Logger {
return log.NewLogger(
log.Name(name),
+2 -2
View File
@@ -35,7 +35,7 @@ func health(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
// TODO: check if services are up and running
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
// io.WriteString should not fail but if it does we want to know.
// io.WriteString should not fail but if it does, we want to know.
if err != nil {
panic(err)
}
@@ -51,7 +51,7 @@ func ready(cfg *config.Config) func(http.ResponseWriter, *http.Request) {
// TODO: check if services are up and running
_, err := io.WriteString(w, http.StatusText(http.StatusOK))
// io.WriteString should not fail but if it does we want to know.
// io.WriteString should not fail but if it does, we want to know.
if err != nil {
panic(err)
}
+1 -1
View File
@@ -114,7 +114,7 @@ func Server(opts ...Option) (http.Service, error) {
requireAdminMiddleware = func(next stdhttp.Handler) stdhttp.Handler {
return next
}
// no gatewayclient needed
// no gateway client needed
}
// Keycloak client is optional, so if it stays nil, it's fine.
@@ -50,14 +50,14 @@ func NewDrivesDriveItemService(logger log.Logger, gatewaySelector pool.Selectabl
}, nil
}
// UnmountShare unmounts a share from the sharejail
// UnmountShare unmounts a share from the share-jail
func (s DrivesDriveItemService) UnmountShare(ctx context.Context, resourceID storageprovider.ResourceId) error {
gatewayClient, err := s.gatewaySelector.Next()
if err != nil {
return err
}
// This is a a bit of a hack. We should not rely on a specific format of the item id.
// This is a bit of a hack. We should not rely on a specific format of the item id.
// But currently there is no other way to get the ShareID.
shareId := resourceID.GetOpaqueId()
@@ -165,7 +165,7 @@ func (s DrivesDriveItemService) MountShare(ctx context.Context, resourceID stora
var acceptedShares []*collaboration.ReceivedShare
// try to accept all of the received shares for this resource. So that the stat is in sync across all
// try to accept all the received shares for this resource. So that the stat is in sync across all
// shares
for _, receivedShare := range receivedSharesResponse.GetShares() {
updateMask := &fieldmaskpb.FieldMask{Paths: []string{_fieldMaskPathState}}
@@ -211,13 +211,13 @@ func (s DrivesDriveItemService) MountShare(ctx context.Context, resourceID stora
return libregraph.DriveItem{}, errors.Join(errs...)
}
// As the accepted shares are all for the same resource they should collapse to a single driveitem
// As the accepted shares are all for the same resource they should collapse to a single drive-item
items, err := cs3ReceivedSharesToDriveItems(ctx, &s.logger, gatewayClient, s.identityCache, s.resharingEnabled, acceptedShares)
switch {
case err != nil:
return libregraph.DriveItem{}, nil
case len(items) != 1:
return libregraph.DriveItem{}, errorcode.New(errorcode.GeneralException, "failed to convert accepted shares into driveitem")
return libregraph.DriveItem{}, errorcode.New(errorcode.GeneralException, "failed to convert accepted shares into drive-item")
}
return items[0], nil
}
@@ -270,7 +270,7 @@ func (api DrivesDriveItemApi) CreateDriveItem(w http.ResponseWriter, r *http.Req
ctx := r.Context()
driveID, err := parseIDParam(r, "driveID")
if err != nil {
api.logger.Debug().Err(err).Msg("invlid driveID")
api.logger.Debug().Err(err).Msg("invalid driveID")
errorcode.InvalidRequest.Render(w, r, http.StatusUnprocessableEntity, "invalid driveID")
return
}
+10 -10
View File
@@ -589,8 +589,8 @@ func (g Graph) Invite(w http.ResponseWriter, r *http.Request) {
if id := createShareResponse.GetShare().GetId().GetOpaqueId(); id != "" {
permission.Id = conversions.ToPointer(id)
} else if IsSpaceRoot(statResponse.GetInfo().GetId()) {
// permissions on a space root are not handled by a share manager so
// they don't get a shareid
// permissions on a space root are not handled by a share manager, so
// they don't get a share-id
permission.SetId(identitySetToSpacePermissionID(permission.GetGrantedToV2()))
}
@@ -691,7 +691,7 @@ func (g Graph) DeletePermission(w http.ResponseWriter, r *http.Request) {
// Check if the ID is referring to a public share
case err == nil:
permissionType = Public
// If the item id is referring to a space root an this is not a public share
// If the item id is referring to a space root and this is not a public share
// we have to deal with space permissions
case IsSpaceRoot(&itemID):
permissionType = Space
@@ -776,15 +776,15 @@ func (g Graph) getPermissionByID(ctx context.Context, permissionID string, itemI
var errcode errorcode.Error
if errors.As(err, &errcode) && errcode.GetCode() == errorcode.ItemNotFound {
// there is no public link with that id, check if this is a user share
share, err := g.getCS3UserShareByID(ctx, permissionID)
shareById, err := g.getCS3UserShareByID(ctx, permissionID)
if err != nil {
return nil, nil, err
}
permission, err := g.cs3UserShareToPermission(ctx, share, false)
permission, err := g.cs3UserShareToPermission(ctx, shareById, false)
if err != nil {
return nil, nil, err
}
return permission, share.GetResourceId(), nil
return permission, shareById.GetResourceId(), nil
}
return nil, nil, err
@@ -806,11 +806,11 @@ func (g Graph) getSpaceRootPermissions(ctx context.Context, spaceID *storageprov
}
func (g Graph) getUserPermissionResourceID(ctx context.Context, permissionID string) (*storageprovider.ResourceId, error) {
share, err := g.getCS3UserShareByID(ctx, permissionID)
shareByID, err := g.getCS3UserShareByID(ctx, permissionID)
if err != nil {
return nil, err
}
return share.GetResourceId(), nil
return shareByID.GetResourceId(), nil
}
func (g Graph) getCS3UserShareByID(ctx context.Context, permissionID string) (*collaboration.Share, error) {
@@ -1012,11 +1012,11 @@ func spacePermissionIdToCS3Grantee(permissionID string) (storageprovider.Grantee
}
func (g Graph) getLinkPermissionResourceID(ctx context.Context, permissionID string) (*storageprovider.ResourceId, error) {
share, err := g.getCS3PublicShareByID(ctx, permissionID)
shareByID, err := g.getCS3PublicShareByID(ctx, permissionID)
if err != nil {
return nil, err
}
return share.GetResourceId(), nil
return shareByID.GetResourceId(), nil
}
func (g Graph) getCS3PublicShareByID(ctx context.Context, permissionID string) (*link.PublicShare, error) {