-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.csx
47 lines (41 loc) · 1.46 KB
/
run.csx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
using RestSharp;
public static void Run(Stream myBlob, string name, TraceWriter log, out string outputQueueItem)
{
var client = new RestClient("https://<threatgrid uri>/api/v2/");
var request = new RestRequest("samples", Method.POST);
request.AlwaysMultipartFormData = true;
// add parameters for all properties on an object
request.AddObject(new Sample(name, myBlob));
// add parameter "private"
request.AddParameter("private", "true");
// execute the request
IRestResponse response = client.Execute(request);
outputQueueItem = response.Content; // raw content as string
log.Info($"C# Blob trigger function Processed blob\n Name:{name} \n Size: {myBlob.Length} Bytes\n{response.Content}");
}
public class Sample
{
public byte[] sample { get; set; }
public string filename { get; set; }
public string os { get; set; }
public string osver { get; set; }
public string vm { get; set; }
public string privates { get; set; }
public string source { get; set; }
public string api_key { get; set; }
public string tags { get; set; }
public Sample(string Filename, Stream myBlob)
{
this.filename = Filename;
this.os = "Unknown";
this.osver = "Unknown";
this.vm = "";
this.privates = "true";
this.tags = "";
using (MemoryStream ms = new MemoryStream())
{
myBlob.CopyTo(ms);
this.sample = ms.ToArray();
}
}
}