|
12 | 12 | import utime |
13 | 13 | import ntptime |
14 | 14 |
|
15 | | -# --- MinIO Configuration --- |
16 | | -# IMPORTANT: Fill in these details for your MinIO server. |
17 | | -MINIO_ENDPOINT = "192.168.1.100:9000" # Your MinIO server IP address and port |
18 | | -MINIO_ACCESS_KEY = "YOUR_ACCESS_KEY" # Your MinIO access key |
19 | | -MINIO_SECRET_KEY = "YOUR_SECRET_KEY" # Your MinIO secret key |
20 | | -MINIO_BUCKET = "micropython-uploads" # The bucket you want to upload to |
21 | | -MINIO_USE_HTTPS = False # Set to True if your MinIO server uses HTTPS |
22 | | - |
23 | | -# MinIO is S3-compatible, but the signing process still requires a region. |
24 | | -# 'us-east-1' is a safe default that works for most MinIO setups. |
25 | | -MINIO_REGION = "us-east-1" |
26 | | - |
27 | 15 |
|
28 | 16 | class MinioClient: |
29 | 17 | """A client for interacting with MinIO object storage. |
@@ -87,13 +75,9 @@ def _get_signature_key(self, date_stamp_string, service_name_string="s3"): |
87 | 75 | Derives the signing key from the secret key. |
88 | 76 | """ |
89 | 77 | k_secret_bytes = ("AWS4" + self.secret_key).encode("utf-8") |
90 | | - k_date_bytes = self._hmac_sha256( |
91 | | - k_secret_bytes, date_stamp_string.encode("utf-8") |
92 | | - ) |
| 78 | + k_date_bytes = self._hmac_sha256(k_secret_bytes, date_stamp_string.encode("utf-8")) |
93 | 79 | k_region_bytes = self._hmac_sha256(k_date_bytes, self.region.encode("utf-8")) |
94 | | - k_service_bytes = self._hmac_sha256( |
95 | | - k_region_bytes, service_name_string.encode("utf-8") |
96 | | - ) |
| 80 | + k_service_bytes = self._hmac_sha256(k_region_bytes, service_name_string.encode("utf-8")) |
97 | 81 | k_signing_bytes = self._hmac_sha256(k_service_bytes, b"aws4_request") |
98 | 82 | return k_signing_bytes |
99 | 83 |
|
@@ -192,22 +176,15 @@ def upload_file( |
192 | 176 | hashed_canonical_request_bytes = uhashlib.sha256( |
193 | 177 | canonical_request.encode("utf-8") |
194 | 178 | ).digest() |
195 | | - hashed_canonical_request_hex = ubinascii.hexlify( |
196 | | - hashed_canonical_request_bytes |
197 | | - ).decode() |
| 179 | + hashed_canonical_request_hex = ubinascii.hexlify(hashed_canonical_request_bytes).decode() |
198 | 180 |
|
199 | 181 | string_to_sign = ( |
200 | | - f"{algorithm}\n" |
201 | | - f"{amz_date}\n" |
202 | | - f"{credential_scope}\n" |
203 | | - f"{hashed_canonical_request_hex}" |
| 182 | + f"{algorithm}\n{amz_date}\n{credential_scope}\n{hashed_canonical_request_hex}" |
204 | 183 | ) |
205 | 184 |
|
206 | 185 | # ---- Task 3: Calculate Signature ---- |
207 | 186 | signing_key_bytes = self._get_signature_key(datestamp, service) |
208 | | - signature_bytes = self._hmac_sha256( |
209 | | - signing_key_bytes, string_to_sign.encode("utf-8") |
210 | | - ) |
| 187 | + signature_bytes = self._hmac_sha256(signing_key_bytes, string_to_sign.encode("utf-8")) |
211 | 188 | signature_hex = ubinascii.hexlify(signature_bytes).decode() |
212 | 189 |
|
213 | 190 | # ---- Task 4: Add Signing Information to the Request ---- |
|
0 commit comments