Skip to content

Commit abecd58

Browse files
authored
Added eventgrid connection property (#229)
1 parent b2f48a5 commit abecd58

File tree

3 files changed

+59
-13
lines changed

3 files changed

+59
-13
lines changed

azure/functions/decorators/eventgrid.py

+15-2
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,23 @@ def get_binding_name() -> str:
2727

2828
def __init__(self,
2929
name: str,
30-
topic_endpoint_uri: str,
31-
topic_key_setting: str,
30+
topic_endpoint_uri: Optional[str] = None,
31+
topic_key_setting: Optional[str] = None,
32+
connection: Optional[str] = None,
3233
data_type: Optional[DataType] = None,
3334
**kwargs):
35+
if (connection is not None and (
36+
topic_endpoint_uri is not None
37+
or topic_key_setting is not None)) or \
38+
(connection is None and (
39+
topic_endpoint_uri is None
40+
or topic_key_setting is None)):
41+
raise ValueError(
42+
"Specify either the 'Connection' property or both "
43+
"'TopicKeySetting' and 'TopicEndpointUri' properties,"
44+
" but not both.")
45+
3446
self.topic_endpoint_uri = topic_endpoint_uri
3547
self.topic_key_setting = topic_key_setting
48+
self.connection = connection
3649
super().__init__(name=name, data_type=data_type)

azure/functions/decorators/function_app.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -2138,8 +2138,9 @@ def decorator():
21382138

21392139
def event_grid_output(self,
21402140
arg_name: str,
2141-
topic_endpoint_uri: str,
2142-
topic_key_setting: str,
2141+
topic_endpoint_uri: Optional[str] = None,
2142+
topic_key_setting: Optional[str] = None,
2143+
connection: Optional[str] = None,
21432144
data_type: Optional[
21442145
Union[DataType, str]] = None,
21452146
**kwargs) -> Callable[..., Any]:
@@ -2164,6 +2165,8 @@ def event_grid_output(self,
21642165
contains the URI for the custom topic.
21652166
:param topic_key_setting: The name of an app setting that
21662167
contains an access key for the custom topic.
2168+
:param connection: The value of the common prefix for the setting that
2169+
contains the topic endpoint URI.
21672170
:return: Decorator function.
21682171
"""
21692172

@@ -2175,6 +2178,7 @@ def decorator():
21752178
name=arg_name,
21762179
topic_endpoint_uri=topic_endpoint_uri,
21772180
topic_key_setting=topic_key_setting,
2181+
connection=connection,
21782182
data_type=parse_singular_param_to_enum(data_type,
21792183
DataType),
21802184
**kwargs))

tests/decorators/test_eventgrid.py

+38-9
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,46 @@ def test_event_grid_output_valid_creation(self):
2727
output = EventGridOutput(name="res",
2828
topic_endpoint_uri="dummy_topic_endpoint_uri",
2929
topic_key_setting="dummy_topic_key_setting",
30-
connection="dummy_connection",
3130
data_type=DataType.UNDEFINED,
3231
dummy_field="dummy")
3332

3433
self.assertEqual(output.get_binding_name(), "eventGrid")
3534
self.assertEqual(output.get_dict_repr(),
36-
{'connection': 'dummy_connection',
37-
'dataType': DataType.UNDEFINED,
38-
'direction': BindingDirection.OUT,
39-
'dummyField': 'dummy',
40-
'topicEndpointUri': 'dummy_topic_endpoint_uri',
41-
'topicKeySetting': 'dummy_topic_key_setting',
42-
'name': 'res',
43-
'type': EVENT_GRID})
35+
{'dataType': DataType.UNDEFINED,
36+
'direction': BindingDirection.OUT,
37+
'dummyField': 'dummy',
38+
'topicEndpointUri': 'dummy_topic_endpoint_uri',
39+
'topicKeySetting': 'dummy_topic_key_setting',
40+
'name': 'res',
41+
'type': EVENT_GRID})
42+
43+
def test_event_grid_output_valid_creation_with_connection(self):
44+
output = EventGridOutput(name="res",
45+
connection="dummy_connection",
46+
data_type=DataType.UNDEFINED,
47+
dummy_field="dummy")
48+
49+
self.assertEqual(output.connection, "dummy_connection")
50+
self.assertIsNone(output.topic_endpoint_uri)
51+
self.assertIsNone(output.topic_key_setting)
52+
53+
def test_event_grid_output_invalid_creation_with_both(self):
54+
with self.assertRaises(ValueError) as context:
55+
EventGridOutput(name="res",
56+
connection="dummy_connection",
57+
topic_endpoint_uri="dummy_topic_endpoint_uri",
58+
topic_key_setting="dummy_topic_key_setting")
59+
60+
self.assertTrue("Specify either the 'Connection' property or both "
61+
"'TopicKeySetting' and 'TopicEndpointUri' properties, "
62+
"but not both." in str(context.exception))
63+
64+
def test_event_grid_output_invalid_creation_with_none(self):
65+
with self.assertRaises(ValueError) as context:
66+
EventGridOutput(name="res",
67+
data_type=DataType.UNDEFINED,
68+
dummy_field="dummy")
69+
70+
self.assertTrue("Specify either the 'Connection' property or both "
71+
"'TopicKeySetting' and 'TopicEndpointUri' properties,"
72+
" but not both." in str(context.exception))

0 commit comments

Comments
 (0)