Skip to content

Commit 19907ac

Browse files
committed
openapi happy, clippy happy, maybe its ok now
1 parent 9ea1427 commit 19907ac

File tree

9 files changed

+870
-195
lines changed

9 files changed

+870
-195
lines changed

dev-tools/reconfigurator-cli/tests/output/cmd-set-mgs-updates-stdout

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ external DNS:
682682

683683

684684

685-
686685
> # diff in the reverse direction. Should show one removal.
687686

688687
> blueprint-diff cca24b71-09b5-4042-9185-b33e9f2ebba0 ad97e762-7bf1-45a6-a98f-60afb7e491c0

dns-server-api/src/lib.rs

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@
9090
//! we'll need to stop queueing them. So why bother at all?
9191
9292
use dropshot::{HttpError, HttpResponseOk, RequestContext};
93-
use internal_dns_types::config::{DnsConfig, DnsConfigParams};
9493
use openapi_manager_types::{
9594
SupportedVersion, SupportedVersions, api_versions,
9695
};
@@ -107,6 +106,7 @@ api_versions!([
107106
// | example for the next person.
108107
// v
109108
// (next_int, IDENT),
109+
(2, SOA_AND_NS),
110110
(1, INITIAL),
111111
]);
112112

@@ -129,17 +129,52 @@ pub trait DnsServerApi {
129129
#[endpoint(
130130
method = GET,
131131
path = "/config",
132+
operation_id = "dns_config_get",
133+
versions = "1.0.0".."2.0.0"
132134
)]
133-
async fn dns_config_get(
135+
async fn dns_config_get_v1(
134136
rqctx: RequestContext<Self::Context>,
135-
) -> Result<HttpResponseOk<DnsConfig>, HttpError>;
137+
) -> Result<
138+
HttpResponseOk<internal_dns_types::config::v1::DnsConfig>,
139+
HttpError,
140+
>;
141+
142+
#[endpoint(
143+
method = GET,
144+
path = "/config",
145+
operation_id = "dns_config_get",
146+
versions = "2.0.0"..
147+
)]
148+
async fn dns_config_get_v2(
149+
rqctx: RequestContext<Self::Context>,
150+
) -> Result<
151+
HttpResponseOk<internal_dns_types::config::v2::DnsConfig>,
152+
HttpError,
153+
>;
154+
155+
#[endpoint(
156+
method = PUT,
157+
path = "/config",
158+
operation_id = "dns_config_put",
159+
versions = "1.0.0".."2.0.0",
160+
)]
161+
async fn dns_config_put_v1(
162+
rqctx: RequestContext<Self::Context>,
163+
rq: dropshot::TypedBody<
164+
internal_dns_types::config::v1::DnsConfigParams,
165+
>,
166+
) -> Result<dropshot::HttpResponseUpdatedNoContent, dropshot::HttpError>;
136167

137168
#[endpoint(
138169
method = PUT,
139170
path = "/config",
171+
operation_id = "dns_config_put",
172+
versions = "2.0.0"..
140173
)]
141-
async fn dns_config_put(
174+
async fn dns_config_put_v2(
142175
rqctx: RequestContext<Self::Context>,
143-
rq: dropshot::TypedBody<DnsConfigParams>,
176+
rq: dropshot::TypedBody<
177+
internal_dns_types::config::v2::DnsConfigParams,
178+
>,
144179
) -> Result<dropshot::HttpResponseUpdatedNoContent, dropshot::HttpError>;
145180
}

dns-server/src/http_server.rs

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use dns_service_client::{
1111
ERROR_CODE_UPDATE_IN_PROGRESS,
1212
};
1313
use dropshot::RequestContext;
14-
use internal_dns_types::config::{DnsConfig, DnsConfigParams};
14+
use internal_dns_types::config::{v1, v2};
1515

1616
pub struct Context {
1717
store: storage::Store,
@@ -33,9 +33,30 @@ enum DnsServerApiImpl {}
3333
impl DnsServerApi for DnsServerApiImpl {
3434
type Context = Context;
3535

36-
async fn dns_config_get(
36+
async fn dns_config_get_v1(
3737
rqctx: RequestContext<Context>,
38-
) -> Result<dropshot::HttpResponseOk<DnsConfig>, dropshot::HttpError> {
38+
) -> Result<dropshot::HttpResponseOk<v1::DnsConfig>, dropshot::HttpError>
39+
{
40+
let apictx = rqctx.context();
41+
let config = apictx
42+
.store
43+
.dns_config()
44+
.await
45+
.map_err(|e| {
46+
dropshot::HttpError::for_internal_error(format!(
47+
"internal error: {:?}",
48+
e
49+
))
50+
})?
51+
.try_into()
52+
.unwrap();
53+
Ok(dropshot::HttpResponseOk(config))
54+
}
55+
56+
async fn dns_config_get_v2(
57+
rqctx: RequestContext<Context>,
58+
) -> Result<dropshot::HttpResponseOk<v2::DnsConfig>, dropshot::HttpError>
59+
{
3960
let apictx = rqctx.context();
4061
let config = apictx.store.dns_config().await.map_err(|e| {
4162
dropshot::HttpError::for_internal_error(format!(
@@ -46,9 +67,25 @@ impl DnsServerApi for DnsServerApiImpl {
4667
Ok(dropshot::HttpResponseOk(config))
4768
}
4869

49-
async fn dns_config_put(
70+
async fn dns_config_put_v1(
71+
rqctx: RequestContext<Context>,
72+
rq: dropshot::TypedBody<v1::DnsConfigParams>,
73+
) -> Result<dropshot::HttpResponseUpdatedNoContent, dropshot::HttpError>
74+
{
75+
let apictx = rqctx.context();
76+
apictx
77+
.store
78+
.dns_config_update(
79+
&rq.into_inner().try_into().unwrap(),
80+
&rqctx.request_id,
81+
)
82+
.await?;
83+
Ok(dropshot::HttpResponseUpdatedNoContent())
84+
}
85+
86+
async fn dns_config_put_v2(
5087
rqctx: RequestContext<Context>,
51-
rq: dropshot::TypedBody<DnsConfigParams>,
88+
rq: dropshot::TypedBody<v2::DnsConfigParams>,
5289
) -> Result<dropshot::HttpResponseUpdatedNoContent, dropshot::HttpError>
5390
{
5491
let apictx = rqctx.context();

dns-server/src/storage.rs

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -503,15 +503,9 @@ impl Store {
503503
// would affect operations after 8,171 years.
504504
let soa_serial = config.generation.as_u64() as u32;
505505
apex_records.push(DnsRecord::Soa(
506-
internal_dns_types::config::Soa {
507-
mname: nsdname,
508-
rname: format!("admin.{}", zone_name),
509-
serial: soa_serial,
510-
refresh: 3600,
511-
retry: 600,
512-
expire: 18000,
513-
minimum: 150,
514-
},
506+
internal_dns_types::config::Soa::new(
507+
nsdname, soa_serial,
508+
),
515509
));
516510
}
517511

@@ -1425,15 +1419,10 @@ mod test {
14251419
Expect::Record(&DnsRecord::Ns("ns1.zone1.internal".to_string())),
14261420
);
14271421

1428-
let zone_soa = DnsRecord::Soa(internal_dns_types::config::Soa {
1429-
mname: "ns1.zone1.internal".to_string(),
1430-
rname: "admin.zone1.internal".to_string(),
1431-
serial: update.generation.as_u64() as u32,
1432-
refresh: 3600,
1433-
retry: 600,
1434-
expire: 18000,
1435-
minimum: 150,
1436-
});
1422+
let zone_soa = DnsRecord::Soa(internal_dns_types::config::Soa::new(
1423+
"ns1.zone1.internal".to_string(),
1424+
update.generation.as_u64() as u32,
1425+
));
14371426

14381427
// The SOA record is created when the server is told it is serving
14391428
// records for a zone.
@@ -1495,15 +1484,10 @@ mod test {
14951484
.await
14961485
.expect("can apply update");
14971486

1498-
let zone_soa = DnsRecord::Soa(internal_dns_types::config::Soa {
1499-
mname: "ns1.zone1.internal".to_string(),
1500-
rname: "admin.zone1.internal".to_string(),
1501-
serial: update3.generation.as_u64() as u32,
1502-
refresh: 3600,
1503-
retry: 600,
1504-
expire: 18000,
1505-
minimum: 150,
1506-
});
1487+
let zone_soa = DnsRecord::Soa(internal_dns_types::config::Soa::new(
1488+
"ns1.zone1.internal".to_string(),
1489+
update3.generation.as_u64() as u32,
1490+
));
15071491

15081492
// The SOA record is created when the server is told it is serving
15091493
// records for a zone.

0 commit comments

Comments
 (0)