Allow spaces in policy names (#3482)
This commit is contained in:
@@ -550,9 +550,6 @@ func getAddPolicyResponse(session *models.Principal, params policyApi.AddPolicyP
|
|||||||
if params.Body == nil {
|
if params.Body == nil {
|
||||||
return nil, ErrorWithContext(ctx, ErrPolicyBodyNotInRequest)
|
return nil, ErrorWithContext(ctx, ErrPolicyBodyNotInRequest)
|
||||||
}
|
}
|
||||||
if strings.Contains(*params.Body.Name, " ") {
|
|
||||||
return nil, ErrorWithContext(ctx, ErrPolicyNameContainsSpace)
|
|
||||||
}
|
|
||||||
mAdmin, err := NewMinioAdminClient(params.HTTPRequest.Context(), session)
|
mAdmin, err := NewMinioAdminClient(params.HTTPRequest.Context(), session)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, ErrorWithContext(ctx, err)
|
return nil, ErrorWithContext(ctx, err)
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ var (
|
|||||||
ErrGroupNameNotInRequest = errors.New("error group name not in request")
|
ErrGroupNameNotInRequest = errors.New("error group name not in request")
|
||||||
ErrPolicyNameNotInRequest = errors.New("error policy name not in request")
|
ErrPolicyNameNotInRequest = errors.New("error policy name not in request")
|
||||||
ErrPolicyBodyNotInRequest = errors.New("error policy body not in request")
|
ErrPolicyBodyNotInRequest = errors.New("error policy body not in request")
|
||||||
ErrPolicyNameContainsSpace = errors.New("error policy name cannot contain spaces")
|
|
||||||
ErrInvalidEncryptionAlgorithm = errors.New("error invalid encryption algorithm")
|
ErrInvalidEncryptionAlgorithm = errors.New("error invalid encryption algorithm")
|
||||||
ErrSSENotConfigured = errors.New("error server side encryption configuration not found")
|
ErrSSENotConfigured = errors.New("error server side encryption configuration not found")
|
||||||
ErrBucketLifeCycleNotConfigured = errors.New("error bucket life cycle configuration not found")
|
ErrBucketLifeCycleNotConfigured = errors.New("error bucket life cycle configuration not found")
|
||||||
@@ -161,10 +160,6 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *CodedAPIError {
|
|||||||
errorCode = 400
|
errorCode = 400
|
||||||
errorMessage = ErrPolicyBodyNotInRequest.Error()
|
errorMessage = ErrPolicyBodyNotInRequest.Error()
|
||||||
}
|
}
|
||||||
if errors.Is(err1, ErrPolicyNameContainsSpace) {
|
|
||||||
errorCode = 400
|
|
||||||
errorMessage = ErrPolicyNameContainsSpace.Error()
|
|
||||||
}
|
|
||||||
// console invalid session errors
|
// console invalid session errors
|
||||||
if errors.Is(err1, ErrInvalidSession) {
|
if errors.Is(err1, ErrInvalidSession) {
|
||||||
errorCode = 401
|
errorCode = 401
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ func Test_AddPolicyAPI(t *testing.T) {
|
|||||||
]
|
]
|
||||||
}`),
|
}`),
|
||||||
},
|
},
|
||||||
expectedStatus: 400,
|
expectedStatus: 201, // Changed the expected status from 400 to 201, as spaces are now allowed in policy names.
|
||||||
expectedError: nil,
|
expectedError: nil,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ const AddPolicyScreen = () => {
|
|||||||
setAddLoading(true);
|
setAddLoading(true);
|
||||||
api.policies
|
api.policies
|
||||||
.addPolicy({
|
.addPolicy({
|
||||||
name: policyName,
|
name: policyName.trim(),
|
||||||
policy: policyDefinition,
|
policy: policyDefinition,
|
||||||
})
|
})
|
||||||
.then((res) => {
|
.then((res) => {
|
||||||
@@ -79,15 +79,12 @@ const AddPolicyScreen = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const validatePolicyname = (policyName: string) => {
|
const validatePolicyname = (policyName: string) => {
|
||||||
if (policyName.indexOf(" ") !== -1) {
|
if (policyName.trim() === "") {
|
||||||
return "Policy name cannot contain spaces";
|
return "Policy name cannot be empty";
|
||||||
} else return "";
|
} else return "";
|
||||||
};
|
};
|
||||||
|
|
||||||
const validSave =
|
const validSave = policyName.trim() !== "" && policyDefinition.trim() !== "";
|
||||||
policyName.trim() !== "" &&
|
|
||||||
policyName.indexOf(" ") === -1 &&
|
|
||||||
policyDefinition.trim() !== "";
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
dispatch(setHelpName("add_policy"));
|
dispatch(setHelpName("add_policy"));
|
||||||
|
|||||||
Reference in New Issue
Block a user