@@ -1386,20 +1386,38 @@ def read_block(self, fn, offset, length, delimiter=None):
1386
1386
length = size - offset
1387
1387
return read_block (f , offset , length , delimiter )
1388
1388
1389
- def to_json (self ) -> str :
1389
+ def to_json (self , * , include_password : bool = True ) -> str :
1390
1390
"""
1391
1391
JSON representation of this filesystem instance.
1392
1392
1393
+ Parameters
1394
+ ----------
1395
+ include_password: bool, default True
1396
+ Whether to include the password (if any) in the output.
1397
+
1393
1398
Returns
1394
1399
-------
1395
1400
JSON string with keys ``cls`` (the python location of this class),
1396
1401
protocol (text name of this class's protocol, first one in case of
1397
1402
multiple), ``args`` (positional args, usually empty), and all other
1398
1403
keyword arguments as their own keys.
1404
+
1405
+ Warnings
1406
+ --------
1407
+ Serialized filesystems may contain sensitive information which have been
1408
+ passed to the constructor, such as passwords and tokens. Make sure you
1409
+ store and send them in a secure environment!
1399
1410
"""
1400
1411
from .json import FilesystemJSONEncoder
1401
1412
1402
- return json .dumps (self , cls = FilesystemJSONEncoder )
1413
+ return json .dumps (
1414
+ self ,
1415
+ cls = type (
1416
+ "_FilesystemJSONEncoder" ,
1417
+ (FilesystemJSONEncoder ,),
1418
+ {"include_password" : include_password },
1419
+ ),
1420
+ )
1403
1421
1404
1422
@staticmethod
1405
1423
def from_json (blob : str ) -> AbstractFileSystem :
@@ -1426,25 +1444,40 @@ def from_json(blob: str) -> AbstractFileSystem:
1426
1444
1427
1445
return json .loads (blob , cls = FilesystemJSONDecoder )
1428
1446
1429
- def to_dict (self ) -> Dict [str , Any ]:
1447
+ def to_dict (self , * , include_password : bool = True ) -> Dict [str , Any ]:
1430
1448
"""
1431
1449
JSON-serializable dictionary representation of this filesystem instance.
1432
1450
1451
+ Parameters
1452
+ ----------
1453
+ include_password: bool, default True
1454
+ Whether to include the password (if any) in the output.
1455
+
1433
1456
Returns
1434
1457
-------
1435
1458
Dictionary with keys ``cls`` (the python location of this class),
1436
1459
protocol (text name of this class's protocol, first one in case of
1437
1460
multiple), ``args`` (positional args, usually empty), and all other
1438
1461
keyword arguments as their own keys.
1462
+
1463
+ Warnings
1464
+ --------
1465
+ Serialized filesystems may contain sensitive information which have been
1466
+ passed to the constructor, such as passwords and tokens. Make sure you
1467
+ store and send them in a secure environment!
1439
1468
"""
1440
1469
cls = type (self )
1441
1470
proto = self .protocol
1442
1471
1472
+ storage_options = dict (self .storage_options )
1473
+ if not include_password :
1474
+ storage_options .pop ("password" , None )
1475
+
1443
1476
return dict (
1444
1477
cls = f"{ cls .__module__ } :{ cls .__name__ } " ,
1445
1478
protocol = proto [0 ] if isinstance (proto , (tuple , list )) else proto ,
1446
1479
args = self .storage_args ,
1447
- ** self . storage_options ,
1480
+ ** storage_options ,
1448
1481
)
1449
1482
1450
1483
@staticmethod
0 commit comments