Accessing Environment variables in Botium.json - bots

In Botium.json, "SIMPLEREST_INIT_CONTEXT": { "token": "367439234324243" ,"sessionid":"34546363dfgfg4545"}, This value needs to taken from env variable PROCESS.ENV.token, How can i set in this file so that i can use it in simplerest endpoints ??? example would be great

Environment variables can be access within the moustache templates scripting functions, see Botium Wiki.
...
"SIMPLEREST_INIT_CONTEXT": {
"token": "{{#fnc.func}}{{process.env.token}}{{/fnc.func}}",
"sessionid":"34546363dfgfg4545"
}
...
It seems as if you want to use the token from the environment variables, and with this token you want to initialize the session before starting a conversation. Could work like this - first make a "ping" request to initialize the session, then use the session id from the ping response body in the following calls:
...
"SIMPLEREST_PING_URL": "some url",
"SIMPLEREST_PING_VERB": "POST",
"SIMPLEREST_PING_HEADERS": {
"token": "{{#fnc.func}}{{process.env.token}}{{/fnc.func}}"
},
"SIMPLEREST_PING_BODY": { some json content for the body },
...
"SIMPLEREST_URL": "...",
"SIMPLEREST_HEADERS_TEMPLATE": {
"sessionid":"{{context.message.key}}"
},
...

Related

Logic App - Expression to get a particular substring from a json

I have out form one of the tasks in Logic App:
{
"headers": {
"Connection": "close",
"Content-Type": "application/json"
},
"body": {
"systemAlertId": "....",
"endTimeUtc": null,
"entities": [
{
"$id": "us_1",
"hostName": "...",
"azureID": "someID",
"type": "host"
},
{
"$id": "us_2",
"address": "fwdedwedwedwed",
"location": {
"countryCode": "",
},
"type": "ip"
},
],
}
}
I need initialize some variable named resourceID that contains value someID which is read from above example.
Value someID will always be found in the first member of Entities array, in that case I guess need to use function first
Any idea how expression of Initial variable should look?
Thanks
Considering the mentioned data you are receiving from Http trigger, I have used Parse JSON in order to get the inner values of the mentioned JSON. Here is how you can do it.
and now you can initialize the resourceID using 'Initialise variable' connector and set its value to azureID as per your requirement.
Have a look at the Parse JSON action.
To reference or access properties in JavaScript Object Notation (JSON) content, you can create user-friendly fields or tokens for those properties by using the Parse JSON action. That way, you can select those properties from the dynamic content list when you specify inputs for your logic app. For this action, you can either provide a JSON schema or generate a JSON schema from your sample JSON content or payload.
With the information in the JSON available in an object, you can more easily access it.

is it possible to set multiple values in a specific json body field in the contract?

for example, I have dto with 2 required fields: name and age.
If i use Spring Cloud Contract then I need to describe several files with contracts:
where request body is {"name": "test", "age": 99}
where request body is {"name": null, "age": 99}
where request body is {"name": "test", "age": null}
or I can describe it in one contract and several tests will be generated from it ?
If you open the documentation of Spring Cloud Contract (https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/project-features.html#contract-dsl) you will see it being written in one of the first sentences.
Spring Cloud Contract supports defining multiple contracts in a single
file.
There's even a whole section about it https://docs.spring.io/spring-cloud-contract/docs/current/reference/html/project-features.html#contract-dsl-multiple
import org.springframework.cloud.contract.spec.Contract
[
Contract.make {
name("should post a user")
request {
method 'POST'
url('/users/1')
}
response {
status OK()
}
},
Contract.make {
request {
method 'POST'
url('/users/2')
}
response {
status OK()
}
}
]
Before asking questions please always read the documentation.

Google cloud function always receive / from API Gateway

Let's setup the basics:
I'm using Google Api Gateway with differents backends like Google Cloud Function.
First, I was parsing the req paramters with a switch statement on a header containing the original request url. (Very messy but working)
So I decided to use an express app instead for my cloud function.
But here is the thing: my functions always receive / from the gateway and generate raging errors like CANNOT GET / when my path is https://mygateway/api/subservice/action
So my question is: can I change the handling of the express app to parse my header containing the original request url and not the default path url?
Here is a part of my config:
{
"swagger": "2.0",
"info": {
"title": "my API",
"version": "1.0.0"
},
"basePath": "/api",
"host": "mygateway.[REGION].gateway.dev",
"schemes": [
"https"
],
"paths": {
"/subservice/action": {
"get": {
"x-google-backend": {
"address": "https://[REGION]-[ProjectID].cloudfunctions.net/[mycloudfunction]"
},
"security": [
{
"jwt_security": []
}
],
I found on this question something similar that guided my search of the response possible duplicate here
According Google's explanation of path translation when we use x-google-backend, the backend will only receive the basic request. we have to define with the parameter path_translation the behaviour we expect. In my case, I want to receive the same path so i use APPEND_PATH_TO_ADDRESS

Updating pipeline variables at a given scope using Azure DevOps REST api

I am currently trying to update a pipeline variable at the scope, DEV however, I am having hard time updating that variable. Is it possible to update the variable at a scope other than "Release"? If so, how? Below is the code that I used and the error that I received.
let reqLink = ' https://vsrm.dev.azure.com/'+ organization +'/'+project+'/_apis/release/releases?api-version=5.1';
let reqBody = {
"definitionId": definitionId,
"variables": {
"someVar":
{
"value": "foo",
"scope": "DEV"
}
}
};
sendHttpRequest('POST',reqLink,reqBody).then(response => {
let data = JSON.parse(response);
console.log(data);
});
This is the error that I am receiving:
{"$id":"1","innerException":null,"message":"Variable(s) someVar do not exist in the release pipeline at scope: Release
Scoped variables are defined not on the root level. But on stage level. So you must modify this here:
Here you have variable SomeVer scoped to Stage 1. The easiest way to achieve this will be hit endpoint with GET, manipulate on json and hit endpoint with PUT.
And what I noticed you are hiting release/releases whereas you should hit rather specific release release/releases/{releaseId}. Or maybe your goal is to update definition itself?
Is it possible to update the variable at a scope other than "Release"? If so, how?
The answer is yes.
The REST API you use is to create a release, if you want to update a release pipeline, using:
PUT https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions?api-version=6.0-preview.4
The request body of the REST API may need detailed information of the release pipeline. Use the following REST API to get it.
GET https://vsrm.dev.azure.com/{organization}/{project}/_apis/release/definitions/{definitionId}?api-version=6.0-preview.4
Then you can modify its response body and use it as the request body of the first REST API.
The property variables doesn't have a property called scope. If you want to update a variable from 'Release' scope to a stage scope, you need to delete the variable's original definition in variables and redefinite it in target environment. Here is an example.
Original script:
{
...
"variables": {
"somevar": {
"value": "foo"
}
},
...
};
The modified script:
{
...
"environments": [
{
"id": {stage id},
"name": DEV
...
"variables": {
"somevar": {
"value": "foo",
},
...
}
],
...
"variables": {},
...
};
Here is the summary: To change the scope of a variable, just move the variable definition to target scope.

Pass data to Azure Logic App Request Trigger

I am a newbie to azure logic app. My aim is to send some variables to logic app(via java service code, which in turn invokes the request trigger with the provided POST URL as REST API) and obtain response as JSON.
Currently i have created a request trigger and the JSON schema looks as follows:-
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {},
"id": "http://example.com/example.json",
"properties": {
"CustomerName": {
"type": "string"
},
"InvoiceFee": {
"type": "integer"
},
"InvoiceNo": {
"type": "integer"
}
},
"required": [
"CustomerName",
"InvoiceFee",
"InvoiceNo"
],
"type": "object"
}
From the request trigger, i am directing to response action and the following to be returned as JSON response.
{
"CustomerName": #{triggerBody()['CustomerName']},
"InvoiceFee": #{triggerBody()['InvoiceFee']},
"InvoiceNo": #{triggerBody()['InvoiceNo']}
}
Screenshot below:-
enter image description here
Could you please provide me some reference links of how to access logic app from java service?
I am don't know regarding how to pass the custom created object such that the parameters of the object maps to "CustomerName", "InvoiceNo", "InvoiceFee" properties.
My created java service code is as follows:-
InvoiceDTO invoiceDTOObject2 = new InvoiceDTO();
invoiceDTOObject2.setCustomerName("Sakthivel");
invoiceDTOObject2.setInvoiceNo(123);
invoiceDTOObject2.setInvoiceFee(4000);
ResteasyClient client = new ResteasyClientBuilder().build();
ResteasyWebTarget target = client.target("URL TO PROVID").resolveTemplate("properties", invoiceDTOObject2);
Response response = target.request().get();
String jsonResponse = response.readEntity(String.class);
System.out.println("JSON Reponse "+jsonResponse);
Looking at your code
Response response = target.request().get();
You are doing a GET-operation. Your Logic App HTTP Trigger would require you to perform a POST-operation using your InvoiceDTO-entity as body (serialized as JSON).
So should look something like this:
Response response = target.request().post( InvoiceDTO.entity(invoiceDTOObject2, MediaType.APPLICATION_JSON));
Not sure if it's 100% correct, my java is a little rusty, but that's the general idea.

Resources