Skip to content

Commit

Permalink
cleanup python env var checks examples (#1362)
Browse files Browse the repository at this point in the history
* cleanup env var checks

* cleanup env var checks
  • Loading branch information
WallysFerreira authored Oct 2, 2023
1 parent 9a860db commit fa366bc
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 76 deletions.
14 changes: 3 additions & 11 deletions bindings/python/examples/exchange/1_create_account.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,9 @@
# should not be done in production.
load_dotenv()

if 'WALLET_DB_PATH' not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")
if 'NODE_URL' not in os.environ:
raise Exception(".env NODE_URL is undefined, see .env.example")
if 'STRONGHOLD_SNAPSHOT_PATH' not in os.environ:
raise Exception(
".env STRONGHOLD_SNAPSHOT_PATH is undefined, see .env.example")
if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")
for env_var in ['WALLET_DB_PATH', 'NODE_URL', 'STRONGHOLD_SNAPSHOT_PATH', 'STRONGHOLD_PASSWORD', 'MNEMONIC']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

client_options = ClientOptions(nodes=[os.environ.get('NODE_URL')])

Expand Down
7 changes: 3 additions & 4 deletions bindings/python/examples/exchange/2_generate_address.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@
# should not be done in production.
load_dotenv()

if 'WALLET_DB_PATH' not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")
if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

wallet = Wallet(os.environ.get('WALLET_DB_PATH'))

Expand Down
9 changes: 3 additions & 6 deletions bindings/python/examples/exchange/5_send_amount.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,9 @@
# should not be done in production.
load_dotenv()

if 'WALLET_DB_PATH' not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")
if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
if 'EXPLORER_URL' not in os.environ:
raise Exception(".env EXPLORER_URL is undefined, see .env.example")
for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', 'EXPLORER_URL']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

wallet = Wallet(os.environ.get('WALLET_DB_PATH'))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
# Shimmer coin type
coin_type = CoinType.SHIMMER

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['STRONGHOLD_PASSWORD', 'MNEMONIC']:
if env_var not in os.environ:
raise Exception(f".env {env_var} is undefined, see .env.example")

secret_manager = StrongholdSecretManager(
os.environ['STRONGHOLD_SNAPSHOT_PATH'], os.environ['STRONGHOLD_PASSWORD'])
Expand All @@ -26,9 +27,6 @@
coin_type,
secret_manager)

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")

# Store the mnemonic in the Stronghold snapshot, this only needs to be
# done once.
wallet.store_mnemonic(os.environ['MNEMONIC'])
Expand Down
11 changes: 3 additions & 8 deletions bindings/python/examples/how_tos/alias/governance_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,9 @@

# In this example we will update the state controller of an alias output.

if 'WALLET_DB_PATH' not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")

if 'EXPLORER_URL' not in os.environ:
raise Exception(".env EXPLORER_URL is undefined, see .env.example")
for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', 'EXPLORER_URL']:
if env_var not in os.environ:
raise Exception(f".env {env_var} is undefined, see .env.example")

wallet = Wallet(os.environ['WALLET_DB_PATH'])

Expand Down
11 changes: 3 additions & 8 deletions bindings/python/examples/how_tos/alias/state_transition.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,9 @@

NEW_STATE_METADATA = 'updated state metadata 1'

if 'WALLET_DB_PATH' not in os.environ:
raise Exception(".env WALLET_DB_PATH is undefined, see .env.example")

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")

if 'EXPLORER_URL' not in os.environ:
raise Exception(".env EXPLORER_URL is undefined, see .env.example")
for env_var in ['WALLET_DB_PATH', 'STRONGHOLD_PASSWORD', 'EXPLORER_URL']:
if env_var not in os.environ:
raise Exception(f".env {env_var} is undefined, see .env.example")

wallet = Wallet(os.environ['WALLET_DB_PATH'])

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
INTERNAL_ADDRESS = False
ADDRESS_INDEX = 0

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['MNEMONIC', 'STRONGHOLD_PASSWORD']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

secret_manager = SecretManager(StrongholdSecretManager(
"sign_ed25519.stronghold", os.environ['STRONGHOLD_PASSWORD']))
Expand Down
8 changes: 3 additions & 5 deletions bindings/python/examples/how_tos/sign_evm/sign_evm.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,9 @@
INTERNAL_ADDRESS = False
ADDRESS_INDEX = 0

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['MNEMONIC', 'STRONGHOLD_PASSWORD']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

secret_manager = SecretManager(StrongholdSecretManager(
"sign_secp256k1_ecdsa.stronghold", os.environ['STRONGHOLD_PASSWORD']))
Expand Down
7 changes: 3 additions & 4 deletions bindings/python/examples/secret_manager/stronghold.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@

load_dotenv()

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")
for env_var in ['MNEMONIC', 'STRONGHOLD_PASSWORD']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")

secret_manager = SecretManager(StrongholdSecretManager(
"example.stronghold", os.environ['STRONGHOLD_PASSWORD']))
Expand Down
8 changes: 3 additions & 5 deletions bindings/python/examples/wallet/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,16 @@
# Shimmer coin type
coin_type = CoinType.SHIMMER

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['STRONGHOLD_PASSWORD', 'MNEMONIC']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

secret_manager = StrongholdSecretManager(
os.environ['STRONGHOLD_SNAPSHOT_PATH'], os.environ['STRONGHOLD_PASSWORD'])

wallet = Wallet('./backup-database', client_options,
coin_type, secret_manager)

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")

# Store the mnemonic in the Stronghold snapshot, this only needs to be
# done once.
account = wallet.store_mnemonic(os.environ['MNEMONIC'])
Expand Down
8 changes: 3 additions & 5 deletions bindings/python/examples/wallet/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@
# Shimmer coin type
coin_type = CoinType.SHIMMER

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['STRONGHOLD_PASSWORD', 'MNEMONIC']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

secret_manager = StrongholdSecretManager(
"wallet.stronghold",
Expand All @@ -37,9 +38,6 @@
wallet = Wallet(os.environ['WALLET_DB_PATH'], client_options,
coin_type, secret_manager)

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")

# Store the mnemonic in the Stronghold snapshot, this only needs to be
# done once.
account = wallet.store_mnemonic(os.environ["MNEMONIC"])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,16 @@
node_url = os.environ.get('NODE_URL', 'https://api.testnet.shimmer.network')
offline_client_options = ClientOptions()

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['STRONGHOLD_PASSWORD', 'MNEMONIC']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

secret_manager = StrongholdSecretManager(
STRONGHOLD_SNAPSHOT_PATH, os.environ['STRONGHOLD_PASSWORD'])

wallet = Wallet(OFFLINE_WALLET_DB_PATH, offline_client_options,
CoinType.IOTA, secret_manager)

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")

# Store the mnemonic in the Stronghold snapshot, this only needs to be
# done once
wallet.store_mnemonic(os.environ['MNEMONIC'])
Expand Down
8 changes: 3 additions & 5 deletions bindings/python/examples/wallet/recover_accounts.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@
# Shimmer coin type
coin_type = CoinType.SHIMMER

if 'STRONGHOLD_PASSWORD' not in os.environ:
raise Exception(".env STRONGHOLD_PASSWORD is undefined, see .env.example")
for env_var in ['STRONGHOLD_PASSWORD', 'MNEMONIC']:
if env_var not in os.environ:
raise Exception(f'.env {env_var} is undefined, see .env.example')

secret_manager = StrongholdSecretManager(
os.environ['STRONGHOLD_SNAPSHOT_PATH'], os.environ['STRONGHOLD_PASSWORD'])
Expand All @@ -27,9 +28,6 @@
coin_type,
secret_manager)

if 'MNEMONIC' not in os.environ:
raise Exception(".env MNEMONIC is undefined, see .env.example")

# Store the mnemonic in the Stronghold snapshot, this only needs to be
# done once.
account = wallet.store_mnemonic(os.environ['MNEMONIC'])
Expand Down

0 comments on commit fa366bc

Please sign in to comment.