Settings must be of the form "name=value" in Eventhub client creation - azure

An exception of type 'System.FormatException' occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code
Additional information: Settings must be of the form "name=value".
while creating eventProcessorHost in EventHub
var eventProcessorHost = new EventProcessorHost(
EhEntityPath,
EventHubConsumerGroup.DefaultGroupName,
EhConnectionString,
StorageConnectionString,
StorageContainerName);
Sample values
string EhConnectionString = "Endpoint=sb://namespacename-ns.servicebus.windows.net/;SharedAccessKeyName=receivepolicy;SharedAccessKey=v7IHIH+jB3+H2UMxEOr9kHYfhwj1Q=;EntityPath=sampleeventhub";
string EhEntityPath = "sampleeventhub";
string StorageContainerName = "containername"; //I have created in blob and type as container
string StorageAccountName = "storegenameinazure";
string StorageAccountKey = "GHasmRRJgI5s123ziDlfOKQ7IBrO23EvHpk++TV0L2hU2erdI7PyY+gtvUop67lIU0+zQsM09sQ==";
static readonly string StorageConnectionString = string.Format("DefaultEndpointsProtocol=https;AccountName={0};AccountKey={1}", StorageAccountName, StorageAccountKey);

According to your description, I leverage Microsoft.Azure.ServiceBus.EventProcessorHost version (2.2.10) to test this issue.
An exception of type 'System.FormatException' occurred in Microsoft.WindowsAzure.Storage.dll but was not handled in user code. Additional information: Settings must be of the form "name=value".
Based on your code, I assumed that you have not built your EventProcessorHost constructor correctly, the constructor you used looks like this:
At this point, the parameter StorageContainerName you passed would be treated as storageConnectionString parameter, then you got the above error.
In summary, please build your EventProcessorHost with the correct constructor. Here are some tutorials you could refer to them (event-processor-host-best-practices and azure-event-hubs-processing).

Related

SQLInjection against CosmosDB in an Azure function

I have implemented an Azure function that is triggered by a HttpRequest. A parameter called name is passed as part of the HttpRequest. In Integration section, I have used the following query to retrieve data from CosmosDB (as an input):
SELECT * FROM c.my_collection pm
WHERE
Contains(pm.first_name,{name})
As you see I am sending the 'name' without sanitizing it. Is there any SQLInjection concern here?
I searched and noticed that parameterization is available but that is not something I can do anything about here.
When the binding occurs (the data from the HTTP Trigger gets sent to the Cosmos DB Input bind), it is passed through a SQLParameterCollection that will handle sanitization.
Please view this article:
Parameterized SQL provides robust handling and escaping of user input, preventing accidental exposure of data through “SQL injection”
This will cover any attempt to inject SQL through the name property.
If you're using Microsoft.Azure.Cosmos instead of Microsoft.Azure.Documents:
public class MyContainerDbService : IMyContainerDbService
{
private Container _container;
public MyContainerDbService(CosmosClient dbClient)
{
this._container = dbClient.GetContainer("MyDatabaseId", "MyContainerId");
}
public async Task<IEnumerable<MyEntry>> GetMyEntriesAsync(string queryString, Dictionary<string, object> parameters)
{
if ((parameters?.Count ?? 0) < 1)
{
throw new ArgumentException("Parameters are required to prevent SQL injection.");
}
var queryDef = new QueryDefinition(queryString);
foreach(var parm in parameters)
{
queryDef.WithParameter(parm.Key, parm.Value);
}
var query = this._container.GetItemQueryIterator<MyEntry>(queryDef);
List<MyEntry> results = new List<MyEntry>();
while (query.HasMoreResults)
{
var response = await query.ReadNextAsync();
results.AddRange(response.ToList());
}
return results;
}
}

Error during run OrganizationRequest 'RetrieveAllEntities'

I got this error during execute, could anyone give suggestion? Thanks
OrganizationRequest oreq = new OrganizationRequest();
oreq.RequestName = "RetrieveAllEntities";// please google for available Request Names
oreq.Parameters = new ParameterCollection();
oreq.Parameters.Add(new KeyValuePair<string, object>("EntityFilters", EntityFilters.Entity));
oreq.Parameters.Add(new KeyValuePair<string, object>("RetrieveAsIfPublished", false));
OrganizationResponse respo = orgProxy.Execute(oreq);
"The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter schemas.microsoft.com/xrm/2011/Contracts/Services:ExecuteResult. The InnerException message was 'Error in line 1 position 727. Element 'schemas.datacontract.org/2004/07/System.Collections.Generic:value' contains data of the 'schemas.microsoft.com/xrm/2011/Metadata:ArrayOfEntityMetadata' data contract. The deserializer has no knowledge of any type that maps to this contract. Add the type corresponding to 'ArrayOfEntityMetadata' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'. Please see InnerException for more details."
Add a reference to Microsoft.Crm.Sdk.Proxy and Microsoft.Xrm.Sdk. Visual Studio may tell you that you need to add an additional couple System.* references - add them.
Use this code:
IOrganizationService service = GetCrmService(connectionString); //This is a helper, just need to setup the service
var request = new Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesRequest()
{
EntityFilters = Microsoft.Xrm.Sdk.Metadata.EntityFilters.All,
RetrieveAsIfPublished = false
};
var response = (Microsoft.Xrm.Sdk.Messages.RetrieveAllEntitiesResponse)service.Execute(request);
Get it work finally there is two KnownTypeAttribute need to be added to the proxy class
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationRequest : object, System.Runtime.Serialization.IExtensibleDataObject
....
**[System.Runtime.Serialization.KnownTypeAttribute(typeof(EntityMetadata[]))]**
public partial class OrganizationResponse : object, System.Runtime.Serialization.IExtensibleDataObject
Thank you for help.

How to access all ASP.NET Identity 2.0 PasswordValidator properties?

I set multiple properties on the PasswordValidator, but the only rule that is checked is password length.
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
// Configure validation logic for passwords
manager.PasswordValidator = new PasswordValidator()
{
RequiredLength = int.Parse(ConfigurationManager.AppSettings["PasswordRequiredLength"]),
RequireNonLetterOrDigit = bool.Parse(ConfigurationManager.AppSettings["PasswordRequireNonLetterOrDigit"]),
RequireDigit = bool.Parse(ConfigurationManager.AppSettings["PasswordRequireDigit"]),
RequireLowercase = bool.Parse(ConfigurationManager.AppSettings["PasswordRequireLowercase"]),
RequireUppercase = bool.Parse(ConfigurationManager.AppSettings["PasswordRequireUppercase"])
};
This is pretty much copied from the ASP.NET Identity sample app except the values are from config instead of hard-coded.
When I view the definition of PasswordValidator() I see that these properties are all defined (and it compiles and runs of course). However, I notice when I test changing a password that only the length causes validation error. The AccountController had this code from the sample:
IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
To get a better look I added
IdentityResult resultPassword = await UserManager.PasswordValidator.ValidateAsync(model.NewPassword);
if (resultPassword.Succeeded)
{
IdentityResult result = await UserManager.ChangePasswordAsync(User.Identity.GetUserId(), model.OldPassword, model.NewPassword);
and I notice that userManager.PasswordValidator is of class MinimumLengthValidator, not the PasswordValidator I thought we started with. Of course, this explains the behavior, but I am at a loss to determine how to
Correctly add the "full" PassordValidator to my userManager and/or
Access the properties of the PassordValidator (such as RequireDigit, RequireUppercase, etc.)
Note, I have attempted
PasswordValidator myPV = (PasswordValidator)UserManager.PasswordValidator;
which results in a Unable to cast object of type 'Microsoft.AspNet.Identity.MinimumLengthValidator' to type 'Microsoft.AspNet.Identity.PasswordValidator' error.
Best,
Scott

Amazon SNS configuration for Data Pipeline success and failure

I am using the Amazon data pipeline for the automation of some shell activity. Which will run once in a day. So, I was configuring the amazon SNS for letting me know whether the last run of the shell activity was successful or fail. If, failed then email me the reason of failure.
So, I was able to configure the SNS for sending me the mail. But, how should I configure the message part of SNS so that in case of failure, it send me the exact error? Also, in case of success send me the status SUCCESS.
You can try node references to refer to the object on which the action is added http://docs.aws.amazon.com/datapipeline/latest/DeveloperGuide/dp-pipeline-expressions.html shows how to do this.
Ok this is my working Dynamo -> S3 import.
https://gist.github.com/osvadimos/2954ce4c0f7fc249594c999822e639f2
Regarding your question.
First you have to create Fail/Success Object
public static PipelineObject getSNSFailActivity() {
String name = "FailureNotify";
String id = "FailureNotify";
Field type = new Field()
.withKey("type")
.withStringValue("SnsAlarm");
Field topicArn = new Field()
.withKey("topicArn")
.withStringValue("#{myTopicFail}");
Field role = new Field()
.withKey("role")
.withStringValue("DataPipelineDefaultRole");
Field subject = new Field()
.withKey("subject")
.withStringValue("FAIL: #{node.#scheduledStartTime}");
Field message = new Field()
.withKey("message")
.withStringValue("#{myDDBTableName}");
List<Field> fieldsList = Lists.newArrayList(type,
role,
topicArn,
subject,
message);
return new PipelineObject()
.withName(name)
.withId(id)
.withFields(fieldsList);
}
You have to add reference of Fail/Success object to your S3BackupLocation object
public static PipelineObject getS3BackupLocation() {
String name = "S3BackupLocation";
String id = "S3BackupLocation";
Field type = new Field()
.withKey("type")
.withStringValue("S3DataNode");
Field directoryPath = new Field()
.withKey("directoryPath")
.withStringValue("#{myOutputS3Location}#{format(#scheduledStartTime, 'YYYY-MM-dd-HH-mm-ss')}");
Field onFail = new Field()
.withKey("onFail")
.withRefValue("FailureNotify");
Field onSuccess = new Field()
.withKey("onSuccess")
.withRefValue("SuccessNotify");
List<Field> fieldsList = Lists.newArrayList(type,
directoryPath,
onFail,
onSuccess);
return new PipelineObject()
.withName(name)
.withId(id)
.withFields(fieldsList);
}

Facebook Event gives error "Param eid must be a valid event id"

I am working on publish event on facebook by Facebook C# SDK. I am able to login and generate Access Token through it. But when I am publishing event I got error :
Facebook.FacebookOAuthException: (OAuthException - #100) (#100) Param eid must be a valid event id
at Facebook.FacebookClient.ProcessResponse(HttpHelper httpHelper, String responseString, Type resultType, Boolean containsEtag, IList`1 batchEtags)
at Facebook.FacebookClient.Api(HttpMethod httpMethod, String path, Object parameters, Type resultType)
at Facebook.FacebookClient.Post(String path, Object parameters)
at FacebookSDK.Facebook.CreateEvent(FBEvent fbEvent)
My code is
public void CreateEvent(FBEvent fbEvent)
{
var fb = new FacebookClient(this.AccessToken);
dynamic parameters = new ExpandoObject();
parameters.eid = "524654568165461";
parameters.owner = "me";
parameters.description = fbEvent.Description;
parameters.name = fbEvent.Title;
parameters.start_time = fbEvent.StartTime.ToString("yyyy-MM-dd hh:mm:ss");
parameters.end_time = fbEvent.EndTime.ToString("yyyy-MM-dd hh:mm:ss");
parameters.privacy = fbEvent.PrivacyInfo;
parameters.access_token = this.AccessToken;
dynamic result = fb.Post("me/event", parameters);
}
How i can resolve it....
Are you creating a new event? If so, delete this line from your code:
parameters.eid = "524654568165461";
If you are trying to edit an event, this eid is wrong.
After searching a lot I found the solution for it ....
You have to consider following link
asp.net + facebook create event
In my case i am trying to get data as dynamic but changed to JsonObject, it is working for me like,
JsonObject result = facebookClient.Post("/me/events", createEventParameters) as JsonObject;
I am using facebook sdk v 6.0.20

Resources