Search in sources :

Example 1 with StorageAccount

use of com.microsoft.azure.serverless.functions.annotation.StorageAccount in project azure-gradle-plugins by lenala.

the class AnnotationHandlerImpl method patchStorageBinding.

private void patchStorageBinding(final Method method, final List<BaseBinding> bindings) {
    final Optional<Annotation> storageAccount = Arrays.stream(method.getAnnotations()).filter(a -> a instanceof StorageAccount).findFirst();
    if (storageAccount.isPresent()) {
        logger.quiet("StorageAccount annotation found.");
        final String connectionString = ((StorageAccount) storageAccount.get()).value();
        bindings.stream().forEach(b -> {
            if (b instanceof StorageBaseBinding) {
                final StorageBaseBinding sb = (StorageBaseBinding) b;
                // Override storage bindings with empty connection
                if (StringUtils.isEmpty(sb.getConnection())) {
                    sb.setConnection(connectionString);
                }
            }
        });
    } else {
        logger.quiet("No StorageAccount annotation found.");
    }
}
Also used : StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) Arrays(java.util.Arrays) URL(java.net.URL) HttpBinding(com.microsoft.azure.gradle.functions.bindings.HttpBinding) HashMap(java.util.HashMap) Reflections(org.reflections.Reflections) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Logger(org.gradle.api.logging.Logger) ArrayList(java.util.ArrayList) StorageAccount(com.microsoft.azure.serverless.functions.annotation.StorageAccount) URLClassLoader(java.net.URLClassLoader) HttpTrigger(com.microsoft.azure.serverless.functions.annotation.HttpTrigger) Parameter(java.lang.reflect.Parameter) Map(java.util.Map) MethodAnnotationsScanner(org.reflections.scanners.MethodAnnotationsScanner) Method(java.lang.reflect.Method) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) BaseBinding(com.microsoft.azure.gradle.functions.bindings.BaseBinding) FunctionConfiguration(com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration) Set(java.util.Set) List(java.util.List) FunctionName(com.microsoft.azure.serverless.functions.annotation.FunctionName) Annotation(java.lang.annotation.Annotation) Optional(java.util.Optional) BindingFactory(com.microsoft.azure.gradle.functions.bindings.BindingFactory) StorageAccount(com.microsoft.azure.serverless.functions.annotation.StorageAccount) StorageBaseBinding(com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding) Annotation(java.lang.annotation.Annotation)

Aggregations

BaseBinding (com.microsoft.azure.gradle.functions.bindings.BaseBinding)1 BindingFactory (com.microsoft.azure.gradle.functions.bindings.BindingFactory)1 HttpBinding (com.microsoft.azure.gradle.functions.bindings.HttpBinding)1 StorageBaseBinding (com.microsoft.azure.gradle.functions.bindings.StorageBaseBinding)1 FunctionConfiguration (com.microsoft.azure.gradle.functions.configuration.FunctionConfiguration)1 FunctionName (com.microsoft.azure.serverless.functions.annotation.FunctionName)1 HttpTrigger (com.microsoft.azure.serverless.functions.annotation.HttpTrigger)1 StorageAccount (com.microsoft.azure.serverless.functions.annotation.StorageAccount)1 Annotation (java.lang.annotation.Annotation)1 Method (java.lang.reflect.Method)1 Parameter (java.lang.reflect.Parameter)1 URL (java.net.URL)1 URLClassLoader (java.net.URLClassLoader)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Optional (java.util.Optional)1 Set (java.util.Set)1