Skip to content

Commit

Permalink
fix, del same CheckPrefixUniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
alty1224 committed Dec 26, 2024
1 parent 1f4fae3 commit 96675a4
Showing 1 changed file with 1 addition and 30 deletions.
31 changes: 1 addition & 30 deletions common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/Netcracker/dbaas-opensearch-adapter/api"
"io"
"io/fs"
"log"
Expand Down Expand Up @@ -242,33 +243,3 @@ func CheckPrefixUniqueness(prefix string, ctx context.Context, opensearchcli Cli
}
return true, nil
}

func CheckPrefixUniqueness(prefix string, ctx context.Context, opensearchcli Client) (bool, error) {
logger.InfoContext(ctx, "Checking user prefix uniqueness during restoration with renaming")
getUsersRequest := api.GetUsersRequest{}
response, err := getUsersRequest.Do(context.Background(), opensearchcli)
if err != nil {
return false, fmt.Errorf("failed to receive users: %+v", err)
}
defer response.Body.Close()
if response.StatusCode == http.StatusOK {
var users map[string]User
err = ProcessBody(response.Body, &users)
if err != nil {
return false, err
}
for element, user := range users {
if strings.HasPrefix(element, prefix) {
logger.ErrorContext(ctx, fmt.Sprintf("provided prefix already exists or a part of another prefix: %+v", prefix))
return false, fmt.Errorf("provided prefix already exists or a part of another prefix: %+v", prefix)
}
if user.Attributes[resourcePrefixAttributeName] != "" && strings.HasPrefix(user.Attributes[resourcePrefixAttributeName], prefix) {
logger.ErrorContext(ctx, fmt.Sprintf("provided prefix already exists or a part of another prefix: %+v", prefix))
return false, fmt.Errorf("provided prefix already exists or a part of another prefix: %+v", prefix)
}
}
} else if response.StatusCode == http.StatusNotFound {
return true, nil
}
return true, nil
}

0 comments on commit 96675a4

Please sign in to comment.