1

I created Python script which truncate Oracle table. I use SQL Plus, but the problem is that I have to hide password which is plain text now. I have arguments like these:

db_name = "DB_NAME"
db_user = "DB_USER"
db_password = "DB_PASS"

Then I run command like:

sqlplus_delete_table = 'echo "TRUNCATE TABLE ' + db_user + '.' + table + ' DROP STORAGE;"'
sqlplus_connection = db_user + '/' + db_password + '@' + db_name
os.system(sqlplus_delete_table + ' | sqlplus -s ' + sqlplus_connection)

Everything works fine, but the problem is password. As I know, SQL Plus does not use jceks files. So what are other solutions to hide password?

1
  • 2
    Try getting environment variables or loading from some other config script/file Commented Jun 19, 2018 at 13:46

2 Answers 2

1

You can use a solution like Django's SECRET_KEY, which I store in a file that is not in the project repository. From this file I load the keys like this in settings.py:

with open(os.path.join(ROOT_DIR, 'etc/secret_key.txt')) as f:
    SECRET_KEY = f.read().strip()

In the above example the contents of the text file is just the key, but you can use structured formats such as JSON, YAML, or even a Python file and import it.

Example of Python secret file:

# secret.py
DB_PSSWD='pswd'
DB_USER='user'

In your source code simply:

import secret

print(DB_USER)

Example of YAML secret file:

# secret.yaml
db_psswd: pswd
db_user: user

In your source code simply:

import yaml

with open('secret.yaml') as yaml_secret:
    rules = yaml.load(cfg)
print(rules['db_user'])
Sign up to request clarification or add additional context in comments.

Comments

1

On Linux it's possible to create bash-script like:

# sql.env
export db_PSSWD='pswd'
export db_USER='user'

Before running python, run bash-script to initialize environment variables:

source sql.env

Then, in python:

db_psswd = os.environ.get("db_PSSWD")
db_user = os.environ.get("db_USER")

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.