Skip to content

Commit cfcc6da

Browse files
committed
Add client SSL context support
The client now support setting SSL context. Also, root certificates from universally trusted CAs are provided built-in.
1 parent 7389044 commit cfcc6da

File tree

12 files changed

+4713
-25
lines changed

12 files changed

+4713
-25
lines changed

README.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,9 @@ It is important to note that you cannot use `asyncio.run` to call asynchronous e
1313

1414
## Navigation
1515
- [Homepage](https://github.com/nobody-night/tencent-cloud-sdk-python)
16-
- Documentation
17-
- [English (Writing...)](https://smallso.gitbook.io/tencent-cloud-sdk/v/english/)
18-
- [简体中文](https://smallso.gitbook.io/tencent-cloud-sdk/)
16+
- [Documentation](https://smallso.gitbook.io/tencent-cloud-sdk/)
1917
- [Release Notes](https://github.com/nobody-night/tencent-cloud-sdk-python/releases)
2018
- [License](LICENSE)
21-
- [Author Homepage](https://cloud.tencent.com/)
2219

2320
## Installation
2421
With the Python package manager, you can quickly install the Tencent Cloud SDK for Python.
@@ -132,7 +129,7 @@ Since the Tencent Cloud product we need to use does not provide a product client
132129
Below we take Cloud Virtual Machine (CVM) products as an example:
133130

134131
```python
135-
virtual_machine_client: client.UniversalClient = client.UniversalClient(
132+
cvm_client = client.UniversalClient(
136133
product_id = 'cvm', # Unique identifier of the product
137134
access_credentials = access_credentials # Access credentials
138135
)
@@ -142,9 +139,10 @@ virtual_machine_client: client.UniversalClient = client.UniversalClient(
142139
Finally, we try to retrieve Zone information operated by a given data center campus, which will use the Tencent Cloud API called [DescribeZones](https://cloud.tencent.com/document/api/213/15707):
143140

144141
```python
145-
action_result: dict = virtual_machine_client.action(
142+
action_result: dict = cvm_client.action(
146143
region_id = 'ap-shanghai', # Unique identifier of the data center
147144
action_id = 'DescribeZones', # Unique identifier of the Tencent Cloud API
145+
action_parameters = None,
148146
action_version = '2017-03-12' # Version name of the Tencent Cloud API
149147
)
150148
```
@@ -160,12 +158,6 @@ for zone_info in action_result['ZoneSet']:
160158

161159
For more ways to use Tencent Cloud SDK for Python, see our online documentation. Thank you!
162160

163-
## To Do
164-
The next things we need to accomplish are:
165-
166-
- [ ] Write and publish component package coding conventions.
167-
- [ ] Add more component packs to support active Tencent Cloud products.
168-
169161
## License
170162
The Tencent Cloud SDK for Python is open source using the MIT license, which means that your use is subject to the license, please [view](LICENSE) license details.
171163

build.sh

100644100755
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
pip install build
3+
pip3 install build
44
rm -rf ./dist
55

66
build_package() {

packages/tencent-cloud-sdk-common/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ To facilitate the deployment and migration of the Tencent Cloud SDK for Python,
3131
- https://pypi.org/project/idna/
3232
- https://pypi.org/project/idna_ssl/
3333
- https://pypi.org/project/typing-extensions/
34+
- https://pypi.org/project/certifi/
3435

3536
It is worth noting that our use of these dependent packages is subject to their open source licenses.
3637

packages/tencent-cloud-sdk-common/setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def read_readme_content() -> str:
3535

3636
setuptools.setup(
3737
name = 'tencent-cloud-sdk-common',
38-
version = '0.1.3',
38+
version = '0.1.4',
3939
packages = [
4040
'tencent.cloud.common',
4141
'tencent.cloud.common.aiohttp',
@@ -48,6 +48,7 @@ def read_readme_content() -> str:
4848
'tencent.cloud.common.idna',
4949
'tencent.cloud.common.multidict',
5050
'tencent.cloud.common.yarl',
51+
'tencent.cloud.common.certifi',
5152
],
5253
keywords = 'tencent-cloud sdk-python',
5354
license = 'MIT License',
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from .core import contents, where
2+
3+
__all__ = ["contents", "where"]
4+
__version__ = "2022.05.18.1"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import argparse
2+
3+
from certifi import contents, where
4+
5+
parser = argparse.ArgumentParser()
6+
parser.add_argument("-c", "--contents", action="store_true")
7+
args = parser.parse_args()
8+
9+
if args.contents:
10+
print(contents())
11+
else:
12+
print(where())

packages/tencent-cloud-sdk-common/tencent/cloud/common/certifi/cacert.pem

Lines changed: 4530 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""
2+
certifi.py
3+
~~~~~~~~~~
4+
5+
This module returns the installation location of cacert.pem or its contents.
6+
"""
7+
import os
8+
import types
9+
from typing import Union
10+
11+
try:
12+
from importlib.resources import path as get_path, read_text
13+
14+
_CACERT_CTX = None
15+
_CACERT_PATH = None
16+
17+
def where() -> str:
18+
# This is slightly terrible, but we want to delay extracting the file
19+
# in cases where we're inside of a zipimport situation until someone
20+
# actually calls where(), but we don't want to re-extract the file
21+
# on every call of where(), so we'll do it once then store it in a
22+
# global variable.
23+
global _CACERT_CTX
24+
global _CACERT_PATH
25+
if _CACERT_PATH is None:
26+
# This is slightly janky, the importlib.resources API wants you to
27+
# manage the cleanup of this file, so it doesn't actually return a
28+
# path, it returns a context manager that will give you the path
29+
# when you enter it and will do any cleanup when you leave it. In
30+
# the common case of not needing a temporary file, it will just
31+
# return the file system location and the __exit__() is a no-op.
32+
#
33+
# We also have to hold onto the actual context manager, because
34+
# it will do the cleanup whenever it gets garbage collected, so
35+
# we will also store that at the global level as well.
36+
_CACERT_CTX = get_path("certifi", "cacert.pem")
37+
_CACERT_PATH = str(_CACERT_CTX.__enter__())
38+
39+
return _CACERT_PATH
40+
41+
42+
except ImportError:
43+
Package = Union[types.ModuleType, str]
44+
Resource = Union[str, "os.PathLike"]
45+
46+
# This fallback will work for Python versions prior to 3.7 that lack the
47+
# importlib.resources module but relies on the existing `where` function
48+
# so won't address issues with environments like PyOxidizer that don't set
49+
# __file__ on modules.
50+
def read_text(
51+
package: Package,
52+
resource: Resource,
53+
encoding: str = 'utf-8',
54+
errors: str = 'strict'
55+
) -> str:
56+
with open(where(), encoding=encoding) as data:
57+
return data.read()
58+
59+
# If we don't have importlib.resources, then we will just do the old logic
60+
# of assuming we're on the filesystem and munge the path directly.
61+
def where() -> str:
62+
f = os.path.dirname(__file__)
63+
64+
return os.path.join(f, "cacert.pem")
65+
66+
67+
def contents() -> str:
68+
return read_text("certifi", "cacert.pem", encoding="ascii")

packages/tencent-cloud-sdk-common/tencent/cloud/common/certifi/py.typed

Whitespace-only changes.

packages/tencent-cloud-sdk-core/setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def read_readme_content() -> str:
3535

3636
setuptools.setup(
3737
name = 'tencent-cloud-sdk-core',
38-
version = '0.2.3',
38+
version = '0.2.4',
3939
packages = [
4040
'tencent.cloud.core'
4141
],
@@ -63,6 +63,6 @@ def read_readme_content() -> str:
6363
],
6464
install_requires = [
6565
'tencent-cloud-sdk-auth>=0.2.2',
66-
'tencent-cloud-sdk-common>=0.1.3'
66+
'tencent-cloud-sdk-common>=0.1.4'
6767
]
6868
)

0 commit comments

Comments
 (0)