forked from envoyproxy/envoy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoptions.py
56 lines (39 loc) · 1.57 KB
/
options.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# Manage internal options on messages/enums/fields/enum values.
from udpa.annotations import versioning_pb2
def AddHideOption(options):
"""Mark message/enum/field/enum value as hidden.
Hidden messages are ignored when generating output.
Args:
options: MessageOptions/EnumOptions/FieldOptions/EnumValueOptions message.
"""
hide_option = options.uninterpreted_option.add()
hide_option.name.add().name_part = 'protoxform_hide'
def HasHideOption(options):
"""Is message/enum/field/enum value hidden?
Hidden messages are ignored when generating output.
Args:
options: MessageOptions/EnumOptions/FieldOptions/EnumValueOptions message.
Returns:
Hidden status.
"""
return any(
option.name[0].name_part == 'protoxform_hide' for option in options.uninterpreted_option)
def SetVersioningAnnotation(options, previous_message_type):
"""Set the udpa.annotations.versioning option.
Used by Envoy to chain back through the message type history.
Args:
options: MessageOptions message.
previous_message_type: string with earlier API type name for the message.
"""
options.Extensions[versioning_pb2.versioning].previous_message_type = previous_message_type
def GetVersioningAnnotation(options):
"""Get the udpa.annotations.versioning option.
Used by Envoy to chain back through the message type history.
Args:
options: MessageOptions message.
Returns:
versioning.Annotation if set otherwise None.
"""
if not options.HasExtension(versioning_pb2.versioning):
return None
return options.Extensions[versioning_pb2.versioning]