Skip to content

Commit

Permalink
Additional checks on DS creation to avoid object services duplicates
Browse files Browse the repository at this point in the history
  • Loading branch information
cdujeu committed Nov 30, 2023
1 parent 227aa1b commit 0f44d3e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions common/config/datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,10 @@ func filterMiniosWithBaseFolder(configs map[string]*object.MinioConfig, peerAddr
if source.StorageType == object.StorageType_LOCAL && net.PeerAddressesAreSameNode(source.PeerAddress, peerAddress) {
sep := string(os.PathSeparator)
if source.LocalFolder == folder {
// If one of these are empty (= start on all node) and not the other one, we don't know how to choose.
if (source.PeerAddress == "" && peerAddress != "") || (source.PeerAddress != "" && peerAddress == "") {
return nil, errors.Conflict("datasource.peer.conflict", "there is a Peer Address conflict between two object services pointing on %s. Make sure to either set Peer Addresses everywhere, or no address at all.", source.LocalFolder)
}
return source, nil
} else if strings.HasPrefix(source.LocalFolder, strings.TrimRight(folder, sep)+sep) || strings.HasPrefix(folder, strings.TrimRight(source.LocalFolder, sep)+sep) {
return nil, errors.Conflict("datasource.nested.path", "object service %s is already pointing to %s, make sure to avoid using nested paths for different datasources", source.Name, source.LocalFolder)
Expand Down
3 changes: 2 additions & 1 deletion common/utils/net/ips.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ func PeerAddressIsLocal(address string) bool {
// PeerAddressesAreSameNode compares two addresses composed of multiple segments (separated by |) and check if any segments are similar
func PeerAddressesAreSameNode(a1, a2 string) bool {

if a1 == "" && a2 == "" {
// If any of them is empty, it will start on every node => return true!
if a1 == "" || a2 == "" {
return true
}
parts1 := strings.Split(a1, "|")
Expand Down
11 changes: 11 additions & 0 deletions discovery/config/web/api-datasources.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import (
service2 "github.com/pydio/cells/v4/common/proto/service"
"github.com/pydio/cells/v4/common/proto/tree"
"github.com/pydio/cells/v4/common/service"
"github.com/pydio/cells/v4/common/service/errors"
"github.com/pydio/cells/v4/common/utils/configx"
"github.com/pydio/cells/v4/common/utils/filesystem"
"github.com/pydio/cells/v4/common/utils/permissions"
Expand Down Expand Up @@ -138,6 +139,16 @@ func (s *Handler) PutDataSource(req *restful.Request, resp *restful.Response) {
service.RestError500(req, resp, e)
return
}
if !update && ds.PeerAddress == "" && ds.StorageType == object.StorageType_LOCAL {
// Make sure it is not a full duplicate
newDsFolder := ds.StorageConfiguration[object.StorageKeyFolder]
for _, src := range currentSources {
if src.StorageType == ds.StorageType && src.StorageConfiguration[object.StorageKeyFolder] == newDsFolder {
service.RestError500(req, resp, errors.Conflict("datasource.folder.conflict", "Cannot create a datasource at the same location than %s", src.Name))
return
}
}
}
currentSources[ds.Name] = &ds
currentMinios[minioConfig.Name] = minioConfig
if ds.ApiSecret != "" {
Expand Down

0 comments on commit 0f44d3e

Please sign in to comment.