stackit-sqlserverflex 0.0.1a0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. stackit/sqlserverflex/__init__.py +107 -0
  2. stackit/sqlserverflex/api/__init__.py +4 -0
  3. stackit/sqlserverflex/api/default_api.py +7045 -0
  4. stackit/sqlserverflex/api_client.py +627 -0
  5. stackit/sqlserverflex/api_response.py +23 -0
  6. stackit/sqlserverflex/configuration.py +112 -0
  7. stackit/sqlserverflex/exceptions.py +199 -0
  8. stackit/sqlserverflex/models/__init__.py +88 -0
  9. stackit/sqlserverflex/models/acl.py +82 -0
  10. stackit/sqlserverflex/models/backup.py +100 -0
  11. stackit/sqlserverflex/models/backup_list_backups_response_grouped.py +99 -0
  12. stackit/sqlserverflex/models/create_database_payload.py +99 -0
  13. stackit/sqlserverflex/models/create_database_response.py +82 -0
  14. stackit/sqlserverflex/models/create_instance_payload.py +141 -0
  15. stackit/sqlserverflex/models/create_instance_response.py +82 -0
  16. stackit/sqlserverflex/models/create_user_payload.py +90 -0
  17. stackit/sqlserverflex/models/create_user_response.py +87 -0
  18. stackit/sqlserverflex/models/database.py +84 -0
  19. stackit/sqlserverflex/models/database_documentation_create_database_request_options.py +92 -0
  20. stackit/sqlserverflex/models/database_options.py +94 -0
  21. stackit/sqlserverflex/models/flavor.py +92 -0
  22. stackit/sqlserverflex/models/get_backup_response.py +100 -0
  23. stackit/sqlserverflex/models/get_database_response.py +89 -0
  24. stackit/sqlserverflex/models/get_instance_response.py +87 -0
  25. stackit/sqlserverflex/models/get_user_response.py +89 -0
  26. stackit/sqlserverflex/models/instance.py +128 -0
  27. stackit/sqlserverflex/models/instance_documentation_acl.py +82 -0
  28. stackit/sqlserverflex/models/instance_documentation_options.py +92 -0
  29. stackit/sqlserverflex/models/instance_documentation_storage.py +90 -0
  30. stackit/sqlserverflex/models/instance_error.py +94 -0
  31. stackit/sqlserverflex/models/instance_flavor_entry.py +94 -0
  32. stackit/sqlserverflex/models/instance_list_instance.py +84 -0
  33. stackit/sqlserverflex/models/instance_list_user.py +83 -0
  34. stackit/sqlserverflex/models/list_backups_response.py +101 -0
  35. stackit/sqlserverflex/models/list_collations_response.py +99 -0
  36. stackit/sqlserverflex/models/list_compatibility_response.py +101 -0
  37. stackit/sqlserverflex/models/list_databases_response.py +99 -0
  38. stackit/sqlserverflex/models/list_flavors_response.py +99 -0
  39. stackit/sqlserverflex/models/list_instances_response.py +101 -0
  40. stackit/sqlserverflex/models/list_restore_jobs_response.py +99 -0
  41. stackit/sqlserverflex/models/list_roles_response.py +82 -0
  42. stackit/sqlserverflex/models/list_storages_response.py +95 -0
  43. stackit/sqlserverflex/models/list_users_response.py +101 -0
  44. stackit/sqlserverflex/models/list_versions_response.py +82 -0
  45. stackit/sqlserverflex/models/mssql_database_collation.py +83 -0
  46. stackit/sqlserverflex/models/mssql_database_compatibility.py +85 -0
  47. stackit/sqlserverflex/models/partial_update_instance_payload.py +110 -0
  48. stackit/sqlserverflex/models/reset_user_response.py +87 -0
  49. stackit/sqlserverflex/models/restore_running_restore.py +100 -0
  50. stackit/sqlserverflex/models/single_database.py +95 -0
  51. stackit/sqlserverflex/models/single_user.py +109 -0
  52. stackit/sqlserverflex/models/storage.py +83 -0
  53. stackit/sqlserverflex/models/storage_range.py +83 -0
  54. stackit/sqlserverflex/models/trigger_database_restore_payload.py +85 -0
  55. stackit/sqlserverflex/models/type.py +41 -0
  56. stackit/sqlserverflex/models/update_instance_payload.py +108 -0
  57. stackit/sqlserverflex/models/update_instance_response.py +87 -0
  58. stackit/sqlserverflex/models/user.py +100 -0
  59. stackit/sqlserverflex/models/user_response_user.py +96 -0
  60. stackit/sqlserverflex/py.typed +0 -0
  61. stackit/sqlserverflex/rest.py +149 -0
  62. stackit_sqlserverflex-0.0.1a0.dist-info/METADATA +45 -0
  63. stackit_sqlserverflex-0.0.1a0.dist-info/RECORD +64 -0
  64. stackit_sqlserverflex-0.0.1a0.dist-info/WHEEL +4 -0
@@ -0,0 +1,85 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT MSSQL Service API
5
+
6
+ This is the documentation for the STACKIT MSSQL service
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@stackit.cloud
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing_extensions import Self
23
+
24
+
25
+ class TriggerDatabaseRestorePayload(BaseModel):
26
+ """
27
+ TriggerDatabaseRestorePayload
28
+ """
29
+
30
+ name: StrictStr = Field(description="Name for the restored database no overwrite allowed at the moment")
31
+ restore_date_time: StrictStr = Field(
32
+ description="Time of the restore point formate RFC3339", alias="restoreDateTime"
33
+ )
34
+ __properties: ClassVar[List[str]] = ["name", "restoreDateTime"]
35
+
36
+ model_config = ConfigDict(
37
+ populate_by_name=True,
38
+ validate_assignment=True,
39
+ protected_namespaces=(),
40
+ )
41
+
42
+ def to_str(self) -> str:
43
+ """Returns the string representation of the model using alias"""
44
+ return pprint.pformat(self.model_dump(by_alias=True))
45
+
46
+ def to_json(self) -> str:
47
+ """Returns the JSON representation of the model using alias"""
48
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
49
+ return json.dumps(self.to_dict())
50
+
51
+ @classmethod
52
+ def from_json(cls, json_str: str) -> Optional[Self]:
53
+ """Create an instance of TriggerDatabaseRestorePayload from a JSON string"""
54
+ return cls.from_dict(json.loads(json_str))
55
+
56
+ def to_dict(self) -> Dict[str, Any]:
57
+ """Return the dictionary representation of the model using alias.
58
+
59
+ This has the following differences from calling pydantic's
60
+ `self.model_dump(by_alias=True)`:
61
+
62
+ * `None` is only added to the output dict for nullable fields that
63
+ were set at model initialization. Other fields with value `None`
64
+ are ignored.
65
+ """
66
+ excluded_fields: Set[str] = set([])
67
+
68
+ _dict = self.model_dump(
69
+ by_alias=True,
70
+ exclude=excluded_fields,
71
+ exclude_none=True,
72
+ )
73
+ return _dict
74
+
75
+ @classmethod
76
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
77
+ """Create an instance of TriggerDatabaseRestorePayload from a dict"""
78
+ if obj is None:
79
+ return None
80
+
81
+ if not isinstance(obj, dict):
82
+ return cls.model_validate(obj)
83
+
84
+ _obj = cls.model_validate({"name": obj.get("name"), "restoreDateTime": obj.get("restoreDateTime")})
85
+ return _obj
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT MSSQL Service API
5
+
6
+ This is the documentation for the STACKIT MSSQL service
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@stackit.cloud
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ from enum import Enum
19
+
20
+ from typing_extensions import Self
21
+
22
+
23
+ class Type(str, Enum):
24
+ """
25
+ Type
26
+ """
27
+
28
+ """
29
+ allowed enum values
30
+ """
31
+ NOTFOUND = "NotFound"
32
+ CREATE = "Create"
33
+ READ = "Read"
34
+ DELETE = "Delete"
35
+ UPDATE = "Update"
36
+ VALIDATION = "Validation"
37
+
38
+ @classmethod
39
+ def from_json(cls, json_str: str) -> Self:
40
+ """Create an instance of Type from a JSON string"""
41
+ return cls(json.loads(json_str))
@@ -0,0 +1,108 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT MSSQL Service API
5
+
6
+ This is the documentation for the STACKIT MSSQL service
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@stackit.cloud
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, Field, StrictStr
22
+ from typing_extensions import Self
23
+
24
+ from stackit.sqlserverflex.models.instance_documentation_acl import (
25
+ InstanceDocumentationACL,
26
+ )
27
+
28
+
29
+ class UpdateInstancePayload(BaseModel):
30
+ """
31
+ UpdateInstancePayload
32
+ """
33
+
34
+ acl: InstanceDocumentationACL = Field(
35
+ description="ACL is the Access Control List defining the IP ranges allowed to connect to the database"
36
+ )
37
+ backup_schedule: StrictStr = Field(
38
+ description="Cronjob for the daily full backup if not provided a job will generated between 00:00 and 04:59",
39
+ alias="backupSchedule",
40
+ )
41
+ flavor_id: StrictStr = Field(description="Id of the selected flavor", alias="flavorId")
42
+ labels: Dict[str, Any] = Field(description="Labels for the instance")
43
+ name: StrictStr = Field(description="Name of the instance")
44
+ version: StrictStr = Field(description="Version of the MSSQL Server")
45
+ __properties: ClassVar[List[str]] = ["acl", "backupSchedule", "flavorId", "labels", "name", "version"]
46
+
47
+ model_config = ConfigDict(
48
+ populate_by_name=True,
49
+ validate_assignment=True,
50
+ protected_namespaces=(),
51
+ )
52
+
53
+ def to_str(self) -> str:
54
+ """Returns the string representation of the model using alias"""
55
+ return pprint.pformat(self.model_dump(by_alias=True))
56
+
57
+ def to_json(self) -> str:
58
+ """Returns the JSON representation of the model using alias"""
59
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
60
+ return json.dumps(self.to_dict())
61
+
62
+ @classmethod
63
+ def from_json(cls, json_str: str) -> Optional[Self]:
64
+ """Create an instance of UpdateInstancePayload from a JSON string"""
65
+ return cls.from_dict(json.loads(json_str))
66
+
67
+ def to_dict(self) -> Dict[str, Any]:
68
+ """Return the dictionary representation of the model using alias.
69
+
70
+ This has the following differences from calling pydantic's
71
+ `self.model_dump(by_alias=True)`:
72
+
73
+ * `None` is only added to the output dict for nullable fields that
74
+ were set at model initialization. Other fields with value `None`
75
+ are ignored.
76
+ """
77
+ excluded_fields: Set[str] = set([])
78
+
79
+ _dict = self.model_dump(
80
+ by_alias=True,
81
+ exclude=excluded_fields,
82
+ exclude_none=True,
83
+ )
84
+ # override the default output from pydantic by calling `to_dict()` of acl
85
+ if self.acl:
86
+ _dict["acl"] = self.acl.to_dict()
87
+ return _dict
88
+
89
+ @classmethod
90
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
91
+ """Create an instance of UpdateInstancePayload from a dict"""
92
+ if obj is None:
93
+ return None
94
+
95
+ if not isinstance(obj, dict):
96
+ return cls.model_validate(obj)
97
+
98
+ _obj = cls.model_validate(
99
+ {
100
+ "acl": InstanceDocumentationACL.from_dict(obj["acl"]) if obj.get("acl") is not None else None,
101
+ "backupSchedule": obj.get("backupSchedule"),
102
+ "flavorId": obj.get("flavorId"),
103
+ "labels": obj.get("labels"),
104
+ "name": obj.get("name"),
105
+ "version": obj.get("version") if obj.get("version") is not None else "2022",
106
+ }
107
+ )
108
+ return _obj
@@ -0,0 +1,87 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT MSSQL Service API
5
+
6
+ This is the documentation for the STACKIT MSSQL service
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@stackit.cloud
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict
22
+ from typing_extensions import Self
23
+
24
+ from stackit.sqlserverflex.models.instance import Instance
25
+
26
+
27
+ class UpdateInstanceResponse(BaseModel):
28
+ """
29
+ UpdateInstanceResponse
30
+ """
31
+
32
+ item: Optional[Instance] = None
33
+ __properties: ClassVar[List[str]] = ["item"]
34
+
35
+ model_config = ConfigDict(
36
+ populate_by_name=True,
37
+ validate_assignment=True,
38
+ protected_namespaces=(),
39
+ )
40
+
41
+ def to_str(self) -> str:
42
+ """Returns the string representation of the model using alias"""
43
+ return pprint.pformat(self.model_dump(by_alias=True))
44
+
45
+ def to_json(self) -> str:
46
+ """Returns the JSON representation of the model using alias"""
47
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
48
+ return json.dumps(self.to_dict())
49
+
50
+ @classmethod
51
+ def from_json(cls, json_str: str) -> Optional[Self]:
52
+ """Create an instance of UpdateInstanceResponse from a JSON string"""
53
+ return cls.from_dict(json.loads(json_str))
54
+
55
+ def to_dict(self) -> Dict[str, Any]:
56
+ """Return the dictionary representation of the model using alias.
57
+
58
+ This has the following differences from calling pydantic's
59
+ `self.model_dump(by_alias=True)`:
60
+
61
+ * `None` is only added to the output dict for nullable fields that
62
+ were set at model initialization. Other fields with value `None`
63
+ are ignored.
64
+ """
65
+ excluded_fields: Set[str] = set([])
66
+
67
+ _dict = self.model_dump(
68
+ by_alias=True,
69
+ exclude=excluded_fields,
70
+ exclude_none=True,
71
+ )
72
+ # override the default output from pydantic by calling `to_dict()` of item
73
+ if self.item:
74
+ _dict["item"] = self.item.to_dict()
75
+ return _dict
76
+
77
+ @classmethod
78
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
79
+ """Create an instance of UpdateInstanceResponse from a dict"""
80
+ if obj is None:
81
+ return None
82
+
83
+ if not isinstance(obj, dict):
84
+ return cls.model_validate(obj)
85
+
86
+ _obj = cls.model_validate({"item": Instance.from_dict(obj["item"]) if obj.get("item") is not None else None})
87
+ return _obj
@@ -0,0 +1,100 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT MSSQL Service API
5
+
6
+ This is the documentation for the STACKIT MSSQL service
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@stackit.cloud
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
22
+ from typing_extensions import Self
23
+
24
+
25
+ class User(BaseModel):
26
+ """
27
+ User
28
+ """
29
+
30
+ database: Optional[StrictStr] = None
31
+ host: Optional[StrictStr] = None
32
+ id: Optional[StrictStr] = None
33
+ password: Optional[StrictStr] = None
34
+ port: Optional[StrictInt] = None
35
+ roles: Optional[List[StrictStr]] = None
36
+ uri: Optional[StrictStr] = None
37
+ username: Optional[StrictStr] = None
38
+ __properties: ClassVar[List[str]] = ["database", "host", "id", "password", "port", "roles", "uri", "username"]
39
+
40
+ model_config = ConfigDict(
41
+ populate_by_name=True,
42
+ validate_assignment=True,
43
+ protected_namespaces=(),
44
+ )
45
+
46
+ def to_str(self) -> str:
47
+ """Returns the string representation of the model using alias"""
48
+ return pprint.pformat(self.model_dump(by_alias=True))
49
+
50
+ def to_json(self) -> str:
51
+ """Returns the JSON representation of the model using alias"""
52
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
53
+ return json.dumps(self.to_dict())
54
+
55
+ @classmethod
56
+ def from_json(cls, json_str: str) -> Optional[Self]:
57
+ """Create an instance of User from a JSON string"""
58
+ return cls.from_dict(json.loads(json_str))
59
+
60
+ def to_dict(self) -> Dict[str, Any]:
61
+ """Return the dictionary representation of the model using alias.
62
+
63
+ This has the following differences from calling pydantic's
64
+ `self.model_dump(by_alias=True)`:
65
+
66
+ * `None` is only added to the output dict for nullable fields that
67
+ were set at model initialization. Other fields with value `None`
68
+ are ignored.
69
+ """
70
+ excluded_fields: Set[str] = set([])
71
+
72
+ _dict = self.model_dump(
73
+ by_alias=True,
74
+ exclude=excluded_fields,
75
+ exclude_none=True,
76
+ )
77
+ return _dict
78
+
79
+ @classmethod
80
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
81
+ """Create an instance of User from a dict"""
82
+ if obj is None:
83
+ return None
84
+
85
+ if not isinstance(obj, dict):
86
+ return cls.model_validate(obj)
87
+
88
+ _obj = cls.model_validate(
89
+ {
90
+ "database": obj.get("database"),
91
+ "host": obj.get("host"),
92
+ "id": obj.get("id"),
93
+ "password": obj.get("password"),
94
+ "port": obj.get("port"),
95
+ "roles": obj.get("roles"),
96
+ "uri": obj.get("uri"),
97
+ "username": obj.get("username"),
98
+ }
99
+ )
100
+ return _obj
@@ -0,0 +1,96 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT MSSQL Service API
5
+
6
+ This is the documentation for the STACKIT MSSQL service
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@stackit.cloud
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ from __future__ import annotations
16
+
17
+ import json
18
+ import pprint
19
+ from typing import Any, ClassVar, Dict, List, Optional, Set
20
+
21
+ from pydantic import BaseModel, ConfigDict, StrictInt, StrictStr
22
+ from typing_extensions import Self
23
+
24
+
25
+ class UserResponseUser(BaseModel):
26
+ """
27
+ UserResponseUser
28
+ """
29
+
30
+ default_database: Optional[StrictStr] = None
31
+ host: Optional[StrictStr] = None
32
+ id: Optional[StrictStr] = None
33
+ port: Optional[StrictInt] = None
34
+ roles: Optional[List[StrictStr]] = None
35
+ username: Optional[StrictStr] = None
36
+ __properties: ClassVar[List[str]] = ["default_database", "host", "id", "port", "roles", "username"]
37
+
38
+ model_config = ConfigDict(
39
+ populate_by_name=True,
40
+ validate_assignment=True,
41
+ protected_namespaces=(),
42
+ )
43
+
44
+ def to_str(self) -> str:
45
+ """Returns the string representation of the model using alias"""
46
+ return pprint.pformat(self.model_dump(by_alias=True))
47
+
48
+ def to_json(self) -> str:
49
+ """Returns the JSON representation of the model using alias"""
50
+ # TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
51
+ return json.dumps(self.to_dict())
52
+
53
+ @classmethod
54
+ def from_json(cls, json_str: str) -> Optional[Self]:
55
+ """Create an instance of UserResponseUser from a JSON string"""
56
+ return cls.from_dict(json.loads(json_str))
57
+
58
+ def to_dict(self) -> Dict[str, Any]:
59
+ """Return the dictionary representation of the model using alias.
60
+
61
+ This has the following differences from calling pydantic's
62
+ `self.model_dump(by_alias=True)`:
63
+
64
+ * `None` is only added to the output dict for nullable fields that
65
+ were set at model initialization. Other fields with value `None`
66
+ are ignored.
67
+ """
68
+ excluded_fields: Set[str] = set([])
69
+
70
+ _dict = self.model_dump(
71
+ by_alias=True,
72
+ exclude=excluded_fields,
73
+ exclude_none=True,
74
+ )
75
+ return _dict
76
+
77
+ @classmethod
78
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
79
+ """Create an instance of UserResponseUser from a dict"""
80
+ if obj is None:
81
+ return None
82
+
83
+ if not isinstance(obj, dict):
84
+ return cls.model_validate(obj)
85
+
86
+ _obj = cls.model_validate(
87
+ {
88
+ "default_database": obj.get("default_database"),
89
+ "host": obj.get("host"),
90
+ "id": obj.get("id"),
91
+ "port": obj.get("port"),
92
+ "roles": obj.get("roles"),
93
+ "username": obj.get("username"),
94
+ }
95
+ )
96
+ return _obj
File without changes
@@ -0,0 +1,149 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ STACKIT MSSQL Service API
5
+
6
+ This is the documentation for the STACKIT MSSQL service
7
+
8
+ The version of the OpenAPI document: 1.0.0
9
+ Contact: support@stackit.cloud
10
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
11
+
12
+ Do not edit the class manually.
13
+ """ # noqa: E501 docstring might be too long
14
+
15
+ import io
16
+ import json
17
+ import re
18
+
19
+ import requests
20
+ from stackit.core.authorization import Authorization
21
+ from stackit.core.configuration import Configuration
22
+
23
+ from stackit.sqlserverflex.exceptions import ApiException, ApiValueError
24
+
25
+
26
+ RESTResponseType = requests.Response
27
+
28
+
29
+ class RESTResponse(io.IOBase):
30
+
31
+ def __init__(self, resp) -> None:
32
+ self.response = resp
33
+ self.status = resp.status_code
34
+ self.reason = resp.reason
35
+ self.data = None
36
+
37
+ def read(self):
38
+ if self.data is None:
39
+ self.data = self.response.content
40
+ return self.data
41
+
42
+ def getheaders(self):
43
+ """Returns a dictionary of the response headers."""
44
+ return self.response.headers
45
+
46
+ def getheader(self, name, default=None):
47
+ """Returns a given response header."""
48
+ return self.response.headers.get(name, default)
49
+
50
+
51
+ class RESTClientObject:
52
+ def __init__(self, config: Configuration) -> None:
53
+ self.session = config.custom_http_session if config.custom_http_session else requests.Session()
54
+ authorization = Authorization(config)
55
+ self.session.auth = authorization.auth_method
56
+
57
+ def request(self, method, url, headers=None, body=None, post_params=None, _request_timeout=None):
58
+ """Perform requests.
59
+
60
+ :param method: http request method
61
+ :param url: http request url
62
+ :param headers: http request headers
63
+ :param body: request json body, for `application/json`
64
+ :param post_params: request post parameters,
65
+ `application/x-www-form-urlencoded`
66
+ and `multipart/form-data`
67
+ :param _request_timeout: timeout setting for this request. If one
68
+ number provided, it will be total request
69
+ timeout. It can also be a pair (tuple) of
70
+ (connection, read) timeouts.
71
+ """
72
+ method = method.upper()
73
+ if method not in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"]:
74
+ raise ValueError("Method %s not allowed", method)
75
+
76
+ if post_params and body:
77
+ raise ApiValueError("body parameter cannot be used with post_params parameter.")
78
+
79
+ post_params = post_params or {}
80
+ headers = headers or {}
81
+
82
+ try:
83
+ # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
84
+ if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
85
+
86
+ # no content type provided or payload is json
87
+ content_type = headers.get("Content-Type")
88
+ if not content_type or re.search("json", content_type, re.IGNORECASE):
89
+ request_body = None
90
+ if body is not None:
91
+ request_body = json.dumps(body)
92
+ r = self.session.request(
93
+ method,
94
+ url,
95
+ data=request_body,
96
+ headers=headers,
97
+ )
98
+ elif content_type == "application/x-www-form-urlencoded":
99
+ r = self.session.request(
100
+ method,
101
+ url,
102
+ params=post_params,
103
+ headers=headers,
104
+ )
105
+ elif content_type == "multipart/form-data":
106
+ # must del headers['Content-Type'], or the correct
107
+ # Content-Type which generated by urllib3 will be
108
+ # overwritten.
109
+ del headers["Content-Type"]
110
+ # Ensures that dict objects are serialized
111
+ post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a, b) for a, b in post_params]
112
+ r = self.session.request(
113
+ method,
114
+ url,
115
+ files=post_params,
116
+ headers=headers,
117
+ )
118
+ # Pass a `string` parameter directly in the body to support
119
+ # other content types than JSON when `body` argument is
120
+ # provided in serialized form.
121
+ elif isinstance(body, str) or isinstance(body, bytes):
122
+ r = self.session.request(
123
+ method,
124
+ url,
125
+ data=body,
126
+ headers=headers,
127
+ )
128
+ elif headers["Content-Type"] == "text/plain" and isinstance(body, bool):
129
+ request_body = "true" if body else "false"
130
+ r = self.session.request(method, url, data=request_body, headers=headers)
131
+ else:
132
+ # Cannot generate the request from given parameters
133
+ msg = """Cannot prepare a request message for provided
134
+ arguments. Please check that your arguments match
135
+ declared content type."""
136
+ raise ApiException(status=0, reason=msg)
137
+ # For `GET`, `HEAD`
138
+ else:
139
+ r = self.session.request(
140
+ method,
141
+ url,
142
+ params={},
143
+ headers=headers,
144
+ )
145
+ except requests.exceptions.SSLError as e:
146
+ msg = "\n".join([type(e).__name__, str(e)])
147
+ raise ApiException(status=0, reason=msg)
148
+
149
+ return RESTResponse(r)