You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by "jiangfucheng (via GitHub)" <gi...@apache.org> on 2023/05/05 13:14:43 UTC

[GitHub] [apisix] jiangfucheng opened a new pull request, #9414: docs: use shell instead of Python to configure protos resources

jiangfucheng opened a new pull request, #9414:
URL: https://github.com/apache/apisix/pull/9414

   ### Description
   
   <!-- Please include a summary of the change and which issue is fixed. -->
   <!-- Please also include relevant motivation and context. -->
   
   Fixes https://github.com/apache/apisix/issues/9405
   
   ### Checklist
   
   - [x] I have explained the need for this PR and the problem it solves
   - [ ] I have explained the changes or the new features added to this PR
   - [ ] I have added tests corresponding to this change
   - [ ] I have updated the documentation to reflect this change
   - [ ] I have verified that this change is backward compatible (If not, please discuss on the [APISIX mailing list](https://github.com/apache/apisix/tree/master#community) first)
   
   <!--
   
   Note
   
   1. Mark the PR as draft until it's ready to be reviewed.
   2. Always add/update tests for any changes unless you have a good reason.
   3. Always update the documentation to reflect the changes made in the PR.
   4. Make a new commit to resolve conversations instead of `push -f`.
   5. To resolve merge conflicts, merge master instead of rebasing.
   6. Use "request review" to notify the reviewer after making changes.
   7. Only a reviewer can mark a conversation as resolved.
   
   -->
   


-- 
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: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] jiangfucheng commented on a diff in pull request #9414: docs: use shell instead of Python to configure protos resources

Posted by "jiangfucheng (via GitHub)" <gi...@apache.org>.
jiangfucheng commented on code in PR #9414:
URL: https://github.com/apache/apisix/pull/9414#discussion_r1186701390


##########
docs/en/latest/plugins/grpc-transcode.md:
##########
@@ -102,34 +102,26 @@ The output binary file, `proto.pb` will contain both `helloworld.proto` and `imp
 
 We can now use the content of `proto.pb` in the `content` field of the API request.
 
-As the content of the proto is binary, we encode it in `base64` using this Python script:
-
-```python title="upload_pb.py"
-#!/usr/bin/env python
-# coding: utf-8
-
-import base64
-import sys
-
-# sudo pip install requests
-import requests
-
-if len(sys.argv) <= 1:
-    print("bad argument")
-    sys.exit(1)
-with open(sys.argv[1], 'rb') as f:
-    content = base64.b64encode(f.read())
-id = sys.argv[2]
-api_key = "edd1c9f034335f136f87ad84b625c8f1" # use a different API key
-
-reqParam = {
-    "content": content,
-}
-resp = requests.put("http://127.0.0.1:9180/apisix/admin/protos/" + id, json=reqParam, headers={
-    "X-API-KEY": api_key,
-})
-print(resp.status_code)
-print(resp.text)
+As the content of the proto is binary, we encode it in `base64` using this shell script:
+
+```shell
+#!/usr/bin/env bash
+
+set -xeu
+
+if [ $# -lt 2 ]; then
+    echo "usage: $0 <proto_file> <proto_id>"
+    exit 1
+fi
+
+proto_file_name=$1
+id=$2
+api_key=edd1c9f034335f136f87ad84b625c8f1
+
+content=$(base64 -i "$proto_file_name")
+request_body="{\"content\": \"$content\"}"
+
+curl http://127.0.0.1:9180/apisix/admin/protos/"$id" -X PUT -H "X-API-KEY: $api_key" -d "$request_body"

Review Comment:
   Updated, thanks.



-- 
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: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] kingluo commented on a diff in pull request #9414: docs: use shell instead of Python to configure protos resources

Posted by "kingluo (via GitHub)" <gi...@apache.org>.
kingluo commented on code in PR #9414:
URL: https://github.com/apache/apisix/pull/9414#discussion_r1186599122


##########
docs/en/latest/plugins/grpc-transcode.md:
##########
@@ -102,34 +102,26 @@ The output binary file, `proto.pb` will contain both `helloworld.proto` and `imp
 
 We can now use the content of `proto.pb` in the `content` field of the API request.
 
-As the content of the proto is binary, we encode it in `base64` using this Python script:
-
-```python title="upload_pb.py"
-#!/usr/bin/env python
-# coding: utf-8
-
-import base64
-import sys
-
-# sudo pip install requests
-import requests
-
-if len(sys.argv) <= 1:
-    print("bad argument")
-    sys.exit(1)
-with open(sys.argv[1], 'rb') as f:
-    content = base64.b64encode(f.read())
-id = sys.argv[2]
-api_key = "edd1c9f034335f136f87ad84b625c8f1" # use a different API key
-
-reqParam = {
-    "content": content,
-}
-resp = requests.put("http://127.0.0.1:9180/apisix/admin/protos/" + id, json=reqParam, headers={
-    "X-API-KEY": api_key,
-})
-print(resp.status_code)
-print(resp.text)
+As the content of the proto is binary, we encode it in `base64` using this shell script:
+
+```shell
+#!/usr/bin/env bash
+
+set -xeu
+
+if [ $# -lt 2 ]; then
+    echo "usage: $0 <proto_file> <proto_id>"
+    exit 1
+fi
+
+proto_file_name=$1
+id=$2
+api_key=edd1c9f034335f136f87ad84b625c8f1
+
+content=$(base64 -i "$proto_file_name")
+request_body="{\"content\": \"$content\"}"
+
+curl http://127.0.0.1:9180/apisix/admin/protos/"$id" -X PUT -H "X-API-KEY: $api_key" -d "$request_body"

Review Comment:
   No need to use a script, instead, to make full use of bash functionality, one command line is enough.
   
   ```bash
   curl http://127.0.0.1:9180/apisix/admin/protos/1 \
   -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "content" : "'"$(base64 -w0 /path/to/proto.pb)"'"
   }'
   ```



-- 
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: notifications-unsubscribe@apisix.apache.org

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


[GitHub] [apisix] monkeyDluffy6017 merged pull request #9414: docs: use shell instead of Python to configure protos resources

Posted by "monkeyDluffy6017 (via GitHub)" <gi...@apache.org>.
monkeyDluffy6017 merged PR #9414:
URL: https://github.com/apache/apisix/pull/9414


-- 
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: notifications-unsubscribe@apisix.apache.org

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