@@ -6,6 +6,29 @@ use log::warn;
6
6
use reqwest:: header:: { HeaderMap , HeaderValue } ;
7
7
use serde:: { Deserialize , Serialize } ;
8
8
9
+ /// GetBillingDimensionMappingOptionalParams is a struct for passing parameters to the method [`UsageMeteringAPI::get_billing_dimension_mapping`]
10
+ #[ non_exhaustive]
11
+ #[ derive( Clone , Default , Debug ) ]
12
+ pub struct GetBillingDimensionMappingOptionalParams {
13
+ /// Datetime in ISO-8601 format, UTC, for mappings beginning this month. Defaults to the current month.
14
+ pub filter_month : Option < chrono:: DateTime < chrono:: Utc > > ,
15
+ /// String to specify whether to retrieve active billing dimension mappings or all available mappings. Available views are `active` and `all`. Defaults to `active`.
16
+ pub filter_view : Option < String > ,
17
+ }
18
+
19
+ impl GetBillingDimensionMappingOptionalParams {
20
+ /// Datetime in ISO-8601 format, UTC, for mappings beginning this month. Defaults to the current month.
21
+ pub fn filter_month ( mut self , value : chrono:: DateTime < chrono:: Utc > ) -> Self {
22
+ self . filter_month = Some ( value) ;
23
+ self
24
+ }
25
+ /// String to specify whether to retrieve active billing dimension mappings or all available mappings. Available views are `active` and `all`. Defaults to `active`.
26
+ pub fn filter_view ( mut self , value : String ) -> Self {
27
+ self . filter_view = Some ( value) ;
28
+ self
29
+ }
30
+ }
31
+
9
32
/// GetCostByOrgOptionalParams is a struct for passing parameters to the method [`UsageMeteringAPI::get_cost_by_org`]
10
33
#[ non_exhaustive]
11
34
#[ derive( Clone , Default , Debug ) ]
@@ -296,6 +319,14 @@ pub enum GetActiveBillingDimensionsError {
296
319
UnknownValue ( serde_json:: Value ) ,
297
320
}
298
321
322
+ /// GetBillingDimensionMappingError is a struct for typed errors of method [`UsageMeteringAPI::get_billing_dimension_mapping`]
323
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
324
+ #[ serde( untagged) ]
325
+ pub enum GetBillingDimensionMappingError {
326
+ APIErrorResponse ( crate :: datadogV2:: model:: APIErrorResponse ) ,
327
+ UnknownValue ( serde_json:: Value ) ,
328
+ }
329
+
299
330
/// GetCostByOrgError is a struct for typed errors of method [`UsageMeteringAPI::get_cost_by_org`]
300
331
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
301
332
#[ serde( untagged) ]
@@ -559,6 +590,147 @@ impl UsageMeteringAPI {
559
590
}
560
591
}
561
592
593
+ /// Get a mapping of billing dimensions to the corresponding keys for the supported usage metering public API endpoints.
594
+ ///
595
+ /// This endpoint is only accessible for [parent-level organizations](<https://docs.datadoghq.com/account_management/multi_organization/>).
596
+ pub async fn get_billing_dimension_mapping (
597
+ & self ,
598
+ params : GetBillingDimensionMappingOptionalParams ,
599
+ ) -> Result <
600
+ crate :: datadogV2:: model:: BillingDimensionsMappingResponse ,
601
+ datadog:: Error < GetBillingDimensionMappingError > ,
602
+ > {
603
+ match self
604
+ . get_billing_dimension_mapping_with_http_info ( params)
605
+ . await
606
+ {
607
+ Ok ( response_content) => {
608
+ if let Some ( e) = response_content. entity {
609
+ Ok ( e)
610
+ } else {
611
+ Err ( datadog:: Error :: Serde ( serde:: de:: Error :: custom (
612
+ "response content was None" ,
613
+ ) ) )
614
+ }
615
+ }
616
+ Err ( err) => Err ( err) ,
617
+ }
618
+ }
619
+
620
+ /// Get a mapping of billing dimensions to the corresponding keys for the supported usage metering public API endpoints.
621
+ ///
622
+ /// This endpoint is only accessible for [parent-level organizations](<https://docs.datadoghq.com/account_management/multi_organization/>).
623
+ pub async fn get_billing_dimension_mapping_with_http_info (
624
+ & self ,
625
+ params : GetBillingDimensionMappingOptionalParams ,
626
+ ) -> Result <
627
+ datadog:: ResponseContent < crate :: datadogV2:: model:: BillingDimensionsMappingResponse > ,
628
+ datadog:: Error < GetBillingDimensionMappingError > ,
629
+ > {
630
+ let local_configuration = & self . config ;
631
+ let operation_id = "v2.get_billing_dimension_mapping" ;
632
+ if local_configuration. is_unstable_operation_enabled ( operation_id) {
633
+ warn ! ( "Using unstable operation {operation_id}" ) ;
634
+ } else {
635
+ let local_error = datadog:: UnstableOperationDisabledError {
636
+ msg : "Operation 'v2.get_billing_dimension_mapping' is not enabled" . to_string ( ) ,
637
+ } ;
638
+ return Err ( datadog:: Error :: UnstableOperationDisabledError ( local_error) ) ;
639
+ }
640
+
641
+ // unbox and build optional parameters
642
+ let filter_month = params. filter_month ;
643
+ let filter_view = params. filter_view ;
644
+
645
+ let local_client = & self . client ;
646
+
647
+ let local_uri_str = format ! (
648
+ "{}/api/v2/usage/billing_dimension_mapping" ,
649
+ local_configuration. get_operation_host( operation_id)
650
+ ) ;
651
+ let mut local_req_builder =
652
+ local_client. request ( reqwest:: Method :: GET , local_uri_str. as_str ( ) ) ;
653
+
654
+ if let Some ( ref local_query_param) = filter_month {
655
+ local_req_builder = local_req_builder. query ( & [ (
656
+ "filter[month]" ,
657
+ & local_query_param. to_rfc3339_opts ( chrono:: SecondsFormat :: Millis , true ) ,
658
+ ) ] ) ;
659
+ } ;
660
+ if let Some ( ref local_query_param) = filter_view {
661
+ local_req_builder =
662
+ local_req_builder. query ( & [ ( "filter[view]" , & local_query_param. to_string ( ) ) ] ) ;
663
+ } ;
664
+
665
+ // build headers
666
+ let mut headers = HeaderMap :: new ( ) ;
667
+ headers. insert (
668
+ "Accept" ,
669
+ HeaderValue :: from_static ( "application/json;datetime-format=rfc3339" ) ,
670
+ ) ;
671
+
672
+ // build user agent
673
+ match HeaderValue :: from_str ( local_configuration. user_agent . as_str ( ) ) {
674
+ Ok ( user_agent) => headers. insert ( reqwest:: header:: USER_AGENT , user_agent) ,
675
+ Err ( e) => {
676
+ log:: warn!( "Failed to parse user agent header: {e}, falling back to default" ) ;
677
+ headers. insert (
678
+ reqwest:: header:: USER_AGENT ,
679
+ HeaderValue :: from_static ( datadog:: DEFAULT_USER_AGENT . as_str ( ) ) ,
680
+ )
681
+ }
682
+ } ;
683
+
684
+ // build auth
685
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "apiKeyAuth" ) {
686
+ headers. insert (
687
+ "DD-API-KEY" ,
688
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
689
+ . expect ( "failed to parse DD-API-KEY header" ) ,
690
+ ) ;
691
+ } ;
692
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "appKeyAuth" ) {
693
+ headers. insert (
694
+ "DD-APPLICATION-KEY" ,
695
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
696
+ . expect ( "failed to parse DD-APPLICATION-KEY header" ) ,
697
+ ) ;
698
+ } ;
699
+
700
+ local_req_builder = local_req_builder. headers ( headers) ;
701
+ let local_req = local_req_builder. build ( ) ?;
702
+ log:: debug!( "request content: {:?}" , local_req. body( ) ) ;
703
+ let local_resp = local_client. execute ( local_req) . await ?;
704
+
705
+ let local_status = local_resp. status ( ) ;
706
+ let local_content = local_resp. text ( ) . await ?;
707
+ log:: debug!( "response content: {}" , local_content) ;
708
+
709
+ if !local_status. is_client_error ( ) && !local_status. is_server_error ( ) {
710
+ match serde_json:: from_str :: < crate :: datadogV2:: model:: BillingDimensionsMappingResponse > (
711
+ & local_content,
712
+ ) {
713
+ Ok ( e) => {
714
+ return Ok ( datadog:: ResponseContent {
715
+ status : local_status,
716
+ content : local_content,
717
+ entity : Some ( e) ,
718
+ } )
719
+ }
720
+ Err ( e) => return Err ( datadog:: Error :: Serde ( e) ) ,
721
+ } ;
722
+ } else {
723
+ let local_entity: Option < GetBillingDimensionMappingError > =
724
+ serde_json:: from_str ( & local_content) . ok ( ) ;
725
+ let local_error = datadog:: ResponseContent {
726
+ status : local_status,
727
+ content : local_content,
728
+ entity : local_entity,
729
+ } ;
730
+ Err ( datadog:: Error :: ResponseError ( local_error) )
731
+ }
732
+ }
733
+
562
734
/// Get cost across multi-org account.
563
735
/// Cost by org data for a given month becomes available no later than the 16th of the following month.
564
736
/// **Note:** This endpoint has been deprecated. Please use the new endpoint
0 commit comments