Skip to content

Commit 66cb7c6

Browse files
authored
feat: fix test cases and CI (#4)
* fix: Refactor test cases * fix: Restore pipy and other configurations * fix: Format code style * fix: Try publishing to the pypi test site * fix: Format code style * fix: Test the master branch * fix: Pypi officially released
1 parent 5f28ab7 commit 66cb7c6

File tree

13 files changed

+277
-279
lines changed

13 files changed

+277
-279
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
- name: Setup semantic-release
5555
run: |
5656
npm init -y
57-
npm install -g semantic-release @semantic-release/github @semantic-release/commit-analyzer @semantic-release/release-notes-generator
57+
npm install -g semantic-release @semantic-release/github @semantic-release/changelog @semantic-release/commit-analyzer @semantic-release/git @semantic-release/release-notes-generator semantic-release-pypi
5858
5959
- name: Set up Python
6060
uses: actions/setup-python@v2
@@ -67,5 +67,5 @@ jobs:
6767
- name: Release
6868
env:
6969
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
70-
# PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
70+
PYPI_TOKEN: ${{ secrets.PYPI_TOKEN }}
7171
run: npx semantic-release

package.json

+18-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
{
22
"name": "casvisor-python-sdk",
3-
"version": "0.1.0",
3+
"version": "1.0.0",
44
"repository": {
55
"type": "git",
6-
"url": "https://github.com/ljl66-66/casvisor-python-sdk.git"
6+
"url": "https://github.com/casvisor/casvisor-python-sdk.git"
77
},
88
"release": {
99
"branches": [
@@ -12,14 +12,24 @@
1212
"plugins": [
1313
"@semantic-release/commit-analyzer",
1414
"@semantic-release/release-notes-generator",
15+
"semantic-release-pypi",
16+
"@semantic-release/github",
1517
[
16-
"@semantic-release/github",
18+
"@semantic-release/changelog",
1719
{
18-
"successComment": false,
19-
"failComment": false,
20-
"failTitle": false,
21-
"releasedLabels": false,
22-
"addReleases": "bottom"
20+
"changelogFile": "CHANGELOG.md",
21+
"changelogTitle": "# Semantic Versioning Changelog"
22+
}
23+
],
24+
[
25+
"@semantic-release/git",
26+
{
27+
"message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}",
28+
"assets": [
29+
"CHANGELOG.md",
30+
"setup.py",
31+
"setup.cfg"
32+
]
2333
}
2434
]
2535
]

pyproject.toml

+26-2
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
[project]
22
name = "casvisor-python-sdk"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
description = "Python SDK for Casvisor"
55
readme = "README.md"
66
requires-python = ">=3.8"
77
authors = [
88
{ name = "Casvisor", email = "[email protected]" }
99
]
1010
license = { file = "LICENSE" }
11+
keywords = ["Casvisor"]
1112
classifiers = [
1213
"Intended Audience :: Developers",
1314
"License :: OSI Approved :: Apache Software License",
1415
"Operating System :: OS Independent",
15-
"Programming Language :: Python :: 3",
16+
"Programming Language :: Python",
1617
"Programming Language :: Python :: 3.8",
1718
"Programming Language :: Python :: 3.9",
1819
"Programming Language :: Python :: 3.10",
1920
"Programming Language :: Python :: 3.11",
21+
"Programming Language :: Python :: 3.12",
2022
]
2123

2224
dynamic = ["dependencies"]
@@ -29,3 +31,25 @@ dependencies = {file = ["requirements.txt"]}
2931
[build-system]
3032
requires = ["setuptools", "wheel"]
3133
build-backend = "setuptools.build_meta"
34+
35+
[tool.black]
36+
line-length = 88
37+
target-version = ["py38", "py39", "py310", "py311"]
38+
include = '\.pyi?$'
39+
40+
[tool.ruff]
41+
line-length = 88
42+
43+
[tool.ruff.lint]
44+
select = [
45+
"E", # pycodestyle errors
46+
"W", # pycodestyle warnings
47+
"F", # pyflakes
48+
"I", # isort
49+
"C", # flake8-comprehensions
50+
"B", # flake8-bugbear
51+
]
52+
53+
# Allow autofix for all enabled rules (when `--fix`) is provided.
54+
fixable = ["I", "F"]
55+
unfixable = []

setup.cfg

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[metadata]
2-
name = casvisor
3-
version = 0.1.0
2+
name = casvisor-python-sdk
3+
version = 1.0.0
44
author = Casvisor
55
author_email = [email protected]
66
url = https://github.com/casvisor/casvisor-python-sdk
@@ -19,6 +19,7 @@ classifiers =
1919
Programming Language :: Python :: 3.9
2020
Programming Language :: Python :: 3.10
2121
Programming Language :: Python :: 3.11
22+
Programming Language :: Python :: 3.12
2223

2324
[options]
2425
package_dir =

src/casvisor/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414
#
15-
from .main import CasvisorSDK
1615
from .base import BaseClient, Response
16+
from .main import CasvisorSDK
1717
from .record import Record, _RecordSDK
1818

1919
__all__ = ["CasvisorSDK", "BaseClient", "Response", "Record", "_RecordSDK"]

src/casvisor/base.py

+12-11
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@
1313
# limitations under the License.
1414

1515
import json
16-
from typing import Dict, Union, List, Tuple
16+
from typing import Dict, List, Tuple, Union
17+
1718
import requests
19+
1820
from . import util
1921

2022

@@ -43,9 +45,9 @@ def set_http_client(http_client: HttpClient):
4345

4446

4547
class BaseClient:
46-
def __init__(self, client_id: str, client_secret: str, endpoint: str):
47-
self.client_id = client_id
48-
self.client_secret = client_secret
48+
def __init__(self, clientId: str, clientSecret: str, endpoint: str):
49+
self.clientId = clientId
50+
self.clientSecret = clientSecret
4951
self.endpoint = endpoint
5052

5153
def do_get_response(self, url: str) -> Response:
@@ -89,16 +91,15 @@ def do_post(
8991
def do_post_bytes_raw(self, url: str, content_type: str, body: bytes) -> bytes:
9092
if not content_type:
9193
content_type = "text/plain;charset=UTF-8"
92-
headers = {
93-
"Content-Type": content_type,
94-
"Authorization": f"Basic {self.client_id}:{self.client_secret}",
95-
}
96-
resp = client.post(url, headers=headers, data=body)
94+
95+
headers = {"Content-Type": content_type}
96+
resp = client.post(
97+
url, headers=headers, data=body, auth=(self.clientId, self.clientSecret)
98+
)
9799
return resp.content
98100

99101
def do_get_bytes_raw_without_check(self, url: str) -> bytes:
100-
headers = {"Authorization": f"Basic {self.client_id}:{self.client_secret}"}
101-
resp = client.get(url, headers=headers)
102+
resp = client.get(url, auth=(self.clientId, self.clientSecret))
102103
return resp.content
103104

104105
def prepare_body(

src/casvisor/main.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,16 @@ class CasvisorSDK(_RecordSDK):
2020
def __init__(
2121
self,
2222
endpoint: str,
23-
client_id: str,
24-
client_secret: str,
25-
organization_name: str,
26-
application_name: str,
23+
clientId: str,
24+
clientSecret: str,
25+
organizationName: str,
26+
applicationName: str,
2727
):
2828
self.endpoint = endpoint
29-
self.client_id = client_id
30-
self.client_secret = client_secret
31-
self.organization_name = organization_name
32-
self.application_name = application_name
29+
self.clientId = clientId
30+
self.clientSecret = clientSecret
31+
self.organizationName = organizationName
32+
self.applicationName = applicationName
3333

3434
# Initialize the base client
35-
self.base_client = BaseClient(client_id, client_secret, endpoint)
35+
self.baseClient = BaseClient(clientId, clientSecret, endpoint)

src/casvisor/record.py

+41-40
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,47 @@
1414

1515
import json
1616
from typing import Dict, List, Optional, Tuple
17-
from .base import BaseClient
17+
1818
from . import util
19+
from .base import BaseClient, Response
1920

2021

2122
class Record:
2223
def __init__(
2324
self,
24-
id: int,
25-
owner: str,
26-
name: str,
27-
created_time: str,
28-
organization: str,
29-
client_ip: str,
30-
user: str,
31-
method: str,
32-
request_uri: str,
33-
action: str,
34-
language: str,
35-
object: str,
36-
response: str,
37-
provider: str,
38-
block: str,
39-
is_triggered: bool,
25+
createdTime: Optional[str] = None,
26+
organization: Optional[str] = None,
27+
clientIp: Optional[str] = None,
28+
user: Optional[str] = None,
29+
method: Optional[str] = None,
30+
requestUri: Optional[str] = None,
31+
action: Optional[str] = None,
32+
language: Optional[str] = None,
33+
object: Optional[str] = None,
34+
response: Optional[str] = None,
35+
provider: Optional[str] = None,
36+
block: Optional[str] = None,
37+
isTriggered: Optional[bool] = None,
38+
id: Optional[int] = None,
39+
owner: Optional[str] = None,
40+
name: Optional[str] = None,
4041
):
4142
self.id = id
4243
self.owner = owner
4344
self.name = name
44-
self.created_time = created_time
45+
self.createdTime = createdTime
4546
self.organization = organization
46-
self.client_ip = client_ip
47+
self.clientIp = clientIp
4748
self.user = user
4849
self.method = method
49-
self.request_uri = request_uri
50+
self.requestUri = requestUri
5051
self.action = action
5152
self.language = language
5253
self.object = object
5354
self.response = response
5455
self.provider = provider
5556
self.block = block
56-
self.is_triggered = is_triggered
57+
self.isTriggered = isTriggered
5758

5859
def to_dict(self) -> Dict:
5960
return self.__dict__
@@ -64,30 +65,30 @@ def from_dict(cls, data: Dict) -> "Record":
6465

6566

6667
class _RecordSDK:
67-
def __init__(self, base_client: BaseClient, organization_name: str):
68-
self.base_client = base_client
69-
self.organization_name = organization_name
68+
def __init__(self, base_client: BaseClient, organizationName: str):
69+
self.baseClient = base_client
70+
self.organizationName = organizationName
7071

7172
def get_records(self) -> List[Record]:
72-
query_map = {"owner": self.organization_name}
73-
url = util.get_url(self.base_client.endpoint, "get-records", query_map)
74-
bytes = self.base_client.do_get_bytes(url)
73+
query_map = {"owner": self.organizationName}
74+
url = util.get_url(self.baseClient.endpoint, "get-records", query_map)
75+
bytes = self.baseClient.do_get_bytes(url)
7576
return [Record.from_dict(record) for record in json.loads(bytes)]
7677

7778
def get_record(self, name: str) -> Record:
78-
query_map = {"id": f"{self.organization_name}/{name}"}
79-
url = util.get_url(self.base_client.endpoint, "get-record", query_map)
80-
bytes = self.base_client.do_get_bytes(url)
79+
query_map = {"id": f"{self.organizationName}/{name}"}
80+
url = util.get_url(self.baseClient.endpoint, "get-record", query_map)
81+
bytes = self.baseClient.do_get_bytes(url)
8182
return Record.from_dict(json.loads(bytes))
8283

8384
def get_pagination_records(
84-
self, p: int, page_size: int, query_map: Dict[str, str]
85+
self, p: int, pageSize: int, query_map: Dict[str, str]
8586
) -> Tuple[List[Record], int]:
86-
query_map["owner"] = self.organization_name
87+
query_map["owner"] = self.organizationName
8788
query_map["p"] = str(p)
88-
query_map["page_size"] = str(page_size)
89-
url = util.get_url(self.base_client.endpoint, "get-records", query_map)
90-
response = self.base_client.do_get_response(url)
89+
query_map["pageSize"] = str(pageSize)
90+
url = util.get_url(self.baseClient.endpoint, "get-records", query_map)
91+
response = self.baseClient.do_get_response(url)
9192
return [Record.from_dict(record) for record in response.data], response.data2
9293

9394
def update_record(self, record: Record) -> bool:
@@ -96,9 +97,9 @@ def update_record(self, record: Record) -> bool:
9697

9798
def add_record(self, record: Record) -> bool:
9899
if not record.owner:
99-
record.owner = self.organization_name
100+
record.owner = self.organizationName
100101
if not record.organization:
101-
record.organization = self.organization_name
102+
record.organization = self.organizationName
102103
_, affected = self.modify_record("add-record", record, None)
103104
return affected
104105

@@ -108,12 +109,12 @@ def delete_record(self, record: Record) -> bool:
108109

109110
def modify_record(
110111
self, action: str, record: Record, columns: Optional[List[str]]
111-
) -> Tuple[Dict, bool]:
112+
) -> Tuple[Response, bool]:
112113
query_map = {"id": f"{record.owner}/{record.name}"}
113114
if columns:
114115
query_map["columns"] = ",".join(columns)
115116
if not record.owner:
116117
record.owner = "admin"
117118
post_bytes = json.dumps(record.to_dict()).encode("utf-8")
118-
resp = self.base_client.do_post(action, query_map, post_bytes, False, False)
119-
return resp, resp["data"] == "Affected"
119+
resp = self.baseClient.do_post(action, query_map, post_bytes, False, False)
120+
return resp, resp.data == "Affected"

src/casvisor/util.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@
1313
# limitations under the License.
1414

1515

16-
from requests_toolbelt.multipart.encoder import MultipartEncoder
1716
from typing import Dict, Tuple
1817

18+
from requests_toolbelt.multipart.encoder import MultipartEncoder
19+
1920

2021
def get_url(base_url: str, action: str, query_map: Dict[str, str]) -> str:
2122
query = "&".join([f"{k}={v}" for k, v in query_map.items()])

0 commit comments

Comments
 (0)