Align the create envfile script to GeoNode project#14434
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new --authapikey CLI argument to the environment file generator and updates the .env.sample template accordingly, alongside some code formatting improvements. The review feedback highlights three main areas for improvement: handling None values for the email configuration to prevent writing literal 'None' strings to the .env file, replacing the fragile ast.literal_eval parsing of the https flag with a more robust string-matching approach, and removing an unnecessary f-string prefix from the hostname argument help text.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| else True | ||
| ) | ||
| _vals_to_replace["debug"] = False if _jsfile.get("env_type", args.env_type) in ["prod", "test"] else True | ||
| _vals_to_replace["email"] = _jsfile.get("email", args.email) |
There was a problem hiding this comment.
When --email is not provided (which is the default when running in HTTP mode), args.email defaults to None. This causes _vals_to_replace["email"] to be None.
During the template replacement loop, because "email" is in the list of keys that are converted to strings (line 121), str(None) is called, resulting in ADMIN_EMAIL=None being written to the generated .env file.
Providing a fallback to an empty string "" prevents this and ensures that the email field remains empty in the generated .env file when not specified.
| _vals_to_replace["email"] = _jsfile.get("email", args.email) | |
| _vals_to_replace["email"] = _jsfile.get("email", args.email) or "" |
| tcp = ( | ||
| "https" | ||
| if ast.literal_eval(f"{_jsfile.get('https', args.https)}".capitalize()) | ||
| else "http" | ||
| ) |
There was a problem hiding this comment.
Using ast.literal_eval on a capitalized string representation of the https parameter is fragile and can easily raise a ValueError or SyntaxError if the input is a string that is not a valid Python literal (for example, if a user specifies "yes", "y", or a malformed string in their JSON configuration).
A more robust and idiomatic approach is to check if the string representation of the value (lowercased) is in a set of truthy values. This safely handles both boolean values and various string representations without risk of throwing parsing exceptions.
https_val = _jsfile.get("https", args.https)
tcp = "https" if str(https_val).lower() in ("true", "1", "t", "y", "yes") else "http"| "-hn", | ||
| "--hostname", | ||
| help="Host name, default localhost", | ||
| help=f"Host name, default localhost", |
No description provided.