cx_sdk/client/
notifications.rs

1// Copyright 2024 Coralogix Ltd.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::{
16    collections::HashMap,
17    str::FromStr,
18};
19
20use cx_api::proto::com::coralogixapis::notification_center::{
21    EntityLabelValues,
22    connectors::v1::{
23        BatchGetConnectorsRequest,
24        BatchGetConnectorsResponse,
25        CreateConnectorRequest,
26        CreateConnectorResponse,
27        DeleteConnectorRequest,
28        DeleteConnectorResponse,
29        GetConnectorRequest,
30        GetConnectorResponse,
31        GetConnectorTypeSummariesRequest,
32        GetConnectorTypeSummariesResponse,
33        ListConnectorsRequest,
34        ListConnectorsResponse,
35        ReplaceConnectorRequest,
36        ReplaceConnectorResponse,
37        connectors_service_client::ConnectorsServiceClient,
38    },
39    notifications::v1::{
40        TestConnectorConfigRequest,
41        TestConnectorConfigResponse,
42        TestDestinationRequest,
43        TestDestinationResponse,
44        TestExistingConnectorRequest,
45        TestExistingConnectorResponse,
46        TestExistingPresetRequest,
47        TestExistingPresetResponse,
48        TestPresetConfigRequest,
49        TestPresetConfigResponse,
50        TestRoutingConditionValidRequest,
51        TestRoutingConditionValidResponse,
52        TestTemplateRenderRequest,
53        TestTemplateRenderResponse,
54        testing_service_client::TestingServiceClient,
55    },
56    presets::v1::{
57        BatchGetPresetsRequest,
58        BatchGetPresetsResponse,
59        CreateCustomPresetRequest,
60        CreateCustomPresetResponse,
61        DeleteCustomPresetRequest,
62        DeleteCustomPresetResponse,
63        GetDefaultPresetSummaryRequest,
64        GetDefaultPresetSummaryResponse,
65        GetPresetRequest,
66        GetPresetResponse,
67        GetSystemDefaultPresetSummaryRequest,
68        GetSystemDefaultPresetSummaryResponse,
69        ListPresetSummariesRequest,
70        ListPresetSummariesResponse,
71        ReplaceCustomPresetRequest,
72        ReplaceCustomPresetResponse,
73        SetPresetAsDefaultRequest,
74        SetPresetAsDefaultResponse,
75        presets_service_client::PresetsServiceClient,
76    },
77    routers::v1::{
78        BatchGetGlobalRoutersRequest,
79        BatchGetGlobalRoutersResponse,
80        CreateOrReplaceGlobalRouterRequest,
81        CreateOrReplaceGlobalRouterResponse,
82        DeleteGlobalRouterRequest,
83        DeleteGlobalRouterResponse,
84        GetGlobalRouterRequest,
85        GetGlobalRouterResponse,
86        ListGlobalRoutersRequest,
87        ListGlobalRoutersResponse,
88        global_routers_service_client::GlobalRoutersServiceClient,
89    },
90};
91
92pub use cx_api::proto::com::coralogixapis::notification_center::{
93    ConditionType,
94    ConfigOverrides,
95    ConnectorConfigField,
96    ConnectorType,
97    EntityType,
98    MatchEntityTypeAndSubTypeCondition,
99    MatchEntityTypeCondition,
100    MessageConfig,
101    MessageConfigField,
102    TemplatedConnectorConfigField,
103    condition_type,
104    connectors::v1::{
105        Connector,
106        ConnectorConfig,
107        EntityTypeConfigOverrides,
108    },
109    notifications::v1::{
110        TestResult,
111        test_result,
112        test_template_render_result,
113    },
114    presets::v1::{
115        Preset,
116        PresetType,
117    },
118
119    routers::v1::{
120        GlobalRouter,
121        RoutingLabels,
122    },
123    routing::{
124        RoutingRule,
125        RoutingTarget,
126    },
127};
128
129use tokio::sync::Mutex;
130use tonic::{
131    metadata::MetadataMap,
132    transport::{
133        Channel,
134        ClientTlsConfig,
135        Endpoint,
136    },
137};
138
139use crate::{
140    CoralogixRegion,
141    auth::AuthContext,
142    error::{
143        Result,
144        SdkApiError,
145        SdkError,
146    },
147    metadata::CallProperties,
148    util::make_request_with_metadata,
149};
150
151const NOTIFICATIONS_FEATURE_GROUP_ID: &str = "notifications";
152
153/// A client for interacting with the Coralogix Notification Center APIs.
154pub struct NotificationsClient {
155    metadata_map: MetadataMap,
156    connectors_client: Mutex<ConnectorsServiceClient<Channel>>,
157    presets_client: Mutex<PresetsServiceClient<Channel>>,
158    global_routers_client: Mutex<GlobalRoutersServiceClient<Channel>>,
159    testing_client: Mutex<TestingServiceClient<Channel>>,
160}
161
162impl NotificationsClient {
163    /// Creates a new client for the Notification Center.
164    /// # Arguments
165    /// * `auth_context` - The [`AuthContext`] to use for authentication.
166    /// * `region` - The [`CoralogixRegion`] to connect to.
167    pub fn new(auth_context: AuthContext, region: CoralogixRegion) -> Result<Self> {
168        let channel: Channel = Endpoint::from_str(region.grpc_endpoint().as_str())?
169            .tls_config(ClientTlsConfig::new().with_native_roots())?
170            .connect_lazy();
171        let request_metadata: CallProperties = (&auth_context.team_level_api_key).into();
172        Ok(Self {
173            metadata_map: request_metadata.to_metadata_map(),
174            connectors_client: Mutex::new(ConnectorsServiceClient::new(channel.clone())),
175            presets_client: Mutex::new(PresetsServiceClient::new(channel.clone())),
176            global_routers_client: Mutex::new(GlobalRoutersServiceClient::new(channel.clone())),
177            testing_client: Mutex::new(TestingServiceClient::new(channel)),
178        })
179    }
180
181    /// Get a connector by ID.
182    /// # Arguments
183    /// * `connector_id` - The ID of the connector to get.
184    pub async fn get_connector(&self, connector_id: String) -> Result<GetConnectorResponse> {
185        let request = make_request_with_metadata(
186            GetConnectorRequest { id: connector_id },
187            &self.metadata_map,
188        );
189        {
190            let mut client = self.connectors_client.lock().await.clone();
191            client
192                .get_connector(request)
193                .await
194                .map(|r| r.into_inner())
195                .map_err(
196                    |status| SdkError::ApiError(SdkApiError {
197                        status,
198                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/GetConnector".into(),
199                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
200                    },
201                ))
202        }
203    }
204
205    /// List all connectors.
206    /// # Arguments
207    /// * `connector_type` - The [`ConnectorType`] to filter by.
208    pub async fn list_connectors(
209        &self,
210        connector_type: ConnectorType,
211        supported_by_entity_type: Option<EntityType>,
212    ) -> Result<ListConnectorsResponse> {
213        let request = make_request_with_metadata(
214            ListConnectorsRequest {
215                connector_type: Some(connector_type.into()),
216                supported_by_entity_type: supported_by_entity_type.map(From::from),
217            },
218            &self.metadata_map,
219        );
220        {
221            let mut client = self.connectors_client.lock().await.clone();
222
223            client
224                .list_connectors(request)
225                .await
226                .map(|r| r.into_inner())
227                .map_err(
228                    |status| SdkError::ApiError(SdkApiError {
229                        status,
230                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/ListConnectors".into(),
231                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
232                    },
233                ))
234        }
235    }
236
237    /// Create a new connector.
238    /// # Arguments
239    /// * `connector` - The [`Connector`] to create.
240    pub async fn create_connector(&self, connector: Connector) -> Result<CreateConnectorResponse> {
241        let request = make_request_with_metadata(
242            CreateConnectorRequest {
243                connector: Some(connector),
244            },
245            &self.metadata_map,
246        );
247        {
248            let mut client = self.connectors_client.lock().await.clone();
249
250            client
251                .create_connector(request)
252                .await
253                .map(|r| r.into_inner())
254                .map_err(
255                    |status| SdkError::ApiError(SdkApiError {
256                        status,
257                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/CreateConnector".into(),
258                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
259                    },
260                ))
261        }
262    }
263
264    /// Replace an existing connector.
265    /// # Arguments
266    /// * `connector` - The [`Connector`] to replace.
267    pub async fn replace_connector(
268        &self,
269        connector: Connector,
270    ) -> Result<ReplaceConnectorResponse> {
271        let request = make_request_with_metadata(
272            ReplaceConnectorRequest {
273                connector: Some(connector),
274            },
275            &self.metadata_map,
276        );
277        {
278            let mut client = self.connectors_client.lock().await.clone();
279
280            client
281                .replace_connector(request)
282                .await
283                .map(|r| r.into_inner())
284                .map_err(
285                    |status| SdkError::ApiError(SdkApiError {
286                        status,
287                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/ReplaceConnector".into(),
288                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
289                    },
290                ))
291        }
292    }
293
294    /// Delete a connector by ID.
295    /// # Arguments
296    /// * `connector_id` - The ID of the connector to delete.
297    pub async fn delete_connector(&self, connector_id: String) -> Result<DeleteConnectorResponse> {
298        let request = make_request_with_metadata(
299            DeleteConnectorRequest { id: connector_id },
300            &self.metadata_map,
301        );
302        {
303            let mut client = self.connectors_client.lock().await.clone();
304
305            client
306                .delete_connector(request)
307                .await
308                .map(|r| r.into_inner())
309                .map_err(
310                    |status| SdkError::ApiError(SdkApiError {
311                        status,
312                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/DeleteConnector".into(),
313                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
314                    },
315                ))
316        }
317    }
318
319    /// Batch get connectors by ID.
320    /// # Arguments
321    /// * `connector_ids` - The IDs of the connectors to get.
322    pub async fn batch_get_connectors(
323        &self,
324        connector_ids: Vec<String>,
325    ) -> Result<BatchGetConnectorsResponse> {
326        let request = make_request_with_metadata(
327            BatchGetConnectorsRequest { connector_ids },
328            &self.metadata_map,
329        );
330        {
331            let mut client = self.connectors_client.lock().await.clone();
332
333            client
334                .batch_get_connectors(request)
335                .await
336                .map(|r| r.into_inner())
337                .map_err(
338                    |status| SdkError::ApiError(SdkApiError {
339                        status,
340                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/BatchGetConnectors".into(),
341                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
342                    },
343                ))
344        }
345    }
346
347    /// Get summaries of connector types.
348    pub async fn get_connector_type_summaries(
349        &self,
350        supported_by_entity_type: Option<EntityType>,
351    ) -> Result<GetConnectorTypeSummariesResponse> {
352        let request = make_request_with_metadata(
353            GetConnectorTypeSummariesRequest {
354                supported_by_entity_type: supported_by_entity_type.map(From::from),
355            },
356            &self.metadata_map,
357        );
358        {
359            let mut client = self.connectors_client.lock().await.clone();
360
361            client
362                .get_connector_type_summaries(request)
363                .await
364                .map(|r| r.into_inner())
365                .map_err(
366                    |status| SdkError::ApiError(SdkApiError {
367                        status,
368                        endpoint: "/com.coralogixapis.notification_center.connectors.v1.ConnectorsService/GetConnectorTypeSummaries".into(),
369                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
370                    },
371                ))
372        }
373    }
374
375    /// Create a new custom preset.
376    /// # Arguments
377    /// * `preset` - The [`Preset`] to create.
378    pub async fn create_custom_preset(&self, preset: Preset) -> Result<CreateCustomPresetResponse> {
379        let request = make_request_with_metadata(
380            CreateCustomPresetRequest {
381                preset: Some(preset),
382            },
383            &self.metadata_map,
384        );
385        {
386            let mut client = self.presets_client.lock().await.clone();
387
388            client
389                .create_custom_preset(request)
390                .await
391                .map(|r| r.into_inner())
392                .map_err(
393                    |status| SdkError::ApiError(SdkApiError {
394                        status,
395                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/CreateCustomPreset".into(),
396                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
397                    },
398                ))
399        }
400    }
401
402    /// Replace an existing custom preset.
403    /// # Arguments
404    /// * `preset` - The [`Preset`] to replace.
405    pub async fn replace_custom_preset(
406        &self,
407        preset: Preset,
408    ) -> Result<ReplaceCustomPresetResponse> {
409        let request = make_request_with_metadata(
410            ReplaceCustomPresetRequest {
411                preset: Some(preset),
412            },
413            &self.metadata_map,
414        );
415        {
416            let mut client = self.presets_client.lock().await.clone();
417
418            client
419                .replace_custom_preset(request)
420                .await
421                .map(|r| r.into_inner())
422                .map_err(
423                    |status| SdkError::ApiError(SdkApiError {
424                        status,
425                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/ReplaceCustomPreset".into(),
426                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
427                    },
428                ))
429        }
430    }
431
432    /// Delete a custom preset by ID.
433    /// # Arguments
434    /// * `id` - The ID of the preset to delete.
435    pub async fn delete_custom_preset(&self, id: String) -> Result<DeleteCustomPresetResponse> {
436        let request =
437            make_request_with_metadata(DeleteCustomPresetRequest { id }, &self.metadata_map);
438        {
439            let mut client = self.presets_client.lock().await.clone();
440
441            client
442                .delete_custom_preset(request)
443                .await
444                .map(|r| r.into_inner())
445                .map_err(
446                    |status| SdkError::ApiError(SdkApiError {
447                        status,
448                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/DeleteCustomPreset".into(),
449                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
450                    },
451                ))
452        }
453    }
454
455    /// Set a preset as the default.
456    /// # Arguments
457    /// * `id` - The user-facing ID of the preset to set as the default.
458    pub async fn set_preset_as_default(&self, id: String) -> Result<SetPresetAsDefaultResponse> {
459        let request =
460            make_request_with_metadata(SetPresetAsDefaultRequest { id }, &self.metadata_map);
461
462        let mut client = self.presets_client.lock().await.clone();
463
464        client
465            .set_preset_as_default(request)
466            .await
467            .map(|r| r.into_inner())
468            .map_err(|status| {
469                SdkError::ApiError(SdkApiError {
470                    status,
471                    endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/SetPresetAsDefault".into(),
472                    feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
473                })
474            })
475    }
476
477    /// Get a preset by ID.
478    /// # Arguments
479    /// * `id` - The ID of the preset to get.
480    pub async fn get_preset(&self, id: String) -> Result<GetPresetResponse> {
481        let request = make_request_with_metadata(GetPresetRequest { id }, &self.metadata_map);
482        {
483            let mut client = self.presets_client.lock().await.clone();
484
485            client
486                .get_preset(request)
487                .await
488                .map(|r| r.into_inner())
489                .map_err(
490                    |status| SdkError::ApiError(SdkApiError {
491                        status,
492                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/GetPreset".into(),
493                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
494                    },
495                ))
496        }
497    }
498
499    /// List summaries of presets.
500    /// # Arguments
501    /// * `connector_type` - The [`ConnectorType`] to list presets for.
502    /// * `entity_type` - The [`EntityType`] to list presets for.
503    pub async fn list_preset_summaries(
504        &self,
505        connector_type: Option<ConnectorType>,
506        entity_type: EntityType,
507    ) -> Result<ListPresetSummariesResponse> {
508        let request = make_request_with_metadata(
509            ListPresetSummariesRequest {
510                connector_type: connector_type.map(From::from),
511                entity_type: Some(entity_type.into()),
512            },
513            &self.metadata_map,
514        );
515        {
516            let mut client = self.presets_client.lock().await.clone();
517
518            client
519                .list_preset_summaries(request)
520                .await
521                .map(|r| r.into_inner())
522                .map_err(
523                    |status| SdkError::ApiError(SdkApiError {
524                        status,
525                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/ListPresetSummaries".into(),
526                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
527                    },
528                ))
529        }
530    }
531
532    /// Batch get presets by ID.
533    /// # Arguments
534    /// * `preset_ids` - The IDs of the presets to get.
535    pub async fn batch_get_presets(
536        &self,
537        preset_ids: Vec<String>,
538    ) -> Result<BatchGetPresetsResponse> {
539        let request =
540            make_request_with_metadata(BatchGetPresetsRequest { preset_ids }, &self.metadata_map);
541        {
542            let mut client = self.presets_client.lock().await.clone();
543
544            client
545                .batch_get_presets(request)
546                .await
547                .map(|r| r.into_inner())
548                .map_err(
549                    |status| SdkError::ApiError(SdkApiError {
550                        status,
551                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/BatchGetPresets".into(),
552                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
553                    },
554                ))
555        }
556    }
557
558    /// Get the default preset summary.
559    /// # Arguments
560    /// * `connector_type` - The [`ConnectorType`] to get the default preset summary for.
561    /// * `entity_type` - The [`EntityType`] to get the default preset summary for.
562    pub async fn get_default_preset_summary(
563        &self,
564        connector_type: ConnectorType,
565        entity_type: EntityType,
566    ) -> Result<GetDefaultPresetSummaryResponse> {
567        let request = make_request_with_metadata(
568            GetDefaultPresetSummaryRequest {
569                connector_type: connector_type.into(),
570                entity_type: entity_type.into(),
571            },
572            &self.metadata_map,
573        );
574        {
575            let mut client = self.presets_client.lock().await.clone();
576
577            client
578                .get_default_preset_summary(request)
579                .await
580                .map(|r| r.into_inner())
581                .map_err(
582                    |status| SdkError::ApiError(SdkApiError {
583                        status,
584                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/GetDefaultPresetSummary".into(),
585                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
586                    },
587                ))
588        }
589    }
590
591    /// Get the system default preset summary.
592    /// # Arguments
593    /// * `connector_type` - The [`ConnectorType`] to get the system default preset summary for.
594    /// * `entity_type` - The [`EntityType`] to get the system default preset summary for.
595    pub async fn get_system_default_preset_summary(
596        &self,
597        connector_type: ConnectorType,
598        entity_type: EntityType,
599    ) -> Result<GetSystemDefaultPresetSummaryResponse> {
600        let request = make_request_with_metadata(
601            GetSystemDefaultPresetSummaryRequest {
602                connector_type: connector_type as i32,
603                entity_type: entity_type.into(),
604            },
605            &self.metadata_map,
606        );
607        {
608            let mut client = self.presets_client.lock().await.clone();
609
610            client
611                .get_system_default_preset_summary(request)
612                .await
613                .map(|r| r.into_inner())
614                .map_err(
615                    |status| SdkError::ApiError(SdkApiError {
616                        status,
617                        endpoint: "/com.coralogixapis.notification_center.presets.v1.PresetsService/GetSystemDefaultPresetSummary".into(),
618                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
619                    },
620                ))
621        }
622    }
623
624    /// Create or replace a global router.
625    /// # Arguments
626    /// * `global_router` - The [`GlobalRouter`] to create or replace.
627    pub async fn create_or_replace_global_router(
628        &self,
629        global_router: GlobalRouter,
630    ) -> Result<CreateOrReplaceGlobalRouterResponse> {
631        let request = make_request_with_metadata(
632            CreateOrReplaceGlobalRouterRequest {
633                router: Some(global_router),
634            },
635            &self.metadata_map,
636        );
637        let mut client = self.global_routers_client.lock().await.clone();
638
639        client
640            .create_or_replace_global_router(request)
641            .await
642            .map(|r| r.into_inner())
643            .map_err(|status| SdkError::ApiError(SdkApiError {
644                status,
645                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/CreateOrReplaceGlobalRouter".into(),
646                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
647            }))
648    }
649
650    /// Delete a global router by identifier.
651    /// # Arguments
652    /// * `id` - The identifier of the global router to delete.
653    pub async fn delete_global_router(&self, id: String) -> Result<DeleteGlobalRouterResponse> {
654        let request =
655            make_request_with_metadata(DeleteGlobalRouterRequest { id }, &self.metadata_map);
656        let mut client = self.global_routers_client.lock().await.clone();
657
658        client
659            .delete_global_router(request)
660            .await
661            .map(|r| r.into_inner())
662            .map_err(|status| SdkError::ApiError(SdkApiError {
663                status,
664                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/DeleteGlobalRouter".into(),
665                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
666            }))
667    }
668
669    /// Get a global router by identifier.
670    /// # Arguments
671    /// * `id` - The identifier of the global router to get.
672    pub async fn get_global_router(&self, id: String) -> Result<GetGlobalRouterResponse> {
673        let request = make_request_with_metadata(GetGlobalRouterRequest { id }, &self.metadata_map);
674        let mut client = self.global_routers_client.lock().await.clone();
675
676        client
677            .get_global_router(request)
678            .await
679            .map(|r| r.into_inner())
680            .map_err(|status| SdkError::ApiError(SdkApiError {
681                status,
682                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/GetGlobalRouter".into(),
683                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
684            }))
685    }
686
687    /// List all global routers.
688    /// # Arguments
689    /// * `entity_type` - The [`EntityType`] to filter global routers by.
690    pub async fn list_global_routers(
691        &self,
692        entity_type: EntityType,
693        source_entity_labels: HashMap<String, EntityLabelValues>,
694    ) -> Result<ListGlobalRoutersResponse> {
695        let request = make_request_with_metadata(
696            ListGlobalRoutersRequest {
697                entity_type: Some(entity_type.into()),
698                source_entity_labels,
699            },
700            &self.metadata_map,
701        );
702        let mut client = self.global_routers_client.lock().await.clone();
703
704        client
705            .list_global_routers(request)
706            .await
707            .map(|r| r.into_inner())
708            .map_err(|status| SdkError::ApiError(SdkApiError {
709                status,
710                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/ListGlobalRouters".into(),
711                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
712            }))
713    }
714
715    /// Batch get global routers by identifiers.
716    /// # Arguments
717    /// * `ids` - The identifiers of the global routers to retrieve.
718    pub async fn batch_get_global_routers(
719        &self,
720        ids: Vec<String>,
721    ) -> Result<BatchGetGlobalRoutersResponse> {
722        let request = make_request_with_metadata(
723            BatchGetGlobalRoutersRequest {
724                global_router_ids: ids,
725            },
726            &self.metadata_map,
727        );
728        let mut client = self.global_routers_client.lock().await.clone();
729
730        client
731            .batch_get_global_routers(request)
732            .await
733            .map(|r| r.into_inner())
734            .map_err(|status| SdkError::ApiError(SdkApiError {
735                status,
736                endpoint: "/com.coralogixapis.notification_center.routers.v1.GlobalRoutersService/BatchGetGlobalRouters".into(),
737                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into(),
738            }))
739    }
740
741    /// Test a connector configuration.
742    /// # Arguments
743    /// * `connector_type` - The [`ConnectorType`] to test.
744    /// * `connector_config_fields` - The [ConnectorConfigField]s to test with.
745    /// * `entity_type` - The [`EntityType`] to test with.
746    /// * `payload_type` - The id of the output schema to test with.
747    pub async fn test_connector_config(
748        &self,
749        connector_type: ConnectorType,
750        connector_config_fields: Vec<ConnectorConfigField>,
751        entity_type: EntityType,
752        payload_type: String,
753    ) -> Result<TestConnectorConfigResponse> {
754        let request = make_request_with_metadata(
755            TestConnectorConfigRequest {
756                r#type: connector_type.into(),
757                fields: connector_config_fields,
758                entity_type: Some(entity_type.into()),
759                payload_type,
760            },
761            &self.metadata_map,
762        );
763        {
764            let mut client = self.testing_client.lock().await.clone();
765
766            client
767                .test_connector_config(request)
768                .await
769                .map(|r| r.into_inner())
770                .map_err(
771                    |status| SdkError::ApiError(SdkApiError {
772                        status,
773                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestConnectorConfig".into(),
774                                                feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
775                    },
776                ))
777        }
778    }
779
780    /// Test an existing connector.
781    /// # Arguments
782    /// * `connector_id` - The id of the connector to test.
783    pub async fn test_existing_connector(
784        &self,
785        connector_id: String,
786        payload_type: String,
787    ) -> Result<TestExistingConnectorResponse> {
788        let request = make_request_with_metadata(
789            TestExistingConnectorRequest {
790                connector_id,
791                payload_type,
792            },
793            &self.metadata_map,
794        );
795        {
796            let mut client = self.testing_client.lock().await.clone();
797
798            client
799                .test_existing_connector(request)
800                .await
801                .map(|r| r.into_inner())
802                .map_err(
803                    |status| SdkError::ApiError(SdkApiError {
804                        status,
805                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestExistingConnector".into(),
806                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
807                    },
808                ))
809        }
810    }
811
812    /// Test a preset configuration.
813    /// # Arguments
814    /// * `entity_type` - The entity type.
815    /// * `entity_sub_type` - The entity sub type.
816    /// * `connector_id` - The ID for the connector to test.
817    /// * `parent_preset_id` - The ID of the preset's parent to test.
818    /// * `config_overrides` - The set of [`ConfigOverrides`] to apply.
819    pub async fn test_preset_config(
820        &self,
821        entity_type: EntityType,
822        entity_sub_type: Option<String>,
823        connector_id: String,
824        parent_preset_id: String,
825        config_overrides: Vec<ConfigOverrides>,
826    ) -> Result<TestPresetConfigResponse> {
827        let request = make_request_with_metadata(
828            TestPresetConfigRequest {
829                entity_type: entity_type.into(),
830                entity_sub_type,
831                connector_id,
832                parent_preset_id,
833                config_overrides,
834            },
835            &self.metadata_map,
836        );
837        {
838            let mut client = self.testing_client.lock().await.clone();
839
840            client
841                .test_preset_config(request)
842                .await
843                .map(|r| r.into_inner())
844                .map_err(
845                    |status| SdkError::ApiError(SdkApiError {
846                        status,
847                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestPreset".into(),
848                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
849                    },
850                ))
851        }
852    }
853
854    /// Test a preset configuration.
855    /// # Arguments
856    /// * `entity_type` - The entity type.
857    /// * `entity_sub_type` - The entity sub type.
858    /// * `connector_id` - The ID for the connector to test.
859    /// * `preset_id` - The ID of the preset to test.
860    pub async fn test_existing_preset_config(
861        &self,
862        entity_type: EntityType,
863        entity_sub_type: Option<String>,
864        connector_id: String,
865        preset_id: String,
866    ) -> Result<TestExistingPresetResponse> {
867        let request = make_request_with_metadata(
868            TestExistingPresetRequest {
869                entity_type: entity_type.into(),
870                entity_sub_type,
871                connector_id,
872                preset_id,
873            },
874            &self.metadata_map,
875        );
876        {
877            let mut client = self.testing_client.lock().await.clone();
878
879            client
880                .test_existing_preset(request)
881                .await
882                .map(|r| r.into_inner())
883                .map_err(
884                    |status| SdkError::ApiError(SdkApiError {
885                        status,
886                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestExistingPreset".into(),
887                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
888                    },
889                ))
890        }
891    }
892
893    /// Test rendering a template.
894    /// # Arguments
895    /// * `entity_type` - The entity type to test with.
896    /// * `entity_sub_type` - The entity sub type to test with.
897    /// * `template` - The template to render.
898    pub async fn test_template_render(
899        &self,
900        entity_type: EntityType,
901        entity_sub_type: Option<String>,
902        template: String,
903    ) -> Result<TestTemplateRenderResponse> {
904        let request = make_request_with_metadata(
905            TestTemplateRenderRequest {
906                entity_type: entity_type.into(),
907                entity_sub_type,
908                template,
909            },
910            &self.metadata_map,
911        );
912        {
913            let mut client = self.testing_client.lock().await.clone();
914
915            client
916                .test_template_render(request)
917                .await
918                .map(|r| r.into_inner())
919                .map_err(
920                    |status| SdkError::ApiError(SdkApiError {
921                        status,
922                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestTemplateRender".into(),
923                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
924                    },
925                ))
926        }
927    }
928
929    /// Test a destination.
930    /// # Arguments
931    /// * `entity_type` - The entity type to test with.
932    /// * `entity_sub_type` - The entity sub type.
933    /// * `connector_config_fields` - Connector configuration (templated).
934    /// * `preset_id` - Preset ID.
935    /// * `connector_id` - Connector ID.
936    /// * `message_config_fields` - Message configuration.
937    #[allow(clippy::too_many_arguments)]
938    pub async fn test_destination(
939        &self,
940        entity_type: EntityType,
941        entity_sub_type: Option<String>,
942        connector_config_fields: Vec<TemplatedConnectorConfigField>,
943        preset_id: String,
944        connector_id: String,
945        message_config_fields: Vec<MessageConfigField>,
946        payload_type: String,
947    ) -> Result<TestDestinationResponse> {
948        let request = make_request_with_metadata(
949            TestDestinationRequest {
950                entity_type: entity_type.into(),
951                entity_sub_type,
952                connector_config_fields,
953                message_config_fields,
954                preset_id,
955                connector_id,
956                payload_type,
957            },
958            &self.metadata_map,
959        );
960        {
961            let mut client = self.testing_client.lock().await.clone();
962
963            client
964                .test_destination(request)
965                .await
966                .map(|r| r.into_inner())
967                .map_err(
968                    |status| SdkError::ApiError(SdkApiError {
969                        status,
970                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestDestination".into(),
971                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
972                    },
973                ))
974        }
975    }
976
977    /// Tests whether a routing condition is valid.
978    /// # Arguments
979    /// * `entity_type` - The entity type to test with.
980    /// * `template` - The template to render.
981    pub async fn test_routing_condition_valid(
982        &self,
983        entity_type: EntityType,
984        template: String,
985    ) -> Result<TestRoutingConditionValidResponse> {
986        let request = make_request_with_metadata(
987            TestRoutingConditionValidRequest {
988                entity_type: entity_type.into(),
989                template,
990            },
991            &self.metadata_map,
992        );
993        {
994            let mut client = self.testing_client.lock().await.clone();
995
996            client
997                .test_routing_condition_valid(request)
998                .await
999                .map(|r| r.into_inner())
1000                .map_err(
1001                    |status| SdkError::ApiError(SdkApiError {
1002                        status,
1003                        endpoint: "/com.coralogixapis.notification_center.notifications.v1.TestingService/TestRoutingConditionValid".into(),
1004                        feature_group: NOTIFICATIONS_FEATURE_GROUP_ID.into()
1005                    },
1006                ))
1007        }
1008    }
1009}