Skip to content

Commit 46f7ecd

Browse files
committed
no reference to "external" types in external API call tree
1 parent f1b1a36 commit 46f7ecd

File tree

6 files changed

+73
-86
lines changed

6 files changed

+73
-86
lines changed

common/src/api/external/mod.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3499,19 +3499,6 @@ pub struct TufArtifactMeta {
34993499
pub sign: Option<Vec<u8>>,
35003500
}
35013501

3502-
/// Status of a TUF repo import.
3503-
#[derive(
3504-
Debug, Clone, Copy, PartialEq, Eq, Deserialize, Serialize, JsonSchema,
3505-
)]
3506-
#[serde(rename_all = "snake_case")]
3507-
pub enum TufRepoInsertStatus {
3508-
/// The repository already existed in the database.
3509-
AlreadyExists,
3510-
3511-
/// The repository did not exist, and was inserted into the database.
3512-
Inserted,
3513-
}
3514-
35153502
#[derive(
35163503
Clone, Debug, Deserialize, JsonSchema, Serialize, PartialEq, ObjectIdentity,
35173504
)]

nexus/db-model/src/tuf_repo.rs

Lines changed: 53 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@ use uuid::Uuid;
3030

3131
/// A description of a TUF update: a repo, along with the artifacts it
3232
/// contains.
33-
///
34-
/// This is the internal variant of [`external::TufRepoDescription`].
3533
#[derive(Debug, Clone)]
3634
pub struct TufRepoDescription {
3735
/// The repository.
@@ -64,7 +62,6 @@ impl TufRepoDescription {
6462
}
6563
}
6664

67-
/// Converts self into [`external::TufRepoDescription`].
6865
pub fn into_external(self) -> external::TufRepoDescription {
6966
external::TufRepoDescription {
7067
repo: self.repo.into_external(),
@@ -78,8 +75,6 @@ impl TufRepoDescription {
7875
}
7976

8077
/// A record representing an uploaded TUF repository.
81-
///
82-
/// This is the internal variant of [`external::TufRepoMeta`].
8378
#[derive(
8479
Queryable, Identifiable, Insertable, Clone, Debug, Selectable, AsChangeset,
8580
)]
@@ -132,7 +127,6 @@ impl TufRepo {
132127
)
133128
}
134129

135-
/// Converts self into [`external::TufRepoMeta`].
136130
pub fn into_external(self) -> external::TufRepoMeta {
137131
external::TufRepoMeta {
138132
hash: self.sha256.into(),
@@ -154,6 +148,18 @@ impl TufRepo {
154148
}
155149
}
156150

151+
impl Into<views::TufRepo> for TufRepo {
152+
fn into(self) -> views::TufRepo {
153+
views::TufRepo {
154+
hash: self.sha256.into(),
155+
targets_role_version: self.targets_role_version as u64,
156+
valid_until: self.valid_until,
157+
system_version: self.system_version.into(),
158+
file_name: self.file_name,
159+
}
160+
}
161+
}
162+
157163
#[derive(Queryable, Insertable, Clone, Debug, Selectable, AsChangeset)]
158164
#[diesel(table_name = tuf_artifact)]
159165
pub struct TufArtifact {
@@ -411,3 +417,44 @@ impl FromSql<Jsonb, diesel::pg::Pg> for DbTufSignedRootRole {
411417
.map_err(|e| e.into())
412418
}
413419
}
420+
421+
// The following aren't real models in the sense that they represent DB data,
422+
// but they are the return types of datastore functions
423+
424+
/// Status of a TUF repo import
425+
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
426+
pub enum TufRepoUploadStatus {
427+
/// The repository already existed in the database
428+
AlreadyExists,
429+
430+
/// The repository did not exist, and was inserted into the database
431+
Inserted,
432+
}
433+
434+
impl From<TufRepoUploadStatus> for views::TufRepoUploadStatus {
435+
fn from(status: TufRepoUploadStatus) -> Self {
436+
match status {
437+
TufRepoUploadStatus::AlreadyExists => {
438+
views::TufRepoUploadStatus::AlreadyExists
439+
}
440+
TufRepoUploadStatus::Inserted => {
441+
views::TufRepoUploadStatus::Inserted
442+
}
443+
}
444+
}
445+
}
446+
447+
/// The return value of the tuf repo insert function
448+
pub struct TufRepoUpload {
449+
pub recorded: TufRepoDescription,
450+
pub status: TufRepoUploadStatus,
451+
}
452+
453+
impl From<TufRepoUpload> for views::TufRepoUpload {
454+
fn from(upload: TufRepoUpload) -> Self {
455+
views::TufRepoUpload {
456+
repo: upload.recorded.repo.into(),
457+
status: upload.status.into(),
458+
}
459+
}
460+
}

nexus/db-queries/src/db/datastore/update.rs

Lines changed: 8 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ use nexus_db_errors::OptionalError;
1818
use nexus_db_errors::{ErrorHandler, public_error_from_diesel};
1919
use nexus_db_lookup::DbConnection;
2020
use nexus_db_model::{
21-
ArtifactHash, TufArtifact, TufRepo, TufRepoDescription, TufTrustRoot,
22-
to_db_typed_uuid,
21+
ArtifactHash, TufArtifact, TufRepo, TufRepoDescription, TufRepoUpload,
22+
TufRepoUploadStatus, TufTrustRoot, to_db_typed_uuid,
2323
};
24-
use nexus_types::external_api::views;
2524
use omicron_common::api::external::{
2625
self, CreateResult, DataPageParams, DeleteResult, Generation,
27-
ListResultVec, LookupResult, LookupType, ResourceType, TufRepoInsertStatus,
26+
ListResultVec, LookupResult, LookupType, ResourceType,
2827
};
2928
use omicron_uuid_kinds::GenericUuid;
3029
use omicron_uuid_kinds::TufRepoKind;
@@ -34,24 +33,6 @@ use swrite::{SWrite, swrite};
3433
use tufaceous_artifact::ArtifactVersion;
3534
use uuid::Uuid;
3635

37-
/// The return value of [`DataStore::tuf_repo_insert`].
38-
///
39-
/// This is similar to [`views::TufRepoUpload`], but uses
40-
/// nexus-db-model's types instead of external types.
41-
pub struct TufRepoInsertResponse {
42-
pub recorded: TufRepoDescription,
43-
pub status: TufRepoInsertStatus,
44-
}
45-
46-
impl TufRepoInsertResponse {
47-
pub fn into_external(self) -> views::TufRepoUpload {
48-
views::TufRepoUpload {
49-
repo: self.recorded.repo.into_external().into(),
50-
status: self.status.into(),
51-
}
52-
}
53-
}
54-
5536
async fn artifacts_for_repo(
5637
repo_id: TypedUuid<TufRepoKind>,
5738
conn: &async_bb8_diesel::Connection<DbConnection>,
@@ -85,7 +66,7 @@ impl DataStore {
8566
&self,
8667
opctx: &OpContext,
8768
description: &external::TufRepoDescription,
88-
) -> CreateResult<TufRepoInsertResponse> {
69+
) -> CreateResult<TufRepoUpload> {
8970
opctx.authorize(authz::Action::Modify, &authz::FLEET).await?;
9071
let log = opctx.log.new(
9172
slog::o!(
@@ -327,7 +308,7 @@ async fn insert_impl(
327308
conn: async_bb8_diesel::Connection<DbConnection>,
328309
desc: &external::TufRepoDescription,
329310
err: OptionalError<InsertError>,
330-
) -> Result<TufRepoInsertResponse, DieselError> {
311+
) -> Result<TufRepoUpload, DieselError> {
331312
// Load the current generation from the database and increment it, then
332313
// use that when creating the `TufRepoDescription`. If we determine there
333314
// are any artifacts to be inserted, we update the generation to this value
@@ -364,9 +345,9 @@ async fn insert_impl(
364345

365346
let recorded =
366347
TufRepoDescription { repo: existing_repo, artifacts };
367-
return Ok(TufRepoInsertResponse {
348+
return Ok(TufRepoUpload {
368349
recorded,
369-
status: TufRepoInsertStatus::AlreadyExists,
350+
status: TufRepoUploadStatus::AlreadyExists,
370351
});
371352
}
372353

@@ -570,10 +551,7 @@ async fn insert_impl(
570551
}
571552

572553
let recorded = TufRepoDescription { repo, artifacts: all_artifacts };
573-
Ok(TufRepoInsertResponse {
574-
recorded,
575-
status: TufRepoInsertStatus::Inserted,
576-
})
554+
Ok(TufRepoUpload { recorded, status: TufRepoUploadStatus::Inserted })
577555
}
578556

579557
async fn get_generation(

nexus/src/app/update.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,13 @@ use dropshot::HttpError;
99
use futures::Stream;
1010
use nexus_auth::authz;
1111
use nexus_db_lookup::LookupPath;
12+
use nexus_db_model::TufRepoUpload;
13+
use nexus_db_model::TufRepoUploadStatus;
1214
use nexus_db_model::TufTrustRoot;
1315
use nexus_db_queries::context::OpContext;
14-
use nexus_db_queries::db::datastore::update::TufRepoInsertResponse;
1516
use nexus_db_queries::db::{datastore::SQL_BATCH_SIZE, pagination::Paginator};
1617
use nexus_types::external_api::shared::TufSignedRootRole;
17-
use omicron_common::api::external::{
18-
DataPageParams, Error, TufRepoInsertStatus,
19-
};
18+
use omicron_common::api::external::{DataPageParams, Error};
2019
use omicron_uuid_kinds::{GenericUuid, TufTrustRootUuid};
2120
use semver::Version;
2221
use update_common::artifacts::{
@@ -30,7 +29,7 @@ impl super::Nexus {
3029
opctx: &OpContext,
3130
body: impl Stream<Item = Result<Bytes, HttpError>> + Send + Sync + 'static,
3231
file_name: String,
33-
) -> Result<TufRepoInsertResponse, HttpError> {
32+
) -> Result<TufRepoUpload, HttpError> {
3433
let mut trusted_roots = Vec::new();
3534
let mut paginator = Paginator::new(
3635
SQL_BATCH_SIZE,
@@ -68,7 +67,7 @@ impl super::Nexus {
6867
// carries with it the `Utf8TempDir`s storing the artifacts) into the
6968
// artifact replication background task, then immediately activate the
7069
// task.
71-
if response.status == TufRepoInsertStatus::Inserted {
70+
if response.status == TufRepoUploadStatus::Inserted {
7271
self.tuf_artifact_replication_tx
7372
.send(artifacts_with_plan)
7473
.await

nexus/src/external_api/http_entrypoints.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6654,8 +6654,7 @@ impl NexusExternalApi for NexusExternalApiImpl {
66546654
let update = nexus
66556655
.updates_put_repository(&opctx, body, query.file_name)
66566656
.await?;
6657-
let repo_upload = update.into_external();
6658-
Ok(HttpResponseOk(repo_upload))
6657+
Ok(HttpResponseOk(update.into()))
66596658
};
66606659
apictx
66616660
.context
@@ -6677,7 +6676,7 @@ impl NexusExternalApi for NexusExternalApiImpl {
66776676
let repo = nexus
66786677
.updates_get_repository(&opctx, params.system_version)
66796678
.await?;
6680-
Ok(HttpResponseOk(repo.into_external().into()))
6679+
Ok(HttpResponseOk(repo.into()))
66816680
};
66826681
apictx
66836682
.context
@@ -6700,10 +6699,8 @@ impl NexusExternalApi for NexusExternalApiImpl {
67006699
let repos =
67016700
nexus.updates_list_repositories(&opctx, &pagparams).await?;
67026701

6703-
let responses: Vec<views::TufRepo> = repos
6704-
.into_iter()
6705-
.map(|repo| repo.into_external().into())
6706-
.collect();
6702+
let responses: Vec<views::TufRepo> =
6703+
repos.into_iter().map(Into::into).collect();
67076704

67086705
Ok(HttpResponseOk(ScanByVersion::results_page(
67096706
&query,

nexus/types/src/external_api/views.rs

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ use chrono::Utc;
1515
use daft::Diffable;
1616
pub use omicron_common::api::external::IpVersion;
1717
use omicron_common::api::external::{
18-
self, AffinityPolicy, AllowedSourceIps as ExternalAllowedSourceIps,
19-
ByteCount, Digest, Error, FailureDomain, IdentityMetadata, InstanceState,
20-
Name, ObjectIdentity, SimpleIdentity, SimpleIdentityOrName,
18+
AffinityPolicy, AllowedSourceIps as ExternalAllowedSourceIps, ByteCount,
19+
Digest, Error, FailureDomain, IdentityMetadata, InstanceState, Name,
20+
ObjectIdentity, SimpleIdentity, SimpleIdentityOrName,
2121
};
2222
use omicron_uuid_kinds::*;
2323
use oxnet::{Ipv4Net, Ipv6Net};
@@ -1599,18 +1599,6 @@ pub struct TufRepo {
15991599
pub file_name: String,
16001600
}
16011601

1602-
impl From<external::TufRepoMeta> for TufRepo {
1603-
fn from(meta: external::TufRepoMeta) -> Self {
1604-
Self {
1605-
hash: meta.hash,
1606-
targets_role_version: meta.targets_role_version,
1607-
valid_until: meta.valid_until,
1608-
system_version: meta.system_version,
1609-
file_name: meta.file_name,
1610-
}
1611-
}
1612-
}
1613-
16141602
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize, JsonSchema)]
16151603
pub struct TufRepoUpload {
16161604
pub repo: TufRepo,
@@ -1631,15 +1619,6 @@ pub enum TufRepoUploadStatus {
16311619
Inserted,
16321620
}
16331621

1634-
impl From<external::TufRepoInsertStatus> for TufRepoUploadStatus {
1635-
fn from(status: external::TufRepoInsertStatus) -> Self {
1636-
match status {
1637-
external::TufRepoInsertStatus::AlreadyExists => Self::AlreadyExists,
1638-
external::TufRepoInsertStatus::Inserted => Self::Inserted,
1639-
}
1640-
}
1641-
}
1642-
16431622
fn expected_one_of<T: strum::VariantArray + fmt::Display>() -> String {
16441623
use std::fmt::Write;
16451624
let mut msg = "expected one of:".to_string();

0 commit comments

Comments
 (0)