copy this function on your azure app function body
[FunctionName("AzureGermlin")]
public static async Task<AzureResult> AzureGermlin(
[HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)] HttpRequest req,
ILogger log)
{
try
{
var tdate = req.Headers["x-ms-date"].FirstOrDefault();
var reqDate = Convert.ToDateTime(tdate);
if (reqDate < DateTime.UtcNow.AddMinutes(-10))
{
throw new HttpResponseException(HttpStatusCode.BadRequest);
}
var auth = req.Headers["Authorization"].FirstOrDefault();
string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
var data = JsonConvert.DeserializeObject<GraphQuery>(requestBody);
var he =
quot;POST{data.Parameters.Count}AzureGermlin{tdate}";
string password = quot;{YOUR_AZURE_GERMLIN_DB_PASSWORD}";
var hmacSha256 = new System.Security.Cryptography.HMACSHA256
{
Key = Convert.FromBase64String(password)
};
byte[] hashPayLoad = hmacSha256.ComputeHash(System.Text.Encoding.UTF8.GetBytes(he));
string signature = Convert.ToBase64String(hashPayLoad);
if (signature != auth)
{
throw new HttpResponseException(HttpStatusCode.Unauthorized);
}
data.Parameters.ForEach(t =>
{
data.Query = data.Query.Replace(t.Name, t.Value);
});
var gremlinServer = new GremlinServer(YOU_AZURE_GERMLIN_DB_HOST, 443, enableSsl: true,
username: YOU_AZURE_GERMLIN_DB_USERNAME,
password: YOUR_AZURE_GERMLIN_DB_PASSWORD);
using (var gremlinClient = new GremlinClient(gremlinServer,
new GraphSON2Reader(), new GraphSON2Writer(), GremlinClient.GraphSON2MimeType))
{
var resultSet = await gremlinClient.SubmitAsync<dynamic>(data.Query);
return new AzureResult() { status = 200, result = resultSet };
}
}
catch (Exception ex)
{
return new AzureResult() { status = 500, result = ex.Message };
}
}
You can follow this articale to implement your own c# germlin app function