|
13 | 13 | if TYPE_CHECKING: |
14 | 14 | from azure.core.credentials import TokenCredential |
15 | 15 |
|
| 16 | + |
16 | 17 | def get_authentication_policy( |
17 | | - credential, # type: TokenCredential |
| 18 | + credential, # type: TokenCredential |
18 | 19 | ): |
19 | 20 | # type: (...) -> BearerTokenCredentialPolicy |
20 | | - """Returns the correct authentication policy |
21 | | - """ |
| 21 | + """Returns the correct authentication policy""" |
22 | 22 |
|
23 | 23 | if credential is None: |
24 | 24 | raise ValueError("Parameter 'credential' must not be None.") |
25 | 25 | if hasattr(credential, "get_token"): |
26 | | - return BearerTokenCredentialPolicy(credential, "https://api.loganalytics.io/.default") |
| 26 | + return BearerTokenCredentialPolicy( |
| 27 | + credential, "https://api.loganalytics.io/.default" |
| 28 | + ) |
27 | 29 |
|
28 | 30 | raise TypeError("Unsupported credential") |
29 | 31 |
|
| 32 | + |
30 | 33 | def get_metrics_authentication_policy( |
31 | | - credential, # type: TokenCredential |
| 34 | + credential, # type: TokenCredential |
32 | 35 | ): |
33 | 36 | # type: (...) -> BearerTokenCredentialPolicy |
34 | | - """Returns the correct authentication policy |
35 | | - """ |
| 37 | + """Returns the correct authentication policy""" |
36 | 38 |
|
37 | 39 | if credential is None: |
38 | 40 | raise ValueError("Parameter 'credential' must not be None.") |
39 | 41 | if hasattr(credential, "get_token"): |
40 | | - return BearerTokenCredentialPolicy(credential, "https://management.azure.com/.default") |
| 42 | + return BearerTokenCredentialPolicy( |
| 43 | + credential, "https://management.azure.com/.default" |
| 44 | + ) |
41 | 45 |
|
42 | 46 | raise TypeError("Unsupported credential") |
43 | 47 |
|
44 | | -def order_results(request_order, mapping, obj, err, allow_partial_errors=False): |
| 48 | + |
| 49 | +def order_results(request_order, mapping, **kwargs): |
45 | 50 | ordered = [mapping[id] for id in request_order] |
46 | 51 | results = [] |
47 | 52 | for item in ordered: |
48 | 53 | if not item.body.error: |
49 | | - results.append(obj._from_generated(item.body)) # pylint: disable=protected-access |
| 54 | + results.append( |
| 55 | + kwargs.get("obj")._from_generated(item.body) # pylint: disable=protected-access |
| 56 | + ) |
50 | 57 | else: |
51 | 58 | error = item.body.error |
52 | | - if allow_partial_errors and error.code == 'PartialError': |
53 | | - res = obj._from_generated(item.body) # pylint: disable=protected-access |
54 | | - res.partial_error = err._from_generated(error) # pylint: disable=protected-access |
| 59 | + if error.code == "PartialError": |
| 60 | + res = kwargs.get("partial_err")._from_generated( # pylint: disable=protected-access |
| 61 | + item.body, kwargs.get("raise_with") |
| 62 | + ) |
55 | 63 | results.append(res) |
56 | 64 | else: |
57 | | - results.append(err._from_generated(error)) # pylint: disable=protected-access |
| 65 | + results.append( |
| 66 | + kwargs.get("err")._from_generated(error) # pylint: disable=protected-access |
| 67 | + ) |
58 | 68 | return results |
59 | 69 |
|
| 70 | + |
60 | 71 | def construct_iso8601(timespan=None): |
61 | 72 | if not timespan: |
62 | 73 | return None |
63 | 74 | try: |
64 | 75 | start, end, duration = None, None, None |
65 | | - if isinstance(timespan[1], datetime): # we treat thi as start_time, end_time |
| 76 | + if isinstance(timespan[1], datetime): # we treat thi as start_time, end_time |
66 | 77 | start, end = timespan[0], timespan[1] |
67 | | - elif isinstance(timespan[1], timedelta): # we treat this as start_time, duration |
| 78 | + elif isinstance( |
| 79 | + timespan[1], timedelta |
| 80 | + ): # we treat this as start_time, duration |
68 | 81 | start, duration = timespan[0], timespan[1] |
69 | 82 | else: |
70 | | - raise ValueError('Tuple must be a start datetime with a timedelta or an end datetime.') |
| 83 | + raise ValueError( |
| 84 | + "Tuple must be a start datetime with a timedelta or an end datetime." |
| 85 | + ) |
71 | 86 | except TypeError: |
72 | | - duration = timespan # it means only duration (timedelta) is provideds |
| 87 | + duration = timespan # it means only duration (timedelta) is provideds |
73 | 88 | if duration: |
74 | 89 | try: |
75 | | - duration = 'PT{}S'.format(duration.total_seconds()) |
| 90 | + duration = "PT{}S".format(duration.total_seconds()) |
76 | 91 | except AttributeError: |
77 | | - raise ValueError('timespan must be a timedelta or a tuple.') |
| 92 | + raise ValueError("timespan must be a timedelta or a tuple.") |
78 | 93 | iso_str = None |
79 | 94 | if start is not None: |
80 | 95 | start = Serializer.serialize_iso(start) |
81 | 96 | if end is not None: |
82 | 97 | end = Serializer.serialize_iso(end) |
83 | | - iso_str = start + '/' + end |
| 98 | + iso_str = start + "/" + end |
84 | 99 | elif duration is not None: |
85 | | - iso_str = start + '/' + duration |
86 | | - else: # means that an invalid value None that is provided with start_time |
87 | | - raise ValueError("Duration or end_time cannot be None when provided with start_time.") |
| 100 | + iso_str = start + "/" + duration |
| 101 | + else: # means that an invalid value None that is provided with start_time |
| 102 | + raise ValueError( |
| 103 | + "Duration or end_time cannot be None when provided with start_time." |
| 104 | + ) |
88 | 105 | else: |
89 | 106 | iso_str = duration |
90 | 107 | return iso_str |
91 | 108 |
|
| 109 | + |
92 | 110 | def native_col_type(col_type, value): |
93 | | - if col_type == 'datetime': |
| 111 | + if col_type == "datetime": |
94 | 112 | value = Deserializer.deserialize_iso(value) |
95 | | - elif col_type in ('timespan', 'guid'): |
| 113 | + elif col_type in ("timespan", "guid"): |
96 | 114 | value = str(value) |
97 | 115 | return value |
98 | 116 |
|
| 117 | + |
99 | 118 | def process_row(col_types, row): |
100 | 119 | return [native_col_type(col_types[ind], val) for ind, val in enumerate(row)] |
101 | 120 |
|
| 121 | + |
102 | 122 | def process_error(error, model): |
103 | 123 | try: |
104 | | - model = model._from_generated(error.model.error) # pylint: disable=protected-access |
105 | | - except AttributeError: # model can be none |
| 124 | + model = model._from_generated( # pylint: disable=protected-access |
| 125 | + error.model.error |
| 126 | + ) |
| 127 | + except AttributeError: # model can be none |
106 | 128 | pass |
107 | | - raise HttpResponseError( |
108 | | - message=error.message, |
109 | | - response=error.response, |
110 | | - model=model) |
| 129 | + raise HttpResponseError(message=error.message, response=error.response, model=model) |
| 130 | + |
111 | 131 |
|
112 | 132 | def process_prefer(server_timeout, include_statistics, include_visualization): |
113 | 133 | prefer = "" |
|
0 commit comments