Skip to content

Commit

Permalink
Allow spaces in policy names (#3482)
Browse files Browse the repository at this point in the history
  • Loading branch information
cniackz authored Dec 5, 2024
1 parent 6afd0b1 commit 5cf02ff
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 16 deletions.
3 changes: 0 additions & 3 deletions api/admin_policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,6 @@ func getAddPolicyResponse(session *models.Principal, params policyApi.AddPolicyP
if params.Body == nil {
return nil, ErrorWithContext(ctx, ErrPolicyBodyNotInRequest)
}
if strings.Contains(*params.Body.Name, " ") {
return nil, ErrorWithContext(ctx, ErrPolicyNameContainsSpace)
}
mAdmin, err := NewMinioAdminClient(params.HTTPRequest.Context(), session)
if err != nil {
return nil, ErrorWithContext(ctx, err)
Expand Down
5 changes: 0 additions & 5 deletions api/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ var (
ErrGroupNameNotInRequest = errors.New("error group name not in request")
ErrPolicyNameNotInRequest = errors.New("error policy name 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")
ErrSSENotConfigured = errors.New("error server side encryption configuration not found")
ErrBucketLifeCycleNotConfigured = errors.New("error bucket life cycle configuration not found")
Expand Down Expand Up @@ -161,10 +160,6 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *CodedAPIError {
errorCode = 400
errorMessage = ErrPolicyBodyNotInRequest.Error()
}
if errors.Is(err1, ErrPolicyNameContainsSpace) {
errorCode = 400
errorMessage = ErrPolicyNameContainsSpace.Error()
}
// console invalid session errors
if errors.Is(err1, ErrInvalidSession) {
errorCode = 401
Expand Down
2 changes: 1 addition & 1 deletion integration/policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
{
Expand Down
11 changes: 4 additions & 7 deletions web-app/src/screens/Console/Policies/AddPolicyScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const AddPolicyScreen = () => {
setAddLoading(true);
api.policies
.addPolicy({
name: policyName,
name: policyName.trim(),
policy: policyDefinition,
})
.then((res) => {
Expand All @@ -79,15 +79,12 @@ const AddPolicyScreen = () => {
};

const validatePolicyname = (policyName: string) => {
if (policyName.indexOf(" ") !== -1) {
return "Policy name cannot contain spaces";
if (policyName.trim() === "") {
return "Policy name cannot be empty";
} else return "";
};

const validSave =
policyName.trim() !== "" &&
policyName.indexOf(" ") === -1 &&
policyDefinition.trim() !== "";
const validSave = policyName.trim() !== "" && policyDefinition.trim() !== "";

useEffect(() => {
dispatch(setHelpName("add_policy"));
Expand Down

0 comments on commit 5cf02ff

Please sign in to comment.