Skip to content

Commit 2ae19f1

Browse files
authored
Upload XLSX template to Google Drive (#993)
* Upload Xlsx file to Google Drive after Xlsx Build * Fix misconfigured build command in checklist build * Update checklists readme with Google Sheets Template * Fix typo in env variable
1 parent ad62435 commit 2ae19f1

File tree

5 files changed

+91
-15
lines changed

5 files changed

+91
-15
lines changed

.github/workflows/build-checklists.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
python-version: "3.10"
4444
- name: Install Dependencies
4545
run: |
46-
pip install openpyxl
46+
pip install openpyxl pydrive
4747
- name: Run XLSX Build
4848
if: env.CHANGED == 'true'
4949
run: npm run-script xlsxgen
@@ -79,3 +79,15 @@ jobs:
7979
git push --set-upstream origin $BRANCH_STAMP
8080
hub pull-request --no-edit
8181
fi
82+
- name: Set XLSXPublishing Secrets
83+
run: |
84+
echo "$GDRIVECREDSFILE" | base64 -d > credentials.json
85+
echo "$GDRIVESETTINGSFILE" | base64 -d > settings.yaml
86+
shell: bash
87+
env:
88+
GDRIVECREDSFILE: ${{ secrets.GDRIVECREDSFILE }}
89+
GDRIVESETTINGSFILE: ${{ secrets.GDRIVESETTINGSFILE }}
90+
- name: Publish XLSX file to Google Drive
91+
run: |
92+
npm run-script publishxlsx -- ${{ secrets.GDRIVEFILEID }} ${{ github.event.inputs.version }}
93+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from pydrive.auth import GoogleAuth
2+
from pydrive.drive import GoogleDrive
3+
4+
# To Create GAuth Credentials file
5+
gauth = GoogleAuth()
6+
gauth.LoadCredentialsFile("credentials.json")
7+
8+
if gauth.credentials is None:
9+
gauth.LocalWebserverAuth()
10+
11+
elif gauth.access_token_expired:
12+
gauth.Refresh()
13+
else:
14+
gauth.Authorize()
15+
16+
gauth.SaveCredentialsFile("credentials.json")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pydrive.drive import GoogleDrive
2+
from pydrive.auth import GoogleAuth
3+
4+
import sys
5+
6+
if len(sys.argv) < 2:
7+
print ('usage: upload-to-google-drive.py <drive-file-id> <version>')
8+
print ('drive-file-id is the id of the file to update, version is optional')
9+
exit(1)
10+
11+
def set_version():
12+
if (len( sys.argv ) > 2):
13+
return "-"+str(sys.argv[2])
14+
else:
15+
return ""
16+
17+
def set_file_id():
18+
if (len( sys.argv ) > 1):
19+
return str(sys.argv[1])
20+
else:
21+
return ""
22+
23+
def set_sheet_title(version):
24+
return "WSTG-Checklist{version}.xlsx".replace('{version}', version)
25+
26+
# The authentication
27+
gauth = GoogleAuth()
28+
drive = GoogleDrive(gauth)
29+
30+
# Set Version
31+
version = set_version()
32+
# Set Title
33+
title = set_sheet_title(version)
34+
#
35+
id = set_file_id()
36+
37+
# Upload file
38+
upload_file_path = 'checklists/checklist.xlsx'
39+
f = drive.CreateFile({'id': id})
40+
f.SetContentFile(upload_file_path)
41+
f.Upload()
42+
43+
# Update title
44+
a=drive.auth.service.files().get(fileId=id).execute()
45+
a['title']= title
46+
update=drive.auth.service.files().update(fileId=id,body=a).execute()
47+
48+
# Insert the permission.
49+
permission = f.InsertPermission({'type': 'anyone', 'value': 'anyone','role': 'reader'})
50+
51+
52+
# Empty the variable used to upload the files to Google Drive
53+
# If the file stays open in memory and causes a memory leak
54+
# therefore preventing its deletion
55+
f = None

checklists/README.md

+5-13
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,10 @@ Contained in this folder is an Excel file which provides the following worksheet
1818

1919
SHA-256: 153e6d19750ce6c02ff4a6b6c30d0e6ac0d3f08a4b8c97eb885902b7328c734f
2020

21-
## Google Sheets Import
21+
## Google Sheets Template
2222

23-
The following instructions can be used to import the Checklist spreadsheet directly into a new Google sheet without having to save the doc locally first.
23+
The following instructions can be used to copy the Checklist spreadsheet template directly into a new Google sheet without having to save the doc locally first.
2424

25-
Note: These instructions are based on use of Mozilla Firefox (72.0.1) on Win 10, and Google sheets on 2020-01-12. Minor procedural differences may be necessary for other browsers, OSes, or future iterations of Google sheets.
26-
27-
1. Visit this page :+1:
28-
2. In another tab create a new [Google sheet](https://sheets.new).
29-
3. Copy the `Direct Link` listed above.
30-
4. In your Google sheet select `File > Import` from the main menu.
31-
5. In the `Import file` dialog select the `Upload` tab.
32-
6. Click `Select a file from your device`.
33-
7. In the `File Upload` dialog, paste the previously copied URL (from step 3) into the `File name` field, click the `Open` button.
34-
8. Wait a few seconds and an `Import file` dialog should be displayed (choose your `Import location`, likely `Replace spreadsheet`), then click the `import data` button.
35-
9. You should now have a fully populated and functional Web Security Testing Guide Checklist Google sheet, with the four tabs as mentioned above.
25+
1. Go to this [Google Spreadsheet template](https://docs.google.com/spreadsheets/d/1csiYqA3DXhpz69K2JCLKN4H-kzkRFlFi/copy?copyCollaborators=false&copyComments=false&title=WSTG+Checklist)
26+
2. Click `Make a copy` button. This will create a new checklist in your logged in Google Drive.
27+
3. You should now have a fully populated and functional Web Security Testing Guide Checklist in a Google sheet, with the four tabs as mentioned above.

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
"scripts": {
1111
"pdfgen": "bash ./.github/pdf/scripts/make-pdf.sh",
1212
"jsongen": "bash ./.github/json/scripts/make-json.sh",
13-
"xlsxgen": "python ./.github/xlsx/scripts/build-checklist.py"
13+
"xlsxgen": "python ./.github/xlsx/scripts/build-checklist.py",
14+
"publishxlsx" :"python ./.github/xlsx/scripts/upload-to-google-drive.py"
1415
},
1516
"repository": {
1617
"type": "git",

0 commit comments

Comments
 (0)