Skip to content

Commit eb7cc86

Browse files
Adding V2 programming model support for Dapr Extension (#181)
* Adding daprServiceInvocation trigger Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Adding daprServiceInvocation trigger Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * moving dapr service invocation trigger to TriggerApi class Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Adding test_dapr_service_invocation_default_args Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * moving dapr related configs to its own file Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Adding bindings for Dapr extension Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Adding test for dapr bindings Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Adding test for dapr bindings Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Using TriggerApi and BindingApi instead of DecoratorApi Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Making route optional param Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Adding aka.ms links for triggers and bindings Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * assigning topic to route when route is empty Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * assigning topic to route when route is empty Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Fixed dapr_address param type Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Fixed dapr_address param type Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * fixed indentations Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * fixed indentations Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * fixed indentations Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * fixed indentations Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * fixed indentations Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * fixed indentations Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Fixed review comments Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * adding SettingsApi Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * line break Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * Adding DaprBluePrint Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> * fixed spacing issue Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> --------- Signed-off-by: MD Ashique <noorani.ashique5@gmail.com> Co-authored-by: gavin-aguiar <80794152+gavin-aguiar@users.noreply.github.com>
1 parent 88f96d3 commit eb7cc86

File tree

6 files changed

+985
-2
lines changed

6 files changed

+985
-2
lines changed

azure/functions/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
AsgiFunctionApp, WsgiFunctionApp,
1313
ExternalHttpFunctionApp)
1414
from ._durable_functions import OrchestrationContext, EntityContext
15+
from .decorators.dapr.dapr_function_app import DaprFunctionApp, DaprBlueprint
1516
from .decorators.function_app import (FunctionRegister, TriggerApi,
1617
BindingApi, SettingsApi)
1718
from .extension import (ExtensionMeta, FunctionExtensionException,
@@ -94,7 +95,9 @@
9495
'AuthLevel',
9596
'Cardinality',
9697
'AccessRights',
97-
'HttpMethod'
98+
'HttpMethod',
99+
'DaprFunctionApp',
100+
'DaprBlueprint'
98101
)
99102

100103
__version__ = '1.16.0'

azure/functions/decorators/__init__.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
AuthLevel, Blueprint, ExternalHttpFunctionApp, AsgiFunctionApp, \
66
WsgiFunctionApp, FunctionRegister, TriggerApi, BindingApi, SettingsApi
77
from .http import HttpMethod
8+
from .dapr.dapr_function_app import DaprFunctionApp, DaprBlueprint
89

910
__all__ = [
1011
'FunctionApp',
@@ -22,5 +23,7 @@
2223
'AuthLevel',
2324
'Cardinality',
2425
'AccessRights',
25-
'HttpMethod'
26+
'HttpMethod',
27+
'DaprFunctionApp',
28+
'DaprBlueprint'
2629
]

azure/functions/decorators/constants.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,12 @@
1919
EVENT_GRID_TRIGGER = "eventGridTrigger"
2020
EVENT_GRID = "eventGrid"
2121
TABLE = "table"
22+
DAPR_SERVICE_INVOCATION_TRIGGER = "daprServiceInvocationTrigger"
23+
DAPR_BINDING_TRIGGER = "daprBindingTrigger"
24+
DAPR_TOPIC_TRIGGER = "daprTopicTrigger"
25+
DAPR_STATE = "daprState"
26+
DAPR_SECRET = "daprSecret"
27+
DAPR_PUBLISH = "daprPublish"
28+
DAPR_INVOKE = "daprInvoke"
29+
DAPR_PUBLISH = "daprPublish"
30+
DAPR_BINDING = "daprBinding"
Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
# Copyright (c) Microsoft Corporation. All rights reserved.
2+
# Licensed under the MIT License.
3+
from typing import Optional
4+
5+
from azure.functions.decorators.constants import DAPR_BINDING, DAPR_INVOKE, \
6+
DAPR_PUBLISH, DAPR_SECRET, DAPR_SERVICE_INVOCATION_TRIGGER, \
7+
DAPR_BINDING_TRIGGER, DAPR_STATE, DAPR_TOPIC_TRIGGER
8+
from azure.functions.decorators.core import InputBinding, Trigger, DataType, \
9+
OutputBinding
10+
11+
12+
class DaprServiceInvocationTrigger(Trigger):
13+
14+
@staticmethod
15+
def get_binding_name() -> str:
16+
return DAPR_SERVICE_INVOCATION_TRIGGER
17+
18+
def __init__(self,
19+
name: str,
20+
method_name: str,
21+
data_type: Optional[DataType] = None,
22+
**kwargs):
23+
self.method_name = method_name
24+
super().__init__(name=name, data_type=data_type)
25+
26+
27+
class DaprBindingTrigger(Trigger):
28+
29+
@staticmethod
30+
def get_binding_name() -> str:
31+
return DAPR_BINDING_TRIGGER
32+
33+
def __init__(self,
34+
name: str,
35+
binding_name: str,
36+
data_type: Optional[DataType] = None,
37+
**kwargs):
38+
self.binding_name = binding_name
39+
super().__init__(name=name, data_type=data_type)
40+
41+
42+
class DaprTopicTrigger(Trigger):
43+
44+
@staticmethod
45+
def get_binding_name() -> str:
46+
return DAPR_TOPIC_TRIGGER
47+
48+
def __init__(self,
49+
name: str,
50+
pub_sub_name: str,
51+
topic: str,
52+
route: Optional[str] = None,
53+
data_type: Optional[DataType] = None,
54+
**kwargs):
55+
self.pub_sub_name = pub_sub_name
56+
self.topic = topic
57+
self.route = route
58+
super().__init__(name=name, data_type=data_type)
59+
60+
61+
class DaprStateInput(InputBinding):
62+
@staticmethod
63+
def get_binding_name() -> str:
64+
return DAPR_STATE
65+
66+
def __init__(self,
67+
name: str,
68+
state_store: str,
69+
key: str,
70+
dapr_address: Optional[str],
71+
data_type: Optional[DataType] = None,
72+
**kwargs):
73+
self.state_store = state_store
74+
self.key = key
75+
self.dapr_address = dapr_address
76+
super().__init__(name=name, data_type=data_type)
77+
78+
79+
class DaprSecretInput(InputBinding):
80+
@staticmethod
81+
def get_binding_name() -> str:
82+
return DAPR_SECRET
83+
84+
def __init__(self,
85+
name: str,
86+
secret_store_name: str,
87+
key: str,
88+
metadata: str,
89+
dapr_address: Optional[str],
90+
data_type: Optional[DataType] = None,
91+
**kwargs):
92+
self.secret_store_name = secret_store_name
93+
self.key = key
94+
self.metadata = metadata
95+
self.dapr_address = dapr_address
96+
super().__init__(name=name, data_type=data_type)
97+
98+
99+
class DaprStateOutput(OutputBinding):
100+
@staticmethod
101+
def get_binding_name() -> str:
102+
return DAPR_STATE
103+
104+
def __init__(self,
105+
name: str,
106+
state_store: str,
107+
key: str,
108+
dapr_address: Optional[str],
109+
data_type: Optional[DataType] = None,
110+
**kwargs):
111+
self.state_store = state_store
112+
self.key = key
113+
self.dapr_address = dapr_address
114+
super().__init__(name=name, data_type=data_type)
115+
116+
117+
class DaprInvokeOutput(OutputBinding):
118+
@staticmethod
119+
def get_binding_name() -> str:
120+
return DAPR_INVOKE
121+
122+
def __init__(self,
123+
name: str,
124+
app_id: str,
125+
method_name: str,
126+
http_verb: str,
127+
dapr_address: Optional[str],
128+
data_type: Optional[DataType] = None,
129+
**kwargs):
130+
self.app_id = app_id
131+
self.method_name = method_name
132+
self.http_verb = http_verb
133+
self.dapr_address = dapr_address
134+
super().__init__(name=name, data_type=data_type)
135+
136+
137+
class DaprPublishOutput(OutputBinding):
138+
@staticmethod
139+
def get_binding_name() -> str:
140+
return DAPR_PUBLISH
141+
142+
def __init__(self,
143+
name: str,
144+
pub_sub_name: str,
145+
topic: str,
146+
dapr_address: Optional[str],
147+
data_type: Optional[DataType] = None,
148+
**kwargs):
149+
self.pub_sub_name = pub_sub_name
150+
self.topic = topic
151+
self.dapr_address = dapr_address
152+
super().__init__(name=name, data_type=data_type)
153+
154+
155+
class DaprBindingOutput(OutputBinding):
156+
@staticmethod
157+
def get_binding_name() -> str:
158+
return DAPR_BINDING
159+
160+
def __init__(self,
161+
name: str,
162+
binding_name: str,
163+
operation: str,
164+
dapr_address: Optional[str],
165+
data_type: Optional[DataType] = None,
166+
**kwargs):
167+
self.binding_name = binding_name
168+
self.operation = operation
169+
self.dapr_address = dapr_address
170+
super().__init__(name=name, data_type=data_type)

0 commit comments

Comments
 (0)