From af9e317480535f24ffe6a8c1f2746761abf6c9fc Mon Sep 17 00:00:00 2001 From: Ahmed ElSayed Date: Mon, 1 May 2017 16:25:32 -0700 Subject: [PATCH] Still use _supportedAttributes list until ServiceBusAttributes have [Binding] --- .../MakeFunction/AttributeExtensions.cs | 33 +++++++++++++++++-- .../MakeFunction/MethodInfoExtensions.cs | 1 + 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/Microsoft.NET.Sdk.Functions/MakeFunction/AttributeExtensions.cs b/src/Microsoft.NET.Sdk.Functions/MakeFunction/AttributeExtensions.cs index fb2792b..bc1d4a6 100644 --- a/src/Microsoft.NET.Sdk.Functions/MakeFunction/AttributeExtensions.cs +++ b/src/Microsoft.NET.Sdk.Functions/MakeFunction/AttributeExtensions.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Reflection; using Microsoft.NET.Sdk.Functions.MakeFunction; using Newtonsoft.Json.Linq; +using System.Collections.Generic; namespace MakeFunctionJson { @@ -22,6 +23,32 @@ namespace MakeFunctionJson return name.ToLowerFirstCharacter(); } + private static readonly HashSet _supportedAttributes = new HashSet + { + // These 2 attributes are not handled currently. + // They can go either on class, method, or parameter. + // The code flow now assumes 1:1 mapping of attributes on parameters to function.json binding. + // "StorageAccountAttribute", + // "ServiceBusAccountAttribute", + + "BlobAttribute", + "BlobTriggerAttribute", + "QueueAttribute", + "QueueTriggerAttribute", + "TableAttribute", + "EventHubAttribute", + "EventHubTriggerAttribute", + "TimerTriggerAttribute", + "DocumentDBAttribute", + "ApiHubTableAttribute", + "MobileTableAttribute", + "ServiceBusTriggerAttribute", + "ServiceBusAttribute", + "TwilioSmsAttribute", + "NotificationHubAttribute", + "HttpTriggerAttribute" + }; + /// /// /// @@ -30,9 +57,11 @@ namespace MakeFunctionJson public static bool IsWebJobsAttribute(this Attribute attribute) { #if NET46 - return attribute.GetType().GetCustomAttributes().Any(a => a.GetType().FullName == "Microsoft.Azure.WebJobs.Description.BindingAttribute"); + return attribute.GetType().GetCustomAttributes().Any(a => a.GetType().FullName == "Microsoft.Azure.WebJobs.Description.BindingAttribute") + || _supportedAttributes.Contains(attribute.GetType().Name); #else - return attribute.GetType().GetTypeInfo().GetCustomAttributes().Any(a => a.GetType().FullName == "Microsoft.Azure.WebJobs.Description.BindingAttribute"); + return attribute.GetType().GetTypeInfo().GetCustomAttributes().Any(a => a.GetType().FullName == "Microsoft.Azure.WebJobs.Description.BindingAttribute") + || _supportedAttributes.Contains(attribute.GetType().Name); #endif } diff --git a/src/Microsoft.NET.Sdk.Functions/MakeFunction/MethodInfoExtensions.cs b/src/Microsoft.NET.Sdk.Functions/MakeFunction/MethodInfoExtensions.cs index a864b87..b4f2d99 100644 --- a/src/Microsoft.NET.Sdk.Functions/MakeFunction/MethodInfoExtensions.cs +++ b/src/Microsoft.NET.Sdk.Functions/MakeFunction/MethodInfoExtensions.cs @@ -62,6 +62,7 @@ namespace MakeFunctionJson // Clear AuthLevel from httpTrigger that has a webHook property var webHook = bindings.FirstOrDefault(b => b["type"]?.ToString() == "httpTrigger" && b["webHookType"]?.ToString() != null); + if (webHook != null) { webHook.Remove("authLevel");