Skip to content
Merged
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
121 changes: 68 additions & 53 deletions bandit-baseline.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"errors": [],
"generated_at": "2024-06-03T07:52:17Z",
"generated_at": "2024-08-06T12:35:09Z",
"metrics": {
"_totals": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 2.0,
"CONFIDENCE.LOW": 3.0,
"CONFIDENCE.MEDIUM": 1.0,
"CONFIDENCE.UNDEFINED": 0.0,
"SEVERITY.HIGH": 0.0,
"SEVERITY.LOW": 1.0,
"SEVERITY.MEDIUM": 2.0,
"SEVERITY.MEDIUM": 3.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 3405,
"loc": 3497,
"nosec": 0
},
"src/setup.py": {
Expand Down Expand Up @@ -50,19 +50,19 @@
"loc": 104,
"nosec": 0
},
"src/sqlitecloud/dbapi2.py": {
"src/sqlitecloud/datatypes.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 0.0,
"CONFIDENCE.MEDIUM": 1.0,
"CONFIDENCE.UNDEFINED": 0.0,
"SEVERITY.HIGH": 0.0,
"SEVERITY.LOW": 0.0,
"SEVERITY.LOW": 1.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 377,
"loc": 177,
"nosec": 0
},
"src/sqlitecloud/download.py": {
"src/sqlitecloud/dbapi2.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 0.0,
Expand All @@ -71,10 +71,10 @@
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 32,
"loc": 376,
"nosec": 0
},
"src/sqlitecloud/driver.py": {
"src/sqlitecloud/download.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 0.0,
Expand All @@ -83,10 +83,10 @@
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 765,
"loc": 32,
"nosec": 0
},
"src/sqlitecloud/pubsub.py": {
"src/sqlitecloud/driver.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 0.0,
Expand All @@ -95,10 +95,10 @@
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 54,
"loc": 787,
"nosec": 0
},
"src/sqlitecloud/resultset.py": {
"src/sqlitecloud/pubsub.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 0.0,
Expand All @@ -107,19 +107,19 @@
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 80,
"loc": 56,
"nosec": 0
},
"src/sqlitecloud/types.py": {
"src/sqlitecloud/resultset.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.MEDIUM": 1.0,
"CONFIDENCE.MEDIUM": 0.0,
"CONFIDENCE.UNDEFINED": 0.0,
"SEVERITY.HIGH": 0.0,
"SEVERITY.LOW": 1.0,
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 194,
"loc": 99,
"nosec": 0
},
"src/sqlitecloud/upload.py": {
Expand Down Expand Up @@ -172,14 +172,14 @@
},
"src/tests/integration/test_client.py": {
"CONFIDENCE.HIGH": 0.0,
"CONFIDENCE.LOW": 0.0,
"CONFIDENCE.LOW": 1.0,
"CONFIDENCE.MEDIUM": 0.0,
"CONFIDENCE.UNDEFINED": 0.0,
"SEVERITY.HIGH": 0.0,
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.MEDIUM": 1.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 492,
"loc": 543,
"nosec": 0
},
"src/tests/integration/test_dbapi2.py": {
Expand Down Expand Up @@ -239,7 +239,7 @@
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 1.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 118,
"loc": 129,
"nosec": 0
},
"src/tests/integration/test_sqlite3_parity.py": {
Expand Down Expand Up @@ -287,7 +287,7 @@
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 242,
"loc": 241,
"nosec": 0
},
"src/tests/unit/test_driver.py": {
Expand All @@ -311,7 +311,7 @@
"SEVERITY.LOW": 0.0,
"SEVERITY.MEDIUM": 0.0,
"SEVERITY.UNDEFINED": 0.0,
"loc": 113,
"loc": 119,
"nosec": 0
},
"src/tests/unit/test_types.py": {
Expand All @@ -329,51 +329,66 @@
},
"results": [
{
"code": "107 class SQLiteCloudAccount:\n108 def __init__(\n109 self,\n110 username: Optional[str] = \"\",\n111 password: Optional[str] = \"\",\n112 hostname: str = \"\",\n113 dbname: Optional[str] = \"\",\n114 port: int = SQLITECLOUD_DEFAULT.PORT.value,\n115 apikey: Optional[str] = \"\",\n116 ) -> None:\n117 # User name is required unless connectionstring is provided\n118 self.username = username\n119 # Password is required unless connection string is provided\n120 self.password = password\n121 # Password is hashed\n122 self.password_hashed = False\n123 # API key instead of username and password\n124 self.apikey = apikey\n125 # Name of database to open\n126 self.dbname = dbname\n127 # Like mynode.sqlitecloud.io\n128 self.hostname = hostname\n129 self.port = port\n130 \n",
"code": "87 class SQLiteCloudAccount:\n88 def __init__(\n89 self,\n90 username: Optional[str] = \"\",\n91 password: Optional[str] = \"\",\n92 hostname: str = \"\",\n93 dbname: Optional[str] = \"\",\n94 port: int = SQLITECLOUD_DEFAULT.PORT.value,\n95 apikey: Optional[str] = \"\",\n96 ) -> None:\n97 # User name is required unless connectionstring is provided\n98 self.username = username\n99 # Password is required unless connection string is provided\n100 self.password = password\n101 # Password is hashed\n102 self.password_hashed = False\n103 # API key instead of username and password\n104 self.apikey = apikey\n105 # Name of database to open\n106 self.dbname = dbname\n107 # Like mynode.sqlitecloud.io\n108 self.hostname = hostname\n109 self.port = port\n110 \n",
"col_offset": 4,
"filename": "src/sqlitecloud/types.py",
"filename": "src/sqlitecloud/datatypes.py",
"issue_confidence": "MEDIUM",
"issue_severity": "LOW",
"issue_text": "Possible hardcoded password: ''",
"line_number": 108,
"line_number": 88,
"line_range": [
88,
89,
90,
91,
92,
93,
94,
95,
96,
97,
98,
99,
100,
101,
102,
103,
104,
105,
106,
107,
108,
109,
110,
111,
112,
113,
114,
115,
116,
117,
118,
119,
120,
121,
122,
123,
124,
125,
126,
127,
128,
129
109
],
"more_info": "https://bandit.readthedocs.io/en/latest/plugins/b107_hardcoded_password_default.html",
"test_id": "B107",
"test_name": "hardcoded_password_default"
},
{
"code": "164 client.exec_query(\n165 f\"UPDATE genres SET Name = '{new_name}' WHERE GenreId = 1;\", connection\n166 )\n",
"code": "639 for i in range(nRows):\n640 sql += f\"INSERT INTO TestCompress (name) VALUES ('Test {i}'); \"\n641 \n",
"col_offset": 23,
"filename": "src/tests/integration/test_client.py",
"issue_confidence": "LOW",
"issue_severity": "MEDIUM",
"issue_text": "Possible SQL injection vector through string-based query construction.",
"line_number": 640,
"line_range": [
640
],
"more_info": "https://bandit.readthedocs.io/en/latest/plugins/b608_hardcoded_sql_expressions.html",
"test_id": "B608",
"test_name": "hardcoded_sql_expressions"
},
{
"code": "179 client.exec_query(\n180 f\"UPDATE genres SET Name = '{new_name}' WHERE GenreId = 1;\", connection\n181 )\n",
"col_offset": 12,
"filename": "src/tests/integration/test_pubsub.py",
"issue_confidence": "LOW",
"issue_severity": "MEDIUM",
"issue_text": "Possible SQL injection vector through string-based query construction.",
"line_number": 165,
"line_number": 180,
"line_range": [
165
180
],
"more_info": "https://bandit.readthedocs.io/en/latest/plugins/b608_hardcoded_sql_expressions.html",
"test_id": "B608",
Expand Down
6 changes: 3 additions & 3 deletions src/sqlitecloud/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
"""
from typing import Dict, Optional, Tuple, Union

from sqlitecloud.driver import Driver
from sqlitecloud.resultset import SQLiteCloudResultSet
from sqlitecloud.types import (
from sqlitecloud.datatypes import (
SQLiteCloudAccount,
SQLiteCloudConfig,
SQLiteCloudConnect,
SQLiteCloudDataTypes,
SQLiteCloudException,
)
from sqlitecloud.driver import Driver
from sqlitecloud.resultset import SQLiteCloudResultSet


class SQLiteCloudClient:
Expand Down
31 changes: 5 additions & 26 deletions src/sqlitecloud/types.py → src/sqlitecloud/datatypes.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import types
from asyncio import AbstractEventLoop
from enum import Enum
from typing import Any, Callable, Dict, Optional, Union
from urllib import parse

from .resultset import SQLiteCloudResultSet

# Basic types supported by SQLite Cloud APIs
SQLiteCloudDataTypes = Union[str, int, bool, Dict[Union[str, int], Any], bytes, None]


class SQLITECLOUD_DEFAULT(Enum):
PORT = 8860
TIMEOUT = 12
TIMEOUT = 30
UPLOAD_SIZE = 512 * 1024


Expand All @@ -37,14 +38,6 @@ class SQLITECLOUD_ROWSET(Enum):
CHUNKS_END = b"/6 0 0 0 "


class SQLITECLOUD_VALUE_TYPE(Enum):
INTEGER = "INTEGER"
FLOAT = "REAL"
TEXT = "TEXT"
BLOB = "BLOB"
NULL = "NULL"


class SQLITECLOUD_INTERNAL_ERRCODE(Enum):
"""
Clients error codes.
Expand All @@ -68,19 +61,6 @@ class SQLITECLOUD_ERRCODE(Enum):
RAFT = 10006


class SQLITECLOUD_RESULT_TYPE(Enum):
RESULT_OK = 0
RESULT_ERROR = 1
RESULT_STRING = 2
RESULT_INTEGER = 3
RESULT_FLOAT = 4
RESULT_ROWSET = 5
RESULT_ARRAY = 6
RESULT_NONE = 7
RESULT_JSON = 8
RESULT_BLOB = 9


class SQLITECLOUD_PUBSUB_SUBJECT(Enum):
"""
Subjects that can be subscribed to by PubSub.
Expand Down Expand Up @@ -141,7 +121,7 @@ def __init__(self):

self.pubsub_socket: any = None
self.pubsub_callback: Callable[
[SQLiteCloudConnect, Optional[types.SqliteCloudResultSet], Optional[any]],
[SQLiteCloudConnect, Optional[SQLiteCloudResultSet], Optional[any]],
None,
] = None
self.pubsub_data: any = None
Expand Down Expand Up @@ -210,8 +190,6 @@ def _parse_connection_string(self, connection_string) -> None:
value = bool(value)
elif value.isdigit():
value = int(value)
else:
value = value

# alias
if opt == "nonlinearizable":
Expand Down Expand Up @@ -248,6 +226,7 @@ def _parse_connection_string(self, connection_string) -> None:

class SQLiteCloudException(Exception):
def __init__(self, message: str, code: int = -1, xerrcode: int = 0) -> None:
super().__init__(message)
self.errmsg = str(message)
self.errcode = code
self.xerrcode = xerrcode
Expand Down
9 changes: 4 additions & 5 deletions src/sqlitecloud/dbapi2.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@
overload,
)

from sqlitecloud.driver import Driver
from sqlitecloud.resultset import SQLiteCloudResult
from sqlitecloud.types import (
SQLITECLOUD_RESULT_TYPE,
from sqlitecloud.datatypes import (
SQLiteCloudAccount,
SQLiteCloudConfig,
SQLiteCloudConnect,
SQLiteCloudDataTypes,
SQLiteCloudException,
)
from sqlitecloud.driver import Driver
from sqlitecloud.resultset import SQLITECLOUD_RESULT_TYPE, SQLiteCloudResult

# Question mark style, e.g. ...WHERE name=?
# Module also supports Named style, e.g. ...WHERE name=:name
Expand Down Expand Up @@ -478,7 +477,7 @@ def __next__(self) -> Optional[Tuple[Any]]:
and self._resultset.data
and self._iter_row < self._resultset.nrows
):
out: tuple[Any] = ()
out: Tuple[Any] = ()

for col in range(self._resultset.ncols):
out += (self._resultset.get_value(self._iter_row, col),)
Expand Down
2 changes: 1 addition & 1 deletion src/sqlitecloud/download.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import logging
from io import BufferedWriter

from sqlitecloud.datatypes import SQLiteCloudConnect
from sqlitecloud.driver import Driver
from sqlitecloud.types import SQLiteCloudConnect


def xCallback(
Expand Down
Loading