Skip to content

Commit f42a5f4

Browse files
committed
Factor out repeated session code.
1 parent 60cad91 commit f42a5f4

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [0.2.1] 2020-04-28
10+
### Added
11+
- Reworked to simplify usage, and add alternate strategies.
12+
913
## [0.1.0] 2020-04-25
1014
### Added
1115
- Initial MacKeychainTransportAdapter source.
1216

13-
[Unreleased]: https://github.com/sheagcraig/MacKeychainTransportAdapter/compare/v0.1.0...HEAD
17+
[Unreleased]: https://github.com/sheagcraig/MacKeychainTransportAdapter/compare/v0.2.1...HEAD
18+
[0.2.0]: https://github.com/sheagcraig/MacKeychainTransportAdapter/compare/v0.1.0...v0.2.1
1419
[0.1.0]: https://github.com/sheagcraig/MacKeychainTransportAdapter/releases/tag/v0.1.0

README.md

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Hello!
1+
# MacSesh
22
This package allows requests to verify certs with the macOS keychain,
33
rather than using certifi. It also includes some tools for easily
44
hooking up a `SecureTransport` adapter (a la Pip) and then later
@@ -50,17 +50,5 @@ Clean up after using the "basic" API:
5050
```macsesh.extract_from_requests()```
5151

5252
Any certs added to the keychains after starting a session will
53-
not be available. The sessions and adapters all have an update_truststore
54-
method for re-dumping the trust.
55-
```
56-
>>> import macsesh
57-
>>> sesh = macsesh.KeychainSession()
58-
>>> response = sesh.get('https://cheeze.co')
59-
<A bunch of angry exception noise!>
60-
SSLVerificationError
61-
>>> # I added the cheeze issuer's cert"
62-
>>> sesh.update_truststore()
63-
>>> response = sesh.get('https://cheeze.co')
64-
>>> response.status_code
65-
200
66-
```
53+
not be available. Digging down in and updating the SSLContext is rough;
54+
just make a new session if you have this need!

macsesh/session.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,28 @@
88
from .simple_adapter import SimpleKeychainAdapter
99

1010

11-
class KeychainSession(requests.Session):
12-
"""Requests session using the injected KeychainAdapter"""
11+
class BaseKeychainSession(requests.Session):
12+
13+
_adapter_class = KeychainAdapter
1314

1415
def __init__(self, *args, **kwargs):
1516
super().__init__(*args, **kwargs)
16-
self.mount('https://', KeychainAdapter())
17+
self.mount('https://', self._adapter_class())
18+
19+
20+
class KeychainSession(BaseKeychainSession):
21+
"""Requests session using the injected KeychainAdapter"""
1722

23+
_adapter_class = KeychainAdapter
1824

19-
class SecureTransportSession(requests.Session):
25+
26+
class SecureTransportSession(BaseKeychainSession):
2027
"""Requests session using the SecureTransport"""
2128

22-
def __init__(self, *args, **kwargs):
23-
super().__init__(*args, **kwargs)
24-
self.mount('https://', SecureTransportAdapter())
29+
_adapter_class = SecureTransportAdapter
2530

2631

27-
class SimpleKeychainSession(requests.Session):
32+
class SimpleKeychainSession(BaseKeychainSession):
2833
"""Requests session using the SimpleKeychainAdapter"""
2934

30-
def __init__(self, *args, **kwargs):
31-
super().__init__(*args, **kwargs)
32-
self.mount('https://', SimpleKeychainAdapter())
35+
_adapter_class = SimpleKeychainAdapter

macsesh/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.2.0'
1+
__version__ = '0.2.1'

0 commit comments

Comments
 (0)