@suffolklitlab/alkiln 5.12.0-delete3 → 5.12.0-delete5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -43,18 +43,22 @@ jobs:
|
|
|
43
43
|
#### Developer note: You can probably leave out these specific
|
|
44
44
|
#### environment variables. You may not even need the `env`
|
|
45
45
|
#### keyword or values at all. See
|
|
46
|
-
#### https://suffolklitlab.org/
|
|
46
|
+
#### https://assemblyline.suffolklitlab.org/docs/alkiln/writing#env-vars
|
|
47
47
|
env:
|
|
48
48
|
SECRET_VAR1: secret-var1-value
|
|
49
49
|
SECRET_VAR2: secret-var2-value
|
|
50
50
|
SECRET_FOR_MISSING_FIELD: secret for missing field
|
|
51
|
+
INVALID_API_KEY: invalidAPIkey
|
|
52
|
+
EMPTY_STRING: ""
|
|
53
|
+
USER_NO_PERMISSIONS_EMAIL: alkiln@example.com
|
|
54
|
+
USER_NO_PERMISSIONS_PASSWORD: User123^
|
|
51
55
|
|
|
52
56
|
steps:
|
|
53
57
|
# Place the root directory in this branch to access
|
|
54
58
|
# relative paths to action files
|
|
55
59
|
- uses: actions/checkout@v4
|
|
56
60
|
|
|
57
|
-
- name: ALKiln - Start the isolated temporary docassemble server on GitHub
|
|
61
|
+
- name: "ALKiln - Start the isolated temporary docassemble server on GitHub"
|
|
58
62
|
id: github_server
|
|
59
63
|
#### Developer note: you'll need to replace `uses: ./action_for_github_server`
|
|
60
64
|
#### with the path to ALKiln’s repository name and branch name. For example,
|
|
@@ -71,21 +75,53 @@ jobs:
|
|
|
71
75
|
shell: bash
|
|
72
76
|
|
|
73
77
|
#### Developer note: You can probably leave this out
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
+
- name: "Create a new normal user with an API key env var"
|
|
79
|
+
env:
|
|
80
|
+
SERVER_URL: "${{ steps.github_server.outputs.SERVER_URL }}"
|
|
81
|
+
KEY: ${{ steps.github_server.outputs.DOCASSEMBLE_DEVELOPER_API_KEY }}
|
|
82
|
+
run: |
|
|
83
|
+
# Create user and their API key
|
|
84
|
+
sudo apt-get install jq
|
|
85
|
+
|
|
86
|
+
# https://docassemble.org/docs/api.html#user_new
|
|
87
|
+
user_data=$(curl -X POST \
|
|
88
|
+
${{ env.SERVER_URL }}/api/user/new \
|
|
89
|
+
-H 'Content-Type: application/json' \
|
|
90
|
+
-d '{
|
|
91
|
+
"key": "${{ env.KEY }}",
|
|
92
|
+
"username": "${{ env.USER_NO_PERMISSIONS_EMAIL }}",
|
|
93
|
+
"password": "${{ env.USER_NO_PERMISSIONS_PASSWORD }}"
|
|
94
|
+
}')
|
|
95
|
+
echo "User data:"
|
|
96
|
+
echo "$user_data"
|
|
97
|
+
|
|
98
|
+
user_id=$(echo "$user_data" | jq '.user_id' -r)
|
|
99
|
+
|
|
100
|
+
# https://docassemble.org/docs/api.html#api_user_user_id_api_post
|
|
101
|
+
new_key=$(curl -X POST \
|
|
102
|
+
${{ env.SERVER_URL }}/api/user/"$user_id"/api \
|
|
103
|
+
-H 'Content-Type: application/json' \
|
|
104
|
+
-d '{
|
|
105
|
+
"key": "${{ env.KEY }}",
|
|
106
|
+
"name": "alkiln_key",
|
|
107
|
+
"method": "none"
|
|
108
|
+
}')
|
|
109
|
+
echo "User new key:"
|
|
110
|
+
echo "$new_key"
|
|
111
|
+
|
|
112
|
+
echo "USER_NO_PERMISSIONS_API_KEY=$new_key" >> "$GITHUB_ENV"
|
|
113
|
+
|
|
114
|
+
### Developer note: You can probably leave this out
|
|
115
|
+
# Optional debugging to explore things like docker issues
|
|
116
|
+
- name: Docker debug tmate session
|
|
117
|
+
#if: ${{ failure() && github.event.inputs.enable_tmate == 'true' }}
|
|
118
|
+
uses: mxschmitt/action-tmate@v3
|
|
78
119
|
|
|
79
120
|
#### Developer note: You can probably leave this out
|
|
80
|
-
- name:
|
|
121
|
+
- name: "Create other env vars for our own tests from server output"
|
|
81
122
|
run: |
|
|
82
123
|
echo "USER1_EMAIL=${{ steps.github_server.outputs.DA_ADMIN_EMAIL }}" >> $GITHUB_ENV
|
|
83
124
|
echo "USER1_PASSWORD=${{ steps.github_server.outputs.DA_ADMIN_PASSWORD }}" >> $GITHUB_ENV
|
|
84
|
-
echo "USER_NO_PERMISSIONS_EMAIL=${{ steps.github_server.outputs.DA_ADMIN_EMAIL }}" >> $GITHUB_ENV
|
|
85
|
-
echo "USER_NO_PERMISSIONS_PASSWORD=${{ steps.github_server.outputs.DA_ADMIN_PASSWORD }}" >> $GITHUB_ENV
|
|
86
|
-
echo "USER_NO_PERMISSIONS_API_KEY=${{ steps.github_server.outputs.DOCASSEMBLE_DEVELOPER_API_KEY }}" >> $GITHUB_ENV
|
|
87
|
-
echo "INVALID_API_KEY=invalidAPIkey" >> $GITHUB_ENV
|
|
88
|
-
echo "EMPTY_STRING=''" >> $GITHUB_ENV
|
|
89
125
|
|
|
90
126
|
#### Developer note:
|
|
91
127
|
#### Example of working with the docker container after it's been
|
|
@@ -111,12 +147,12 @@ jobs:
|
|
|
111
147
|
ALKILN_TAG_EXPRESSION: "${{ (github.event.inputs.tags && format('{0}', github.event.inputs.tags)) || '(not @error) and (not @temp_error)' }}"
|
|
112
148
|
with:
|
|
113
149
|
#### Developer note: Required inputs. See
|
|
114
|
-
#### https://suffolklitlab.org/
|
|
150
|
+
#### https://assemblyline.suffolklitlab.org/docs/alkiln/writing/#sandbox-inputs
|
|
115
151
|
SERVER_URL: "${{ steps.github_server.outputs.SERVER_URL }}"
|
|
116
152
|
DOCASSEMBLE_DEVELOPER_API_KEY: "${{ steps.github_server.outputs.DOCASSEMBLE_DEVELOPER_API_KEY }}"
|
|
117
153
|
INSTALL_METHOD: "server"
|
|
118
154
|
#### Developer note: You can probably leave the rest out
|
|
119
|
-
#### To learn more, see https://suffolklitlab.org/
|
|
155
|
+
#### To learn more, see https://assemblyline.suffolklitlab.org/docs/alkiln/writing/#optional-inputs
|
|
120
156
|
ALKILN_TAG_EXPRESSION: "${{ env.ALKILN_TAG_EXPRESSION }}"
|
|
121
157
|
ALKILN_VERSION: delete
|
|
122
158
|
|
|
@@ -69,10 +69,10 @@ jobs:
|
|
|
69
69
|
ALKILN_TAG_EXPRESSION: "${{ (github.event.inputs.tags && format('{0}', github.event.inputs.tags)) || '(not @error) and (not @temp_error)' }}"
|
|
70
70
|
with:
|
|
71
71
|
#### Developer note: Required ALKiln inputs. You can read more at
|
|
72
|
-
#### https://suffolklitlab.org/
|
|
72
|
+
#### https://assemblyline.suffolklitlab.org/docs/alkiln/writing/#githubNyou-inputs
|
|
73
73
|
SERVER_URL: "${{ env.SERVER_URL }}"
|
|
74
74
|
DOCASSEMBLE_DEVELOPER_API_KEY: "${{ env.DOCASSEMBLE_DEVELOPER_API_KEY }}"
|
|
75
|
-
#### Developer note: See https://suffolklitlab.org/
|
|
75
|
+
#### Developer note: See https://assemblyline.suffolklitlab.org/docs/alkiln/writing/#optional-inputs
|
|
76
76
|
#### You can probably leave this out
|
|
77
77
|
# Internal: docassemble changes sometimes break @a11y tests. That is
|
|
78
78
|
# a da problem, not ours. We will trigger these tests manually when we
|
|
@@ -232,7 +232,7 @@ da_i.get_api_key_access_status = async function ({ timeout = null, api_key = nul
|
|
|
232
232
|
} // ends try
|
|
233
233
|
} // ends auth_data.codes only has the first code
|
|
234
234
|
|
|
235
|
-
log.
|
|
235
|
+
log.info({ type: `da api info`, code: `ALK0202`,
|
|
236
236
|
pre: `API key authentication info`, data: auth_data });
|
|
237
237
|
|
|
238
238
|
return auth_data;
|
|
@@ -280,11 +280,10 @@ da_i.quietly_try_to_delete_interviews = async function ({ interviews = {}, api_k
|
|
|
280
280
|
});
|
|
281
281
|
responses.push( sub_responses );
|
|
282
282
|
} else {
|
|
283
|
-
log.
|
|
283
|
+
log.info({ type: `da api info`, code: `ALK0191`, pre: `There is no interview to delete.` });
|
|
284
284
|
}
|
|
285
285
|
}
|
|
286
286
|
return responses;
|
|
287
|
-
|
|
288
287
|
}; // Ends da_i.quietly_try_to_delete_interviews()
|
|
289
288
|
|
|
290
289
|
// node -e 'require("./lib/docassemble/docassemble_api_interface.js").quietly_delete_one_interview(...)'
|
|
@@ -292,11 +291,11 @@ da_i.quietly_delete_one_interview = async function ( timeout, { interview = {},
|
|
|
292
291
|
/** Try to delete an interview using all available API keys. Fail silently.
|
|
293
292
|
* Example failure: the test did not log in any users and the testing
|
|
294
293
|
* account's role prevents access to other user's interviews. */
|
|
295
|
-
|
|
294
|
+
|
|
296
295
|
let responses = [];
|
|
297
296
|
for ( let api_key of api_keys ) {
|
|
298
297
|
try {
|
|
299
|
-
log.
|
|
298
|
+
log.info({ type: `da api info`, code: `ALK0188`,
|
|
300
299
|
pre: `Trying to delete the interview with the id ${ interview.uid } and an API key.`
|
|
301
300
|
});
|
|
302
301
|
|
|
@@ -307,13 +306,13 @@ da_i.quietly_delete_one_interview = async function ( timeout, { interview = {},
|
|
|
307
306
|
});
|
|
308
307
|
responses.push( response );
|
|
309
308
|
|
|
310
|
-
log.
|
|
309
|
+
log.info({ type: `da api info`, code: `ALK0189`,
|
|
311
310
|
pre: `No error when trying to delete interview ${ interview.uid } at ${ interview.i }.`
|
|
312
311
|
});
|
|
313
312
|
} catch ( error ) {
|
|
314
313
|
error.interview = interview;
|
|
315
314
|
let msg = `Error when deleting the interview. See https://docassemble.org/docs/api.html#session_delete.`
|
|
316
|
-
log.
|
|
315
|
+
log.info({ type: `da api info`, code: `ALK0190`, pre: msg, data: error });
|
|
317
316
|
}
|
|
318
317
|
} // ends for api keys
|
|
319
318
|
return responses;
|
|
@@ -324,8 +323,6 @@ da_i.get_interviews = async function ({ interviews = {}, api_keys = [], options
|
|
|
324
323
|
/** Return an object of interviews that exist on the server
|
|
325
324
|
* that match the given interviews. Keys are the session ids. */
|
|
326
325
|
|
|
327
|
-
api_keys = normalize_api_keys( api_keys );
|
|
328
|
-
|
|
329
326
|
let fetched_interviews = {};
|
|
330
327
|
if ( interviews ) {
|
|
331
328
|
for ( let id in interviews ) {
|
|
@@ -346,12 +343,11 @@ da_i.get_interview = async function ({ interview = {}, api_keys = [], options =
|
|
|
346
343
|
|
|
347
344
|
// Defaults
|
|
348
345
|
let { timeout } = options || { timeout: DEFAULT_MAX_REQUEST_MS };
|
|
349
|
-
api_keys = normalize_api_keys( api_keys );
|
|
350
346
|
|
|
351
347
|
if ( interview && interview.uid ) {
|
|
352
348
|
for ( let api_key of api_keys ) {
|
|
353
349
|
try {
|
|
354
|
-
log.
|
|
350
|
+
log.info({ type: `da api info`, code: `ALK0192`, pre: `Trying to get the interview with the id ${ interview.uid } and an API key.` });
|
|
355
351
|
|
|
356
352
|
// Actual work:
|
|
357
353
|
let response = await _da_REST.get_interview( timeout, {
|
|
@@ -360,30 +356,21 @@ da_i.get_interview = async function ({ interview = {}, api_keys = [], options =
|
|
|
360
356
|
});
|
|
361
357
|
|
|
362
358
|
if ( response && response.data && response.data.items && response.data.items[0] && response.data.items[0].session ) {
|
|
363
|
-
log.
|
|
359
|
+
log.info({ type: `da api info`, code: `ALK0193`, pre: `Status ${ response.status }. Got ${ response.data.items[0].session }.`});
|
|
364
360
|
return response.data.items[0];
|
|
365
361
|
} else {
|
|
366
|
-
log.
|
|
362
|
+
log.info({ type: `da api info`, code: `ALK0194`, pre: `Status ${ response.status }. Cannot find ${ interview.uid }`});
|
|
367
363
|
}
|
|
368
364
|
|
|
369
365
|
} catch ( error ) {
|
|
370
366
|
error.interview = interview;
|
|
371
367
|
let msg = `${ error.status || `No error.status.` } ${ error.statusText || error.data || `No error.statusText.` } Ran into an error when getting the interview ${ interview.uid }. See https://docassemble.org/docs/api.html#interviews.`
|
|
372
|
-
log.
|
|
368
|
+
log.info({ type: `da api info`, code: `ALK0195`, pre: msg, data: error });
|
|
373
369
|
}
|
|
374
370
|
} // ends for api_keys
|
|
375
371
|
} else {
|
|
376
|
-
log.
|
|
372
|
+
log.info({ type: `da api info`, code: `ALK0196`, pre: `There is no interview to get.` });
|
|
377
373
|
}
|
|
378
374
|
|
|
379
375
|
return null;
|
|
380
|
-
|
|
381
376
|
}; // Ends da_i.get_interview()
|
|
382
|
-
|
|
383
|
-
let normalize_api_keys = function ( api_keys = [] ) {
|
|
384
|
-
/** Ensure the dev API key is in the api_keys list. */
|
|
385
|
-
let dev_key = session_vars.get_dev_api_key();
|
|
386
|
-
if ( !api_keys ) { api_keys = [ dev_key ]; }
|
|
387
|
-
if ( !api_keys.includes( dev_key ) ) { api_keys.unshift( dev_key ); }
|
|
388
|
-
return api_keys;
|
|
389
|
-
};
|
package/lib/scope.js
CHANGED
|
@@ -2996,17 +2996,17 @@ module.exports = {
|
|
|
2996
2996
|
// Save API key to clean up interviews later. Nice to have, not critical
|
|
2997
2997
|
if ( api_key_secret_name ) {
|
|
2998
2998
|
let api_key = process.env[ api_key_secret_name ];
|
|
2999
|
-
let api_key_msg = `The API key
|
|
2999
|
+
let api_key_msg = `The API key in the variable "${ api_key_secret_name }" is missing. Check for a typo in your test, workflow file, GitHub secret, or server config.`
|
|
3000
3000
|
if ( api_key === undefined ) {
|
|
3001
3001
|
reports.addToReport( scope, { type: `warning`, code: `ALK0199`, value: api_key_msg });
|
|
3002
3002
|
} else if ( api_key === `` ) {
|
|
3003
3003
|
reports.addToReport( scope, { type: `warning`, code: `ALK0200`,
|
|
3004
|
-
value: `ALKiln found the API key
|
|
3004
|
+
value: `ALKiln found the API key in the variable "${ api_key_secret_name }", but it was empty. It had no text in it. Edit the value of the GitHub secret or server config variable called "${ api_key_secret_name }".` });
|
|
3005
3005
|
} else {
|
|
3006
3006
|
let access_info = await da_api.get_api_key_access_status({ api_key });
|
|
3007
3007
|
if ( !access_info.has_auth ) {
|
|
3008
3008
|
reports.addToReport( scope, { type: `warning`, code: `ALK0201`,
|
|
3009
|
-
value: `The server rejected the API key
|
|
3009
|
+
value: `The server rejected the API key in the variable "${ api_key_secret_name }". Does it exist on this server? Was it deleted somehow? You can always make a new one.` });
|
|
3010
3010
|
}
|
|
3011
3011
|
// Even if it doesn't have access, give it a shot anyway.
|
|
3012
3012
|
// Maybe we got something wrong.
|
package/lib/steps.js
CHANGED
|
@@ -140,7 +140,7 @@ Before(async (scenario) => {
|
|
|
140
140
|
scope.scenario_id = uuidv4();
|
|
141
141
|
scope.scenarios.set( scope.scenario_id, {} );
|
|
142
142
|
scope.scenarios.get( scope.scenario_id ).interviews = {};
|
|
143
|
-
scope.scenarios.get( scope.scenario_id ).api_keys = [
|
|
143
|
+
scope.scenarios.get( scope.scenario_id ).api_keys = [];
|
|
144
144
|
scope.expected_status = null;
|
|
145
145
|
scope.expected_in_report = null;
|
|
146
146
|
scope.expected_not_in_report = null;
|
|
@@ -1481,7 +1481,7 @@ After(async function(scenario) {
|
|
|
1481
1481
|
// going to the wrong file). If it becomes a problem we can track it down later.
|
|
1482
1482
|
if ( visible_keys.length > 0 ) {
|
|
1483
1483
|
// Can an API key ever see an interview that it can't delete?
|
|
1484
|
-
log.
|
|
1484
|
+
log.info({ type: `internal warning`, code: `ALK0197`,
|
|
1485
1485
|
pre: `The API key can see ${ visible_keys.length } interviews that were not deleted: ${ visible_keys.join( ', ' ) }`
|
|
1486
1486
|
});
|
|
1487
1487
|
}
|
|
@@ -1493,7 +1493,7 @@ After(async function(scenario) {
|
|
|
1493
1493
|
// interview. If it becomes a problem we can track it down later.
|
|
1494
1494
|
// Consider add "internal" to docs: "If you see this, make an
|
|
1495
1495
|
// issue in ALKiln with your debug/verbose log"
|
|
1496
|
-
log.
|
|
1496
|
+
log.info({ type: `internal warning`, code: `ALK0198`, pre: `Error while cleaning up interviews.`, data: error });
|
|
1497
1497
|
}
|
|
1498
1498
|
}
|
|
1499
1499
|
|
package/package.json
CHANGED