| 1 |
import json |
| 2 |
from typing import Any |
| 3 |
|
| 4 |
from ._string_utils import assert_string_is_not_empty |
| 5 |
|
| 6 |
|
| 7 |
class ClientRequestProperties: |
| 8 |
"""This class is a POD used by client making requests to describe specific needs from the service executing the requests. |
| 9 |
For more information please look at: https://docs.microsoft.com/en-us/azure/kusto/api/netfx/request-properties |
| 10 |
""" |
| 11 |
|
| 12 |
client_request_id: str |
| 13 |
application: str |
| 14 |
user: str |
| 15 |
_CLIENT_REQUEST_ID = "client_request_id" |
| 16 |
|
| 17 |
results_defer_partial_query_failures_option_name = "deferpartialqueryfailures" |
| 18 |
request_timeout_option_name = "servertimeout" |
| 19 |
no_request_timeout_option_name = "norequesttimeout" |
| 20 |
|
| 21 |
def __init__(self): |
| 22 |
self._options = {} |
| 23 |
self._parameters = {} |
| 24 |
self.client_request_id = None |
| 25 |
self.application = None |
| 26 |
self.user = None |
| 27 |
|
| 28 |
def set_parameter(self, name: str, value: str): |
| 29 |
"""Sets a parameter's value""" |
| 30 |
assert_string_is_not_empty(name) |
| 31 |
self._parameters[name] = value |
| 32 |
|
| 33 |
def has_parameter(self, name: str) -> bool: |
| 34 |
"""Checks if a parameter is specified.""" |
| 35 |
return name in self._parameters |
| 36 |
|
| 37 |
def get_parameter(self, name: str, default_value: str) -> str: |
| 38 |
"""Gets a parameter's value.""" |
| 39 |
return self._parameters.get(name, default_value) |
| 40 |
|
| 41 |
def set_option(self, name: str, value: Any): |
| 42 |
"""Sets an option's value""" |
| 43 |
assert_string_is_not_empty(name) |
| 44 |
self._options[name] = value |
| 45 |
|
| 46 |
def has_option(self, name: str) -> bool: |
| 47 |
"""Checks if an option is specified.""" |
| 48 |
return name in self._options |
| 49 |
|
| 50 |
def get_option(self, name: str, default_value: Any) -> str: |
| 51 |
"""Gets an option's value.""" |
| 52 |
return self._options.get(name, default_value) |
| 53 |
|
| 54 |
def to_json(self) -> str: |
| 55 |
"""Safe serialization to a JSON string.""" |
| 56 |
return json.dumps({"Options": self._options, "Parameters": self._parameters}, default=str) |
| 57 |
|
| 58 |
def get_tracing_attributes(self) -> dict: |
| 59 |
"""Gets dictionary of attributes to be documented during tracing""" |
| 60 |
return {self._CLIENT_REQUEST_ID: str(self.client_request_id)} |