Repository navigation
Releases: JulianStiebler/secureRequests
Releases · JulianStiebler/secureRequests
Release list
v1.1.0 🌈
🔆 What changed?
🚀 Added Features
- Write up for why to use TLS and certificates added
- Verify checksum of certificate
- Better and extensive logging
[2024-07-28 02:54:20][CRITICAL][Certificate] Certificate does not exist. Fetching it.
[2024-07-28 02:54:20][REQUEST][UNSAFE][TLS] GET request to https://curl.se/ca/cacert.pem with Status Code 200 - OK
[2024-07-28 02:54:20][INFO][Certificate] Verifying checksum of the fetched certificate.
[2024-07-28 02:54:20][INFO][Certificate] Fetching checksum of the certificate.
[2024-07-28 02:54:20][REQUEST][UNSAFE][TLS] GET request to https://curl.se/ca/cacert.pem.sha256 with Status Code 200 - OK
[2024-07-28 02:54:20][INFO][Certificate] Calculated checksum: 1bf458412568e134a4514f5e170a328d11091e071c7110955c9884ed87972ac9
[2024-07-28 02:54:20][INFO][Certificate] Expected checksum: 1bf458412568e134a4514f5e170a328d11091e071c7110955c9884ed87972ac9
[2024-07-28 02:54:20][INFO][Certificate] Checksum verification successful.
[2024-07-28 02:54:20][INFO][Certificate] Successfully fetched certificate and saved.
[2024-07-28 02:54:20][DEBUG][Certificate] Setting certificate. Status: /resources/cacert.pem
[2024-07-28 02:54:22][REQUEST][SAFE][TLS] GET request to https://api.github.com/repos/julianstiebler/secureRequests/releases/latest with Status Code 200 - OK
GPG Signed Release
- GPG key ID: B5690EEEBB952194
v1.0.2 🌈
🔆 What changed?
🚀 Better UnitTest
- Better unitTest + some fixes relating cookie serialization @JulianStiebler (#3)
🐛 Bug Fixes
- Better unitTest + some fixes relating cookie serialization @JulianStiebler (#3)
v1.0.1 🌈
🔆 What changed?
🚀 Added Features
- Passing **kwargs into makeRequest to allow access to all other request-args
🐛 Bug Fixes
- Small fix for data/payload arg in makeRequest
⚡ Workflow Changes
- Added unitTest & TypeTests for Mac, Windows & Linux respectively
v1.0.0 🌈
SecureRequests
A simple library designed to make secure HTTP requests more widespread with flexibility in SSL certificate management. Requests use a TSL Adapter and allow easy request execution and configuration with SSLContext and Certificates. Also wraps good practice around the general use of requests.
General Information
Depends only on
requests,os,datetime.
Example
from datetime import datetime, timedelta
# Import library
from secureRequests import SecureRequests
from secureRequests import HeaderKeys, CookieKeys, CookieAttributeKeys
# Initialize secureRequests with a custom header value
sr = SecureRequests(headers={HeaderKeys.CONTENT_TYPE.value: "application/json"})
# Set another key extra, couldve done earlier but to demonstrate
sr.headerSetKey(HeaderKeys.AUTHORIZATION, "Bearer token123")
# Add cookies
sr.cookieUpdate(CookieKeys.SESSION_ID, {
CookieAttributeKeys.PATH: '/',
CookieAttributeKeys.EXPIRES: datetime.now() + timedelta(days=7),
CookieAttributeKeys.SECURE: True
})
# Print our example data
print(sr.headers)
print(sr.cookieGetAll())
# Make the request
response = sr.makeRequest("https://httpbin.org/get")
print(response.status_code)
# This was an SSL encrypted, with TSL adapter mounted request. How easy right!Features
- Flexible SSL Certificate Management: Can automatically fetch and manage SSL certificates or allows manual configuration.
- Custom Exceptions: Uses custom exceptions to print out responses so you can try/catch/finalize your responses very easily.
- Easy Headers: Generates valid HTTP header to mimic different browsers and platforms for enhanced security or accept custom ones powered with enums.
- Easy Cookies: Generates cookies as needed/specified powered by enums.
- Request Logging: Optional logging to file for tracking request details and responses.
- Secure and Easy Request Method: Supports standard HTTP methods (GET, POST, PUT, DELETE, PATCH) with customizable payloads and headers.
Configuration Options
The SecureRequests class constructor accepts the following optional parameters, they can also be set via the config module.
- `requests`: Module reference to `requests`
- `os`: Module reference to `os`
- `datetime`: Module reference to `datetime.datetime`
- `useEVar`: Boolean flag to determine if the configuration should be loaded from environment variables. Default is `False`.
- `envVars`: Dictionary mapping configuration attributes to their corresponding environment variable names.
- `useTLS`: Boolean indicating whether to use TLS. Default is `True`.
- `unsafe`: Boolean indicating if unsafe operations are allowed. Default is `False`.
- `certificateNeedFetch`: Boolean indicating if a certificate needs to be fetched. Default is `True`.
- `certificateURL`: String URL from which the certificate should be fetched. Default is `False`.
- `certificatePath`: String path to the certificate file. Default is `cacert.pem`.
- `logToFile`: Boolean indicating if logs should be written to a file. Default is `True`.
- `logLevel`: Logging level. Default is `logging.INFO`.
- `logPath`: Specifies the log path.
- `logExtensive`: If to include extra data such as cookies and headers in the log.
- `silent`: Boolean indicating if logging should be silent. Default is `False`.
- `suppressWarnings`: Boolean indicating if warnings should be suppressed. Default is `False`.
What not specified will be loaded from config.py, there you can see or set defaults.16:35 - 21.07.2024 | Added small fix.