From 96675a49662491d4c450f4e929c0d1b01c1e9a25 Mon Sep 17 00:00:00 2001 From: alty1224 Date: Thu, 26 Dec 2024 14:59:54 +0500 Subject: [PATCH] fix, del same CheckPrefixUniqueness --- common/common.go | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/common/common.go b/common/common.go index 1235069..ac29d95 100644 --- a/common/common.go +++ b/common/common.go @@ -18,6 +18,7 @@ import ( "context" "encoding/json" "fmt" + "github.com/Netcracker/dbaas-opensearch-adapter/api" "io" "io/fs" "log" @@ -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 -}