Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix:check pool name before add #1628

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package api
import (
"context"
"errors"
"net/http"
"strings"

"github.com/go-openapi/swag"
Expand Down Expand Up @@ -72,6 +73,7 @@ var (
ErrEncryptionConfigNotFound = errors.New("encryption configuration not found")
ErrPolicyNotFound = errors.New("policy does not exist")
ErrLoginNotAllowed = errors.New("login not allowed")
ErrPoolExists = errors.New("pool exists")
)

// ErrorWithContext :
Expand Down Expand Up @@ -240,6 +242,10 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *models.Error {
errorCode = 400
errorMessage = "Bucket already exists"
}
if errors.Is(err1, ErrPoolExists) {
errorCode = http.StatusNotAcceptable
errorMessage = err1.Error()
}
LogError("ErrorWithContext:%v", err...)
LogIf(ctx, err1, err...)
}
Expand Down
14 changes: 13 additions & 1 deletion api/pool-handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,18 @@ import (
func registerPoolHandlers(api *operations.OperatorAPI) {
// Add Tenant Pools
api.OperatorAPITenantAddPoolHandler = operator_api.TenantAddPoolHandlerFunc(func(params operator_api.TenantAddPoolParams, session *models.Principal) middleware.Responder {
err := getTenantAddPoolResponse(session, params)
// check the poolName if it exists
resp, err := getTenantDetailsResponse(session, operator_api.TenantDetailsParams{Namespace: params.Namespace, Tenant: params.Tenant, HTTPRequest: params.HTTPRequest})
if err != nil {
return operator_api.NewTenantAddPoolDefault(int(err.Code)).WithPayload(err)
}
for _, p := range resp.Pools {
if p.Name == params.Body.Name {
err = ErrorWithContext(params.HTTPRequest.Context(), ErrPoolExists)
return operator_api.NewTenantAddPoolDefault(int(err.Code)).WithPayload(err)
}
}
err = getTenantAddPoolResponse(session, params)
if err != nil {
return operator_api.NewTenantAddPoolDefault(int(err.Code)).WithPayload(err)
}
Expand All @@ -52,6 +63,7 @@ func registerPoolHandlers(api *operations.OperatorAPI) {
func getTenantAddPoolResponse(session *models.Principal, params operator_api.TenantAddPoolParams) *models.Error {
ctx, cancel := context.WithCancel(params.HTTPRequest.Context())
defer cancel()

opClientClientSet, err := GetOperatorClient(session.STSSessionToken)
if err != nil {
return ErrorWithContext(ctx, err)
Expand Down