This is an automated email from the ASF dual-hosted git repository.

monkeydluffy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 647fa2348 docs: use shell instead of Python to configure protos 
resources (#9414)
647fa2348 is described below

commit 647fa234866a0fa579f871306375a783a922b97d
Author: Tristan <[email protected]>
AuthorDate: Sun May 7 00:07:32 2023 +0800

    docs: use shell instead of Python to configure protos resources (#9414)
---
 docs/en/latest/plugins/grpc-transcode.md | 36 +++++++-------------------------
 docs/zh/latest/plugins/grpc-transcode.md | 36 +++++++-------------------------
 2 files changed, 16 insertions(+), 56 deletions(-)

diff --git a/docs/en/latest/plugins/grpc-transcode.md 
b/docs/en/latest/plugins/grpc-transcode.md
index 3e75b428d..198eb1cdf 100644
--- a/docs/en/latest/plugins/grpc-transcode.md
+++ b/docs/en/latest/plugins/grpc-transcode.md
@@ -102,34 +102,14 @@ 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 command:
+
+```shell
+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 script will take in a `.pb` file and the `id` to create, encodes the 
content of the proto to `base64`, and calls the Admin API with this encoded 
content.
diff --git a/docs/zh/latest/plugins/grpc-transcode.md 
b/docs/zh/latest/plugins/grpc-transcode.md
index 5d0760768..35ef481c8 100644
--- a/docs/zh/latest/plugins/grpc-transcode.md
+++ b/docs/zh/latest/plugins/grpc-transcode.md
@@ -103,34 +103,14 @@ protoc --include_imports --descriptor_set_out=proto.pb 
proto/helloworld.proto
 
 然后将 `proto.pb` 的内容作为 proto 的 `content` 字段提交。
 
-由于 proto 的内容是二进制的,我们需要使用以下 Python 脚本将其转换成 `base64`:
-
-```python
-#!/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 your 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)
+由于 proto 的内容是二进制的,我们需要使用以下 shell 命令将其转换成 `base64`:
+
+```shell
+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)"'"
+}'
 ```
 
 该脚本将使用 `.pb` 文件和要创建的 `id`,将 proto 的内容转换成 `base64`,并使用转换后的内容调用 Admin API。

Reply via email to