Skip to content

Commit f7d360f

Browse files
ARSN-227: bump package version and improve tags validation
1 parent 0a61b43 commit f7d360f

File tree

3 files changed

+12
-16
lines changed

3 files changed

+12
-16
lines changed

lib/models/BucketInfo.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import ObjectLockConfiguration from './ObjectLockConfiguration';
88
import BucketPolicy from './BucketPolicy';
99
import NotificationConfiguration from './NotificationConfiguration';
1010
import { ACL as OACL } from './ObjectMD';
11-
import { validateTags, BucketTag } from '../s3middleware/tagging';
11+
import { areTagsValid, BucketTag } from '../s3middleware/tagging';
1212

1313
// WHEN UPDATING THIS NUMBER, UPDATE BucketInfoModelVersion.md CHANGELOG
1414
// BucketInfoModelVersion.md can be found in documentation/ at the root
@@ -246,7 +246,7 @@ export default class BucketInfo {
246246
if (tags === undefined) {
247247
tags = [] as BucketTag[];
248248
}
249-
validateTags(tags);
249+
assert.strictEqual(areTagsValid(tags), true);
250250

251251
// IF UPDATING PROPERTIES, INCREMENT MODELVERSION NUMBER ABOVE
252252
this._acl = aclInstance;

lib/s3middleware/tagging.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,42 +121,38 @@ function _validateTags(tags: Array<{ Key: string[], Value: string[] }>) {
121121
return tagsResult;
122122
}
123123

124-
/** validateTags - Validate tags, throwing an error if tags are invalid
124+
/** areTagsValid - Validate bucket tags
125125
* @param tags - tags parsed from xml to be validated
126-
* @param tags[].Key - Name of the tag
127-
* @param tags[].Value - Value of the tag
128-
* @return tagsResult - return object tags on success
129-
* { key: value }; error on failure
126+
* @return result - true if the tags are valide, false otherwise
130127
*/
131-
export function validateTags(tags: Array<BucketTag>) {
128+
export function areTagsValid(tags: Array<BucketTag>) {
132129
if (tags.length === 0) {
133-
return {};
130+
return true;
134131
}
135132
// Maximum number of tags per resource: 50
136133
if (tags.length > 50) {
137-
return errorBadRequestLimit50();
134+
return false;
138135
}
139136

140137
const tagsResult = {};
141138
for (const tag of tags) {
142139
if (!_validator.validateTagObjectStructure(tag)) {
143-
throw errors.MalformedXML;
140+
return false;
144141
}
145142
const { Key: key, Value: value } = tag;
146143

147144
const result = _validator.validateKeyValue(key, value);
148145
if (result instanceof Error) {
149-
throw result;
146+
return false;
150147
}
151148

152149
tagsResult[key] = value;
153150
}
154151
// not repeating keys
155152
if (tags.length > Object.keys(tagsResult).length) {
156-
throw errors.InvalidTag.customizeDescription('Cannot provide ' +
157-
'multiple Tags with the same key');
153+
return false;
158154
}
159-
return tagsResult;
155+
return true;
160156
}
161157

162158
/** parseTagXml - Parse and validate xml body, returning callback with object

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"engines": {
44
"node": ">=16"
55
},
6-
"version": "8.1.55",
6+
"version": "8.1.56",
77
"description": "Common utilities for the S3 project components",
88
"main": "build/index.js",
99
"repository": {

0 commit comments

Comments
 (0)