This handy script allows you to create/recreate an API key for a user of your choice on a PureStorage FlashArray. As Pure doesn't allow to read out API keys in plaintext due to security reasons, you have to recreate the API key if you lost or forgot it. This script checks for an existing API key for the specified user, deletes it and creates a new one. The API key is printed out at the end.
Usage overview:
usage: gen_api_key.py [-h] -i IP -u USER -a API_USER -e expiration
Create an API key for a PureStorage FlashArray user.
required arguments:
-i IP, --ip IP FlashArray management IP address
-u USER, --user USER Login username for FlashArray
-a API_USER, --api-user API_USER User for whom the API key will be created
-e EXPIRATION, --expiration EXPIRATION API key expiration (e.g., 10s, 5m, 1h, 2d, 1w)
optional arguments:
-h, --help show this help message and exitMake sure you have Python installed on your system. You can check your Python version by running:
python3 --versionClone the repository:
git clone https://github.com/stschappo/FlashArray-Create-API-Key.git
cd FlashArray-Create-API-KeyCreate a virtual environment (optional but recommended):
python3 -m venv venv
source venv/bin/activate pip3 install -r requirements.txtTo run the script, use the following command:
python3 gen_api_key.py -i <FlashArray IP> -u <Username> -a <API User> -e 52wHere is an example:
python3 gen_api_key.py -i 172.16.100.10 -u Testuser -a APIuser -e 52wTo remove the virtual environment and dependencies:
rm -rf venvIf you encounter issues, make sure:
-
Your dependencies are installed correctly.
-
The FlashArray IP and credentials are valid.