Skip to content

Commit 5cf02ff

Browse files
authored
Allow spaces in policy names (#3482)
1 parent 6afd0b1 commit 5cf02ff

File tree

4 files changed

+5
-16
lines changed

4 files changed

+5
-16
lines changed

api/admin_policies.go

-3
Original file line numberDiff line numberDiff line change
@@ -550,9 +550,6 @@ func getAddPolicyResponse(session *models.Principal, params policyApi.AddPolicyP
550550
if params.Body == nil {
551551
return nil, ErrorWithContext(ctx, ErrPolicyBodyNotInRequest)
552552
}
553-
if strings.Contains(*params.Body.Name, " ") {
554-
return nil, ErrorWithContext(ctx, ErrPolicyNameContainsSpace)
555-
}
556553
mAdmin, err := NewMinioAdminClient(params.HTTPRequest.Context(), session)
557554
if err != nil {
558555
return nil, ErrorWithContext(ctx, err)

api/errors.go

-5
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ var (
4343
ErrGroupNameNotInRequest = errors.New("error group name not in request")
4444
ErrPolicyNameNotInRequest = errors.New("error policy name not in request")
4545
ErrPolicyBodyNotInRequest = errors.New("error policy body not in request")
46-
ErrPolicyNameContainsSpace = errors.New("error policy name cannot contain spaces")
4746
ErrInvalidEncryptionAlgorithm = errors.New("error invalid encryption algorithm")
4847
ErrSSENotConfigured = errors.New("error server side encryption configuration not found")
4948
ErrBucketLifeCycleNotConfigured = errors.New("error bucket life cycle configuration not found")
@@ -161,10 +160,6 @@ func ErrorWithContext(ctx context.Context, err ...interface{}) *CodedAPIError {
161160
errorCode = 400
162161
errorMessage = ErrPolicyBodyNotInRequest.Error()
163162
}
164-
if errors.Is(err1, ErrPolicyNameContainsSpace) {
165-
errorCode = 400
166-
errorMessage = ErrPolicyNameContainsSpace.Error()
167-
}
168163
// console invalid session errors
169164
if errors.Is(err1, ErrInvalidSession) {
170165
errorCode = 401

integration/policy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ func Test_AddPolicyAPI(t *testing.T) {
176176
]
177177
}`),
178178
},
179-
expectedStatus: 400,
179+
expectedStatus: 201, // Changed the expected status from 400 to 201, as spaces are now allowed in policy names.
180180
expectedError: nil,
181181
},
182182
{

web-app/src/screens/Console/Policies/AddPolicyScreen.tsx

+4-7
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const AddPolicyScreen = () => {
5252
setAddLoading(true);
5353
api.policies
5454
.addPolicy({
55-
name: policyName,
55+
name: policyName.trim(),
5656
policy: policyDefinition,
5757
})
5858
.then((res) => {
@@ -79,15 +79,12 @@ const AddPolicyScreen = () => {
7979
};
8080

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

87-
const validSave =
88-
policyName.trim() !== "" &&
89-
policyName.indexOf(" ") === -1 &&
90-
policyDefinition.trim() !== "";
87+
const validSave = policyName.trim() !== "" && policyDefinition.trim() !== "";
9188

9289
useEffect(() => {
9390
dispatch(setHelpName("add_policy"));

0 commit comments

Comments
 (0)