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

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

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