Error while running Logic Apps (Standard) - azure-logic-apps

I decided to ask here since the Logic Apps team won't answer me on github. Anyways, I have tried to run a logic app locally in VS Code following this guide: Create Single Tenant Workflows Visual Studio Code (I have tried following other guides too) but I always get this same error when I run it:
Job dispatching error: operationName='JobDispatchingWorker.ExecuteTriggerInnerLoop', jobPartition='F106FDA38562443473E3DC4790D974E6:2D08585773452306434462235104894CU00', jobId='08585773234586434462235104894CU00', message='Job dispatching worker unable to execute inner trigger loop.', exception='System.FormatException: Input string was not in a correct format.
at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
at System.Convert.ToDouble(String value)
at Microsoft.Azure.Workflows.Common.Logging.FlowEventSource.JobHistory(String jobPartition, String jobId, String callback, String startTime, String endTime, String executionTimeInMilliseconds, String
executionDelayInMilliseconds, String executionIntervalInMilliseconds, String executionStatus, String executionMessage, String executionDetails, String nextExecutionTime, String subscriptionId, String correlationId, String principalOid, String principalPuid, String tenantId, String dequeueCount, String advanceVersion, String triggerId, String messageId, String state, String organizationId, String activityVector, String realPuid, String altSecId, String additionalProperties, String jobDurabilityLevel)
at Microsoft.WindowsAzure.ResourceStack.Common.BackgroundJobs.Execution.JobDispatchingWorker.HandleJobExecution(JobTrigger trigger, JobDefinition definition, BackgroundJob backgroundJob, DateTime startTime, DateTime endTime, TimeSpan executionTime, TimeSpan executionDelay, TimeSpan executionInterval, JobExecutionResult executionResult, Boolean executeJobInline)
at Microsoft.WindowsAzure.ResourceStack.Common.BackgroundJobs.Execution.JobDispatchingWorker.ExecuteJobWithCancellation(JobTrigger trigger, JobDefinition definition, CancellationToken cancellationToken)
at Microsoft.WindowsAzure.ResourceStack.Common.BackgroundJobs.Execution.JobDispatchingWorker.ExecuteJobWithWatchdog(JobTrigger trigger, JobDefinition definition)
at Microsoft.WindowsAzure.ResourceStack.Common.BackgroundJobs.Execution.JobDispatchingWorker.ExecuteTriggerInnerLoop(JobTrigger trigger, JobDefinition definition)', correlationId='', organizationId='', activityVector='', additionalProperties='', extensionVersion='1.0.0.0', siteName='UNDEFINED_SITE_NAME', slotName='', activityId='00000000-0000-0000-0000-000000000000'.
The error occurs after
Host lock lease acquired by instance ID '00000000000000000000000051282CB2'
workflow.json (generated by vsc designer):
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {
"Send_an_email_(V2)": {
"type": "ApiConnection",
"inputs": {
"host": {
"connection": {
"referenceName": "office365"
}
},
"method": "post",
"body": {
"To": "myEmail#something.com",
"Subject": "#triggerOutputs()?['body']?['name']",
"Body": "<p>#{triggerOutputs()?['body']?['name']} has been Updated</p>"
},
"path": "/v2/Mail"
},
"runAfter": {}
}
},
"triggers": {
"When_a_blob_is_Added_or_Modified_in_Azure_Storage": {
"type": "ServiceProvider",
"inputs": {
"parameters": {
"path": "test/host"
},
"serviceProviderConfiguration": {
"connectionName": "AzureBlob",
"operationId": "whenABlobIsAddedOrModified",
"serviceProviderId": "/serviceProviders/AzureBlob"
}
}
}
},
"contentVersion": "1.0.0.0",
"outputs": {}
},
"kind": "Stateless"
}
connections.json
{
"serviceProviderConnections": {
"AzureBlob": {
"parameterValues": {
"connectionString": "#appsetting('AzureBlob_connectionString')"
},
"serviceProvider": {
"id": "/serviceProviders/AzureBlob"
},
"displayName": "sample"
}
},
"managedApiConnections": {
"office365": {
"api": {
"id": "/subscriptions/***/providers/Microsoft.Web/locations/***/managedApis/office365"
},
"connection": {
"id": "/subscriptions/***/resourceGroups/***/providers/Microsoft.Web/connections/office365"
},
"connectionRuntimeUrl": "https://***.**.common.logic-***.azure-apihub.net/apim/office365/***/",
"authentication": {
"type": "Raw",
"scheme": "Key",
"parameter": "#appsetting('office365-connectionKey')"
}
}
}
}
host.json
{
"version": "2.0",
"extensionBundle": {
"id": "Microsoft.Azure.Functions.ExtensionBundle.Workflows",
"version": "[1.*, 2.0.0)"
}
}
local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "DefaultEndpointsProtocol=https;AccountName=***;AccountKey=**********",
"FUNCTIONS_WORKER_RUNTIME": "node",
"WORKFLOWS_TENANT_ID": "***",
"WORKFLOWS_SUBSCRIPTION_ID": "***",
"WORKFLOWS_RESOURCE_GROUP_NAME": "***",
"WORKFLOWS_LOCATION_NAME": "***",
"WORKFLOWS_MANAGEMENT_BASE_URI": "https://management.azure.com/",
"AzureBlob_connectionString": "***********",
"office365-connectionKey": "**********************************"
}
}

There is nothing wrong with the Logic app itself and the problem lies within Azure Functions Core Tools and my country's way of using commas instead of dots. The problem was that my country uses , (comma) as a decimal separator and not . (dot). This caused the error and by changing my regional setting to the US, it works just fine.

Related

Users Get Access Key and Secret Key Stored to Secrets Manager in Cloud Formation

{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Installing CloudAuth Application in Ubuntu 18.04 LTS",
"Parameters": {
"secretname": {
"Type": "String",
"Description": "A descriptive name that helps you find your secret later"
},
"myuser": {
"Type": "String",
"Description": "Enter existing user name"
}
},
"Resources": {
"myaccesskey": {
"Type": "AWS::IAM::AccessKey",
"Properties": {
"UserName": {
"Ref": "myuser"
}
}
},
"mysecrets": {
"Type": "AWS::SecretsManager::Secret",
"Properties": {
"Name": {
"Ref": "secretname"
},
"SecretString": "{\"Access_Key\":\"${myaccesskey}\",\"Secret_Key\":\"${myaccesskey.SecretAccessKey}\"}"
}
}
}
}
From my understanding, you are trying to pass the Access Key and Secret Key to the secret string of Secrets manager resources.
Instead of using:
"SecretString":
"{"Access_Key":"${myaccesskey}","Secret_Key":"${myaccesskey.SecretAccessKey}"}"
Try the following format(Fn::Sub function):
SecretString: !Sub '{ "access_key": "${AccessKey}",
"secret_key": "${AccessKey.SecretAccessKey}" }'
I used the YAML format for the stack creation.

AWS IoT JITPovisioning template with Fn::Join

I am trying to add registrationConfig for my CA certificate in AWS IoT. I would like to do some manipulation of data for Thing attributes. But I can't seem to get that JITP to work if the template body has Fn::Join in it.
Following are extract of the template body (string unescaped for reading purpose)
NOT working:
"Resources": {
"thing": {
"Type": "AWS::IoT::Thing",
"Properties": {
"ThingName": {
"Ref": "AWS::IoT::Certificate::CommonName"
},
"ThingTypeName" : "w2-device",
"ThingGroups" : ["w2-devices"],
"AttributePayload": {
"location": {
"Fn::Join":["",["ThingPrefix_",{"Ref":"SerialNumber"}]]
},
"organization": {
"Ref": "AWS::IoT::Certificate::Organization"
},
"version": "w2",
"country": {
"Ref": "AWS::IoT::Certificate::Country"
}
}
}
},
In the above when I have Fn::Join in AttributePayload/location it fails to create the Thing during JITP. I don't see any errors in CloudWatch either.
Working:
"Resources": {
"thing": {
"Type": "AWS::IoT::Thing",
"Properties": {
"ThingName": {
"Ref": "AWS::IoT::Certificate::CommonName"
},
"ThingTypeName" : "w2-device",
"ThingGroups" : ["w2-devices"],
"AttributePayload": {
"location": {
"Ref": "AWS::IoT::Certificate::StateName"
},
"organization": {
"Ref": "AWS::IoT::Certificate::Organization"
},
"version": "w2",
"country": {
"Ref": "AWS::IoT::Certificate::Country"
}
}
}
},
Note: I have also asked this in aws forum but without any answer there yet.
Provisioning templates for JITP define a set of parameters beginning with AWS::IoT::Certificate.
The AWS::IoT::Certificate::SerialNumber parameter should be used instead of just SerialNumber in the attribute payload. e.g.
"AttributePayload": {
"location": {
"Fn::Join":["",["ThingPrefix_",{"Ref":"AWS::IoT::Certificate::SerialNumber"}]]
},
https://docs.aws.amazon.com/iot/latest/developerguide/jit-provisioning.html lists the defined parameters for JITP as:
AWS::IoT::Certificate::Country
AWS::IoT::Certificate::Organization
AWS::IoT::Certificate::OrganizationalUnit
AWS::IoT::Certificate::DistinguishedNameQualifier
AWS::IoT::Certificate::StateName
AWS::IoT::Certificate::CommonName
AWS::IoT::Certificate::SerialNumber
AWS::IoT::Certificate::Id
The SerialNumber examples in the AWS documentation (without the AWS::IoT::Certificate prefix are used for the Bulk Registration process.

How to set a variable to 'null' in a Azure Logic App?

I need to send null under a certain if case to a CRM Endpoint.
Since I need the value on multiple parts of the Logic App I would like to use a variable.
This code only set the variable to "" but not to null.
I need the null in the case when the IC_CODE is not '05'.
"Set_variable_conditional_interchangability": {
"type": "SetVariable",
"inputs": {
"name": "conditional_interchangability",
"value": "#{if(equals(items('For_each')?['IC_CODE'], '05'), 928350000, null)}"
},
"runAfter": {
"Set_variable_direction": [
"Succeeded"
]
}
}
Because you are using curly braces {} in the value, the runtime is converting the null value to an empty string.
Try this:
"Set_variable_conditional_interchangability": {
"type": "SetVariable",
"inputs": {
"name": "conditional_interchangability",
"value": "#if(equals(items('For_each')?['IC_CODE'], '05'), 928350000, null)"
},
"runAfter": {
"Set_variable_direction": [
"Succeeded"
]
}
}
HTH

Generate descriptions in OpenAPI docs using Google Cloud Endpoints Framework

I'm building an API using Google Cloud Endpoints Framework v2 on Python App Engine Standard.
Using Endpoints Framework means you can automatically generate OpenAPI / Swagger documentation directly from the code.
However I am unable to work out how to generate descriptions for each of the parameters (each field in a message) in the API directly from the code.
It's possible to generate a description for the entire API but not for each individual parameter.
Using Cloud Endpoints Framework Echo as an example:
"""This is a sample Hello World API implemented using Google Cloud
Endpoints."""
# [START imports]
import endpoints
from protorpc import message_types
from protorpc import messages
from protorpc import remote
# [END imports]
# [START messages]
class EchoRequest(messages.Message):
content = messages.StringField(1)
class EchoResponse(messages.Message):
"""A proto Message that contains a simple string field."""
content = messages.StringField(1)
ECHO_RESOURCE = endpoints.ResourceContainer(
EchoRequest,
n=messages.IntegerField(2, default=1))
# [END messages]
# [START echo_api]
#endpoints.api(name='echo', version='v1')
class EchoApi(remote.Service):
#endpoints.method(
# This method takes a ResourceContainer defined above.
ECHO_RESOURCE,
# This method returns an Echo message.
EchoResponse,
path='echo',
http_method='POST',
name='echo')
def echo(self, request):
output_content = ' '.join([request.content] * request.n)
return EchoResponse(content=output_content)
#endpoints.method(
# This method takes a ResourceContainer defined above.
ECHO_RESOURCE,
# This method returns an Echo message.
EchoResponse,
path='echo/{n}',
http_method='POST',
name='echo_path_parameter')
def echo_path_parameter(self, request):
output_content = ' '.join([request.content] * request.n)
return EchoResponse(content=output_content)
#endpoints.method(
# This method takes a ResourceContainer defined above.
message_types.VoidMessage,
# This method returns an Echo message.
EchoResponse,
path='echo/getApiKey',
http_method='GET',
name='echo_api_key')
def echo_api_key(self, request):
return EchoResponse(content=request.get_unrecognized_field_info('key'))
#endpoints.method(
# This method takes an empty request body.
message_types.VoidMessage,
# This method returns an Echo message.
EchoResponse,
path='echo/getUserEmail',
http_method='GET',
# Require auth tokens to have the following scopes to access this API.
scopes=[endpoints.EMAIL_SCOPE],
# OAuth2 audiences allowed in incoming tokens.
audiences=['your-oauth-client-id.com'])
def get_user_email(self, request):
user = endpoints.get_current_user()
# If there's no user defined, the request was unauthenticated, so we
# raise 401 Unauthorized.
if not user:
raise endpoints.UnauthorizedException
return EchoResponse(content=user.email())
# [END echo_api]
# [START api_server]
api = endpoints.api_server([EchoApi])
# [END api_server]
This is the accompanying swagger documentation that has been generated:
{
"basePath": "/_ah/api",
"consumes": [
"application/json"
],
"definitions": {
"MainEchoRequest": {
"properties": {
"content": {
"type": "string"
}
},
"type": "object"
},
"MainEchoResponse": {
"properties": {
"content": {
"type": "string"
}
},
"type": "object"
}
},
"host": "echo-api.endpoints.8085-dot-3333519-dot-5002-dot-devshell.appspot.com",
"info": {
"title": "echo",
"version": "v1"
},
"paths": {
"/echo/v1/echo": {
"post": {
"operationId": "EchoApi_echo",
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/MainEchoRequest"
}
},
{
"default": 1,
"format": "int64",
"in": "query",
"name": "n",
"type": "string"
}
],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/MainEchoResponse"
}
}
}
}
},
"/echo/v1/echo/getApiKey": {
"get": {
"operationId": "EchoApi_echoApiKey",
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/MainEchoResponse"
}
}
}
}
},
"/echo/v1/echo/getUserEmail": {
"get": {
"operationId": "EchoApi_getUserEmail",
"parameters": [],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/MainEchoResponse"
}
}
},
"security": [
{
"google_id_token-c0b0c9d9": []
}
]
}
},
"/echo/v1/echo/{n}": {
"post": {
"operationId": "EchoApi_echoPathParameter",
"parameters": [
{
"in": "body",
"name": "body",
"schema": {
"$ref": "#/definitions/MainEchoRequest"
}
},
{
"default": 1,
"format": "int64",
"in": "path",
"name": "n",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "A successful response",
"schema": {
"$ref": "#/definitions/MainEchoResponse"
}
}
}
}
}
},
"produces": [
"application/json"
],
"schemes": [
"https"
],
"securityDefinitions": {
"google_id_token": {
"authorizationUrl": "",
"flow": "implicit",
"type": "oauth2",
"x-google-issuer": "https://accounts.google.com",
"x-google-jwks_uri": "https://www.googleapis.com/oauth2/v3/certs"
},
"google_id_token-c0b0c9d9": {
"authorizationUrl": "",
"flow": "implicit",
"type": "oauth2",
"x-google-audiences": "your-oauth-client-id.com",
"x-google-issuer": "https://accounts.google.com",
"x-google-jwks_uri": "https://www.googleapis.com/oauth2/v3/certs"
}
},
"swagger": "2.0"
}
In the example above I'm looking to try and include a description for the content field in the EchoResponse and EchoRequest message types.
This could be done manually by navigating the OpenAPI specification path --> /echo/v1/echo --> parameters and adding in a description key/field there -
but can it be generated through the code?
Unfortunately, Endpoints Frameworks does not currently support this. The alternative you suggested of manually adding the description is the only way right now.

Retrieve inline images from gmail api?

I'm retrieving messages from my Gmail using Gmail API. specifically, the email with Hangouts conversations using this url: https://www.googleapis.com/gmail/v1/users/me/messages?q=in:chats
When I enter in a message, I see this structure
{
"id": "1555561f7b8e1sdf56b",
"threadId": "155552511dfsd83ce98",
"labelIds": [
"CHAT"
],
"snippet": "df",
"historyId": "270812",
"internalDate": "1466016331704",
"payload": {
"partId": "",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "From",
"value": "\"Oscar J. IrĂșn\" <Oscarjiv91#gmail.com>"
}
],
"body": {
"size": 2,
"data": "ZGY="
}
},
"sizeEstimate": 100
}
as you can see, the body message is "df". Everything it's ok so far.
The problem comes when the Hangout message is an image. The snippet field is empty, and it doesnt show any attachment in the message. This is an example:
{
"id": "155558233274d78c91",
"threadId": "15fd5552511d83ce98",
"labelIds": [
"CHAT"
],
"snippet": "",
"historyId": "27sd0827",
"internalDate": "1466018445133",
"payload": {
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "From",
"value": "\"Oscar J. IrĂșn\" <Oscarjiv91#gmail.com>"
}
],
"body": {
"size": 0,
"data": ""
}
},
"sizeEstimate": 100
}
I need to retrieve this inline images. Any help will be appreciated!
You can retrieve attachments by using Users.messages.attachments:get. Take note that this request requires authorization. All requests to the Gmail API must be authorized by an authenticated user. Gmail uses the OAuth 2.0 protocol for authenticating a Google account and authorizing access to user data.
HTTP request
GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id
public static void getAttachments(Gmail service, String userId, String messageId)
throws IOException {
Message message = service.users().messages().get(userId, messageId).execute();
List<MessagePart> parts = message.getPayload().getParts();
for (MessagePart part : parts) {
if (part.getFilename() != null && part.getFilename().length() > 0) {
String filename = part.getFilename();
String attId = part.getBody().getAttachmentId();
MessagePartBody attachPart = service.users().messages().attachment().
get(userId, messageId, attId).execute();
byte[] fileByteArray = Base64.decodeBase64(attachPart.getData());
FileOutputStream fileOutFile =
new FileOutputStream("directory_to_store_attachments" + filename);
fileOutFile.write(fileByteArray);
file OutFile.close();
}
}
}
JUST FYI for PHP the solution is something similar to this:
base64_decode(strtr($gmail->service->users_messages_attachments->get('me', $message->id, $arrPart['body']['attachmentId'])->data,'-_', '+/'));

Resources