Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
from .types import EnableCustomAlertRulesRequest
from .types import EnableCustomAlertRulesResponse
from .types import EventsOverview
from .types import GetCustomAlertRuleRequest
from .types import GetLastEventsOverviewRequest
from .types import ListAlertRulesRequest
from .types import ListAlertRulesResponse
Expand Down Expand Up @@ -259,6 +260,7 @@
"EnableCustomAlertRulesRequest",
"EnableCustomAlertRulesResponse",
"EventsOverview",
"GetCustomAlertRuleRequest",
"GetLastEventsOverviewRequest",
"ListAlertRulesRequest",
"ListAlertRulesResponse",
Expand Down
84 changes: 83 additions & 1 deletion scaleway-async/scaleway_async/audit_trail/v1alpha1/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
# If you have any remark or suggestion do not hesitate to open an issue.

from datetime import datetime
from typing import Optional
from typing import Awaitable, Optional, Union

from scaleway_core.api import API
from scaleway_core.bridge import (
Region as ScwRegion,
)
from scaleway_core.utils import (
WaitForOptions,
validate_path_param,
fetch_all_pages_async,
wait_for_resource_async,
)
from .types import (
AlertRuleStatus,
Expand Down Expand Up @@ -54,6 +56,9 @@
TestCustomAlertRuleResponse,
UpdateCustomAlertRuleRequest,
)
from .content import (
CUSTOM_ALERT_RULE_TRANSIENT_STATUSES,
)
from .marshalling import (
unmarshal_CustomAlertRule,
unmarshal_ExportJob,
Expand Down Expand Up @@ -725,6 +730,83 @@ async def list_custom_alert_rules_all(
},
)

async def get_custom_alert_rule(
self,
*,
custom_alert_rule_id: str,
region: Optional[ScwRegion] = None,
) -> CustomAlertRule:
"""
Get custom alert rule metadata.
Retrieve metadata for a specified custom alert rule using the `region` and `custom_alert_rule_id` parameters.
:param custom_alert_rule_id: ID of the custom alert rule to retrieve.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`CustomAlertRule <CustomAlertRule>`

Usage:
::

result = await api.get_custom_alert_rule(
custom_alert_rule_id="example",
)
"""

param_region = validate_path_param(
"region", region or self.client.default_region
)
param_custom_alert_rule_id = validate_path_param(
"custom_alert_rule_id", custom_alert_rule_id
)

res = self._request(
"GET",
f"/audit-trail/v1alpha1/regions/{param_region}/custom-alert-rules/{param_custom_alert_rule_id}",
)

self._throw_on_error(res)
return unmarshal_CustomAlertRule(res.json())

async def wait_for_custom_alert_rule(
self,
*,
custom_alert_rule_id: str,
region: Optional[ScwRegion] = None,
options: Optional[
WaitForOptions[CustomAlertRule, Union[bool, Awaitable[bool]]]
] = None,
) -> CustomAlertRule:
"""
Get custom alert rule metadata.
Retrieve metadata for a specified custom alert rule using the `region` and `custom_alert_rule_id` parameters.
:param custom_alert_rule_id: ID of the custom alert rule to retrieve.
:param region: Region to target. If none is passed will use default region from the config.
:return: :class:`CustomAlertRule <CustomAlertRule>`

Usage:
::

result = await api.get_custom_alert_rule(
custom_alert_rule_id="example",
)
"""

if not options:
options = WaitForOptions()

if not options.stop:
options.stop = lambda res: (
res.status not in CUSTOM_ALERT_RULE_TRANSIENT_STATUSES
)

return await wait_for_resource_async(
fetcher=self.get_custom_alert_rule,
options=options,
args={
"custom_alert_rule_id": custom_alert_rule_id,
"region": region,
},
)

async def enable_alert_rules(
self,
*,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,12 @@ def unmarshal_AlertRule(data: Any) -> AlertRule:
else:
args["id"] = None

field = data.get("srn", None)
if field is not None:
args["srn"] = field
else:
args["srn"] = None

field = data.get("name", None)
if field is not None:
args["name"] = field
Expand All @@ -377,6 +383,12 @@ def unmarshal_AlertRule(data: Any) -> AlertRule:
else:
args["status"] = AlertRuleStatus.UNKNOWN_STATUS

field = data.get("region", None)
if field is not None:
args["region"] = field
else:
args["region"] = None

return AlertRule(**args)


Expand Down
23 changes: 23 additions & 0 deletions scaleway-async/scaleway_async/audit_trail/v1alpha1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1098,6 +1098,11 @@ class AlertRule:
ID of the alert rule.
"""

srn: str
"""
The SRN of the alert rule.
"""

name: str
"""
Name of the alert rule.
Expand All @@ -1113,6 +1118,11 @@ class AlertRule:
Current status of the alert rule.
"""

region: ScwRegion
"""
Region of the alert rule.
"""


@dataclass
class CustomAlertRule:
Expand Down Expand Up @@ -1476,6 +1486,19 @@ class EventsOverview:
last_events: list[Event]


@dataclass
class GetCustomAlertRuleRequest:
custom_alert_rule_id: str
"""
ID of the custom alert rule to retrieve.
"""

region: Optional[ScwRegion] = None
"""
Region to target. If none is passed will use default region from the config.
"""


@dataclass
class GetLastEventsOverviewRequest:
region: Optional[ScwRegion] = None
Expand Down
54 changes: 45 additions & 9 deletions scaleway-async/scaleway_async/cockpit/v1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,18 @@ def unmarshal_DataSource(data: Any) -> DataSource:
else:
args["synchronized_with_grafana"] = False

field = data.get("created_at", None)
if field is not None:
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["created_at"] = None

field = data.get("updated_at", None)
if field is not None:
args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["updated_at"] = None

field = data.get("retention_days", None)
if field is not None:
args["retention_days"] = field
Expand All @@ -181,17 +193,11 @@ def unmarshal_DataSource(data: Any) -> DataSource:
else:
args["region"] = None

field = data.get("created_at", None)
if field is not None:
args["created_at"] = parser.isoparse(field) if isinstance(field, str) else field
else:
args["created_at"] = None

field = data.get("updated_at", None)
field = data.get("srn", None)
if field is not None:
args["updated_at"] = parser.isoparse(field) if isinstance(field, str) else field
args["srn"] = field
else:
args["updated_at"] = None
args["srn"] = None

field = data.get("current_month_usage", None)
if field is not None:
Expand Down Expand Up @@ -298,6 +304,12 @@ def unmarshal_Exporter(data: Any) -> Exporter:
else:
args["region"] = None

field = data.get("srn", None)
if field is not None:
args["srn"] = field
else:
args["srn"] = None

field = data.get("datadog_destination", None)
if field is not None:
args["datadog_destination"] = unmarshal_ExporterDatadogDestination(field)
Expand Down Expand Up @@ -527,6 +539,12 @@ def unmarshal_AlertManager(data: Any) -> AlertManager:

args: dict[str, Any] = {}

field = data.get("project_id", None)
if field is not None:
args["project_id"] = field
else:
args["project_id"] = None

field = data.get("alert_manager_enabled", None)
if field is not None:
args["alert_manager_enabled"] = field
Expand All @@ -545,6 +563,12 @@ def unmarshal_AlertManager(data: Any) -> AlertManager:
else:
args["region"] = None

field = data.get("srn", None)
if field is not None:
args["srn"] = field
else:
args["srn"] = None

field = data.get("alert_manager_url", None)
if field is not None:
args["alert_manager_url"] = field
Expand Down Expand Up @@ -732,6 +756,18 @@ def unmarshal_Grafana(data: Any) -> Grafana:
else:
args["grafana_url"] = None

field = data.get("project_id", None)
if field is not None:
args["project_id"] = field
else:
args["project_id"] = None

field = data.get("srn", None)
if field is not None:
args["srn"] = field
else:
args["srn"] = None

return Grafana(**args)


Expand Down
30 changes: 30 additions & 0 deletions scaleway-async/scaleway_async/cockpit/v1/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ class DataSource:
Region of the data source.
"""

srn: str
"""
The SRN of the data-source.
"""

created_at: Optional[datetime] = None
"""
Date the data source was created.
Expand Down Expand Up @@ -429,6 +434,11 @@ class Exporter:
The region in which the export is located.
"""

srn: str
"""
The SRN of the exporter.
"""

created_at: Optional[datetime] = None
"""
A timestamp of the creation date of the data export.
Expand Down Expand Up @@ -658,6 +668,11 @@ class AlertManager:
Alert manager information.
"""

project_id: str
"""
ID of the project.
"""

alert_manager_enabled: bool
"""
The Alert manager is enabled.
Expand All @@ -673,6 +688,11 @@ class AlertManager:
Regions where the Alert manager is enabled.
"""

srn: str
"""
The SRN of the alert-manager.
"""

alert_manager_url: Optional[str] = None
"""
Alert manager URL.
Expand Down Expand Up @@ -965,6 +985,16 @@ class Grafana:
URL to access your Cockpit's Grafana.
"""

project_id: str
"""
ID of the project.
"""

srn: str
"""
The SRN of the grafana.
"""


@dataclass
class ListAlertsResponse:
Expand Down
15 changes: 12 additions & 3 deletions scaleway-async/scaleway_async/iam/v1alpha1/marshalling.py
Original file line number Diff line number Diff line change
Expand Up @@ -1563,6 +1563,12 @@ def unmarshal_Rule(data: Any) -> Rule:
else:
args["id"] = None

field = data.get("srn", None)
if field is not None:
args["srn"] = field
else:
args["srn"] = None

field = data.get("permission_sets_scope_type", None)
if field is not None:
args["permission_sets_scope_type"] = field
Expand All @@ -1575,11 +1581,11 @@ def unmarshal_Rule(data: Any) -> Rule:
else:
args["condition"] = None

field = data.get("srn", None)
field = data.get("deny", None)
if field is not None:
args["srn"] = field
args["deny"] = field
else:
args["srn"] = None
args["deny"] = False

field = data.get("permission_set_names", None)
if field is not None:
Expand Down Expand Up @@ -2238,6 +2244,9 @@ def marshal_RuleSpecs(
if request.condition is not None:
output["condition"] = request.condition

if request.deny is not None:
output["deny"] = request.deny

if request.permission_set_names is not None:
output["permission_set_names"] = request.permission_set_names

Expand Down
Loading
Loading