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

INTEGRATION [PR#2191 > development/8.1] Improvement/arsn 363 retention day condition #2197

19 changes: 18 additions & 1 deletion lib/models/ObjectLockConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export type ParsedRetention =
export default class ObjectLockConfiguration {
_parsedXml: any;
_config: Config;
_days: number | null;

/**
* Create an Object Lock Configuration instance
Expand All @@ -45,6 +46,7 @@ export default class ObjectLockConfiguration {
constructor(xml: any) {
this._parsedXml = xml;
this._config = {};
this._days = null;
}

/**
Expand Down Expand Up @@ -118,7 +120,7 @@ export default class ObjectLockConfiguration {
return { error };
}
if ((timeType === 'Days' && timeValue > 36500) ||
(timeType === 'Years' && timeValue > 100)) {
(timeType === 'Years' && timeValue > 100)) {
const msg = 'retention period is too large';
const error = errors.InvalidArgument.customizeDescription(msg);
return { error };
Expand Down Expand Up @@ -183,6 +185,21 @@ export default class ObjectLockConfiguration {
this._config.rule = {};
this._config.rule.mode = validMode.mode;
this._config.rule[validTime.timeType!] = validTime.timeValue;
// Store the number of days
function isLeapYear(year) {
return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
}
function getDaysForYears(years) {
let days = 0;
const currentYear = new Date().getFullYear();

for (let i = 0; i < years; i++) {
days += isLeapYear(currentYear + i) ? 366 : 365;
}

return days;
}
this._days = validTime.timeType === 'years' ? getDaysForYears(validTime.timeValue) : validTime.timeValue;
}
return validConfig;
}
Expand Down
37 changes: 31 additions & 6 deletions lib/policyEvaluator/RequestContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ function _buildArn(
}
if (specificResource) {
return `arn:aws:iam::${accountId}:` +
`${generalResource}${specificResource}`;
`${generalResource}${specificResource}`;
}
return `arn:aws:iam::${accountId}:${generalResource}`;
}
case 'ring': {
// arn:aws:iam::<account-id>:<resource-type>/<resource>
if (specificResource) {
return `arn:aws:ring::${requesterInfo!.accountid}:` +
`${generalResource}/${specificResource}`;
`${generalResource}/${specificResource}`;
}
return `arn:aws:ring::${requesterInfo!.accountid}:${generalResource}`;
}
Expand All @@ -85,10 +85,10 @@ function _buildArn(
// (possible resource types are buckets, accounts or users)
if (specificResource) {
return `arn:scality:utapi::${requesterInfo!.accountid}:` +
`${generalResource}/${specificResource}`;
`${generalResource}/${specificResource}`;
}
return `arn:scality:utapi::${requesterInfo!.accountid}:` +
`${generalResource}/`;
`${generalResource}/`;
}
case 'sso': {
if (specificResource) {
Expand All @@ -100,10 +100,10 @@ function _buildArn(
// arn:scality:metadata::<account-id>:<resource-type>/<resource>
if (specificResource) {
return `arn:scality:metadata::${requesterInfo!.accountid}:` +
`${generalResource}/${specificResource}`;
`${generalResource}/${specificResource}`;
}
return `arn:scality:metadata::${requesterInfo!.accountid}:` +
`${generalResource}/`;
`${generalResource}/`;
}
default:
return undefined;
Expand Down Expand Up @@ -173,6 +173,7 @@ export default class RequestContext {
_needTagEval: boolean;
_foundAction?: string;
_foundResource?: string;
_objectLockRetentionDays?: number | null;

constructor(
headers: { [key: string]: string | string[] },
Expand All @@ -194,6 +195,7 @@ export default class RequestContext {
requestObjTags?: string,
existingObjTag?: string,
needTagEval?: false,
objectLockRetentionDays?: number,
) {
this._headers = headers;
this._query = query;
Expand Down Expand Up @@ -226,6 +228,7 @@ export default class RequestContext {
this._requestObjTags = requestObjTags || null;
this._existingObjTag = existingObjTag || null;
this._needTagEval = needTagEval || false;
this._objectLockRetentionDays = objectLockRetentionDays || null;
return this;
}

Expand Down Expand Up @@ -257,6 +260,7 @@ export default class RequestContext {
requestObjTags: this._requestObjTags,
existingObjTag: this._existingObjTag,
needTagEval: this._needTagEval,
objectLockRetentionDays: this._objectLockRetentionDays,
};
return JSON.stringify(requestInfo);
}
Expand Down Expand Up @@ -297,6 +301,7 @@ export default class RequestContext {
obj.requestObjTags,
obj.existingObjTag,
obj.needTagEval,
obj.objectLockRetentionDays,
);
}

Expand Down Expand Up @@ -700,4 +705,24 @@ export default class RequestContext {
getNeedTagEval() {
return this._needTagEval;
}

/**
* Get object lock retention days
*
* @returns objectLockRetentionDays - object lock retention days
*/
getObjectLockRetentionDays() {
return this._objectLockRetentionDays;
}

/**
* Set object lock retention days
*
* @param objectLockRetentionDays - object lock retention days
* @returns itself
*/
setObjectLockRetentionDays(objectLockRetentionDays: number) {
this._objectLockRetentionDays = objectLockRetentionDays;
return this;
}
}
Loading
Loading