I'm trying to specifiy the constructor to use in autofac json configuration file.
By code a can use the UsingConstructor(...) method.
I tried different configuration but no one works.
Example of my tests :
{
"type": "BlueCurve.Search.Messaging.PubSub.Producer, BlueCurve.Search.Messaging",
"services": [
{
"type": "BlueCurve.Search.Messaging.Abstraction.IProducer, BlueCurve.Search.Messaging.Abstraction",
"constructor": "System.String, System.Guid, System.String, BlueCurve.Search.Messaging.Abstraction.IAmqpConnectionFactory"
}
]
}
{
"type": "BlueCurve.Search.Messaging.PubSub.Producer, BlueCurve.Search.Messaging",
"services": [
{
"type": "BlueCurve.Search.Messaging.Abstraction.IProducer, BlueCurve.Search.Messaging.Abstraction",
"using-constructor": "System.String, System.Guid, System.String, BlueCurve.Search.Messaging.Abstraction.IAmqpConnectionFactory"
}
]
}
{
"type": "BlueCurve.Search.Messaging.PubSub.Producer, BlueCurve.Search.Messaging",
"services": [
{
"type": "BlueCurve.Search.Messaging.Abstraction.IProducer, BlueCurve.Search.Messaging.Abstraction"
}
],
"using-constructor": "System.String, System.Guid, System.String, BlueCurve.Search.Messaging.Abstraction.IAmqpConnectionFactory"
}
Thanks you for your help!
JSON configuration doesn't support specifying constructor. Config isn't a feature for feature replacement for code based setup. See documentation here.
Related
I'm deploying a deny policy through powershell and get the following error
New-AzPolicyDefinition : InvalidPolicyRule : Failed to parse policy rule: 'Could not find member 'properties' on object of type
'PolicyRuleDefinition'. Path 'properties'.'.
The code I'm using is:
1New-AzPolicyDefinition
-name 'externalDeny’
-Policy 'C:\tmp\denyoms-temp.json'
-Parameter 'C:\tmp\denyoms-param.json' `
The policy templates are below.
Template File - https://pastebin.com/embed_js/HrjUWrvf
Parameter - https://pastebin.com/embed_js/QxEX92jf
I think it could be the tags, thanks in advance.
The problem is with the template. According to this documentation, the template should be in this format (template.json):
{
"if": {
"allOf": [
{
"field": "tags",
"Equals": "ExternalVM"
},
{
"field": "type",
"equals": "Microsoft.Compute/virtualMachines/extensions"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/publisher",
"equals": "Microsoft.Compute"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/type",
"in": "[parameters(\'notAllowedExtensions\')]"
}
]
},
"then": {
"effect": "deny"
}
}
Also, a minor change in your parameters file, template expects a "Array" type as per the condition you have applied:
{
"notAllowedExtensions": {
"type": "Array",
"metadata": {
"description": "The list of extensions that will be denied. Example: BGInfo, CustomScriptExtension, JsonAADDomainExtension, VMAccessAgent.",
"displayName": "OmsAgentForLinux"
}
}
}
Use this command to execute:
New-AzPolicyDefinition -Name 'Not allowed VM Extensions' -Description 'This policy governs which VM extensions that are explicitly denied.' -Policy 'template.json' -Parameter 'parameters.json'
Hope this helps!
I'm trying to write a powershell script that creates a new streamAnalytics job in my azure portal account, with input source as iot-hub and output source as blob storage account.
To do so, I'm using AzureRM command new-streamAnalyticsJob, and json files.
my problem is: I have not seen any documentation or example for json file where the inputs source is iot-hub. only event-hub.
what are the parameters I need to give in the json file? can anyone display an example for json file with input source to streamAnalytics job as Iot-hub?
I got the answer eventually: the required field I had to add to the inputs Oliver posted earlier here is:
"endpoint":"messages/events"
I added it under Datasource Properties section, and it works fine!
Thanks Oliver
To come back on the error message you are seeing, to add to Olivier's sample you need a Property named endpoint which corresponds to the endpoint in IoT Hub. If you are looking for Telemetry messages this will be:
"endpoint": "messages/events"
This can be found in the schema for Azure ARM: https://github.com/Azure/azure-rest-api-specs/blob/current/specification/streamanalytics/resource-manager/Microsoft.StreamAnalytics/2016-03-01/examples/Input_Create_Stream_IoTHub_Avro.json
So to complete Olivier's example, when using API version '':
"Inputs": [
{
"Name": "Hub",
"Properties": {
"DataSource": {
"Properties": {
"consumerGroupName": "[variables('asaConsumerGroup')]",
"iotHubNamespace": "[parameters('iotHubName')]",
"sharedAccessPolicyKey": "[listkeys(variables('iotHubKeyResource'), variables('iotHubVersion')).primaryKey]",
"sharedAccessPolicyName": "[variables('iotHubKeyName')]",
"endpoint": "messages/events"
},
"Type": "Microsoft.Devices/IotHubs"
},
"Serialization": {
"Properties": {
"Encoding": "UTF8"
},
"Type": "Json"
},
"Type": "Stream"
}
}
],
That'd look like the following for the inputs part of the ASA resource:
"Inputs": [
{
"Name": "IoTHubStream",
"Properties": {
"DataSource": {
"Properties": {
"consumerGroupName": "[variables('CGName')]",
"iotHubNamespace": "[variables('iotHubName')]",
"sharedAccessPolicyKey": "[listkeys(variables('iotHubKeyResource'), variables('iotHubVersion')).primaryKey]",
"sharedAccessPolicyName": "[variables('iotHubKeyName')]"
},
"Type": "Microsoft.Devices/IotHubs"
},
"Serialization": {
"Properties": {
"Encoding": "UTF8"
},
"Type": "Json"
},
"Type": "Stream"
}
}
]
I'm trying to conditionally provide resource property values through translation of runtime resource properties within a copyIndex loop..
Upon deploying the following ARM template, I receive the error:
Unable to process template language expressions for resource '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm-name}/extensions/Microsoft.EnterpriseCloud.Monitoring' at line '30' and column '10'. 'The template resource '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Compute/virtualMachines/{vm-name}' is not found.' (Code: InvalidTemplate)
"type": "[variables('extensionType')[reference(concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachines')[copyIndex()].name)).storageProfile.osDisk.osType]]",
However, the VM exists with the ID it provides, so it doesn't make sense that the engine cannot find it. If I hard-code the Extension Type, there are no errors and the Extension is installed on the VM with the same ID.
Unfortunately, I don't know if this is a bug within ARM or if I'm just doing something wrong..
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"workspaceResourceId": { "type": "string" },
"virtualMachines": { "type": "array" }
},
"variables": {
"extensionType": {
"Windows": "MicrosoftMonitoringAgent",
"Linux": "OmsAgentForLinux"
}
},
"resources": [
{
"copy": {
"name": "VMMonitoringExtensionsCopy",
"count": "[length(parameters('virtualMachines'))]"
},
"type": "Microsoft.Compute/virtualMachines/extensions",
"apiVersion": "2015-05-01-preview",
"location": "[parameters('virtualMachines')[copyIndex()].location]",
"name": "[concat(parameters('virtualMachines')[copyIndex()].name, '/Microsoft.EnterpriseCloud.Monitoring')]",
"properties": {
"publisher": "Microsoft.EnterpriseCloud.Monitoring",
"type": "[variables('extensionType')[reference(concat('Microsoft.Compute/virtualMachines/', parameters('virtualMachines')[copyIndex()].name)).storageProfile.osDisk.osType]]",
"typeHandlerVersion": "1.0",
"autoUpgradeMinorVersion": true,
"settings": {
"workspaceId": "[reference(parameters('workspaceResourceId'), '2015-11-01-preview').customerId]"
},
"protectedSettings": {
"workspaceKey": "[listKeys(parameters('workspaceResourceId'), '2015-11-01-preview').primarySharedKey]"
}
}
}
]
}
The object array being passed in for virtualMachines looks like this:
[
{ "name": "vm-name", "location": "azure-region" }
]
A couple things you can try:
1) Assuming the VM is not defined in the same template try using the "full" resourceId in the reference function. See the last example in this doc:
https://azure.microsoft.com/en-us/documentation/articles/resource-group-template-functions/#reference - it seems like the error already knows the full resourceId, but it's worth trying
2) the other thought is that the reference function is evaluated at runtime and the resource provider doesn't like the expression but that's a swag.
I will do some more poking and see if we can't nail this down.
How to pass base url in the form http://localhost:3000/resources/api/?key=aslkdajd1323121lklakskdl to swagger ui ?
I was able to access http://localhost:3000/resources/api but when I add auth filter and pass key, it says, Unauthorized.
Using swagger 1.X
Pre-populating the parameter through apiKeyauthorization in index.html did not help, but when I type in the key in UI, it worked. Unable to understand the reason for this. Hope someone can help me make sense out of it.
Try this swagger 2.0 file (use http://studio.restlet.com to downgrade to version 1.2) :
{
"swagger": "2.0",
"info": {
"version": "0.0.1",
"title": "Todo App"
},
"host": "localhost:3000",
"schemes": [
"http"
],
"paths": {
"/resources/api": {
"post": {
"parameters": [
{
"name": "key",
"in": "query",
"description": "key",
"required": true,
"type": "string"
}
],
"responses": {
"200": {
"description": "Successful response"
}
}
}
}
}
}
I was able to solve this by adding
window.authorizations.add("key", new ApiKeyAuthorization("key", yourKeyValue, "query"));
in the SwaggerUI constructor function
window.swaggerUi = new SwaggerUi({ . . .
right before the statement
window.swaggerUi.load()
You just need get the parameter from the url with javscript. In the file "index.html", under swagger-ui/dist folder, add something like this to get your key:
var key = window.location.search.match(/key=([^&]+)/);
You can see a simple example in my GIST.
Request:
{
"PersonSearch":
{
"LastName": "Doe",
"Gender":"Male",
"State" : "FL"
}
}
or
{
"PersonSearch":
{
"FirstName": "John",
"Gender":"Male",
"State" : "FL"
}
}
What is the json schema that I can validate both requests.
It has to be compatible with drraftV3.
Your requirements seem to be that you need either "FirstName" or "LastName", correct?
There is no way to specify a single schema that works for both v4 and v3, because of some fundamental changes in the spec: in v4 type can only hold a string (or array of strings). It is not permitted to use schemas inside type.
You should avoid using v3 if possible, and move over to v4.
v4 method:
In that case, you'll need to use anyOf for that particular constraint:
{
"type": "object",
"anyOf": [
{"required": ["FirstName"]},
{"required": ["LastName"]}
],
"properties": {...}
}
v3
In v3 syntax, you use type instead of anyOf (also, required is a boolean):
{
"type": [
{
"type": "object",
"properties": {
"FirstName": {"required": true}
}
},
{
"type": "object",
"properties": {
"LastName": {"required": true}
}
}
],
"properties": {...}
}
v3 -> v4 conversion
If you're stuck with a mixture of v3/v4 schemas, this tool (json-schema-compatibility) will normalise schemas (v3 or v4) into v4 syntax.
If you're working in JavaScript, you can run the schemas through the compatibility tool before you use them. You can then use purely v4-tools for your actual validation/whatever.