Skip to content

Commit

Permalink
feat: 配置示例:1.配置项区分配置项名称和配置文件名...--story=120240982 (#3586)
Browse files Browse the repository at this point in the history
* 配置示例:1.配置项区分配置项名称和配置文件名;2.命令行工具添加配置下拉框;对应说明文案调整、复制命令内容调整、增加未选择配置文件时禁止复制逻辑;3.http(s)接口调用的python脚本修改、file型的shell方法脚本去除/;4.配置文件下拉框多层级路径处理--story=120240982

* feat: 去除labels的空格--story=120240982
  • Loading branch information
q15971095971 authored Oct 22, 2024
1 parent 70cacb2 commit 3bfec00
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function # 使print函数在Python 2中可用
import requests
import json
import os
import sys

# 检查Python版本
PY2 = sys.version_info[0] == 2

# 设置参数
feed_addr="{{ .Bk_Bscp_Variable_FEED_ADDR }}"
biz_id={{ .Bk_Bscp_Variable_BkBizId }}
service_name="{{ .Bk_Bscp_Variable_ServiceName }}"
file_path={{ .Bk_Bscp_Variable_KeyName }}
token={{ .Bk_Bscp_Variable_ClientKey }}
labels={{ .Bk_Bscp_Variable_Leabels }}
save_path='./'
feed_addr = "{{ .Bk_Bscp_Variable_FEED_ADDR }}"
biz_id = {{ .Bk_Bscp_Variable_BkBizId }}
service_name = "{{ .Bk_Bscp_Variable_ServiceName }}"
file_path = {{ .Bk_Bscp_Variable_KeyName }}
token = {{ .Bk_Bscp_Variable_ClientKey }}
labels = {{ .Bk_Bscp_Variable_Leabels }}
save_path = './'

# 使用参数构建URL
url = f"{feed_addr}/api/v1/feed/biz/{biz_id}/app/{service_name}/files{file_path}"
url = "{}/api/v1/feed/biz/{}/app/{}/files{}".format(feed_addr, biz_id, service_name, file_path)

# 设置请求头,包括Authorization token
headers = {
"Authorization": f"Bearer {token}",
"Authorization": "Bearer {}".format(token),
}

# 设置请求参数
Expand All @@ -27,7 +34,10 @@ params = {

# 发送 GET 请求下载文件(以标准输出在终端打印显示)
response = requests.get(url, params=params, headers=headers)
print("Response content:", response.content)

# 统一输出内容
content = response.content.decode('utf-8') if not PY2 else response.content
print("Response content:", content)

"""
# 把下载的文件保存在指定位置
Expand All @@ -36,5 +46,5 @@ if response.status_code == 200:
file.write(response.content)
print("The file has been saved to " + os.path.join(save_path, os.path.basename(file_path)))
else:
print(f'Request failed, status code:{response.status_code}')
print('Request failed, status code:{}'.format(response.status_code))
"""
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ auth_header="Authorization: Bearer ${token}"
curl -s -X GET -H "${auth_header}" "${url}"

# 把下载的文件保存在指定位置
# curl -s -X GET -H "${auth_header}" "${url}" -o ${save_path}/${file_path##*/}
# echo "The file has been saved to ${save_path}/${file_path##*/}"
# curl -s -X GET -H "${auth_header}" "${url}" -o ${save_path}${file_path##*/}
# echo "The file has been saved to ${save_path}${file_path##*/}"
Original file line number Diff line number Diff line change
@@ -1,20 +1,24 @@
#!/usr/bin/env python3
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from __future__ import print_function # 在Python 2中使用print函数
import requests

# 设置参数
feed_addr="{{ .Bk_Bscp_Variable_FEED_ADDR }}"
feed_addr = "{{ .Bk_Bscp_Variable_FEED_ADDR }}"
biz_id = {{ .Bk_Bscp_Variable_BkBizId }}
service_name = "{{ .Bk_Bscp_Variable_ServiceName }}"
key_name = {{ .Bk_Bscp_Variable_KeyName }}
token = {{ .Bk_Bscp_Variable_ClientKey }}
labels={{ .Bk_Bscp_Variable_Leabels }}
labels = {{ .Bk_Bscp_Variable_Leabels }}

# 使用参数构建URL
url = f"{feed_addr}/api/v1/feed/biz/{biz_id}/kvs/value/{key_name}"
# 在Python 2中使用format来替代f-string
url = "{}/api/v1/feed/biz/{}/kvs/value/{}".format(feed_addr, biz_id, key_name)

# 设置请求头,包括Authorization token
headers = {
"Authorization": f"Bearer {token}",
"Authorization": "Bearer {}".format(token),
}

# 设置请求数据
Expand All @@ -29,10 +33,11 @@ data = {
response = requests.post(url, headers=headers, json=data)

# 打印响应内容
# 使用response.text来获取字符串形式的响应内容,这在Python 2和3中都是一致的

# 当调用接口成功并正确获取配置项值时,返回“data”字段
# 返回格式样例:{"data": "value"}

# 当调用接口失败或获取配置项值出错时,返回“code”与“message”字段
# 返回格式样例:{"code": "PERMISSION_DENIED", "message": "credential is disabled"}

print("Response content:", response.text)
12 changes: 7 additions & 5 deletions bcs-services/bcs-bscp/ui/src/i18n/en-us.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ export default {
'节点管理插件客户端用于非容器化应用程序 (传统主机) 拉取文件型配置场景。': 'The node management plug-in client is used in the non-containerized application (traditional host) pull-file configuration scenario',
'命令行工具通常用于在脚本 (如 Bash、Python 等) 中手动拉取应用程序配置,同时支持文件型和键值型配置的获取。': 'Command line tools are commonly used to manually pull application configuration in scripts (such as Bash, Python, etc.), and support both file - and key-value configuration acquisition',
'请先选择客户端密钥,替换下方示例代码后,再尝试复制示例': 'Please select the client key first. After replacing the example code below, try to copy the example',
'请先选择配置文件名,替换下方示例代码后,再尝试复制示例': 'Please select a configuration file name, replace the example code below, and then try copying the example',
'请先选择配置项名称,替换下方示例代码后,再尝试复制示例': 'Please select the configuration item name first. After replacing the example code below, try to copy the example',
'请输入路径地址,替换下方示例代码后,再尝试复制示例': 'Please enter the path address, replace the sample code below, and then try to copy the sample',
临时目录: 'Temp directory',
Expand Down Expand Up @@ -843,17 +844,17 @@ export default {
'客户端下载配置文件后,会将其保存在': 'After downloading the configuration file, the client will save it in the',
目录复制成功: 'Directory copied successfully',
获取指定服务下所有配置项列表: 'Gets a list of all configuration items for the specified service',
'获取指定服务下指定配置项列表,多个配置项': 'Retrieve a list of specified configuration items under a specified service, multiple items',
'获取指定服务下指定配置项列表,支持多个配置项,配置项之间用空格分隔': 'Retrieve the list of specified configuration items under the specified service, supporting multiple configuration items separated by spaces',
'获取指定服务下指定配置项值,只支持单个配置项值获取': 'Obtain the value of a specified configuration item of a specified service. You can obtain only a single configuration item',
'获取指定服务下指定配置项元数据,支持多个配置项元数据获取,没有指定配置项,获取服务下所有配置项的元数据': 'Obtain the metadata of the specified configuration item of the specified service. You can obtain the metadata of multiple configuration items. Obtain the metadata of all configuration items of the service if no configuration item is specified',
'暂无可用密钥,可前往密钥管理新建/启用密钥,或将已有密钥关联至此服务': 'No available keys found. You can go to key management to create/enable a key or associate an existing key with this service',
'搜索结果为空,可前往密钥管理新建/启用密钥,或将已有密钥关联至此服务': 'Search result is empty. You can go to key management to create/enable a key or associate an existing key with this service',
禁止使用系统目录: 'Prohibited from using system directories',
复制成功: 'Copy Successful',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到 /tmp 目录时,文件保存在 /tmp/etc/nginx.conf': 'When downloading configuration files, preserve directory structure and save them to a specified directory. For example, downloading the file /etc/nginx.conf to the /tmp directory would save it as /tmp/etc/nginx.conf',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到 /tmp 目录时,文件保存在 /tmp/nginx.conf': 'When downloading configuration files, do not preserve directory structure and save them directly to a specified directory. For example, downloading the file /etc/nginx.conf to the /tmp directory would save it as /tmp/nginx.conf',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到当前目录时,文件保存在 .\\etc\\nginx.conf': 'When downloading the configuration file, retain the directory structure and save it to a specified directory. For example, when downloading the /etc/nginx.conf file to the current directory, it should be saved as .\\etc\\nginx.conf',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到当前目录时,文件保存在 .\\nginx.conf': 'When downloading the configuration file, do not retain the directory structure and save it to a specified directory. For example, when downloading the /etc/nginx.conf file to the current directory, it should be saved as .\\nginx.conf',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到 /tmp 目录时,文件保存在 /tmp{path}': 'When downloading configuration files, preserve directory structure and save them to a specified directory. For example, downloading the file {path} to the /tmp directory would save it as /tmp{path}',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到 /tmp 目录时,文件保存在 /tmp/{name}': 'When downloading configuration files, do not preserve directory structure and save them directly to a specified directory. For example, downloading the file {path} to the /tmp directory would save it as /tmp/{name}',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到当前目录时,文件保存在 .{windowsPath}': 'When downloading the configuration file, retain the directory structure and save it to a specified directory. For example, when downloading the {path} file to the current directory, it should be saved as .{windowsPath}',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到当前目录时,文件保存在 .\\{windowsName}': 'When downloading the configuration file, do not retain the directory structure and save it to a specified directory. For example, when downloading the {path} file to the current directory, it should be saved as .\\{windowsName}',
'BSCP Python SDK依赖说明': 'dependency instructions in the BSCP Python SDK',
'用于主动获取配置项值的场景,此方法不会监听服务器端的配置更改,有关Python SDK的部署环境和依赖组件,请参阅白皮书中的': 'For scenarios where configuration values are actively retrieved, this method does not monitor server-side configuration changes. For information on the deployment environment and dependent components of the Python SDK, please refer to the',
'通过建立长连接,实时监听配置版本的变更,当新版本的配置发布时,将自动调用回调方法处理新的配置信息,适用于需要实时响应配置变更的场景,有关Python SDK的部署环境和依赖组件,请参阅白皮书中的': 'By establishing a persistent connection, real-time changes to configuration versions are monitored. When a new version of configuration is released, the callback method is automatically invoked to handle the new configuration information. This method is suitable for scenarios requiring real-time response to configuration changes. For information on the deployment environment and dependent components of the Python SDK, please refer to the',
Expand All @@ -878,6 +879,7 @@ export default {
搜索视图: 'Search view',
'请先选择BCS 集群 ID,替换下方示例代码后,再尝试复制示例': 'Please select the BCS cluster ID first, replace the example code below, and then try to copy the example',
'请选择一个配置文件名,用于测试下载相应文件': 'Please select a configuration file name for testing the download of the corresponding file',
'请选择一个配置项名称,用于测试下载相应文件': 'Please select a configuration item name for testing the download of the corresponding file',
'HTTP(S)接口调用': 'HTTP(S) interface invocation',
'请输入BCS 集群 ID,替换下方示例代码后,再尝试复制示例': 'Please enter the BCS cluster ID, replace the example code below, and then try copying the example',
'BCS集群ID须符合以下格式:BCS-K8S-xxxxx,其中xxxxx为5位数字': 'The BCS cluster ID must follow the format: BCS-K8S-xxxxx, where xxxxx is a five-digit numbe',
Expand Down
12 changes: 7 additions & 5 deletions bcs-services/bcs-bscp/ui/src/i18n/zh-cn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,7 @@ export default {
'节点管理插件客户端用于非容器化应用程序 (传统主机) 拉取文件型配置场景。': '节点管理插件客户端用于非容器化应用程序 (传统主机) 拉取文件型配置场景。',
'命令行工具通常用于在脚本 (如 Bash、Python 等) 中手动拉取应用程序配置,同时支持文件型和键值型配置的获取。': '命令行工具通常用于在脚本 (如 Bash、Python 等) 中手动拉取应用程序配置,同时支持文件型和键值型配置的获取。',
'请先选择客户端密钥,替换下方示例代码后,再尝试复制示例': '请先选择客户端密钥,替换下方示例代码后,再尝试复制示例',
'请先选择配置文件名,替换下方示例代码后,再尝试复制示例': '请先选择配置文件名,替换下方示例代码后,再尝试复制示例',
'请先选择配置项名称,替换下方示例代码后,再尝试复制示例': '请先选择配置项名称,替换下方示例代码后,再尝试复制示例',
'请输入路径地址,替换下方示例代码后,再尝试复制示例': '请输入路径地址,替换下方示例代码后,再尝试复制示例',
临时目录: '临时目录',
Expand Down Expand Up @@ -847,17 +848,17 @@ export default {
'客户端下载配置文件后,会将其保存在': '客户端下载配置文件后,会将其保存在',
目录复制成功: '目录复制成功',
获取指定服务下所有配置项列表: '获取指定服务下所有配置项列表',
'获取指定服务下指定配置项列表,多个配置项': '获取指定服务下指定配置项列表,多个配置项',
'获取指定服务下指定配置项列表,支持多个配置项,配置项之间用空格分隔': '获取指定服务下指定配置项列表,支持多个配置项,配置项之间用空格分隔',
'获取指定服务下指定配置项值,只支持单个配置项值获取': '获取指定服务下指定配置项值,只支持单个配置项值获取',
'获取指定服务下指定配置项元数据,支持多个配置项元数据获取,没有指定配置项,获取服务下所有配置项的元数据': '获取指定服务下指定配置项元数据,支持多个配置项元数据获取,没有指定配置项,获取服务下所有配置项的元数据',
'暂无可用密钥,可前往密钥管理新建/启用密钥,或将已有密钥关联至此服务': '暂无可用密钥,可前往密钥管理新建/启用密钥,或将已有密钥关联至此服务',
'搜索结果为空,可前往密钥管理新建/启用密钥,或将已有密钥关联至此服务': '搜索结果为空,可前往密钥管理新建/启用密钥,或将已有密钥关联至此服务',
禁止使用系统目录: '禁止使用系统目录',
复制成功: '复制成功',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到 /tmp 目录时,文件保存在 /tmp/etc/nginx.conf': '下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到 /tmp 目录时,文件保存在 /tmp/etc/nginx.conf',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到 /tmp 目录时,文件保存在 /tmp/nginx.conf': '下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到 /tmp 目录时,文件保存在 /tmp/nginx.conf',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到当前目录时,文件保存在 .\\etc\\nginx.conf': '下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到当前目录时,文件保存在 .\\etc\\nginx.conf',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到当前目录时,文件保存在 .\\nginx.conf': '下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 /etc/nginx.conf 文件下载到当前目录时,文件保存在 .\\nginx.conf',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到 /tmp 目录时,文件保存在 /tmp{path}': '下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到 /tmp 目录时,文件保存在 /tmp{path}',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到 /tmp 目录时,文件保存在 /tmp/{name}': '下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到 /tmp 目录时,文件保存在 /tmp/{name}',
'下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到当前目录时,文件保存在 .{windowsPath}': '下载配置文件时,保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到当前目录时,文件保存在 .{windowsPath}',
'下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到当前目录时,文件保存在 .\\{windowsName}': '下载配置文件时,不保留目录层级,并将其保存到指定目录下,例如:将 {path} 文件下载到当前目录时,文件保存在 .\\{windowsName}',
'BSCP Python SDK依赖说明': 'BSCP Python SDK依赖说明',
'用于主动获取配置项值的场景,此方法不会监听服务器端的配置更改,有关Python SDK的部署环境和依赖组件,请参阅白皮书中的': '用于主动获取配置项值的场景,此方法不会监听服务器端的配置更改,有关Python SDK的部署环境和依赖组件,请参阅白皮书中的',
'通过建立长连接,实时监听配置版本的变更,当新版本的配置发布时,将自动调用回调方法处理新的配置信息,适用于需要实时响应配置变更的场景,有关Python SDK的部署环境和依赖组件,请参阅白皮书中的': '通过建立长连接,实时监听配置版本的变更,当新版本的配置发布时,将自动调用回调方法处理新的配置信息,适用于需要实时响应配置变更的场景,有关Python SDK的部署环境和依赖组件,请参阅白皮书中的',
Expand All @@ -881,6 +882,7 @@ export default {
'BCS 集群 ID': 'BCS 集群 ID',
搜索视图: '搜索视图',
'请选择一个配置文件名,用于测试下载相应文件': '请选择一个配置文件名,用于测试下载相应文件',
'请选择一个配置项名称,用于测试下载相应文件': '请选择一个配置项名称,用于测试下载相应文件',
'HTTP(S)接口调用': 'HTTP(S)接口调用',
'请输入BCS 集群 ID,替换下方示例代码后,再尝试复制示例': '请输入BCS 集群 ID,替换下方示例代码后,再尝试复制示例',
'BCS集群ID须符合以下格式:BCS-K8S-xxxxx,其中xxxxx为5位数字': 'BCS集群ID须符合以下格式:BCS-K8S-xxxxx,其中xxxxx为5位数字',
Expand Down
Loading

0 comments on commit 3bfec00

Please sign in to comment.