stackit-cost 0.1.0__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.
- src/stackit/cost/__init__.py +85 -0
- src/stackit/cost/api/__init__.py +4 -0
- src/stackit/cost/api/default_api.py +1285 -0
- src/stackit/cost/api_client.py +652 -0
- src/stackit/cost/api_response.py +23 -0
- src/stackit/cost/configuration.py +163 -0
- src/stackit/cost/exceptions.py +217 -0
- src/stackit/cost/models/__init__.py +30 -0
- src/stackit/cost/models/auth_error_response.py +108 -0
- src/stackit/cost/models/detailed_service_cost.py +143 -0
- src/stackit/cost/models/error_response.py +81 -0
- src/stackit/cost/models/project_cost.py +203 -0
- src/stackit/cost/models/project_cost_with_detailed_services.py +132 -0
- src/stackit/cost/models/project_cost_with_reports.py +133 -0
- src/stackit/cost/models/project_cost_with_summarized_services.py +129 -0
- src/stackit/cost/models/report_data.py +104 -0
- src/stackit/cost/models/report_data_time_period.py +83 -0
- src/stackit/cost/models/summarized_project_cost.py +113 -0
- src/stackit/cost/models/summarized_service_cost.py +113 -0
- src/stackit/cost/py.typed +0 -0
- src/stackit/cost/rest.py +164 -0
- stackit_cost-0.1.0.dist-info/METADATA +46 -0
- stackit_cost-0.1.0.dist-info/RECORD +24 -0
- stackit_cost-0.1.0.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Cost API
|
|
5
|
+
|
|
6
|
+
The cost API provides detailed reports on the costs for a customer or project over a certain amount of time
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import pprint
|
|
18
|
+
from typing import Any, ClassVar, Dict, List, Optional, Set, Union
|
|
19
|
+
|
|
20
|
+
from pydantic import (
|
|
21
|
+
BaseModel,
|
|
22
|
+
ConfigDict,
|
|
23
|
+
Field,
|
|
24
|
+
StrictFloat,
|
|
25
|
+
StrictInt,
|
|
26
|
+
)
|
|
27
|
+
from typing_extensions import Self
|
|
28
|
+
|
|
29
|
+
from stackit.cost.models.report_data_time_period import ReportDataTimePeriod
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class ReportData(BaseModel):
|
|
33
|
+
"""
|
|
34
|
+
Costs report for a certain period of time
|
|
35
|
+
""" # noqa: E501
|
|
36
|
+
|
|
37
|
+
charge: Union[StrictFloat, StrictInt] = Field(description="Charge, value in cents")
|
|
38
|
+
discount: Union[StrictFloat, StrictInt] = Field(description="Discount, value in cents")
|
|
39
|
+
quantity: StrictInt = Field(description="Quantity")
|
|
40
|
+
time_period: ReportDataTimePeriod = Field(alias="timePeriod")
|
|
41
|
+
__properties: ClassVar[List[str]] = ["charge", "discount", "quantity", "timePeriod"]
|
|
42
|
+
|
|
43
|
+
model_config = ConfigDict(
|
|
44
|
+
populate_by_name=True,
|
|
45
|
+
validate_assignment=True,
|
|
46
|
+
protected_namespaces=(),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
def to_str(self) -> str:
|
|
50
|
+
"""Returns the string representation of the model using alias"""
|
|
51
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
52
|
+
|
|
53
|
+
def to_json(self) -> str:
|
|
54
|
+
"""Returns the JSON representation of the model using alias"""
|
|
55
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
56
|
+
return json.dumps(self.to_dict())
|
|
57
|
+
|
|
58
|
+
@classmethod
|
|
59
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
60
|
+
"""Create an instance of ReportData from a JSON string"""
|
|
61
|
+
return cls.from_dict(json.loads(json_str))
|
|
62
|
+
|
|
63
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
64
|
+
"""Return the dictionary representation of the model using alias.
|
|
65
|
+
|
|
66
|
+
This has the following differences from calling pydantic's
|
|
67
|
+
`self.model_dump(by_alias=True)`:
|
|
68
|
+
|
|
69
|
+
* `None` is only added to the output dict for nullable fields that
|
|
70
|
+
were set at model initialization. Other fields with value `None`
|
|
71
|
+
are ignored.
|
|
72
|
+
"""
|
|
73
|
+
excluded_fields: Set[str] = set([])
|
|
74
|
+
|
|
75
|
+
_dict = self.model_dump(
|
|
76
|
+
by_alias=True,
|
|
77
|
+
exclude=excluded_fields,
|
|
78
|
+
exclude_none=True,
|
|
79
|
+
)
|
|
80
|
+
# override the default output from pydantic by calling `to_dict()` of time_period
|
|
81
|
+
if self.time_period:
|
|
82
|
+
_dict["timePeriod"] = self.time_period.to_dict()
|
|
83
|
+
return _dict
|
|
84
|
+
|
|
85
|
+
@classmethod
|
|
86
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
87
|
+
"""Create an instance of ReportData from a dict"""
|
|
88
|
+
if obj is None:
|
|
89
|
+
return None
|
|
90
|
+
|
|
91
|
+
if not isinstance(obj, dict):
|
|
92
|
+
return cls.model_validate(obj)
|
|
93
|
+
|
|
94
|
+
_obj = cls.model_validate(
|
|
95
|
+
{
|
|
96
|
+
"charge": obj.get("charge"),
|
|
97
|
+
"discount": obj.get("discount"),
|
|
98
|
+
"quantity": obj.get("quantity"),
|
|
99
|
+
"timePeriod": (
|
|
100
|
+
ReportDataTimePeriod.from_dict(obj["timePeriod"]) if obj.get("timePeriod") is not None else None
|
|
101
|
+
),
|
|
102
|
+
}
|
|
103
|
+
)
|
|
104
|
+
return _obj
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Cost API
|
|
5
|
+
|
|
6
|
+
The cost API provides detailed reports on the costs for a customer or project over a certain amount of time
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import pprint
|
|
18
|
+
from datetime import date
|
|
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
|
+
|
|
25
|
+
class ReportDataTimePeriod(BaseModel):
|
|
26
|
+
"""
|
|
27
|
+
Time period according to desired granularity
|
|
28
|
+
""" # noqa: E501
|
|
29
|
+
|
|
30
|
+
end: Optional[date] = None
|
|
31
|
+
start: Optional[date] = None
|
|
32
|
+
__properties: ClassVar[List[str]] = ["end", "start"]
|
|
33
|
+
|
|
34
|
+
model_config = ConfigDict(
|
|
35
|
+
populate_by_name=True,
|
|
36
|
+
validate_assignment=True,
|
|
37
|
+
protected_namespaces=(),
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def to_str(self) -> str:
|
|
41
|
+
"""Returns the string representation of the model using alias"""
|
|
42
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
43
|
+
|
|
44
|
+
def to_json(self) -> str:
|
|
45
|
+
"""Returns the JSON representation of the model using alias"""
|
|
46
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
47
|
+
return json.dumps(self.to_dict())
|
|
48
|
+
|
|
49
|
+
@classmethod
|
|
50
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
51
|
+
"""Create an instance of ReportDataTimePeriod from a JSON string"""
|
|
52
|
+
return cls.from_dict(json.loads(json_str))
|
|
53
|
+
|
|
54
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
55
|
+
"""Return the dictionary representation of the model using alias.
|
|
56
|
+
|
|
57
|
+
This has the following differences from calling pydantic's
|
|
58
|
+
`self.model_dump(by_alias=True)`:
|
|
59
|
+
|
|
60
|
+
* `None` is only added to the output dict for nullable fields that
|
|
61
|
+
were set at model initialization. Other fields with value `None`
|
|
62
|
+
are ignored.
|
|
63
|
+
"""
|
|
64
|
+
excluded_fields: Set[str] = set([])
|
|
65
|
+
|
|
66
|
+
_dict = self.model_dump(
|
|
67
|
+
by_alias=True,
|
|
68
|
+
exclude=excluded_fields,
|
|
69
|
+
exclude_none=True,
|
|
70
|
+
)
|
|
71
|
+
return _dict
|
|
72
|
+
|
|
73
|
+
@classmethod
|
|
74
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
75
|
+
"""Create an instance of ReportDataTimePeriod from a dict"""
|
|
76
|
+
if obj is None:
|
|
77
|
+
return None
|
|
78
|
+
|
|
79
|
+
if not isinstance(obj, dict):
|
|
80
|
+
return cls.model_validate(obj)
|
|
81
|
+
|
|
82
|
+
_obj = cls.model_validate({"end": obj.get("end"), "start": obj.get("start")})
|
|
83
|
+
return _obj
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Cost API
|
|
5
|
+
|
|
6
|
+
The cost API provides detailed reports on the costs for a customer or project over a certain amount of time
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import pprint
|
|
18
|
+
from typing import Any, ClassVar, Dict, List, Optional, Set, Union
|
|
19
|
+
from uuid import UUID
|
|
20
|
+
|
|
21
|
+
from pydantic import (
|
|
22
|
+
BaseModel,
|
|
23
|
+
ConfigDict,
|
|
24
|
+
Field,
|
|
25
|
+
StrictFloat,
|
|
26
|
+
StrictInt,
|
|
27
|
+
StrictStr,
|
|
28
|
+
)
|
|
29
|
+
from typing_extensions import Self
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SummarizedProjectCost(BaseModel):
|
|
33
|
+
"""
|
|
34
|
+
Summarized costs for a project
|
|
35
|
+
""" # noqa: E501
|
|
36
|
+
|
|
37
|
+
customer_account_id: UUID = Field(alias="customerAccountId")
|
|
38
|
+
project_id: UUID = Field(alias="projectId")
|
|
39
|
+
project_name: StrictStr = Field(alias="projectName")
|
|
40
|
+
total_charge: Union[StrictFloat, StrictInt] = Field(
|
|
41
|
+
description="Total charge (including discounts) for all services and the whole requested date range (value in cents)",
|
|
42
|
+
alias="totalCharge",
|
|
43
|
+
)
|
|
44
|
+
total_discount: Union[StrictFloat, StrictInt] = Field(
|
|
45
|
+
description="Total discount for all services and the whole requested date range (value in cents)",
|
|
46
|
+
alias="totalDiscount",
|
|
47
|
+
)
|
|
48
|
+
__properties: ClassVar[List[str]] = [
|
|
49
|
+
"customerAccountId",
|
|
50
|
+
"projectId",
|
|
51
|
+
"projectName",
|
|
52
|
+
"totalCharge",
|
|
53
|
+
"totalDiscount",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
model_config = ConfigDict(
|
|
57
|
+
populate_by_name=True,
|
|
58
|
+
validate_assignment=True,
|
|
59
|
+
protected_namespaces=(),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def to_str(self) -> str:
|
|
63
|
+
"""Returns the string representation of the model using alias"""
|
|
64
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
65
|
+
|
|
66
|
+
def to_json(self) -> str:
|
|
67
|
+
"""Returns the JSON representation of the model using alias"""
|
|
68
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
69
|
+
return json.dumps(self.to_dict())
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
73
|
+
"""Create an instance of SummarizedProjectCost from a JSON string"""
|
|
74
|
+
return cls.from_dict(json.loads(json_str))
|
|
75
|
+
|
|
76
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
77
|
+
"""Return the dictionary representation of the model using alias.
|
|
78
|
+
|
|
79
|
+
This has the following differences from calling pydantic's
|
|
80
|
+
`self.model_dump(by_alias=True)`:
|
|
81
|
+
|
|
82
|
+
* `None` is only added to the output dict for nullable fields that
|
|
83
|
+
were set at model initialization. Other fields with value `None`
|
|
84
|
+
are ignored.
|
|
85
|
+
"""
|
|
86
|
+
excluded_fields: Set[str] = set([])
|
|
87
|
+
|
|
88
|
+
_dict = self.model_dump(
|
|
89
|
+
by_alias=True,
|
|
90
|
+
exclude=excluded_fields,
|
|
91
|
+
exclude_none=True,
|
|
92
|
+
)
|
|
93
|
+
return _dict
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
97
|
+
"""Create an instance of SummarizedProjectCost from a dict"""
|
|
98
|
+
if obj is None:
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
if not isinstance(obj, dict):
|
|
102
|
+
return cls.model_validate(obj)
|
|
103
|
+
|
|
104
|
+
_obj = cls.model_validate(
|
|
105
|
+
{
|
|
106
|
+
"customerAccountId": obj.get("customerAccountId"),
|
|
107
|
+
"projectId": obj.get("projectId"),
|
|
108
|
+
"projectName": obj.get("projectName"),
|
|
109
|
+
"totalCharge": obj.get("totalCharge"),
|
|
110
|
+
"totalDiscount": obj.get("totalDiscount"),
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
return _obj
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Cost API
|
|
5
|
+
|
|
6
|
+
The cost API provides detailed reports on the costs for a customer or project over a certain amount of time
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
from __future__ import annotations
|
|
15
|
+
|
|
16
|
+
import json
|
|
17
|
+
import pprint
|
|
18
|
+
from typing import Any, ClassVar, Dict, List, Optional, Set, Union
|
|
19
|
+
from uuid import UUID
|
|
20
|
+
|
|
21
|
+
from pydantic import (
|
|
22
|
+
BaseModel,
|
|
23
|
+
ConfigDict,
|
|
24
|
+
Field,
|
|
25
|
+
StrictFloat,
|
|
26
|
+
StrictInt,
|
|
27
|
+
StrictStr,
|
|
28
|
+
)
|
|
29
|
+
from typing_extensions import Self
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
class SummarizedServiceCost(BaseModel):
|
|
33
|
+
"""
|
|
34
|
+
Summarized costs for a project
|
|
35
|
+
""" # noqa: E501
|
|
36
|
+
|
|
37
|
+
customer_account_id: UUID = Field(alias="customerAccountId")
|
|
38
|
+
project_id: UUID = Field(alias="projectId")
|
|
39
|
+
project_name: StrictStr = Field(alias="projectName")
|
|
40
|
+
total_charge: Union[StrictFloat, StrictInt] = Field(
|
|
41
|
+
description="Total charge (including discounts) for all services and the whole requested date range (value in cents)",
|
|
42
|
+
alias="totalCharge",
|
|
43
|
+
)
|
|
44
|
+
total_discount: Union[StrictFloat, StrictInt] = Field(
|
|
45
|
+
description="Total discount for all services and the whole requested date range (value in cents)",
|
|
46
|
+
alias="totalDiscount",
|
|
47
|
+
)
|
|
48
|
+
__properties: ClassVar[List[str]] = [
|
|
49
|
+
"customerAccountId",
|
|
50
|
+
"projectId",
|
|
51
|
+
"projectName",
|
|
52
|
+
"totalCharge",
|
|
53
|
+
"totalDiscount",
|
|
54
|
+
]
|
|
55
|
+
|
|
56
|
+
model_config = ConfigDict(
|
|
57
|
+
populate_by_name=True,
|
|
58
|
+
validate_assignment=True,
|
|
59
|
+
protected_namespaces=(),
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
def to_str(self) -> str:
|
|
63
|
+
"""Returns the string representation of the model using alias"""
|
|
64
|
+
return pprint.pformat(self.model_dump(by_alias=True))
|
|
65
|
+
|
|
66
|
+
def to_json(self) -> str:
|
|
67
|
+
"""Returns the JSON representation of the model using alias"""
|
|
68
|
+
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
|
|
69
|
+
return json.dumps(self.to_dict())
|
|
70
|
+
|
|
71
|
+
@classmethod
|
|
72
|
+
def from_json(cls, json_str: str) -> Optional[Self]:
|
|
73
|
+
"""Create an instance of SummarizedServiceCost from a JSON string"""
|
|
74
|
+
return cls.from_dict(json.loads(json_str))
|
|
75
|
+
|
|
76
|
+
def to_dict(self) -> Dict[str, Any]:
|
|
77
|
+
"""Return the dictionary representation of the model using alias.
|
|
78
|
+
|
|
79
|
+
This has the following differences from calling pydantic's
|
|
80
|
+
`self.model_dump(by_alias=True)`:
|
|
81
|
+
|
|
82
|
+
* `None` is only added to the output dict for nullable fields that
|
|
83
|
+
were set at model initialization. Other fields with value `None`
|
|
84
|
+
are ignored.
|
|
85
|
+
"""
|
|
86
|
+
excluded_fields: Set[str] = set([])
|
|
87
|
+
|
|
88
|
+
_dict = self.model_dump(
|
|
89
|
+
by_alias=True,
|
|
90
|
+
exclude=excluded_fields,
|
|
91
|
+
exclude_none=True,
|
|
92
|
+
)
|
|
93
|
+
return _dict
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
|
|
97
|
+
"""Create an instance of SummarizedServiceCost from a dict"""
|
|
98
|
+
if obj is None:
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
if not isinstance(obj, dict):
|
|
102
|
+
return cls.model_validate(obj)
|
|
103
|
+
|
|
104
|
+
_obj = cls.model_validate(
|
|
105
|
+
{
|
|
106
|
+
"customerAccountId": obj.get("customerAccountId"),
|
|
107
|
+
"projectId": obj.get("projectId"),
|
|
108
|
+
"projectName": obj.get("projectName"),
|
|
109
|
+
"totalCharge": obj.get("totalCharge"),
|
|
110
|
+
"totalDiscount": obj.get("totalDiscount"),
|
|
111
|
+
}
|
|
112
|
+
)
|
|
113
|
+
return _obj
|
|
File without changes
|
src/stackit/cost/rest.py
ADDED
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
|
|
3
|
+
"""
|
|
4
|
+
STACKIT Cost API
|
|
5
|
+
|
|
6
|
+
The cost API provides detailed reports on the costs for a customer or project over a certain amount of time
|
|
7
|
+
|
|
8
|
+
The version of the OpenAPI document: 3.0
|
|
9
|
+
Generated by OpenAPI Generator (https://openapi-generator.tech)
|
|
10
|
+
|
|
11
|
+
Do not edit the class manually.
|
|
12
|
+
""" # noqa: E501
|
|
13
|
+
|
|
14
|
+
import io
|
|
15
|
+
import json
|
|
16
|
+
import re
|
|
17
|
+
|
|
18
|
+
import requests
|
|
19
|
+
from stackit.core.authorization import Authorization
|
|
20
|
+
from stackit.core.configuration import Configuration
|
|
21
|
+
|
|
22
|
+
from stackit.cost.exceptions import ApiException, ApiValueError
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
RESTResponseType = requests.Response
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
class RESTResponse(io.IOBase):
|
|
29
|
+
|
|
30
|
+
def __init__(self, resp) -> None:
|
|
31
|
+
self.response = resp
|
|
32
|
+
self.status = resp.status_code
|
|
33
|
+
self.reason = resp.reason
|
|
34
|
+
self.data = None
|
|
35
|
+
|
|
36
|
+
def read(self):
|
|
37
|
+
if self.data is None:
|
|
38
|
+
self.data = self.response.content
|
|
39
|
+
return self.data
|
|
40
|
+
|
|
41
|
+
@property
|
|
42
|
+
def headers(self):
|
|
43
|
+
"""Returns a dictionary of response headers."""
|
|
44
|
+
return self.response.headers
|
|
45
|
+
|
|
46
|
+
def getheaders(self):
|
|
47
|
+
"""Returns a dictionary of the response headers; use ``headers`` instead."""
|
|
48
|
+
return self.response.headers
|
|
49
|
+
|
|
50
|
+
def getheader(self, name, default=None):
|
|
51
|
+
"""Returns a given response header; use ``headers.get()`` instead."""
|
|
52
|
+
return self.response.headers.get(name, default)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class RESTClientObject:
|
|
56
|
+
def __init__(self, config: Configuration) -> None:
|
|
57
|
+
self.session = config.custom_http_session if config.custom_http_session else requests.Session()
|
|
58
|
+
authorization = Authorization(config)
|
|
59
|
+
self.session.auth = authorization.auth_method
|
|
60
|
+
|
|
61
|
+
def request(self, method, url, headers=None, body=None, post_params=None, _request_timeout=None):
|
|
62
|
+
"""Perform requests.
|
|
63
|
+
|
|
64
|
+
:param method: http request method
|
|
65
|
+
:param url: http request url
|
|
66
|
+
:param headers: http request headers
|
|
67
|
+
:param body: request json body, for `application/json`
|
|
68
|
+
:param post_params: request post parameters,
|
|
69
|
+
`application/x-www-form-urlencoded`
|
|
70
|
+
and `multipart/form-data`
|
|
71
|
+
:param _request_timeout: timeout setting for this request. If one
|
|
72
|
+
number provided, it will be total request
|
|
73
|
+
timeout. It can also be a pair (tuple) of
|
|
74
|
+
(connection, read) timeouts.
|
|
75
|
+
"""
|
|
76
|
+
method = method.upper()
|
|
77
|
+
if method not in ["GET", "HEAD", "DELETE", "POST", "PUT", "PATCH", "OPTIONS"]:
|
|
78
|
+
raise ValueError("Method %s not allowed", method)
|
|
79
|
+
|
|
80
|
+
if post_params and body:
|
|
81
|
+
raise ApiValueError("body parameter cannot be used with post_params parameter.")
|
|
82
|
+
|
|
83
|
+
post_params = post_params or {}
|
|
84
|
+
headers = headers or {}
|
|
85
|
+
|
|
86
|
+
try:
|
|
87
|
+
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
|
|
88
|
+
if method in ["POST", "PUT", "PATCH", "OPTIONS", "DELETE"]:
|
|
89
|
+
|
|
90
|
+
# no content type provided or payload is json
|
|
91
|
+
content_type = headers.get("Content-Type")
|
|
92
|
+
if not content_type or re.search("json", content_type, re.IGNORECASE):
|
|
93
|
+
request_body = None
|
|
94
|
+
if body is not None:
|
|
95
|
+
request_body = json.dumps(body)
|
|
96
|
+
r = self.session.request(
|
|
97
|
+
method,
|
|
98
|
+
url,
|
|
99
|
+
data=request_body,
|
|
100
|
+
headers=headers,
|
|
101
|
+
timeout=_request_timeout,
|
|
102
|
+
)
|
|
103
|
+
elif content_type == "application/x-www-form-urlencoded":
|
|
104
|
+
r = self.session.request(
|
|
105
|
+
method,
|
|
106
|
+
url,
|
|
107
|
+
params=post_params,
|
|
108
|
+
headers=headers,
|
|
109
|
+
timeout=_request_timeout,
|
|
110
|
+
)
|
|
111
|
+
elif content_type == "multipart/form-data":
|
|
112
|
+
# must del headers['Content-Type'], or the correct
|
|
113
|
+
# Content-Type which generated by urllib3 will be
|
|
114
|
+
# overwritten.
|
|
115
|
+
del headers["Content-Type"]
|
|
116
|
+
# Ensures that dict objects are serialized
|
|
117
|
+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a, b) for a, b in post_params]
|
|
118
|
+
r = self.session.request(
|
|
119
|
+
method,
|
|
120
|
+
url,
|
|
121
|
+
files=post_params,
|
|
122
|
+
headers=headers,
|
|
123
|
+
timeout=_request_timeout,
|
|
124
|
+
)
|
|
125
|
+
# Pass a `string` parameter directly in the body to support
|
|
126
|
+
# other content types than JSON when `body` argument is
|
|
127
|
+
# provided in serialized form.
|
|
128
|
+
elif isinstance(body, str) or isinstance(body, bytes):
|
|
129
|
+
r = self.session.request(
|
|
130
|
+
method,
|
|
131
|
+
url,
|
|
132
|
+
data=body,
|
|
133
|
+
headers=headers,
|
|
134
|
+
timeout=_request_timeout,
|
|
135
|
+
)
|
|
136
|
+
elif headers["Content-Type"].startswith("text/") and isinstance(body, bool):
|
|
137
|
+
request_body = "true" if body else "false"
|
|
138
|
+
r = self.session.request(
|
|
139
|
+
method,
|
|
140
|
+
url,
|
|
141
|
+
data=request_body,
|
|
142
|
+
headers=headers,
|
|
143
|
+
timeout=_request_timeout,
|
|
144
|
+
)
|
|
145
|
+
else:
|
|
146
|
+
# Cannot generate the request from given parameters
|
|
147
|
+
msg = """Cannot prepare a request message for provided
|
|
148
|
+
arguments. Please check that your arguments match
|
|
149
|
+
declared content type."""
|
|
150
|
+
raise ApiException(status=0, reason=msg)
|
|
151
|
+
# For `GET`, `HEAD`
|
|
152
|
+
else:
|
|
153
|
+
r = self.session.request(
|
|
154
|
+
method,
|
|
155
|
+
url,
|
|
156
|
+
params={},
|
|
157
|
+
headers=headers,
|
|
158
|
+
timeout=_request_timeout,
|
|
159
|
+
)
|
|
160
|
+
except requests.exceptions.SSLError as e:
|
|
161
|
+
msg = "\n".join([type(e).__name__, str(e)])
|
|
162
|
+
raise ApiException(status=0, reason=msg)
|
|
163
|
+
|
|
164
|
+
return RESTResponse(r)
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: stackit-cost
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: STACKIT Cost API
|
|
5
|
+
Project-URL: Homepage, https://github.com/stackitcloud/stackit-sdk-python
|
|
6
|
+
Project-URL: Issues, https://github.com/stackitcloud/stackit-sdk-python/issues
|
|
7
|
+
Author-email: STACKIT Developer Tools <developer-tools@stackit.cloud>
|
|
8
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
9
|
+
Classifier: Operating System :: OS Independent
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Requires-Python: <4.0,>=3.9
|
|
18
|
+
Requires-Dist: pydantic>=2.9.2
|
|
19
|
+
Requires-Dist: python-dateutil>=2.9.0.post0
|
|
20
|
+
Requires-Dist: requests>=2.32.3
|
|
21
|
+
Requires-Dist: stackit-core>=0.0.1a
|
|
22
|
+
Description-Content-Type: text/markdown
|
|
23
|
+
|
|
24
|
+
# stackit.cost
|
|
25
|
+
The cost API provides detailed reports on the costs for a customer or project over a certain amount of time
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
This package is part of the STACKIT Python SDK. For additional information, please visit the [GitHub repository](https://github.com/stackitcloud/stackit-sdk-python) of the SDK.
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
## Installation & Usage
|
|
33
|
+
### pip install
|
|
34
|
+
|
|
35
|
+
```sh
|
|
36
|
+
pip install stackit-cost
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Then import the package:
|
|
40
|
+
```python
|
|
41
|
+
import stackit.cost
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Getting Started
|
|
45
|
+
|
|
46
|
+
[Examples](https://github.com/stackitcloud/stackit-sdk-python/tree/main/examples) for the usage of the package can be found in the [GitHub repository](https://github.com/stackitcloud/stackit-sdk-python) of the SDK.
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
src/stackit/cost/__init__.py,sha256=DK-gM_pIJrTmK99mZIUzYaTkWnb_wmKKByT861VbpfQ,2850
|
|
2
|
+
src/stackit/cost/api_client.py,sha256=66PhJ28bo883S8vTGmkhQBeTjkPQHEHQxz9kNGw113k,23874
|
|
3
|
+
src/stackit/cost/api_response.py,sha256=HRYkVqMNIlfODacTQPTbiVj2YdcnutpQrKJdeAoCSpM,642
|
|
4
|
+
src/stackit/cost/configuration.py,sha256=DoRSwqsd0PVykPPx_cfZ6tnm0ritVNuw4FQItm4Lfc0,5695
|
|
5
|
+
src/stackit/cost/exceptions.py,sha256=WnMgOMOmsNM_uiKulEwcxQ2LMqXMCQ5iakLvBN8rklU,6426
|
|
6
|
+
src/stackit/cost/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
|
+
src/stackit/cost/rest.py,sha256=iw_nR3SFaDgVhURPSH3kWmOKhwB9mbH1PRhEDXRW_es,6413
|
|
8
|
+
src/stackit/cost/api/__init__.py,sha256=U-N7aodHMDHitoR_l15qjMQqfjwwNbl_DpmFcxN3oBw,99
|
|
9
|
+
src/stackit/cost/api/default_api.py,sha256=ZvqWYBGAe-puyHu94FfhAY50c3m7e2qWk2KGRn9ye28,65621
|
|
10
|
+
src/stackit/cost/models/__init__.py,sha256=lZtLrMSAsEAVZ7UDarbOh5mE3B_OuSy-MYiNmsI7ym4,1229
|
|
11
|
+
src/stackit/cost/models/auth_error_response.py,sha256=48IQVVLs7aOAR-2bLy-4KJQivpC3uxsjAsJF1nNSEOs,3599
|
|
12
|
+
src/stackit/cost/models/detailed_service_cost.py,sha256=FISqR8dENrUqoFWmhH0yyo6n5U3k3xWRZIasBTfrEAE,5012
|
|
13
|
+
src/stackit/cost/models/error_response.py,sha256=030DPLtt1qrWTkwP9Gf5v6-TSVEaOfhf4Ot009rM3cQ,2400
|
|
14
|
+
src/stackit/cost/models/project_cost.py,sha256=cdRPazSfeCVsSFyqNo0MDUABTmJI8NXeYPDTHQq2xpE,7408
|
|
15
|
+
src/stackit/cost/models/project_cost_with_detailed_services.py,sha256=jlTmtqLcR7JglKY3bAZySMJW1XzF86ojE0TldnxiLSQ,4472
|
|
16
|
+
src/stackit/cost/models/project_cost_with_reports.py,sha256=6AOn-YhqNREd5IcXZsyqwAREz10FKtTwgPk1mhgOnq8,4408
|
|
17
|
+
src/stackit/cost/models/project_cost_with_summarized_services.py,sha256=Y11rYm4O5XbAkzS13vIEQ1gEyEnNoARdG40OuiVbJlo,4358
|
|
18
|
+
src/stackit/cost/models/report_data.py,sha256=WQrnXoHR5lS6TL-2_yWIpZk6XnGzySdM5o2El5jj2qw,3378
|
|
19
|
+
src/stackit/cost/models/report_data_time_period.py,sha256=__kVt06jw-3dNP-uE7t3lrHAu1ZJEN5nchAQwTpqG6c,2548
|
|
20
|
+
src/stackit/cost/models/summarized_project_cost.py,sha256=XN33OJqejjOFGmWQs3nQbWm1F8mM5fNK_RkNZM5jI8Y,3525
|
|
21
|
+
src/stackit/cost/models/summarized_service_cost.py,sha256=AI002T2yRWdQx86rhCCKS1RcIJzEldDK4XhwMmAN3k8,3525
|
|
22
|
+
stackit_cost-0.1.0.dist-info/METADATA,sha256=aE-csz-qwfGCN3kWZY2Ekb9lJBHHHh4zcjDqQHIC1qk,1656
|
|
23
|
+
stackit_cost-0.1.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
24
|
+
stackit_cost-0.1.0.dist-info/RECORD,,
|