Skip to content

Commit 780cb32

Browse files
Kilo59yanyongyu
andauthored
✨ Feature: add httpx verify config (#209)
Co-authored-by: Ju4tCode <42488585+yanyongyu@users.noreply.github.com>
1 parent dd3a764 commit 780cb32

File tree

4 files changed

+28
-2
lines changed

4 files changed

+28
-2
lines changed

docs/usage/configuration.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ github = GitHub(
1212
user_agent="GitHubKit/Python",
1313
follow_redirects=True,
1414
timeout=None,
15+
ssl_verify=True,
1516
cache_strategy=None,
1617
http_cache=True,
1718
throttler=None,
@@ -34,6 +35,7 @@ config = Config(
3435
user_agent="GitHubKit/Python",
3536
follow_redirects=True,
3637
timeout=httpx.Timeout(None),
38+
ssl_verify=True,
3739
cache_strategy=DEFAULT_CACHE_STRATEGY,
3840
http_cache=True,
3941
throttler=None,
@@ -70,6 +72,10 @@ The `follow_redirects` option is used to enable or disable the HTTP redirect fol
7072

7173
The `timeout` option is used to set the request timeout. You can pass a float, `None` or `httpx.Timeout` to this field. By default, the requests will never timeout. See [Timeout](https://www.python-httpx.org/advanced/timeouts/) for more information.
7274

75+
### `ssl_verify`
76+
77+
The `ssl_verify` option is used to customize the SSL certificate verification. By default, githubkit enables the SSL certificate verification. If you want to disable the SSL certificate verification, you can set this option to `False`. Or you can provide a custom ssl context to this option. See [SSL](https://www.python-httpx.org/advanced/ssl/) for more information.
78+
7379
### `cache_strategy`
7480

7581
The `cache_strategy` option defines how to cache the tokens or http responses. You can provide a githubkit built-in cache strategy or a custom one that implements the `BaseCacheStrategy` interface. By default, githubkit uses the `MemCacheStrategy` to cache the data in memory.

githubkit/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from collections.abc import Sequence
22
from dataclasses import dataclass, fields
3-
from typing import Any, Optional, Union
3+
from typing import TYPE_CHECKING, Any, Optional, Union
44
from typing_extensions import Self
55

66
import httpx
@@ -10,6 +10,9 @@
1010
from .throttling import BaseThrottler, LocalThrottler
1111
from .typing import RetryDecisionFunc
1212

13+
if TYPE_CHECKING:
14+
import ssl
15+
1316

1417
@dataclass(frozen=True)
1518
class Config:
@@ -18,6 +21,7 @@ class Config:
1821
user_agent: str
1922
follow_redirects: bool
2023
timeout: httpx.Timeout
24+
ssl_verify: Union[bool, "ssl.SSLContext"]
2125
cache_strategy: BaseCacheStrategy
2226
http_cache: bool
2327
throttler: BaseThrottler
@@ -104,6 +108,7 @@ def get_config(
104108
user_agent: Optional[str] = None,
105109
follow_redirects: bool = True,
106110
timeout: Optional[Union[float, httpx.Timeout]] = None,
111+
ssl_verify: Union[bool, "ssl.SSLContext"] = True,
107112
cache_strategy: Optional[BaseCacheStrategy] = None,
108113
http_cache: bool = True,
109114
throttler: Optional[BaseThrottler] = None,
@@ -117,6 +122,7 @@ def get_config(
117122
build_user_agent(user_agent),
118123
follow_redirects,
119124
build_timeout(timeout),
125+
ssl_verify,
120126
build_cache_strategy(cache_strategy),
121127
http_cache,
122128
build_throttler(throttler),

githubkit/core.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from datetime import datetime, timedelta, timezone
55
import time
66
from types import TracebackType
7-
from typing import Any, Generic, Optional, TypeVar, Union, cast, overload
7+
from typing import TYPE_CHECKING, Any, Generic, Optional, TypeVar, Union, cast, overload
88

99
import anyio
1010
import hishel
@@ -36,6 +36,9 @@
3636
)
3737
from .utils import UNSET
3838

39+
if TYPE_CHECKING:
40+
import ssl
41+
3942
T = TypeVar("T")
4043
A = TypeVar("A", bound="BaseAuthStrategy")
4144
AS = TypeVar("AS", bound="BaseAuthStrategy")
@@ -81,6 +84,7 @@ def __init__(
8184
user_agent: Optional[str] = None,
8285
follow_redirects: bool = True,
8386
timeout: Optional[Union[float, httpx.Timeout]] = None,
87+
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
8488
cache_strategy: Optional[BaseCacheStrategy] = None,
8589
http_cache: bool = True,
8690
throttler: Optional[BaseThrottler] = None,
@@ -100,6 +104,7 @@ def __init__(
100104
user_agent: Optional[str] = None,
101105
follow_redirects: bool = True,
102106
timeout: Optional[Union[float, httpx.Timeout]] = None,
107+
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
103108
cache_strategy: Optional[BaseCacheStrategy] = None,
104109
http_cache: bool = True,
105110
throttler: Optional[BaseThrottler] = None,
@@ -119,6 +124,7 @@ def __init__(
119124
user_agent: Optional[str] = None,
120125
follow_redirects: bool = True,
121126
timeout: Optional[Union[float, httpx.Timeout]] = None,
127+
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
122128
cache_strategy: Optional[BaseCacheStrategy] = None,
123129
http_cache: bool = True,
124130
throttler: Optional[BaseThrottler] = None,
@@ -137,6 +143,7 @@ def __init__(
137143
user_agent: Optional[str] = None,
138144
follow_redirects: bool = True,
139145
timeout: Optional[Union[float, httpx.Timeout]] = None,
146+
ssl_verify: Union[bool, "ssl.SSLContext"] = True,
140147
cache_strategy: Optional[BaseCacheStrategy] = None,
141148
http_cache: bool = True,
142149
throttler: Optional[BaseThrottler] = None,
@@ -155,6 +162,7 @@ def __init__(
155162
user_agent=user_agent,
156163
follow_redirects=follow_redirects,
157164
timeout=timeout,
165+
ssl_verify=ssl_verify,
158166
cache_strategy=cache_strategy,
159167
http_cache=http_cache,
160168
throttler=throttler,
@@ -212,6 +220,7 @@ def _get_client_defaults(self):
212220
},
213221
"timeout": self.config.timeout,
214222
"follow_redirects": self.config.follow_redirects,
223+
"verify": self.config.ssl_verify,
215224
}
216225

217226
# create sync client

githubkit/github.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
from .versions import RestVersionSwitcher, WebhooksVersionSwitcher
1313

1414
if TYPE_CHECKING:
15+
import ssl
16+
1517
import httpx
1618

1719
from .auth import TokenAuthStrategy, UnauthAuthStrategy
@@ -74,6 +76,7 @@ def __init__(
7476
user_agent: Optional[str] = None,
7577
follow_redirects: bool = True,
7678
timeout: Optional[Union[float, httpx.Timeout]] = None,
79+
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
7780
cache_strategy: Optional["BaseCacheStrategy"] = None,
7881
http_cache: bool = True,
7982
throttler: Optional["BaseThrottler"] = None,
@@ -93,6 +96,7 @@ def __init__(
9396
user_agent: Optional[str] = None,
9497
follow_redirects: bool = True,
9598
timeout: Optional[Union[float, httpx.Timeout]] = None,
99+
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
96100
cache_strategy: Optional["BaseCacheStrategy"] = None,
97101
http_cache: bool = True,
98102
throttler: Optional["BaseThrottler"] = None,
@@ -112,6 +116,7 @@ def __init__(
112116
user_agent: Optional[str] = None,
113117
follow_redirects: bool = True,
114118
timeout: Optional[Union[float, httpx.Timeout]] = None,
119+
ssl_verify: Union[bool, "ssl.SSLContext"] = ...,
115120
cache_strategy: Optional["BaseCacheStrategy"] = None,
116121
http_cache: bool = True,
117122
throttler: Optional["BaseThrottler"] = None,

0 commit comments

Comments
 (0)