@@ -42,6 +42,14 @@ pub enum GetDatasetError {
4242 UnknownValue ( serde_json:: Value ) ,
4343}
4444
45+ /// UpdateDatasetError is a struct for typed errors of method [`DatasetsAPI::update_dataset`]
46+ #[ derive( Debug , Clone , Serialize , Deserialize ) ]
47+ #[ serde( untagged) ]
48+ pub enum UpdateDatasetError {
49+ APIErrorResponse ( crate :: datadogV2:: model:: APIErrorResponse ) ,
50+ UnknownValue ( serde_json:: Value ) ,
51+ }
52+
4553/// Data Access Controls in Datadog is a feature that allows administrators and access managers to regulate
4654/// access to sensitive data. By defining Restricted Datasets, you can ensure that only specific teams or roles can
4755/// view certain types of telemetry (for example, logs, traces, metrics, and RUM data).
@@ -558,4 +566,159 @@ impl DatasetsAPI {
558566 Err ( datadog:: Error :: ResponseError ( local_error) )
559567 }
560568 }
569+
570+ /// Edits the dataset associated with the ID.
571+ pub async fn update_dataset (
572+ & self ,
573+ dataset_id : String ,
574+ body : crate :: datadogV2:: model:: DatasetUpdateRequest ,
575+ ) -> Result < crate :: datadogV2:: model:: DatasetResponseSingle , datadog:: Error < UpdateDatasetError > >
576+ {
577+ match self . update_dataset_with_http_info ( dataset_id, body) . await {
578+ Ok ( response_content) => {
579+ if let Some ( e) = response_content. entity {
580+ Ok ( e)
581+ } else {
582+ Err ( datadog:: Error :: Serde ( serde:: de:: Error :: custom (
583+ "response content was None" ,
584+ ) ) )
585+ }
586+ }
587+ Err ( err) => Err ( err) ,
588+ }
589+ }
590+
591+ /// Edits the dataset associated with the ID.
592+ pub async fn update_dataset_with_http_info (
593+ & self ,
594+ dataset_id : String ,
595+ body : crate :: datadogV2:: model:: DatasetUpdateRequest ,
596+ ) -> Result <
597+ datadog:: ResponseContent < crate :: datadogV2:: model:: DatasetResponseSingle > ,
598+ datadog:: Error < UpdateDatasetError > ,
599+ > {
600+ let local_configuration = & self . config ;
601+ let operation_id = "v2.update_dataset" ;
602+
603+ let local_client = & self . client ;
604+
605+ let local_uri_str = format ! (
606+ "{}/api/v2/datasets/{dataset_id}" ,
607+ local_configuration. get_operation_host( operation_id) ,
608+ dataset_id = datadog:: urlencode( dataset_id)
609+ ) ;
610+ let mut local_req_builder =
611+ local_client. request ( reqwest:: Method :: PUT , local_uri_str. as_str ( ) ) ;
612+
613+ // build headers
614+ let mut headers = HeaderMap :: new ( ) ;
615+ headers. insert ( "Content-Type" , HeaderValue :: from_static ( "application/json" ) ) ;
616+ headers. insert ( "Accept" , HeaderValue :: from_static ( "application/json" ) ) ;
617+
618+ // build user agent
619+ match HeaderValue :: from_str ( local_configuration. user_agent . as_str ( ) ) {
620+ Ok ( user_agent) => headers. insert ( reqwest:: header:: USER_AGENT , user_agent) ,
621+ Err ( e) => {
622+ log:: warn!( "Failed to parse user agent header: {e}, falling back to default" ) ;
623+ headers. insert (
624+ reqwest:: header:: USER_AGENT ,
625+ HeaderValue :: from_static ( datadog:: DEFAULT_USER_AGENT . as_str ( ) ) ,
626+ )
627+ }
628+ } ;
629+
630+ // build auth
631+ if let Some ( local_key) = local_configuration. auth_keys . get ( "apiKeyAuth" ) {
632+ headers. insert (
633+ "DD-API-KEY" ,
634+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
635+ . expect ( "failed to parse DD-API-KEY header" ) ,
636+ ) ;
637+ } ;
638+ if let Some ( local_key) = local_configuration. auth_keys . get ( "appKeyAuth" ) {
639+ headers. insert (
640+ "DD-APPLICATION-KEY" ,
641+ HeaderValue :: from_str ( local_key. key . as_str ( ) )
642+ . expect ( "failed to parse DD-APPLICATION-KEY header" ) ,
643+ ) ;
644+ } ;
645+
646+ // build body parameters
647+ let output = Vec :: new ( ) ;
648+ let mut ser = serde_json:: Serializer :: with_formatter ( output, datadog:: DDFormatter ) ;
649+ if body. serialize ( & mut ser) . is_ok ( ) {
650+ if let Some ( content_encoding) = headers. get ( "Content-Encoding" ) {
651+ match content_encoding. to_str ( ) . unwrap_or_default ( ) {
652+ "gzip" => {
653+ let mut enc = GzEncoder :: new ( Vec :: new ( ) , Compression :: default ( ) ) ;
654+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
655+ match enc. finish ( ) {
656+ Ok ( buf) => {
657+ local_req_builder = local_req_builder. body ( buf) ;
658+ }
659+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
660+ }
661+ }
662+ "deflate" => {
663+ let mut enc = ZlibEncoder :: new ( Vec :: new ( ) , Compression :: default ( ) ) ;
664+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
665+ match enc. finish ( ) {
666+ Ok ( buf) => {
667+ local_req_builder = local_req_builder. body ( buf) ;
668+ }
669+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
670+ }
671+ }
672+ "zstd1" => {
673+ let mut enc = zstd:: stream:: Encoder :: new ( Vec :: new ( ) , 0 ) . unwrap ( ) ;
674+ let _ = enc. write_all ( ser. into_inner ( ) . as_slice ( ) ) ;
675+ match enc. finish ( ) {
676+ Ok ( buf) => {
677+ local_req_builder = local_req_builder. body ( buf) ;
678+ }
679+ Err ( e) => return Err ( datadog:: Error :: Io ( e) ) ,
680+ }
681+ }
682+ _ => {
683+ local_req_builder = local_req_builder. body ( ser. into_inner ( ) ) ;
684+ }
685+ }
686+ } else {
687+ local_req_builder = local_req_builder. body ( ser. into_inner ( ) ) ;
688+ }
689+ }
690+
691+ local_req_builder = local_req_builder. headers ( headers) ;
692+ let local_req = local_req_builder. build ( ) ?;
693+ log:: debug!( "request content: {:?}" , local_req. body( ) ) ;
694+ let local_resp = local_client. execute ( local_req) . await ?;
695+
696+ let local_status = local_resp. status ( ) ;
697+ let local_content = local_resp. text ( ) . await ?;
698+ log:: debug!( "response content: {}" , local_content) ;
699+
700+ if !local_status. is_client_error ( ) && !local_status. is_server_error ( ) {
701+ match serde_json:: from_str :: < crate :: datadogV2:: model:: DatasetResponseSingle > (
702+ & local_content,
703+ ) {
704+ Ok ( e) => {
705+ return Ok ( datadog:: ResponseContent {
706+ status : local_status,
707+ content : local_content,
708+ entity : Some ( e) ,
709+ } )
710+ }
711+ Err ( e) => return Err ( datadog:: Error :: Serde ( e) ) ,
712+ } ;
713+ } else {
714+ let local_entity: Option < UpdateDatasetError > =
715+ serde_json:: from_str ( & local_content) . ok ( ) ;
716+ let local_error = datadog:: ResponseContent {
717+ status : local_status,
718+ content : local_content,
719+ entity : local_entity,
720+ } ;
721+ Err ( datadog:: Error :: ResponseError ( local_error) )
722+ }
723+ }
561724}
0 commit comments