@@ -714,6 +714,14 @@ pub enum ConvertSecurityMonitoringRuleFromJSONToTerraformError {
714
714
UnknownValue ( serde_json:: Value ) ,
715
715
}
716
716
717
+ /// CreateCustomFrameworkError is a struct for typed errors of method [`SecurityMonitoringAPI::create_custom_framework`]
718
+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
719
+ #[ serde( untagged) ]
720
+ pub enum CreateCustomFrameworkError {
721
+ APIErrorResponse ( crate :: datadogV2:: model:: APIErrorResponse ) ,
722
+ UnknownValue ( serde_json:: Value ) ,
723
+ }
724
+
717
725
/// CreateSecurityFilterError is a struct for typed errors of method [`SecurityMonitoringAPI::create_security_filter`]
718
726
#[ derive( Debug , Clone , Serialize , Deserialize ) ]
719
727
#[ serde( untagged) ]
@@ -1557,6 +1565,139 @@ impl SecurityMonitoringAPI {
1557
1565
}
1558
1566
}
1559
1567
1568
+ /// Create a custom framework.
1569
+ pub async fn create_custom_framework (
1570
+ & self ,
1571
+ body : crate :: datadogV2:: model:: CreateCustomFrameworkRequest ,
1572
+ ) -> Result < ( ) , datadog:: Error < CreateCustomFrameworkError > > {
1573
+ match self . create_custom_framework_with_http_info ( body) . await {
1574
+ Ok ( _) => Ok ( ( ) ) ,
1575
+ Err ( err) => Err ( err) ,
1576
+ }
1577
+ }
1578
+
1579
+ /// Create a custom framework.
1580
+ pub async fn create_custom_framework_with_http_info (
1581
+ & self ,
1582
+ body : crate :: datadogV2:: model:: CreateCustomFrameworkRequest ,
1583
+ ) -> Result < datadog:: ResponseContent < ( ) > , datadog:: Error < CreateCustomFrameworkError > > {
1584
+ let local_configuration = & self . config ;
1585
+ let operation_id = "v2.create_custom_framework" ;
1586
+
1587
+ let local_client = & self . client ;
1588
+
1589
+ let local_uri_str = format ! (
1590
+ "{}/api/v2/cloud_security_management/custom_frameworks" ,
1591
+ local_configuration. get_operation_host( operation_id)
1592
+ ) ;
1593
+ let mut local_req_builder =
1594
+ local_client. request ( reqwest:: Method :: POST , local_uri_str. as_str ( ) ) ;
1595
+
1596
+ // build headers
1597
+ let mut headers = HeaderMap :: new ( ) ;
1598
+ headers. insert ( "Content-Type" , HeaderValue :: from_static ( "application/json" ) ) ;
1599
+ headers. insert ( "Accept" , HeaderValue :: from_static ( "*/*" ) ) ;
1600
+
1601
+ // build user agent
1602
+ match HeaderValue :: from_str ( local_configuration. user_agent . as_str ( ) ) {
1603
+ Ok ( user_agent) => headers. insert ( reqwest:: header:: USER_AGENT , user_agent) ,
1604
+ Err ( e) => {
1605
+ log:: warn!( "Failed to parse user agent header: {e}, falling back to default" ) ;
1606
+ headers. insert (
1607
+ reqwest:: header:: USER_AGENT ,
1608
+ HeaderValue :: from_static ( datadog:: DEFAULT_USER_AGENT . as_str ( ) ) ,
1609
+ )
1610
+ }
1611
+ } ;
1612
+
1613
+ // build auth
1614
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "apiKeyAuth" ) {
1615
+ headers. insert (
1616
+ "DD-API-KEY" ,
1617
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
1618
+ . expect ( "failed to parse DD-API-KEY header" ) ,
1619
+ ) ;
1620
+ } ;
1621
+ if let Some ( local_key) = local_configuration. auth_keys . get ( "appKeyAuth" ) {
1622
+ headers. insert (
1623
+ "DD-APPLICATION-KEY" ,
1624
+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
1625
+ . expect ( "failed to parse DD-APPLICATION-KEY header" ) ,
1626
+ ) ;
1627
+ } ;
1628
+
1629
+ // build body parameters
1630
+ let output = Vec :: new ( ) ;
1631
+ let mut ser = serde_json:: Serializer :: with_formatter ( output, datadog:: DDFormatter ) ;
1632
+ if body. serialize ( & mut ser) . is_ok ( ) {
1633
+ if let Some ( content_encoding) = headers. get ( "Content-Encoding" ) {
1634
+ match content_encoding. to_str ( ) . unwrap_or_default ( ) {
1635
+ "gzip" => {
1636
+ let mut enc = GzEncoder :: new ( Vec :: new ( ) , Compression :: default ( ) ) ;
1637
+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
1638
+ match enc. finish ( ) {
1639
+ Ok ( buf) => {
1640
+ local_req_builder = local_req_builder. body ( buf) ;
1641
+ }
1642
+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
1643
+ }
1644
+ }
1645
+ "deflate" => {
1646
+ let mut enc = ZlibEncoder :: new ( Vec :: new ( ) , Compression :: default ( ) ) ;
1647
+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
1648
+ match enc. finish ( ) {
1649
+ Ok ( buf) => {
1650
+ local_req_builder = local_req_builder. body ( buf) ;
1651
+ }
1652
+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
1653
+ }
1654
+ }
1655
+ "zstd1" => {
1656
+ let mut enc = zstd:: stream:: Encoder :: new ( Vec :: new ( ) , 0 ) . unwrap ( ) ;
1657
+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
1658
+ match enc. finish ( ) {
1659
+ Ok ( buf) => {
1660
+ local_req_builder = local_req_builder. body ( buf) ;
1661
+ }
1662
+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
1663
+ }
1664
+ }
1665
+ _ => {
1666
+ local_req_builder = local_req_builder. body ( ser. into_inner ( ) ) ;
1667
+ }
1668
+ }
1669
+ } else {
1670
+ local_req_builder = local_req_builder. body ( ser. into_inner ( ) ) ;
1671
+ }
1672
+ }
1673
+
1674
+ local_req_builder = local_req_builder. headers ( headers) ;
1675
+ let local_req = local_req_builder. build ( ) ?;
1676
+ log:: debug!( "request content: {:?}" , local_req. body( ) ) ;
1677
+ let local_resp = local_client. execute ( local_req) . await ?;
1678
+
1679
+ let local_status = local_resp. status ( ) ;
1680
+ let local_content = local_resp. text ( ) . await ?;
1681
+ log:: debug!( "response content: {}" , local_content) ;
1682
+
1683
+ if !local_status. is_client_error ( ) && !local_status. is_server_error ( ) {
1684
+ Ok ( datadog:: ResponseContent {
1685
+ status : local_status,
1686
+ content : local_content,
1687
+ entity : None ,
1688
+ } )
1689
+ } else {
1690
+ let local_entity: Option < CreateCustomFrameworkError > =
1691
+ serde_json:: from_str ( & local_content) . ok ( ) ;
1692
+ let local_error = datadog:: ResponseContent {
1693
+ status : local_status,
1694
+ content : local_content,
1695
+ entity : local_entity,
1696
+ } ;
1697
+ Err ( datadog:: Error :: ResponseError ( local_error) )
1698
+ }
1699
+ }
1700
+
1560
1701
/// Create a security filter.
1561
1702
///
1562
1703
/// See the [security filter guide](<https://docs.datadoghq.com/security_platform/guide/how-to-setup-security-filters-using-security-monitoring-api/>)
0 commit comments