WGU D522 Python for IT Automation |
Secure Coding, Secrets & Logging Quick
Reference | Git, Exams of Information
Technology
1. What is the recommended approach for handling credentials in an
automation script?
A. Hard-code passwords directly in the source code
B. Commit tokens to version control for easy sharing
C. Retrieve credentials through an approved secure mechanism rather than
embedding secrets in source code
D. Print secrets to logs for debugging purposes
Answer: C — Secrets should be protected through approved credential-
management mechanisms. Hard-coding passwords, committing tokens, or printing
secrets to logs are all security violations .
2. A script must execute an external command. 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. 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 verification
Answer: C — Approved credential-management mechanisms protect secrets while
supporting automation .
4. 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 .
5. 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 .
6. 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 .
7. 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 .
8. 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
Secure Coding, Secrets & Logging Quick
Reference | Git, Exams of Information
Technology
1. What is the recommended approach for handling credentials in an
automation script?
A. Hard-code passwords directly in the source code
B. Commit tokens to version control for easy sharing
C. Retrieve credentials through an approved secure mechanism rather than
embedding secrets in source code
D. Print secrets to logs for debugging purposes
Answer: C — Secrets should be protected through approved credential-
management mechanisms. Hard-coding passwords, committing tokens, or printing
secrets to logs are all security violations .
2. A script must execute an external command. 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. 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 verification
Answer: C — Approved credential-management mechanisms protect secrets while
supporting automation .
4. 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 .
5. 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 .
6. 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 .
7. 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 .
8. 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