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

Add new upload and edit download requests #206

Merged
merged 8 commits into from
May 29, 2024

Conversation

tatiana-nspcc
Copy link
Contributor

@tatiana-nspcc tatiana-nspcc commented May 12, 2024

Close #168.

Copy link

codecov bot commented May 12, 2024

Codecov Report

Attention: Patch coverage is 21.83908% with 340 lines in your changes are missing coverage. Please review.

Project coverage is 22.13%. Comparing base (d860495) to head (3747724).
Report is 1 commits behind head on master.

Files Patch % Lines
handlers/newObjects.go 0.00% 152 Missing ⚠️
handlers/apiserver/rest-server.gen.go 36.62% 92 Missing and 17 partials ⚠️
handlers/objects.go 0.00% 57 Missing ⚠️
handlers/preflight.go 0.00% 15 Missing ⚠️
handlers/util.go 82.05% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #206      +/-   ##
==========================================
- Coverage   22.14%   22.13%   -0.02%     
==========================================
  Files          16       17       +1     
  Lines        2894     3293     +399     
==========================================
+ Hits          641      729      +88     
- Misses       2137     2431     +294     
- Partials      116      133      +17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@roman-khimov roman-khimov requested a review from mike-petrov May 13, 2024 09:35
Copy link
Member

@roman-khimov roman-khimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think in general this approach should be OK for us. S3 goes via PutObjectTagging with XML-encoded data, but we can't have a separate request since objects are immutable. Caveats:

  • data with embedded newlines, it can't be handled in headers easily (requires safe encoding), special characters can be a problem too
  • some data comes from headers and some from these attributes, we need to lay down the rules explicitly on how they interact
  • well-known attributes can be handled via well-known headers

spec/rest.yaml Outdated Show resolved Hide resolved
spec/rest.yaml Outdated Show resolved Hide resolved
spec/rest.yaml Outdated
type: string
requestBody:
content:
multipart/form-data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's think if we need it to be a multipart/form-data.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? What other options do we have?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the object can be uploaded directly to the body request.

handlers/objects.go Show resolved Hide resolved
@tatiana-nspcc tatiana-nspcc force-pushed the 168-new-upload-download branch from a11b6e2 to fa56453 Compare May 16, 2024 21:35
@tatiana-nspcc tatiana-nspcc marked this pull request as ready for review May 17, 2024 10:30
@tatiana-nspcc tatiana-nspcc requested a review from smallhive as a code owner May 17, 2024 10:30
@tatiana-nspcc tatiana-nspcc changed the title 168 new upload download Add new upload and edit download requests May 17, 2024
spec/rest.yaml Outdated Show resolved Hide resolved
spec/rest.yaml Outdated Show resolved Hide resolved
spec/rest.yaml Outdated Show resolved Hide resolved
spec/rest.yaml Show resolved Hide resolved
handlers/util.go Outdated Show resolved Hide resolved
spec/rest.yaml Outdated
- "2024-12-31T23:59:59Z" represents the last moment of 2024 in UTC.
- "2024-12-31T15:59:59-08:00" represents 3:59 PM on December 31, 2024, Pacific Time.
- `__NEOFS__EXPIRATION_TIMESTAMP` - specifies the exact timestamp of expiration.
- `__NEOFS__EXPIRATION_DURATION` - specifies the duration until expiration in Go's duration format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where this comes from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was here for ages:

ExpirationDurationAttr = SystemAttributePrefix + "EXPIRATION_DURATION"
and
func prepareExpirationHeader(headers map[string]string, epochDurations *epochDurations, now time.Time) error {

spec/rest.yaml Outdated
Examples:
- "2024-12-31T23:59:59Z" represents the last moment of 2024 in UTC.
- "2024-12-31T15:59:59-08:00" represents 3:59 PM on December 31, 2024, Pacific Time.
- `__NEOFS__EXPIRATION_TIMESTAMP` - specifies the exact timestamp of expiration.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And this one?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Answered in the other thread.

spec/rest.yaml Outdated
All attributes are in a JSON-formatted map of key-value pairs, where the key is the
attribute name and the value is the attribute value.
You can also use one of these special attributes:
- `__NEOFS__EXPIRATION_RFC3339` - specifies the expiration time in RFC3339 format.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These shouldn't be written like this, they're not a real object attributes, API knows nothing about them. We can emulate some of them for user convenience, but we better do this via real HTTP headers, leave JSON for real attributes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case, we will use the following headers for the three attributes: X-Neofs-EXPIRATION_DURATION, X-Neofs-EXPIRATION_TIMESTAMP, X-Neofs-EXPIRATION_RFC3339 as they are in the old GET request. Okay?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

docs/migration-new-upload.md Outdated Show resolved Hide resolved
@@ -434,7 +436,7 @@ func (a *RestAPI) getByAddress(ctx echo.Context, addr oid.Address, downloadParam

var (
payloadSize = header.PayloadSize()
contentType = a.setAttributes(ctx, payloadSize, addr.Container().String(), addr.Object().String(), header, downloadParam)
contentType = a.setAttributes(ctx, payloadSize, addr.Container().String(), addr.Object().String(), header, downloadParam, jsonParam)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this function may require a small argument refactoring. To many parameters, we should consider moving them in struct. But maybe in different issue

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed using a structure.

Comment on lines 556 to 558
var useJSON bool
if jsonParam != nil && paramIsPositive(*jsonParam) {
useJSON = true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may simplify a bit

useJSON := jsonParam != nil && paramIsPositive(*jsonParam)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tnx, fixed.

handlers/util.go Outdated
Comment on lines 382 to 389
func paramIsPositive(s string) bool {
switch s {
case "1", "t", "T", "true", "TRUE", "True", "y", "yes", "Y", "YES", "Yes":
return true
}
return false
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All usage of the func is working with the pointer. I consider it makes sense to replace the parameter s string to s *string and handle nil inside this function. Yes, it can affect the tests, but simplify the code in general

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

spec/rest.yaml Outdated Show resolved Hide resolved
spec/rest.yaml Outdated Show resolved Hide resolved
@tatiana-nspcc tatiana-nspcc force-pushed the 168-new-upload-download branch 2 times, most recently from bde50cf to a7b4cd7 Compare May 26, 2024 23:12
Signed-off-by: Tatiana Nesterenko <[email protected]>
Add a new POST request `/objects/{cId}` that accepts the `X-Attributes`
header. Also, new GET and HEAD requests are added for object downloading:
`/objects/{containerId}/by_id/{objectId}` and
`/objects/{containerId}/by_attribute/{attrKey}/{attrVal}`.

Signed-off-by: Tatiana Nesterenko <[email protected]>
@tatiana-nspcc tatiana-nspcc force-pushed the 168-new-upload-download branch from a7b4cd7 to 3747724 Compare May 27, 2024 09:14
@tatiana-nspcc
Copy link
Contributor Author

After smallhive's review, I only rebased the branch on the current master.

@roman-khimov roman-khimov merged commit 93e652d into master May 29, 2024
12 of 14 checks passed
@roman-khimov roman-khimov deleted the 168-new-upload-download branch May 29, 2024 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide more reliable binary upload/download API
3 participants