Skip to content

Store lock meta in single attribute #1168

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

Merged
merged 1 commit into from
May 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 29 additions & 9 deletions api/layer/system_object.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ func (n *layer) getLockDataFromObjects(ctx context.Context, bkt *data.BucketInfo
object.AttributeFilePath,
object.AttributeTimestamp,
object.AttributeExpirationEpoch,
s3headers.AttributeComplianceMode,
s3headers.AttributeRetentionUntilMode,
s3headers.AttributeLockMeta,
}

opts client.SearchObjectsOptions
Expand Down Expand Up @@ -165,12 +164,21 @@ func (n *layer) getLockDataFromObjects(ctx context.Context, bkt *data.BucketInfo
}
}

psr.IsComplianceMode = item.Attributes[3] == "true"
if item.Attributes[3] != "" {
fields := make(map[string]string)
if err = json.Unmarshal([]byte(item.Attributes[3]), &fields); err != nil {
return nil, fmt.Errorf("unmarshal retention fields: %w", err)
}

if item.Attributes[4] != "" {
psr.RetentionUntilMode, err = time.Parse(time.RFC3339, item.Attributes[4])
if err != nil {
return nil, fmt.Errorf("parse retention until attribute: %w", err)
psr.IsComplianceMode = fields[s3headers.FieldComplianceMode] == "true"

if fields[s3headers.FieldRetentionUntilMode] != "" {
ts, err := strconv.ParseInt(fields[s3headers.FieldRetentionUntilMode], 10, 64)
if err != nil {
return nil, fmt.Errorf("invalid retention until time: %w", err)
}

psr.RetentionUntilMode = time.Unix(ts, 0).UTC()
}
}

Expand Down Expand Up @@ -375,11 +383,23 @@ func (n *layer) attributesFromLock(ctx context.Context, lock *data.ObjectLock) (
return nil, fmt.Errorf("fetch time to epoch: %w", err)
}

result[s3headers.AttributeRetentionUntilMode] = lock.Retention.Until.UTC().Format(time.RFC3339)
var (
retention = make(map[string]string, 2)
attributePayload []byte
)

retention[s3headers.FieldRetentionUntilMode] = strconv.FormatInt(lock.Retention.Until.UTC().Unix(), 10)

if lock.Retention.IsCompliance {
result[s3headers.AttributeComplianceMode] = "true"
retention[s3headers.FieldComplianceMode] = "true"
}

attributePayload, err = json.Marshal(retention)
if err != nil {
return nil, fmt.Errorf("marshal attribute: %w", err)
}

result[s3headers.AttributeLockMeta] = string(attributePayload)
}

if lock.LegalHold != nil && lock.LegalHold.Enabled {
Expand Down
12 changes: 9 additions & 3 deletions api/s3headers/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ const (
bucketSettingsPrefix = attributePrefix + "BucketSettings-"

// BucketSettingsVersioning contains versioning setting for bucket.
BucketSettingsVersioning = bucketSettingsPrefix + "Versioning"
AttributeComplianceMode = bucketSettingsPrefix + "ComplianceMode"
AttributeRetentionUntilMode = bucketSettingsPrefix + "RetentionUntil"
BucketSettingsVersioning = bucketSettingsPrefix + "Versioning"
// BucketSettingsMetaVersion contains version of bucket settings file.
BucketSettingsMetaVersion = bucketSettingsPrefix + "MetaVersion"

AttributeObjectVersion = attributePrefix + "ObjectVersion"
AttributeObjectNonce = "__NEOFS__NONCE"

// Result: S3-Lock-Meta.
AttributeLockMeta = attributePrefix + "Lock-Meta"

NeoFSSystemMetadataPrefix = attributePrefix + "Meta-"
// Result: S3-Meta-Algorithm.
AttributeEncryptionAlgorithm = NeoFSSystemMetadataPrefix + "Algorithm"
Expand All @@ -79,3 +80,8 @@ const (
AttributeDeleteMarker = NeoFSSystemMetadataPrefix + "DeleteMarker"
UploadCompletedParts = NeoFSSystemMetadataPrefix + "Completed-Parts"
)

const (
FieldComplianceMode = "ComplianceMode"
FieldRetentionUntilMode = "RetentionUntil"
)
15 changes: 5 additions & 10 deletions docs/attribute_mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,17 +170,11 @@ Specifies the version of the bucket settings object's file structure

If bucket versioning is enabled, this attribute indicates which version the object belongs to.

### `S3-BucketSettings-ComplianceMode`
### `S3-Lock-Meta`

Indicates whether the object is under a compliance-mode retention lock.

**Possible values:**

- `true`

### `S3-BucketSettings-RetentionUntil`

Contains the retention expiration timestamp in `time.RFC3339` format.
Contains JSON encoded lock metadata in the next fields:
- `ComplianceMode`. Indicates whether the object is under a compliance-mode retention lock.
- `RetentionUntil`. Contains the retention expiration timestamp.

### S3-Algorithm

Expand Down Expand Up @@ -235,6 +229,7 @@ contents for NeoFS lock objects.
- `S3-MetaType: lock`
- `S3-ObjectVersion`
- `S3-Meta-VersioningState`
- `S3-Lock-Meta`

### Tags Object

Expand Down
Loading