Introduction
There may be cases, where customers would need to verify if the Boundary session token is still valid and proceed with their workflows, or instead - execute boundary authenticate again.
Boundary has a built-in command that we can use:
boundary config get-token
Prerequisites
2. Reference to the exit code statuses:
For the shell’s purposes, a command which exits with a zero exit status has succeeded.
A non-zero exit status indicates failure.
3. "echo $?"- a command that will print the exit status of the most recently executed foreground pipeline
Procedure
When a user or a client executes:
boundary config get-token
it can either display the token and exit with a status code zero (success):
❯ boundary config get-token
at_kxuoyp26Q5_s18pBCkkVTuL73e1C...qxHNE
❯ echo $?
0
or display an error message and exit with a status code of non-zero:
❯ boundary config get-token
No token could be discovered
❯ echo $?
2
Additional Information
Using both boundary config get-token
and the exit codes, we can build a simple verification shell script:
#!/bin/bash
boundary config get-token 2> /dev/null
if [ $? -eq 0 ]
then
echo "Boundary session token was discovered."
exit 0
else
echo "No token could be discovered"
boundary authenticate
exit 1
fi
For additional questions or support, please open a support ticket.