|
| 1 | +name: "Preare maven evidence example" |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + id-token: write |
| 8 | + contents: read |
| 9 | + actions: read |
| 10 | + |
| 11 | +jobs: |
| 12 | + prepare-maven-evidence-example: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + steps: |
| 15 | + - name: Call the prepare API |
| 16 | + run: | |
| 17 | + REQUEST=$(cat << EOF |
| 18 | + { |
| 19 | + "subject": { |
| 20 | + "subject_type": "package", |
| 21 | + "package_repo": "commons-dev-maven-local", |
| 22 | + "package_name": "com.example:quote-of-day-service", |
| 23 | + "package_version": "1.0.0" |
| 24 | + }, |
| 25 | + "predicate": { |
| 26 | + "statement": "This maven package is great." |
| 27 | + }, |
| 28 | + "predicate_type": "https://example.com/evidence/statement/v1", |
| 29 | + "markdown": "# Example Statement\n\n## Statement\n\nThis maven package is great." |
| 30 | + } |
| 31 | + EOF |
| 32 | + ) |
| 33 | + echo "Request: $REQUEST" |
| 34 | + URL="${{ vars.ARTIFACTORY_URL }}/evidence/api/v1/evidence/prepare?include_pae=true" |
| 35 | + echo "URL: $URL" |
| 36 | + [ "${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}" == "" ] && echo "secrets.ARTIFACTORY_ACCESS_TOKEN is empty!" && exit 1 |
| 37 | + curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}" -d "$REQUEST" -o response.json "$URL" |
| 38 | + echo "Response: $(cat response.json)" |
| 39 | + # Make sure it is valid response |
| 40 | + cat response.json | grep "dsse_payload" |
| 41 | + - name: Sign the payload |
| 42 | + run: | |
| 43 | + PRE_AUTH_ENC=$(cat response.json | jq -r .pre_authentication_encoding) |
| 44 | + echo "Pre-authentication encoding: $PRE_AUTH_ENC" |
| 45 | + echo -n "${{ secrets.JIRA_TEST_PKEY }}" > key_file |
| 46 | + PAYLOAD_SIGNATURE=$(echo -n "$PRE_AUTH_ENC" | openssl dgst -sha256 -sign key_file | openssl base64 | tr -d '\n') |
| 47 | + [ "$?" != "0" -o "$PAYLOAD_SIGNATURE" == "" ] && echo "Failed to create signature." && exit 1 |
| 48 | + rm key_file |
| 49 | + echo "Signature: $PAYLOAD_SIGNATURE" |
| 50 | + echo -n "$PAYLOAD_SIGNATURE" > signature_file |
| 51 | + - name: Build the DSSE |
| 52 | + run: | |
| 53 | + DSSE=$(cat << EOF |
| 54 | + { |
| 55 | + "payloadType": $(cat response.json | jq .dsse_payload_type), |
| 56 | + "payload": $(cat response.json | jq .dsse_payload), |
| 57 | + "signatures": [ |
| 58 | + { |
| 59 | + "keyid": "${{ vars.JIRA_TEST_KEY }}", |
| 60 | + "sig": "$(cat signature_file)" |
| 61 | + } |
| 62 | + ] |
| 63 | + } |
| 64 | + EOF |
| 65 | + ) |
| 66 | + echo "DSSE: $DSSE" |
| 67 | + echo -n "$DSSE" > dsse.json |
| 68 | + - name: Create the evidence |
| 69 | + run: | |
| 70 | + POST_URL=$(cat response.json | jq -r .post_url) |
| 71 | + echo "POST_URL: $POST_URL" |
| 72 | + URL="${{ vars.ARTIFACTORY_URL }}$POST_URL" |
| 73 | + echo "URL: $URL" |
| 74 | + BODY=$(cat dsse.json) |
| 75 | + echo "BODY: $BODY" |
| 76 | + echo |
| 77 | + echo |
| 78 | + curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}" -d "$BODY" "$URL" |
| 79 | + [ $? -ne 0 ] && echo "Failed to create evidece." && exit 1 |
| 80 | + echo |
| 81 | + echo "Created evidence successfully :-)" |
| 82 | +
|
| 83 | +
|
0 commit comments