diff --git a/internal/fod-login/action.yml b/internal/fod-login/action.yml index 6a6a230..29ff572 100644 --- a/internal/fod-login/action.yml +++ b/internal/fod-login/action.yml @@ -4,27 +4,30 @@ author: 'Fortify' runs: using: composite steps: - # Define login options - - run: | - if [ -z "$FOD_URL" ]; then - echo "ERROR: FOD_URL environment variable must be set"; exit 1; - fi - if [ -n "${FOD_CLIENT_ID}" -a -n "${FOD_CLIENT_SECRET}" ]; then - echo '_FOD_LOGIN_OPTS=--url "${FOD_URL}" --client-id "${FOD_CLIENT_ID}" --client-secret "${FOD_CLIENT_SECRET}" ${EXTRA_FOD_LOGIN_OPTS}' >> $GITHUB_ENV - elif [ -n "${FOD_USER}" -a -n "${FOD_PASSWORD}" -a -n "${FOD_TENANT}" ]; then - echo '_FOD_LOGIN_OPTS=--url "${FOD_URL}" -t "${FOD_TENANT}" -u "${FOD_USER}" -p "${FOD_PASSWORD}" ${EXTRA_FOD_LOGIN_OPTS}' >> $GITHUB_ENV - else - echo "ERROR: Either FOD_CLIENT_ID and FOD_CLIENT_SECRET, or FOD_TENANT, FOD_USER and FOD_PASSWORD environment variables must be set"; exit 1; - fi - shell: bash - # Run fcli login command; note that the calling action/workflow is responsible for installing fcli - - uses: fortify/github-action/internal/run@feat-1.3.0 + # 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/with-post-step@feat-1.3.0 + if: ${{ !env._FOD_LOGGED_IN }} with: - cmd: '"${FCLI_CMD}" fod session login ${_FOD_LOGIN_OPTS}' - # Clean up temporary environment variables - - run: | - echo '_FOD_LOGIN_OPTS=""' >> $GITHUB_ENV - shell: bash + main: | + if [ -z "$FOD_URL" ]; then + echo "ERROR: FOD_URL environment variable must be set"; exit 1; + fi + if [ -n "${FOD_CLIENT_ID}" -a -n "${FOD_CLIENT_SECRET}" ]; then + export _FOD_LOGIN_OPTS=--url "${FOD_URL}" --client-id "${FOD_CLIENT_ID}" --client-secret "${FOD_CLIENT_SECRET}" ${EXTRA_FOD_LOGIN_OPTS} + elif [ -n "${FOD_USER}" -a -n "${FOD_PASSWORD}" -a -n "${FOD_TENANT}" ]; then + export _FOD_LOGIN_OPTS=--url "${FOD_URL}" -t "${FOD_TENANT}" -u "${FOD_USER}" -p "${FOD_PASSWORD}" ${EXTRA_FOD_LOGIN_OPTS} + else + echo "ERROR: Either FOD_CLIENT_ID and FOD_CLIENT_SECRET, or FOD_TENANT, FOD_USER and FOD_PASSWORD environment variables must be set"; exit 1; + fi + "${FCLI_CMD}" fod session login ${_FOD_LOGIN_OPTS} ${EXTRA_FOD_LOGIN_OPTS} + echo '_FOD_LOGGED_IN=true' >> $GITHUB_ENV + post: | + if [[] "${_FOD_LOGGED_IN}" == "true" ]; then + echo '_FOD_LOGGED_IN=false' >> $GITHUB_ENV + "${FCLI_CMD}" fod session logout + fi branding: icon: 'shield' color: 'blue' diff --git a/internal/fod-logout/action.yml b/internal/fod-logout/action.yml deleted file mode 100644 index ebe4eb6..0000000 --- a/internal/fod-logout/action.yml +++ /dev/null @@ -1,14 +0,0 @@ -name: 'Run "fcli fod session login" command' -description: 'Run "fcli fod session login" command based on environment variables' -author: 'Fortify' -runs: - using: composite - steps: - # Run fcli logout command; note that the calling action/workflow is responsible for installing fcli - - uses: fortify/github-action/internal/run@feat-1.3.0 - with: - cmd: '"${FCLI_CMD}" fod session logout' -branding: - icon: 'shield' - color: 'blue' - diff --git a/internal/sc-sast-login/action.yml b/internal/sc-sast-login/action.yml index 703c013..21ffc9b 100644 --- a/internal/sc-sast-login/action.yml +++ b/internal/sc-sast-login/action.yml @@ -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/run@feat-1.3.0 + + # 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/with-post-step@feat-1.3.0 + 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' diff --git a/internal/sc-sast-logout/action.yml b/internal/sc-sast-logout/action.yml deleted file mode 100644 index c4e7cf9..0000000 --- a/internal/sc-sast-logout/action.yml +++ /dev/null @@ -1,16 +0,0 @@ -name: 'Run "fcli fod session login" command' -description: 'Run "fcli fod session login" command based on environment variables' -author: 'Fortify' -runs: - using: composite - steps: - # Run fcli logout command; note that the calling action/workflow is responsible for installing fcli - - uses: fortify/github-action/internal/run@feat-1.3.0 - with: - # TODO If we add functionality for generating a CIToken in the sc-sast-login - # action, we should clean it up here. - cmd: '"${FCLI_CMD}" sc-sast session logout --no-revoke-token' -branding: - icon: 'shield' - color: 'blue' -