diff --git a/cli/raft-tools/auth/node-js/msal/msal_token.js b/cli/raft-tools/auth/node-js/msal/msal_token.js index 4ed0150f..df5af8ad 100644 --- a/cli/raft-tools/auth/node-js/msal/msal_token.js +++ b/cli/raft-tools/auth/node-js/msal/msal_token.js @@ -45,7 +45,7 @@ function get_token(client_id, tenant_id, secret, scopes, authority_uri, callback msalInstance.acquireTokenByClientCredential(accessTokenRequest).then(function(accessTokenResponse) { callback(null, accessTokenResponse.tokenType + ' ' + accessTokenResponse.accessToken); }).catch(function (error) { - log.error(error); + console.error(error); callback(error); }) } diff --git a/cli/raft-tools/tools/Dredd/index.js b/cli/raft-tools/tools/Dredd/index.js index c74cef8c..5422f6d3 100644 --- a/cli/raft-tools/tools/Dredd/index.js +++ b/cli/raft-tools/tools/Dredd/index.js @@ -1,5 +1,7 @@ 'use strict'; +const { config } = require('../../libs/node-js/raft'); + const toolDirectory = process.env.RAFT_TOOL_RUN_DIRECTORY; console.log(toolDirectory + "/../../libs/node-js/raft.js"); @@ -26,15 +28,14 @@ raft.installCertificates((error, result) => { raftUtils.flush(); }); } else { + var Dredd = require('dredd'); + const EventEmitter = require('events'); + let eventEmitter = new EventEmitter(); let headers = []; if (result) { headers = ["Authorization: " + result]; } - var Dredd = require('dredd'); - const EventEmitter = require('events'); - let eventEmitter = new EventEmitter(); - console.log(raftUtils.config); let configuration = { init: false, @@ -53,8 +54,45 @@ raft.installCertificates((error, result) => { require: null, // String, When using nodejs hooks, require the given module before executing hooks color: true, emitter: eventEmitter, // listen to test progress, your own instance of EventEmitter - path: raft.config.targetConfiguration.apiSpecifications + path: raft.config.targetConfiguration.apiSpecifications, + sorted : false + } + + if (raft.config.toolConfiguration) { + const toolConfig = raft.config.toolConfiguration; + if (toolConfig.header) { + console.log("Adding extra headers to configuration"); + configuration.header = configuration.header.concat(toolConfig.header); + } + + if (toolConfig["dry-run"]) { + console.log("Dry-run is set"); + configuration['dry-run'] = toolConfig["dry-run"]; + } + + if (toolConfig.only) { + console.log("Setting 'only' transaction names"); + configuration.only = toolConfig.only; + } + + if (toolConfig.hookfiles) { + console.log("Setting hook files"); + configuration.hookfiles = toolConfig.hookfiles; + } + + if (toolConfig.require) { + console.log("Setting node-js hooks require"); + configuration.require = toolConfig.require; + } + + if (toolConfig.sorted) { + console.log("Setting sorted configuration"); + configuration.sorted = toolConfig.sorted; + } } + + console.log(raft.config); + var dredd = new Dredd(configuration); //This is very ugly hack to address: diff --git a/cli/raft-tools/tools/Dredd/schema.json b/cli/raft-tools/tools/Dredd/schema.json new file mode 100644 index 00000000..c36a3e01 --- /dev/null +++ b/cli/raft-tools/tools/Dredd/schema.json @@ -0,0 +1,54 @@ + +{ + "openapi": "3.0.1", + "info": { + "title": "Dredd", + "version": "v2" + }, + "paths": {}, + "components": { + "schemas": { + "Dredd" : { + "type" : "object", + "properties" : { + "sorted" : { + "type" : "boolean", + "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." + }, + "dry-run" : { + "type" : "boolean", + "description": "Boolean, do not run any real HTTP transaction" + }, + "only" : { + "type": "array", + "items": { + "type": "string" + }, + "description" : "Array of Strings, run only transaction that match these names" + }, + "header" : { + "type": "array", + "items": { + "type": "string" + }, + "description" : "Array of Strings, these strings are then added as headers (key:value) to every transaction" + }, + "hookfiles" : { + "type": "array", + "items": { + "type": "string" + }, + "description" : "Array of Strings, filepaths to files containing hooks (can use glob wildcards)" + }, + "require" : { + "type": "array", + "items": { + "type": "string" + }, + "description" : "String, When using nodejs hooks, require the given module before executing hooks" + } + } + } + } + } +} \ No newline at end of file diff --git a/cli/raft.py b/cli/raft.py index f9009a88..17270412 100644 --- a/cli/raft.py +++ b/cli/raft.py @@ -110,7 +110,7 @@ def validate(defaults): skip_sp_deployment = args.get('skip_sp_deployment') service_cli.deploy( args['sku'], skip_sp_deployment and skip_sp_deployment is True) - elif service_action == 'upload-tools': + elif service_action == 'upload-tools' or service_action == 'update': utils_file_share = f'{uuid.uuid4()}' service_cli.upload_utils( utils_file_share, args.get('custom_tools_path')) @@ -313,7 +313,7 @@ def main(): formatter_class=argparse.RawTextHelpFormatter) service_parser.add_argument( 'service-action', - choices=['deploy', 'restart', 'info', 'upload-tools'], + choices=['deploy', 'restart', 'info', 'upload-tools', 'update'], help=textwrap.dedent('''\ deploy - Deploys the service @@ -322,7 +322,10 @@ def main(): info - Show the version of the service and the last time it was started -upload-tools - Uploads the tool definitions to the service +upload-tools - Uploads the tools definitions to the service + +update - Uploads the tools definitions to the service and + restarts service to get latest service components ''')) allowed_skus = [ diff --git a/cli/samples/dredd/petstore/dredd.json b/cli/samples/dredd/petstore/dredd.json index 533c3c68..91b7ea53 100644 --- a/cli/samples/dredd/petstore/dredd.json +++ b/cli/samples/dredd/petstore/dredd.json @@ -29,7 +29,14 @@ "tasks": [ { "toolName" : "Dredd", - "outputFolder" : "dredd" + "outputFolder" : "dredd", + "toolConfiguration" : { + "dry-run" : true, + "only" : [], + "header" : [], + "hookfiles" : [], + "require" : null + } } ] }