Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions tccli/plugins/cos/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# encoding: utf-8
"""
COS命令行工具插件
将coscmd的所有命令集成到tencentcloud-cli中
"""
from .list_object import list_object

service_name = "cos"
service_version = "2021-02-24"

_spec = {
"metadata": {
"serviceShortName": service_name,
"apiVersion": service_version,
"description": "COS (Cloud Object Storage) command line tool",
},
"actions": {
"list": {
"name": "列出文件",
"document": "List files on COS",
"input": "ListRequest",
"output": "ListResponse",
"action_caller": list_object,
}
},
"objects": {
"listRequest": {
"members": [
{"name": "bucket", "member": "string", "type": "string", "required": False, "document": "bucket id"},
],
},
"listResponse": {
"members": [],
},
},
"version": "1.0",
}


def register_service(specs):
specs[service_name] = {
service_version: _spec,
}
19 changes: 19 additions & 0 deletions tccli/plugins/cos/list_object.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from qcloud_cos import CosConfig
from qcloud_cos import CosS3Client


def list_object(args, parsed_globals):
secret_id = parsed_globals["secretId"]
secret_key = parsed_globals["secretKey"]
token = parsed_globals["token"]
region = parsed_globals["region"] or "ap-guangzhou"
endpoint = parsed_globals["endpoint"]

config = CosConfig(Region=region, SecretId=secret_id, SecretKey=secret_key, Token=token, Endpoint=endpoint)
client = CosS3Client(config)

response = client.list_objects(Bucket=args["bucket"])
if 'Contents' in response:
for content in response['Contents']:
print(content['Key'])