The objective of this track is to learn how to inject data dynamically at test time using just-in-time data.
You'll emulate user input that is typically added in a track's challenge manually using a solve
script that will be verified later in a check
script.
In this first challenge, you're going to get a random word from an online resource and then assign that random word to an environment variable that you'll persist in the /root/.bashrc
file. Saving the environment variable to the /root/.bashrc
file will makes its value available later on.
The online resource you'll use to get a random word is an API published by https://wordnik.com. You'll need to register to the site and get an API key in order to have the website provide a random word. You'll add the API to the URL that you'll call using a curl
command. The command you'll use to get the random word is:
SECRET_MESSAGE=$(curl -s 'https://api.wordnik.com/v4/words.json/randomWord?api_key=<YOUR_API_KEY> | jq -r '.word')
WHERE <YOUR_API_KEY>
is the API key generated for you by the wordnik.com website.**
Once a random word is assigned to SECRET_MESSAGE
, you'll add the environment variable and its value to the /root/.bashrc
script of reuse in a later challenge.
Step 1:
Copy the following command into a terminal window substituting the value of your API key assigned by Wordnik for the string <YOUR_API_KEY>
. You'll be assigning your API key to an environment variable named MY_KEY_API
.
export MY_API_KEY=<YOUR_API_KEY>
Step 2:
Assign a random word to the environment variable named SECRET_MESSAGE
using the WordNik API. Use the following command to get the random word and assign it to the environment variable named SECRET_MESSAGE
.
SECRET_MESSAGE=$(curl -s https://api.wordnik.com/v4/words.json/randomWord?api_key=$MY_API_KEY | jq -r '.word')
Step 3:
Echo the value of SECRET_MESSAGE
to make sure you got a valid random word
echo $SECRET_MESSAGE
You'll get output that is a random word, similar to the following:
alphabet
```
---
`Step 4:` Save the `SECRET_MESSAGE` environment variable and its value to `/root/.bashrc` for persistence and later use
```bash
echo "export SECRET_MESSAGE=${SECRET_MESSAGE}" >> /root/.bashrc
```
**NEXT**: Access the environment variable and its value.