Skip to content

Commit

Permalink
chore: Refactor login/logout actions
Browse files Browse the repository at this point in the history
  • Loading branch information
rsenden committed May 31, 2024
1 parent d2fc8ae commit f6aa791
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 36 deletions.
44 changes: 24 additions & 20 deletions internal/sc-sast-login/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,31 @@ runs:
# TODO If we wait for scan completion, potentially we could generate a CIToken if
# SSC_USER and SSC_PASSWORD have been set, and then revoke the token once the
# scan has been successfully processed on SSC.
# Define login options
- run: |
if [ -z "$SSC_URL" ]; then
echo "ERROR: SSC_URL environment variable must be set"; exit 1;
fi
if [ -z "$SC_SAST_TOKEN" ]; then
echo "ERROR: SC_SAST_TOKEN environment variable must be set"; exit 1;
fi
if [ -z "SSC_TOKEN" ]; then
echo "ERROR: SSC_TOKEN environment variable must be set"; exit 1;
fi
echo '_SC_SAST_LOGIN_OPTS=--ssc-url "${SSC_URL}" -t "${SSC_TOKEN}" -c "${SC_SAST_TOKEN}" ${EXTRA_SC_SAST_LOGIN_OPTS}' >> $GITHUB_ENV
shell: bash
# Run fcli login command; note that the calling action/workflow is responsible for installing fcli
- uses: fortify/github-action/internal/[email protected]

# If not run before: check preconditions, run fcli login command, and run
# post-job fcli logout command.
# Note that the calling action/workflow is responsible for installing fcli
- uses: fortify/github-action/internal/[email protected]
if: ${{ !env._SC_SAST_LOGGED_IN }
with:
cmd: '"${FCLI_CMD}" sc-sast session login ${_SC_SAST_LOGIN_OPTS}'
# Clean up temporary environment variables
- run: |
echo '_SC_SAST_LOGIN_OPTS=""' >> $GITHUB_ENV
shell: bash
main: |
if [ -z "$SSC_URL" ]; then
echo "ERROR: SSC_URL environment variable must be set"; exit 1;
fi
if [ -z "$SC_SAST_TOKEN" ]; then
echo "ERROR: SC_SAST_TOKEN environment variable must be set"; exit 1;
fi
if [ -z "SSC_TOKEN" ]; then
echo "ERROR: SSC_TOKEN environment variable must be set"; exit 1;
fi
"${FCLI_CMD}" sc-sast session login --ssc-url "${SSC_URL}" -t "${SSC_TOKEN}" -c "${SC_SAST_TOKEN}" ${EXTRA_SC_SAST_LOGIN_OPTS}
echo '_SC_SAST_LOGGED_IN=true' >> $GITHUB_ENV
post: |
if [[] "${_SC_SAST_LOGGED_IN}" == "true" ]; then
echo '_SC_SAST_LOGGED_IN=false' >> $GITHUB_ENV
"${FCLI_CMD}" sc-sast session logout --no-revoke-token
fi
branding:
icon: 'shield'
color: 'blue'
Expand Down
16 changes: 0 additions & 16 deletions internal/sc-sast-logout/action.yml

This file was deleted.

0 comments on commit f6aa791

Please sign in to comment.