You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by "suyanhanx (via GitHub)" <gi...@apache.org> on 2023/03/26 08:00:05 UTC

[GitHub] [incubator-opendal] suyanhanx opened a new pull request, #1772: feat(bindings/nodejs): Support presign

suyanhanx opened a new pull request, #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772

   add support of presign


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148539603


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   Cool!



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148537279


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   > ```js
   > const request = new Request(presignedRequest.uri, {
   >    headers: presignedRequest.headers,
   >    method: presignedRequest.method
   > })
   > fetch(request)
   > ```
   
   Cool, this is what I want. So users can pass `presignedRequest.headers` to `Request`'s construct without anyother changes?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] promer94 commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "promer94 (via GitHub)" <gi...@apache.org>.
promer94 commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148533288


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   ## Benefit
   The benefit of presigned url is that data could be safely downloaded (uploaded) from(to) data storage without passing through the server.  
   It can save a lot of traffic and reduce the server load.
   
   ## Example usage
   
   * Redirect the client to download the data directly from the data storage
   ```js
   const server = http.createServer(async (req, res) => {
     if (req.url.startsWith('/download') && req.method === 'GET') {
       const urlParts = url.parse(req.url, true)
       const path = urlParts.query.path
       const expires = urlParts.query.expires
   
       const presignedRequest = op.presignRead(path, parseInt(expires))
   
       res.statusCode = 307
       res.setHeader('Location', presignedRequest.uri)
       res.end(end)
     } else {
       res.statusCode = 404
       res.end('Not Found')
     }
   })
   ```
   
   
   * Pass the `presignedRequest` to the client, client could build a stander web `request` from it.
   ```js
   const request = new Request(presignedRequest.uri, {
      headers: presignedRequest.headers,
      method: presignedRequest.method
   })
   fetch(request)
   ```
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148504451


##########
bindings/nodejs/index.d.ts:
##########
@@ -101,3 +119,15 @@ export class Lister {
 export class BlockingLister {
   next(): Entry | null
 }
+export class PresignedRequest {
+  /** Returns the HTTP method of this request. */
+  get method(): string
+  /** Returns the URI of this request. */
+  get uri(): string
+  /**
+   * Returns the headers of this request.
+   *
+   * The key of the map is the header name, and the value is the header value AS bytes.
+   */
+  headers(): Record<string, Array<number>>

Review Comment:
   I'm not completely sure yet. This is still a draft.
   
   According to the HTTP spec, the values should all be strings. I'm considering changing them to string.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148501429


##########
bindings/nodejs/index.d.ts:
##########
@@ -101,3 +119,15 @@ export class Lister {
 export class BlockingLister {
   next(): Entry | null
 }
+export class PresignedRequest {
+  /** Returns the HTTP method of this request. */
+  get method(): string
+  /** Returns the URI of this request. */
+  get uri(): string
+  /**
+   * Returns the headers of this request.
+   *
+   * The key of the map is the header name, and the value is the header value AS bytes.
+   */
+  headers(): Record<string, Array<number>>

Review Comment:
   Is this normal in nodejs ecosystem?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148517807


##########
bindings/nodejs/examples/presign.js:
##########
@@ -0,0 +1,49 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+const http = require('node:http')
+const url = require('node:url')
+const { Operator } = require('../index')
+
+const op = new Operator('s3', {
+  root: '/',
+  bucket: 'example-bucket',
+})
+
+const server = http.createServer(async (req, res) => {
+  res.setHeader('Content-Type', 'text/json; charset=utf-8')
+
+  if (req.url.startsWith('/presign') && req.method === 'GET') {
+    const urlParts = url.parse(req.url, true)
+    const path = urlParts.query.path
+    const expires = urlParts.query.expires
+
+    const presignedRequest = op.presignRead(path, parseInt(expires))

Review Comment:
   In presigning, the `method` and `headers` are important factors. Could you demonstrate how users can utilize the `presignedRequest` struct to create their own HTTP request?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] promer94 commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "promer94 (via GitHub)" <gi...@apache.org>.
promer94 commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148533288


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   ## Benefit
   The benefit of presigned url is that data could be safely downloaded (uploaded) from(to) data storage without passing through the server.  
   It can save a lot of traffic and reduce the server load.
   
   ## Example usage
   
   * Redirect the client to download the data directly from the data storage
   ```js
   const server = http.createServer(async (req, res) => {
     if (req.url.startsWith('/download') && req.method === 'GET') {
       const urlParts = url.parse(req.url, true)
       const path = urlParts.query.path
       const expires = urlParts.query.expires
   
       const presignedRequest = op.presignRead(path, parseInt(expires))
   
       res.statusCode = 307
       res.setHeader('Location', presignedRequest.uri)
       res.end(end)
     } else {
       res.statusCode = 404
       res.end('Not Found')
     }
   })
   ```
   
   
   * user could build a stander web `request` from `presignedRequest`.
   ```js
   const request = new Request(presignedRequest.uri, {
      headers: presignedRequest.headers,
      method: presignedRequest.method
   })
   fetch(request)
   ```
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] promer94 commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "promer94 (via GitHub)" <gi...@apache.org>.
promer94 commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148533288


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   ## Benefit
   The benefit of presigned url is that data could be safely downloaded (uploaded) from(to) data storage without passing through the server.  
   It can save a lot of traffic and reduce the server load.
   
   ## Example usage
   
   * Redirect the client to download the data directly from the data storage
   ```js
   const server = http.createServer(async (req, res) => {
     if (req.url.startsWith('/download') && req.method === 'GET') {
       const urlParts = url.parse(req.url, true)
       const path = urlParts.query.path
       const expires = urlParts.query.expires
   
       const presignedRequest = op.presignRead(path, parseInt(expires))
   
       res.statusCode = 307
       res.setHeader('Location', presignedRequest.uri)
       res.end(end)
     } else {
       res.statusCode = 404
       res.end('Not Found')
     }
   })
   ```
   
   
   * user could build a standard web `request` from `presignedRequest`.
   ```js
   const request = new Request(presignedRequest.uri, {
      headers: presignedRequest.headers,
      method: presignedRequest.method
   })
   fetch(request)
   ```
   
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo merged pull request #1772: feat(bindings/nodejs): Support presign

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo merged PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] Xuanwo commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "Xuanwo (via GitHub)" <gi...@apache.org>.
Xuanwo commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148511144


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   I'm hesitant about the API. Could you please write a simple demo to show how a JavaScript or TypeScript developer can use this API? The most important thing for me is whether they will enjoy using `opendal`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] suyanhanx commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "suyanhanx (via GitHub)" <gi...@apache.org>.
suyanhanx commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148518181


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   Example added. 
   
   /cc @promer94



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [incubator-opendal] promer94 commented on a diff in pull request #1772: feat(bindings/nodejs): Support presign

Posted by "promer94 (via GitHub)" <gi...@apache.org>.
promer94 commented on code in PR #1772:
URL: https://github.com/apache/incubator-opendal/pull/1772#discussion_r1148539555


##########
bindings/nodejs/index.d.ts:
##########
@@ -64,6 +64,24 @@ export class Operator {
    * An error will be returned if given path doesn't end with `/`.
    */
   listSync(path: string): BlockingLister
+  /**
+   * Get a presigned request for read.
+   *
+   * Unit of expires is seconds.
+   */
+  presignRead(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for write.
+   *
+   * Unit of expires is seconds.
+   */
+  presignWrite(path: string, expires: number): PresignedRequest
+  /**
+   * Get a presigned request for stat.
+   *
+   * Unit of expires is seconds.
+   */
+  presignStat(path: string, expires: number): PresignedRequest

Review Comment:
   > Cool, this is what I want. So users can pass presignedRequest.headers to Request's construct without changes?
   
   Yes, the allowed header format is 
   ```ts
   type HeadersInit = [string, string][] | Record<string, string> | Headers;
   ```
   <img width="463" alt="CleanShot 2023-03-26 at 19 57 16@2x" src="https://user-images.githubusercontent.com/15878786/227774032-c13a9cb9-b1cc-4cbd-9ee7-bd0c4d7e46c7.png">
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@opendal.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org