Skip to content

Commit

Permalink
docs: use shell instead of Python to configure protos resources (#9414)
Browse files Browse the repository at this point in the history
  • Loading branch information
jiangfucheng authored May 6, 2023
1 parent 29872c5 commit 647fa23
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 56 deletions.
36 changes: 8 additions & 28 deletions docs/en/latest/plugins/grpc-transcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 8 additions & 28 deletions docs/zh/latest/plugins/grpc-transcode.md
Original file line number Diff line number Diff line change
Expand Up @@ -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。
Expand Down

0 comments on commit 647fa23

Please sign in to comment.