Skip to content
This repository was archived by the owner on Feb 2, 2022. It is now read-only.

Commit 2f68c86

Browse files
stishkinstas
andauthored
Expose dredd configuration values through RAFT job definition - Add swagger scheman.json to dredd - Expose 'header', 'dry-run', 'only', 'hookfiles', 'require' confgiuration values (#142)
Co-authored-by: stas <[email protected]>
1 parent b8d2f77 commit 2f68c86

File tree

5 files changed

+112
-10
lines changed

5 files changed

+112
-10
lines changed

cli/raft-tools/auth/node-js/msal/msal_token.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function get_token(client_id, tenant_id, secret, scopes, authority_uri, callback
4545
msalInstance.acquireTokenByClientCredential(accessTokenRequest).then(function(accessTokenResponse) {
4646
callback(null, accessTokenResponse.tokenType + ' ' + accessTokenResponse.accessToken);
4747
}).catch(function (error) {
48-
log.error(error);
48+
console.error(error);
4949
callback(error);
5050
})
5151
}

cli/raft-tools/tools/Dredd/index.js

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
'use strict';
22

3+
const { config } = require('../../libs/node-js/raft');
4+
35
const toolDirectory = process.env.RAFT_TOOL_RUN_DIRECTORY;
46
console.log(toolDirectory + "/../../libs/node-js/raft.js");
57

@@ -26,15 +28,14 @@ raft.installCertificates((error, result) => {
2628
raftUtils.flush();
2729
});
2830
} else {
31+
var Dredd = require('dredd');
32+
const EventEmitter = require('events');
33+
let eventEmitter = new EventEmitter();
2934

3035
let headers = [];
3136
if (result) {
3237
headers = ["Authorization: " + result];
3338
}
34-
var Dredd = require('dredd');
35-
const EventEmitter = require('events');
36-
let eventEmitter = new EventEmitter();
37-
console.log(raftUtils.config);
3839

3940
let configuration = {
4041
init: false,
@@ -53,8 +54,45 @@ raft.installCertificates((error, result) => {
5354
require: null, // String, When using nodejs hooks, require the given module before executing hooks
5455
color: true,
5556
emitter: eventEmitter, // listen to test progress, your own instance of EventEmitter
56-
path: raft.config.targetConfiguration.apiSpecifications
57+
path: raft.config.targetConfiguration.apiSpecifications,
58+
sorted : false
59+
}
60+
61+
if (raft.config.toolConfiguration) {
62+
const toolConfig = raft.config.toolConfiguration;
63+
if (toolConfig.header) {
64+
console.log("Adding extra headers to configuration");
65+
configuration.header = configuration.header.concat(toolConfig.header);
66+
}
67+
68+
if (toolConfig["dry-run"]) {
69+
console.log("Dry-run is set");
70+
configuration['dry-run'] = toolConfig["dry-run"];
71+
}
72+
73+
if (toolConfig.only) {
74+
console.log("Setting 'only' transaction names");
75+
configuration.only = toolConfig.only;
76+
}
77+
78+
if (toolConfig.hookfiles) {
79+
console.log("Setting hook files");
80+
configuration.hookfiles = toolConfig.hookfiles;
81+
}
82+
83+
if (toolConfig.require) {
84+
console.log("Setting node-js hooks require");
85+
configuration.require = toolConfig.require;
86+
}
87+
88+
if (toolConfig.sorted) {
89+
console.log("Setting sorted configuration");
90+
configuration.sorted = toolConfig.sorted;
91+
}
5792
}
93+
94+
console.log(raft.config);
95+
5896
var dredd = new Dredd(configuration);
5997

6098
//This is very ugly hack to address:
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
2+
{
3+
"openapi": "3.0.1",
4+
"info": {
5+
"title": "Dredd",
6+
"version": "v2"
7+
},
8+
"paths": {},
9+
"components": {
10+
"schemas": {
11+
"Dredd" : {
12+
"type" : "object",
13+
"properties" : {
14+
"sorted" : {
15+
"type" : "boolean",
16+
"description" : "Sorts requests in a sensible way so that objects are not modified before they are created. Order: CONNECT, OPTIONS, POST, GET, HEAD, PUT, PATCH, LINK, UNLINK, DELETE, TRACE."
17+
},
18+
"dry-run" : {
19+
"type" : "boolean",
20+
"description": "Boolean, do not run any real HTTP transaction"
21+
},
22+
"only" : {
23+
"type": "array",
24+
"items": {
25+
"type": "string"
26+
},
27+
"description" : "Array of Strings, run only transaction that match these names"
28+
},
29+
"header" : {
30+
"type": "array",
31+
"items": {
32+
"type": "string"
33+
},
34+
"description" : "Array of Strings, these strings are then added as headers (key:value) to every transaction"
35+
},
36+
"hookfiles" : {
37+
"type": "array",
38+
"items": {
39+
"type": "string"
40+
},
41+
"description" : "Array of Strings, filepaths to files containing hooks (can use glob wildcards)"
42+
},
43+
"require" : {
44+
"type": "array",
45+
"items": {
46+
"type": "string"
47+
},
48+
"description" : "String, When using nodejs hooks, require the given module before executing hooks"
49+
}
50+
}
51+
}
52+
}
53+
}
54+
}

cli/raft.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def validate(defaults):
110110
skip_sp_deployment = args.get('skip_sp_deployment')
111111
service_cli.deploy(
112112
args['sku'], skip_sp_deployment and skip_sp_deployment is True)
113-
elif service_action == 'upload-tools':
113+
elif service_action == 'upload-tools' or service_action == 'update':
114114
utils_file_share = f'{uuid.uuid4()}'
115115
service_cli.upload_utils(
116116
utils_file_share, args.get('custom_tools_path'))
@@ -313,7 +313,7 @@ def main():
313313
formatter_class=argparse.RawTextHelpFormatter)
314314
service_parser.add_argument(
315315
'service-action',
316-
choices=['deploy', 'restart', 'info', 'upload-tools'],
316+
choices=['deploy', 'restart', 'info', 'upload-tools', 'update'],
317317
help=textwrap.dedent('''\
318318
deploy - Deploys the service
319319
@@ -322,7 +322,10 @@ def main():
322322
323323
info - Show the version of the service and the last time it was started
324324
325-
upload-tools - Uploads the tool definitions to the service
325+
upload-tools - Uploads the tools definitions to the service
326+
327+
update - Uploads the tools definitions to the service and
328+
restarts service to get latest service components
326329
'''))
327330

328331
allowed_skus = [

cli/samples/dredd/petstore/dredd.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@
2929
"tasks": [
3030
{
3131
"toolName" : "Dredd",
32-
"outputFolder" : "dredd"
32+
"outputFolder" : "dredd",
33+
"toolConfiguration" : {
34+
"dry-run" : true,
35+
"only" : [],
36+
"header" : [],
37+
"hookfiles" : [],
38+
"require" : null
39+
}
3340
}
3441
]
3542
}

0 commit comments

Comments
 (0)