You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: py_hamt/store.py
+35-1
Original file line number
Diff line number
Diff line change
@@ -66,6 +66,11 @@ class IPFSStore(Store):
66
66
Use IPFS as a backing store for a HAMT. The IDs returned from save and used by load are IPFS CIDs.
67
67
68
68
Save methods use the RPC API but `load` uses the HTTP Gateway, so read-only HAMTs will only access the HTTP Gateway. This allows for connection to remote gateways as well.
69
+
70
+
You can write to an authenticated IPFS node by providing credentials in the constructor. The following authentication methods are supported:
71
+
- Basic Authentication: Provide a tuple of (username, password) to the `basic_auth` parameter.
72
+
- Bearer Token: Provide a bearer token to the `bearer_token` parameter.
73
+
- API Key: Provide an API key to the `api_key` parameter. You can customize the header name for the API key by setting the `api_key_header` parameter.
api_key_header: str="X-API-Key", # Customizable API key header
79
89
):
80
90
self.timeout_seconds=timeout_seconds
81
91
"""
@@ -100,6 +110,16 @@ def __init__(
100
110
self.total_received: None|int=0ifdebugelseNone
101
111
"""Total bytes in responses from IPFS for blocks. Used for debugging purposes."""
102
112
113
+
# Authentication settings
114
+
self.basic_auth=basic_auth
115
+
"""Tuple of (username, password) for Basic Authentication"""
116
+
self.bearer_token=bearer_token
117
+
"""Bearer token for token-based authentication"""
118
+
self.api_key=api_key
119
+
"""API key for API key-based authentication"""
120
+
self.api_key_header=api_key_header
121
+
"""Header name to use for API key authentication"""
122
+
103
123
defsave(self, data: bytes, cid_codec: str) ->CID:
104
124
"""
105
125
This saves the data to an ipfs daemon by calling the RPC API, and then returns the CID, with a multicodec set by the input cid_codec. We need to do this since the API always returns either a multicodec of raw or dag-pb if it had to shard the input data.
0 commit comments