66
77use crate :: storage:: { self , UpdateError } ;
88use dns_server_api:: DnsServerApi ;
9- use dns_service_client:: {
10- ERROR_CODE_BAD_UPDATE_GENERATION , ERROR_CODE_INCOMPATIBLE_RECORD ,
11- ERROR_CODE_UPDATE_IN_PROGRESS ,
12- } ;
139use dropshot:: RequestContext ;
14- use internal_dns_types:: {
15- v1 :: { self , config :: TranslationError as V1TranslationError } ,
16- v2 :: { self , config :: TranslationError as V2TranslationError } ,
10+ use internal_dns_types:: config :: {
11+ DnsConfig , DnsConfigParams , ERROR_CODE_BAD_UPDATE_GENERATION ,
12+ ERROR_CODE_UPDATE_IN_PROGRESS ,
1713} ;
1814
1915pub struct Context {
@@ -36,66 +32,9 @@ enum DnsServerApiImpl {}
3632impl DnsServerApi for DnsServerApiImpl {
3733 type Context = Context ;
3834
39- async fn dns_config_get_v1 (
40- rqctx : RequestContext < Context > ,
41- ) -> Result <
42- dropshot:: HttpResponseOk < v1:: config:: DnsConfig > ,
43- dropshot:: HttpError ,
44- > {
45- let result = Self :: dns_config_get ( rqctx) . await ?;
46- match result. 0 . try_into ( ) {
47- Ok ( config) => Ok ( dropshot:: HttpResponseOk ( config) ) ,
48- Err ( V2TranslationError :: IncompatibleRecord ) => {
49- Err ( dropshot:: HttpError :: for_bad_request (
50- None ,
51- ERROR_CODE_INCOMPATIBLE_RECORD . to_string ( ) ,
52- ) )
53- }
54- }
55- }
56-
57- async fn dns_config_get_v2 (
58- rqctx : RequestContext < Context > ,
59- ) -> Result <
60- dropshot:: HttpResponseOk < v2:: config:: DnsConfig > ,
61- dropshot:: HttpError ,
62- > {
63- Self :: dns_config_get ( rqctx) . await
64- }
65-
66- async fn dns_config_put_v1 (
67- rqctx : RequestContext < Context > ,
68- rq : dropshot:: TypedBody < v1:: config:: DnsConfigParams > ,
69- ) -> Result < dropshot:: HttpResponseUpdatedNoContent , dropshot:: HttpError >
70- {
71- let provided_config = match rq. into_inner ( ) . try_into ( ) {
72- Ok ( config) => config,
73- Err ( V1TranslationError :: GenerationTooLarge ) => {
74- return Err ( dropshot:: HttpError :: for_bad_request (
75- None ,
76- ERROR_CODE_INCOMPATIBLE_RECORD . to_string ( ) ,
77- ) ) ;
78- }
79- } ;
80- Self :: dns_config_put ( rqctx, provided_config) . await
81- }
82-
83- async fn dns_config_put_v2 (
84- rqctx : RequestContext < Context > ,
85- rq : dropshot:: TypedBody < v2:: config:: DnsConfigParams > ,
86- ) -> Result < dropshot:: HttpResponseUpdatedNoContent , dropshot:: HttpError >
87- {
88- Self :: dns_config_put ( rqctx, rq. into_inner ( ) ) . await
89- }
90- }
91-
92- impl DnsServerApiImpl {
9335 async fn dns_config_get (
9436 rqctx : RequestContext < Context > ,
95- ) -> Result <
96- dropshot:: HttpResponseOk < v2:: config:: DnsConfig > ,
97- dropshot:: HttpError ,
98- > {
37+ ) -> Result < dropshot:: HttpResponseOk < DnsConfig > , dropshot:: HttpError > {
9938 let apictx = rqctx. context ( ) ;
10039 let config = apictx. store . dns_config ( ) . await . map_err ( |e| {
10140 dropshot:: HttpError :: for_internal_error ( format ! (
@@ -108,11 +47,14 @@ impl DnsServerApiImpl {
10847
10948 async fn dns_config_put (
11049 rqctx : RequestContext < Context > ,
111- params : v2 :: config :: DnsConfigParams ,
50+ rq : dropshot :: TypedBody < DnsConfigParams > ,
11251 ) -> Result < dropshot:: HttpResponseUpdatedNoContent , dropshot:: HttpError >
11352 {
11453 let apictx = rqctx. context ( ) ;
115- apictx. store . dns_config_update ( & params, & rqctx. request_id ) . await ?;
54+ apictx
55+ . store
56+ . dns_config_update ( & rq. into_inner ( ) , & rqctx. request_id )
57+ . await ?;
11658 Ok ( dropshot:: HttpResponseUpdatedNoContent ( ) )
11759 }
11860}
0 commit comments