WGU D522 Python for IT Automation |
Secure Coding, Secrets & Logging Quick
Reference | Git, Exams of Information
Technology
1. Which practice best supports secure and reliable operations when a script
authenticates to a production service?
A. Hard-code passwords in the script
B. Commit tokens to version control
C. Retrieve credentials through an approved secure mechanism rather than
embedding secrets in source code
D. Print secrets to logs for debugging
Answer: C — Secrets should be protected through approved credential-
management mechanisms, not embedded in source code or committed to version
control .
2. A script must execute an external command safely. Which approach
minimizes operational and security risk?
A. Concatenate untrusted input into shell commands
B. Execute arbitrary user input directly
C. Disable all validation for speed
D. Validate inputs and use safe command-execution mechanisms rather than
constructing unsafe shell strings
Answer: D — Safe command execution reduces injection and unintended command
risks. Using shell=True with untrusted input creates shell injection vulnerabilities .
3. Production automation should include which safeguards to limit operational
risk?
A. Disabled logs and no validation
B. Untested code running with administrator rights
C. Validation, limited permissions, logging, testing, and an appropriate approval
process
D. Unlimited retries without exception handling
Answer: C — Production automation should include safeguards that limit
operational risk: validation, limited permissions, logging, testing, and approval
processes .
4. What is idempotent automation?
A. Automation that produces different results each run
, B. Automation designed to produce the desired state without unnecessary repeated
side effects
C. Automation that runs only once
D. Automation that deletes all data on each run
Answer: B — Idempotent automation produces the desired state without
unnecessary repeated side effects when rerun .
5. When a multi-system automation task encounters a failure on one target,
what is the recommended approach?
A. Stop at the first error automatically
B. Handle expected exceptions per target and record the failure without
unnecessarily terminating the entire workflow
C. Hide all exceptions
D. Retry forever until success
Answer: B — Targeted exception handling supports resilient multi-system
automation, allowing the workflow to continue while recording failures .
6. How should JSON data from an API be handled in automation scripts?
A. Assume every field exists
B. Parse the JSON into appropriate Python structures and validate required fields
before using them
C. Treat it as trusted executable code
D. Ignore malformed responses
Answer: B — Structured API data should be parsed and validated before
processing .
7. What does the principle of least privilege mean for automation scripts?
A. Give all scripts administrator rights for simplicity
B. Run scripts with only the permissions necessary for their function
C. Disable all authentication
D. Use the same credentials for all environments
Answer: B — Least privilege limits permissions to only what is necessary, reducing
potential damage from compromised or buggy scripts.
8. Why should automation scripts validate inputs before processing?
A. To slow down execution
B. To prevent injection attacks and malformed data from causing failures
C. To increase code complexity
D. To reduce logging output
Secure Coding, Secrets & Logging Quick
Reference | Git, Exams of Information
Technology
1. Which practice best supports secure and reliable operations when a script
authenticates to a production service?
A. Hard-code passwords in the script
B. Commit tokens to version control
C. Retrieve credentials through an approved secure mechanism rather than
embedding secrets in source code
D. Print secrets to logs for debugging
Answer: C — Secrets should be protected through approved credential-
management mechanisms, not embedded in source code or committed to version
control .
2. A script must execute an external command safely. Which approach
minimizes operational and security risk?
A. Concatenate untrusted input into shell commands
B. Execute arbitrary user input directly
C. Disable all validation for speed
D. Validate inputs and use safe command-execution mechanisms rather than
constructing unsafe shell strings
Answer: D — Safe command execution reduces injection and unintended command
risks. Using shell=True with untrusted input creates shell injection vulnerabilities .
3. Production automation should include which safeguards to limit operational
risk?
A. Disabled logs and no validation
B. Untested code running with administrator rights
C. Validation, limited permissions, logging, testing, and an appropriate approval
process
D. Unlimited retries without exception handling
Answer: C — Production automation should include safeguards that limit
operational risk: validation, limited permissions, logging, testing, and approval
processes .
4. What is idempotent automation?
A. Automation that produces different results each run
, B. Automation designed to produce the desired state without unnecessary repeated
side effects
C. Automation that runs only once
D. Automation that deletes all data on each run
Answer: B — Idempotent automation produces the desired state without
unnecessary repeated side effects when rerun .
5. When a multi-system automation task encounters a failure on one target,
what is the recommended approach?
A. Stop at the first error automatically
B. Handle expected exceptions per target and record the failure without
unnecessarily terminating the entire workflow
C. Hide all exceptions
D. Retry forever until success
Answer: B — Targeted exception handling supports resilient multi-system
automation, allowing the workflow to continue while recording failures .
6. How should JSON data from an API be handled in automation scripts?
A. Assume every field exists
B. Parse the JSON into appropriate Python structures and validate required fields
before using them
C. Treat it as trusted executable code
D. Ignore malformed responses
Answer: B — Structured API data should be parsed and validated before
processing .
7. What does the principle of least privilege mean for automation scripts?
A. Give all scripts administrator rights for simplicity
B. Run scripts with only the permissions necessary for their function
C. Disable all authentication
D. Use the same credentials for all environments
Answer: B — Least privilege limits permissions to only what is necessary, reducing
potential damage from compromised or buggy scripts.
8. Why should automation scripts validate inputs before processing?
A. To slow down execution
B. To prevent injection attacks and malformed data from causing failures
C. To increase code complexity
D. To reduce logging output