@@ -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, and 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 for the contract or for all available mappings. Allowed views have the string `active` or `all`. Defaults to `active`.
16
+ pub filter_view : Option < String > ,
17
+ }
18
+
19
+ impl GetBillingDimensionMappingOptionalParams {
20
+ /// Datetime in ISO-8601 format, UTC, and 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 for the contract or for all available mappings. Allowed views have the string `active` or `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 ) ]
@@ -303,6 +326,14 @@ pub enum GetActiveBillingDimensionsError {
303
326
UnknownValue ( serde_json:: Value ) ,
304
327
}
305
328
329
+ /// GetBillingDimensionMappingError is a struct for typed errors of method [`UsageMeteringAPI::get_billing_dimension_mapping`]
330
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
331
+ #[ serde( untagged) ]
332
+ pub enum GetBillingDimensionMappingError {
333
+ APIErrorResponse ( crate :: datadogV2:: model:: APIErrorResponse ) ,
334
+ UnknownValue ( serde_json:: Value ) ,
335
+ }
336
+
306
337
/// GetCostByOrgError is a struct for typed errors of method [`UsageMeteringAPI::get_cost_by_org`]
307
338
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
308
339
#[ serde( untagged) ]
@@ -566,6 +597,149 @@ impl UsageMeteringAPI {
566
597
}
567
598
}
568
599
600
+ /// Get a mapping of billing dimensions to the corresponding keys for the supported usage metering public API endpoints.
601
+ /// Mapping data is updated on a monthly cadence.
602
+ ///
603
+ /// This endpoint is only accessible to [parent-level organizations](<https://docs.datadoghq.com/account_management/multi_organization/>).
604
+ pub async fn get_billing_dimension_mapping (
605
+ & self ,
606
+ params : GetBillingDimensionMappingOptionalParams ,
607
+ ) -> Result <
608
+ crate :: datadogV2:: model:: BillingDimensionsMappingResponse ,
609
+ datadog:: Error < GetBillingDimensionMappingError > ,
610
+ > {
611
+ match self
612
+ . get_billing_dimension_mapping_with_http_info ( params)
613
+ . await
614
+ {
615
+ Ok ( response_content) => {
616
+ if let Some ( e) = response_content. entity {
617
+ Ok ( e)
618
+ } else {
619
+ Err ( datadog:: Error :: Serde ( serde:: de:: Error :: custom (
620
+ "response content was None" ,
621
+ ) ) )
622
+ }
623
+ }
624
+ Err ( err) => Err ( err) ,
625
+ }
626
+ }
627
+
628
+ /// Get a mapping of billing dimensions to the corresponding keys for the supported usage metering public API endpoints.
629
+ /// Mapping data is updated on a monthly cadence.
630
+ ///
631
+ /// This endpoint is only accessible to [parent-level organizations](<https://docs.datadoghq.com/account_management/multi_organization/>).
632
+ pub async fn get_billing_dimension_mapping_with_http_info (
633
+ & self ,
634
+ params : GetBillingDimensionMappingOptionalParams ,
635
+ ) -> Result <
636
+ datadog:: ResponseContent < crate :: datadogV2:: model:: BillingDimensionsMappingResponse > ,
637
+ datadog:: Error < GetBillingDimensionMappingError > ,
638
+ > {
639
+ let local_configuration = & self . config ;
640
+ let operation_id = "v2.get_billing_dimension_mapping" ;
641
+ if local_configuration. is_unstable_operation_enabled ( operation_id) {
642
+ warn ! ( "Using unstable operation {operation_id}" ) ;
643
+ } else {
644
+ let local_error = datadog:: UnstableOperationDisabledError {
645
+ msg : "Operation 'v2.get_billing_dimension_mapping' is not enabled" . to_string ( ) ,
646
+ } ;
647
+ return Err ( datadog:: Error :: UnstableOperationDisabledError ( local_error) ) ;
648
+ }
649
+
650
+ // unbox and build optional parameters
651
+ let filter_month = params. filter_month ;
652
+ let filter_view = params. filter_view ;
653
+
654
+ let local_client = & self . client ;
655
+
656
+ let local_uri_str = format ! (
657
+ "{}/api/v2/usage/billing_dimension_mapping" ,
658
+ local_configuration. get_operation_host( operation_id)
659
+ ) ;
660
+ let mut local_req_builder =
661
+ local_client. request ( reqwest:: Method :: GET , local_uri_str. as_str ( ) ) ;
662
+
663
+ if let Some ( ref local_query_param) = filter_month {
664
+ local_req_builder = local_req_builder. query ( & [ (
665
+ "filter[month]" ,
666
+ & local_query_param. to_rfc3339_opts ( chrono:: SecondsFormat :: Millis , true ) ,
667
+ ) ] ) ;
668
+ } ;
669
+ if let Some ( ref local_query_param) = filter_view {
670
+ local_req_builder =
671
+ local_req_builder. query ( & [ ( "filter[view]" , & local_query_param. to_string ( ) ) ] ) ;
672
+ } ;
673
+
674
+ // build headers
675
+ let mut headers = HeaderMap :: new ( ) ;
676
+ headers. insert (
677
+ "Accept" ,
678
+ HeaderValue :: from_static ( "application/json;datetime-format=rfc3339" ) ,
679
+ ) ;
680
+
681
+ // build user agent
682
+ match HeaderValue :: from_str ( local_configuration. user_agent . as_str ( ) ) {
683
+ Ok ( user_agent) => headers. insert ( reqwest:: header:: USER_AGENT , user_agent) ,
684
+ Err ( e) => {
685
+ log:: warn!( "Failed to parse user agent header: {e}, falling back to default" ) ;
686
+ headers. insert (
687
+ reqwest:: header:: USER_AGENT ,
688
+ HeaderValue :: from_static ( datadog:: DEFAULT_USER_AGENT . as_str ( ) ) ,
689
+ )
690
+ }
691
+ } ;
692
+
693
+ // build auth
694
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "apiKeyAuth" ) {
695
+ headers. insert (
696
+ "DD-API-KEY" ,
697
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
698
+ . expect ( "failed to parse DD-API-KEY header" ) ,
699
+ ) ;
700
+ } ;
701
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "appKeyAuth" ) {
702
+ headers. insert (
703
+ "DD-APPLICATION-KEY" ,
704
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
705
+ . expect ( "failed to parse DD-APPLICATION-KEY header" ) ,
706
+ ) ;
707
+ } ;
708
+
709
+ local_req_builder = local_req_builder. headers ( headers) ;
710
+ let local_req = local_req_builder. build ( ) ?;
711
+ log:: debug!( "request content: {:?}" , local_req. body( ) ) ;
712
+ let local_resp = local_client. execute ( local_req) . await ?;
713
+
714
+ let local_status = local_resp. status ( ) ;
715
+ let local_content = local_resp. text ( ) . await ?;
716
+ log:: debug!( "response content: {}" , local_content) ;
717
+
718
+ if !local_status. is_client_error ( ) && !local_status. is_server_error ( ) {
719
+ match serde_json:: from_str :: < crate :: datadogV2:: model:: BillingDimensionsMappingResponse > (
720
+ & local_content,
721
+ ) {
722
+ Ok ( e) => {
723
+ return Ok ( datadog:: ResponseContent {
724
+ status : local_status,
725
+ content : local_content,
726
+ entity : Some ( e) ,
727
+ } )
728
+ }
729
+ Err ( e) => return Err ( datadog:: Error :: Serde ( e) ) ,
730
+ } ;
731
+ } else {
732
+ let local_entity: Option < GetBillingDimensionMappingError > =
733
+ serde_json:: from_str ( & local_content) . ok ( ) ;
734
+ let local_error = datadog:: ResponseContent {
735
+ status : local_status,
736
+ content : local_content,
737
+ entity : local_entity,
738
+ } ;
739
+ Err ( datadog:: Error :: ResponseError ( local_error) )
740
+ }
741
+ }
742
+
569
743
/// Get cost across multi-org account.
570
744
/// Cost by org data for a given month becomes available no later than the 16th of the following month.
571
745
/// **Note:** This endpoint has been deprecated. Please use the new endpoint
0 commit comments