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