0
0
Apache Airflowdevops~10 mins

Variable encryption for secrets in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to enable encryption for Airflow variables.

Apache Airflow
from airflow.models import Variable

secret_value = Variable.get('[1]', deserialize_json=True)
Drag options to blanks, or click blank then click option'
Amy_secret
Bmy_variable
Cconfig_value
Dpassword
Attempts:
3 left
💡 Hint
Common Mistakes
Using a variable name that does not exist in Airflow variables.
Not setting deserialize_json=True when the secret is stored as JSON.
2fill in blank
medium

Complete the code to set an encrypted variable in Airflow using the CLI.

Apache Airflow
airflow variables [1] my_secret_key my_secret_value
Drag options to blanks, or click blank then click option'
Adelete
Blist
Cget
Dset
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'get' instead of 'set' to create a variable.
Trying to use 'list' or 'delete' commands to set a variable.
3fill in blank
hard

Fix the error in the code to correctly retrieve an encrypted variable as a string.

Apache Airflow
secret = Variable.get('[1]', deserialize_json=[2])
Drag options to blanks, or click blank then click option'
AFalse
BNone
CTrue
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Setting deserialize_json to True when the variable is not JSON.
Passing None or 0 instead of a boolean value.
4fill in blank
hard

Fill both blanks to create a variable dictionary comprehension filtering secrets with length greater than 5.

Apache Airflow
secrets = {key: Variable.get(key) for key in Variable.get('[1]') if len(Variable.get(key)) [2] 5}
Drag options to blanks, or click blank then click option'
Aall_keys
B>
C<
Dkeys_list
Attempts:
3 left
💡 Hint
Common Mistakes
Using the wrong variable name for keys.
Using less than operator instead of greater than.
5fill in blank
hard

Fill all three blanks to create a dictionary of uppercase keys and their decrypted values where values are not empty.

Apache Airflow
decrypted = { [1]: Variable.get([2]) for [3] in Variable.get('all_keys') if Variable.get([3]) != '' }
Drag options to blanks, or click blank then click option'
Akey.upper()
Bkey
Dkeys
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Not converting keys to uppercase.