Skip to content

Commit 4a4406d

Browse files
Remove secrets from config __repr__ (#417)
1 parent 75e4d6e commit 4a4406d

File tree

3 files changed

+24
-6
lines changed

3 files changed

+24
-6
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
### Fixed
1010

1111
* cli: Fixed `hasura configure` command crash when models have empty `Meta.table`.
12+
* config: Removed secrets from config `__repr__`.
1213

1314
## [5.2.2] - 2022-07-03
1415

src/dipdup/config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class PostgresDatabaseConfig:
126126
database: str = DEFAULT_POSTGRES_DATABASE
127127
port: int = DEFAULT_POSTGRES_PORT
128128
schema_name: str = DEFAULT_POSTGRES_SCHEMA
129-
password: str = ''
129+
password: str = field(default='', repr=False)
130130
immune_tables: Tuple[str, ...] = field(default_factory=tuple)
131131
connection_timeout: int = 60
132132

@@ -1023,7 +1023,7 @@ class HasuraConfig:
10231023
"""
10241024

10251025
url: str
1026-
admin_secret: Optional[str] = None
1026+
admin_secret: Optional[str] = field(default=None, repr=False)
10271027
create_source: bool = False
10281028
source: str = 'default'
10291029
select_limit: int = 100

tests/test_dipdup/test_config.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
from dipdup.config import ContractConfig
99
from dipdup.config import DipDupConfig
10+
from dipdup.config import HasuraConfig
11+
from dipdup.config import PostgresDatabaseConfig
1012
from dipdup.config import TzktDatasourceConfig
1113
from dipdup.datasources.subscription import OriginationSubscription
1214
from dipdup.datasources.subscription import TransactionSubscription
@@ -15,10 +17,10 @@
1517

1618

1719
class ConfigTest(IsolatedAsyncioTestCase):
18-
async def asyncSetUp(self):
20+
async def asyncSetUp(self) -> None:
1921
self.path = join(dirname(__file__), 'dipdup.yml')
2022

21-
async def test_load_initialize(self):
23+
async def test_load_initialize(self) -> None:
2224
config = DipDupConfig.load([self.path])
2325

2426
config.initialize()
@@ -59,15 +61,15 @@ async def test_subscriptions(self) -> None:
5961
config.indexes['hen_mainnet'].subscriptions, # type: ignore
6062
)
6163

62-
async def test_validators(self):
64+
async def test_validators(self) -> None:
6365
with self.assertRaises(ConfigurationError):
6466
ContractConfig(address='KT1lalala')
6567
with self.assertRaises(ConfigurationError):
6668
ContractConfig(address='lalalalalalalalalalalalalalalalalala')
6769
with self.assertRaises(ConfigurationError):
6870
TzktDatasourceConfig(kind='tzkt', url='not_an_url')
6971

70-
async def test_dump(self):
72+
async def test_dump(self) -> None:
7173
config = DipDupConfig.load([self.path])
7274
config.initialize()
7375

@@ -77,3 +79,18 @@ async def test_dump(self):
7779

7880
config = DipDupConfig.load([tmp], environment=False)
7981
config.initialize()
82+
83+
async def test_secrets(self) -> None:
84+
db_config = PostgresDatabaseConfig(
85+
kind='postgres',
86+
host='localhost',
87+
password='SeCrEt=)',
88+
)
89+
hasura_config = HasuraConfig(
90+
url='https://localhost',
91+
admin_secret='SeCrEt=)',
92+
)
93+
self.assertIn('localhost', str(db_config))
94+
self.assertNotIn('SeCrEt=)', str(db_config))
95+
self.assertIn('localhost', str(db_config))
96+
self.assertNotIn('SeCrEt=)', str(hasura_config))

0 commit comments

Comments
 (0)