Skip to content

Commit 936dc59

Browse files
Prepare API example
1 parent 4eb2f77 commit 936dc59

File tree

1 file changed

+91
-0
lines changed

1 file changed

+91
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
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+
BASE64_PAYLOAD=$(cat response.json | jq -r .dsse_payload)
44+
echo "Base64 payload: $BASE64_PAYLOAD"
45+
PAYLOAD=$(echo -n "$BASE64_PAYLOAD" | base64 -d)
46+
echo "Payload: $PAYLOAD"
47+
PAYLOAD_TYPE=$(cat response.json | jq -r .dsse_payload_type)
48+
echo "Payload type: $PAYLOAD_TYPE"
49+
PAYLOAD_LEN="${#PAYLOAD}"
50+
PAYLOAD_TYPE_LEN="${#PAYLOAD_TYPE}"
51+
PRE_AUTH_ENC="DSSEv1 $PAYLOAD_TYPE_LEN $PAYLOAD_TYPE $PAYLOAD_LEN $PAYLOAD"
52+
echo "Pre-authentication encoding: $PRE_AUTH_ENC"
53+
echo -n "${{ secrets.JIRA_TEST_PKEY }}" > key_file
54+
PAYLOAD_SIGNATURE=$(echo -n "$PRE_AUTH_ENC" | openssl dgst -sha256 -sign key_file | openssl base64 | tr -d '\n')
55+
[ "$?" != "0" -o "$PAYLOAD_SIGNATURE" == "" ] && echo "Failed to create signature." && exit 1
56+
rm key_file
57+
echo "Signature: $PAYLOAD_SIGNATURE"
58+
echo -n "$PAYLOAD_SIGNATURE" > signature_file
59+
- name: Build the DSSE
60+
run: |
61+
DSSE=$(cat << EOF
62+
{
63+
"payloadType": $(cat response.json | jq .dsse_payload_type),
64+
"payload": $(cat response.json | jq .dsse_payload),
65+
"signatures": [
66+
{
67+
"keyid": "${{ vars.JIRA_TEST_KEY }}",
68+
"sig": "$(cat signature_file)"
69+
}
70+
]
71+
}
72+
EOF
73+
)
74+
echo "DSSE: $DSSE"
75+
echo -n "$DSSE" > dsse.json
76+
- name: Create the evidence
77+
run: |
78+
POST_URL=$(cat response.json | jq -r .post_url)
79+
echo "POST_URL: $POST_URL"
80+
URL="${{ vars.ARTIFACTORY_URL }}$POST_URL"
81+
echo "URL: $URL"
82+
BODY=$(cat dsse.json)
83+
echo "BODY: $BODY"
84+
echo
85+
echo
86+
curl -X POST -H 'Content-Type: application/json' -H "Authorization: Bearer ${{ secrets.ARTIFACTORY_ACCESS_TOKEN }}" -d "$BODY" "$URL"
87+
[ $? -ne 0 ] && echo "Failed to create evidece." && exit 1
88+
echo
89+
echo "Created evidence successfully :-)"
90+
91+

0 commit comments

Comments
 (0)