File tree 5 files changed +18
-8
lines changed
authorized_storage_account 5 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 7
7
get_imp_name ,
8
8
)
9
9
from addon_service .common .static_dataclass_model import StaticDataclassModel
10
- from addon_toolkit import AddonOperationImp
10
+ from addon_toolkit import (
11
+ AddonCapabilities ,
12
+ AddonOperationImp ,
13
+ )
11
14
from addon_toolkit .json_arguments import jsonschema_for_signature_params
12
15
from addon_toolkit .operation import AddonOperationType
13
16
14
17
15
18
# dataclass wrapper for addon_toolkit.AddonOperationImp that sufficiently
16
19
# meets rest_framework_json_api expectations on a model class
17
- @dataclasses .dataclass (frozen = True , kw_only = True )
20
+ @dataclasses .dataclass (frozen = True )
18
21
class AddonOperationModel (StaticDataclassModel ):
19
22
operation_imp : AddonOperationImp
20
23
@@ -42,7 +45,7 @@ def implementation_docstring(self) -> str:
42
45
return self .operation_imp .imp_function .__doc__ or ""
43
46
44
47
@cached_property
45
- def capability (self ) -> str :
48
+ def capability (self ) -> AddonCapabilities :
46
49
return self .operation_imp .declaration .capability
47
50
48
51
@cached_property
Original file line number Diff line number Diff line change 1
1
from rest_framework_json_api import serializers
2
2
from rest_framework_json_api .utils import get_resource_type_from_model
3
3
4
- from addon_service .addon_imp .models import AddonImp
5
4
from addon_service .common import view_names
6
5
from addon_service .common .enums .serializers import EnumNameChoiceField
7
6
from addon_service .common .serializer_fields import DataclassRelatedDataField
8
7
from addon_toolkit import AddonCapabilities
8
+ from addon_toolkit .imp import AddonImp
9
9
10
10
from .models import AddonOperationModel
11
11
Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ def authorized_operation_names(self):
121
121
]
122
122
123
123
@property
124
- def auth_url (self ) -> str :
124
+ def auth_url (self ) -> str | None :
125
125
"""Generates the url required to initiate OAuth2 credentials exchange.
126
126
127
127
Returns None if the ExternalStorageService does not support OAuth2
Original file line number Diff line number Diff line change 7
7
Iterator ,
8
8
)
9
9
10
+ from .capabilities import AddonCapabilities
10
11
from .declarator import Declarator
11
12
12
13
@@ -35,7 +36,7 @@ class AddonOperationDeclaration:
35
36
"""
36
37
37
38
operation_type : AddonOperationType
38
- capability : enum . Enum
39
+ capability : AddonCapabilities
39
40
operation_fn : Callable # the decorated function
40
41
return_type : type = dataclasses .field (
41
42
default = type (None ), # if not provided, inferred by __post_init__
@@ -99,7 +100,13 @@ def param_dataclasses(self) -> Iterator[type]:
99
100
@dataclasses .dataclass
100
101
class RedirectResult :
101
102
url : str
102
- method : HTTPMethod = HTTPMethod .GET
103
+ method : str = HTTPMethod .GET
104
+
105
+ def __post_init__ (self ):
106
+ try :
107
+ HTTPMethod (self .method )
108
+ except ValueError :
109
+ raise ValueError (f'invalid http method "{ self .method } "' )
103
110
104
111
105
112
# decorator for operations that may be performed by a client request (e.g. redirect to waterbutler)
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ class _MyCapability(enum.Enum):
25
25
UNUSED = "unused" # for testing when a capability has no operations
26
26
27
27
###
28
- # shared test env (on `self` )
28
+ # shared test env (initialized by setUpClass )
29
29
_MyProtocol : type # typing.Protocol subclass decorated with `@addon_protocol`
30
30
_MyImplementation : type # subclass of _MyProtocol
31
31
_my_imp : AddonImp
You can’t perform that action at this time.
0 commit comments