Skip to content

Commit d93e35f

Browse files
authored
Structure for moving views and params structs out of common (#374)
* Revert "Relocate 'api_identity' derive macro - it's a helper for omicron-common (#288)" This reverts commit ec737d3. * create external_api and internal_api modules, put entrypoints inside * pull project and org views and params out of common * do an example of internal params * update openapi spec fixture * comment symmetry on params files * update comment * address comments
1 parent 71f45d0 commit d93e35f

File tree

26 files changed

+215
-186
lines changed

26 files changed

+215
-186
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/src/api/external/api_identity/src/lib.rs renamed to api_identity/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ fn do_object_identity(item: TokenStream) -> Result<TokenStream, syn::Error> {
4343
};
4444

4545
let stream = quote! {
46-
impl crate::api::external::ObjectIdentity for #name {
47-
fn identity(&self) -> &crate::api::external::IdentityMetadata {
46+
impl ObjectIdentity for #name {
47+
fn identity(&self) -> &IdentityMetadata {
4848
&self.identity
4949
}
5050
}
@@ -68,8 +68,8 @@ mod test {
6868
);
6969

7070
let expected = quote! {
71-
impl crate::api::external::ObjectIdentity for Foo {
72-
fn identity(&self) -> &crate::api::external::IdentityMetadata {
71+
impl ObjectIdentity for Foo {
72+
fn identity(&self) -> &IdentityMetadata {
7373
&self.identity
7474
}
7575
}

common/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ progenitor = { git = "https://github.com/oxidecomputer/progenitor" }
2828
percent-encoding = "2.1.0"
2929

3030
[dependencies.api_identity]
31-
path = "src/api/external/api_identity"
31+
path = "../api_identity"
3232

3333
[dependencies.backoff]
3434
version = "0.3.0"

common/src/api/external/mod.rs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -558,79 +558,6 @@ pub struct IdentityMetadataUpdateParams {
558558
* Specific API resources
559559
*/
560560

561-
/*
562-
* ORGANIZATIONS
563-
*/
564-
565-
/**
566-
* Client view of an [`Organization`]
567-
*/
568-
#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)]
569-
#[serde(rename_all = "camelCase")]
570-
pub struct Organization {
571-
#[serde(flatten)]
572-
pub identity: IdentityMetadata,
573-
}
574-
575-
/**
576-
* Create-time parameters for an [`Organization`]
577-
*/
578-
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
579-
#[serde(rename_all = "camelCase")]
580-
pub struct OrganizationCreateParams {
581-
#[serde(flatten)]
582-
pub identity: IdentityMetadataCreateParams,
583-
}
584-
585-
/**
586-
* Updateable properties of an [`Organization`]
587-
*/
588-
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
589-
#[serde(rename_all = "camelCase")]
590-
pub struct OrganizationUpdateParams {
591-
#[serde(flatten)]
592-
pub identity: IdentityMetadataUpdateParams,
593-
}
594-
595-
/*
596-
* PROJECTS
597-
*/
598-
599-
/**
600-
* Client view of an [`Project`]
601-
*/
602-
#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)]
603-
#[serde(rename_all = "camelCase")]
604-
pub struct Project {
605-
/*
606-
* TODO-correctness is flattening here (and in all the other types) the
607-
* intent in RFD 4?
608-
*/
609-
#[serde(flatten)]
610-
pub identity: IdentityMetadata,
611-
pub organization_id: Uuid,
612-
}
613-
614-
/**
615-
* Create-time parameters for an [`Project`]
616-
*/
617-
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
618-
#[serde(rename_all = "camelCase")]
619-
pub struct ProjectCreateParams {
620-
#[serde(flatten)]
621-
pub identity: IdentityMetadataCreateParams,
622-
}
623-
624-
/**
625-
* Updateable properties of an [`Project`]
626-
*/
627-
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
628-
#[serde(rename_all = "camelCase")]
629-
pub struct ProjectUpdateParams {
630-
#[serde(flatten)]
631-
pub identity: IdentityMetadataUpdateParams,
632-
}
633-
634561
/*
635562
* INSTANCES
636563
*/

common/src/api/internal/nexus.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,6 @@ pub struct InstanceRuntimeState {
4545
pub time_updated: DateTime<Utc>,
4646
}
4747

48-
/// Sent by a sled agent on startup to Nexus to request further instruction
49-
#[derive(Serialize, Deserialize, JsonSchema)]
50-
pub struct SledAgentStartupInfo {
51-
/// the address of the sled agent's API endpoint
52-
pub sa_address: SocketAddr,
53-
}
54-
5548
// Oximeter producer/collector objects.
5649

5750
/// Information announced by a metric server, used so that clients can contact it and collect
@@ -72,13 +65,3 @@ impl ProducerEndpoint {
7265
format!("{}/{}", &self.base_route, &self.id)
7366
}
7467
}
75-
76-
/// Message used to notify Nexus that this oximeter instance is up and running.
77-
#[derive(Debug, Clone, Copy, JsonSchema, Serialize, Deserialize)]
78-
pub struct OximeterInfo {
79-
/// The ID for this oximeter instance.
80-
pub collector_id: Uuid,
81-
82-
/// The address on which this oximeter instance listens for requests
83-
pub address: SocketAddr,
84-
}

nexus/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ structopt = "0.3"
3737
thiserror = "1.0"
3838
toml = "0.5.6"
3939

40+
[dependencies.api_identity]
41+
path = "../api_identity"
42+
4043
[dependencies.chrono]
4144
version = "0.4"
4245
features = [ "serde" ]

nexus/src/db/datastore.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,11 +1737,9 @@ mod test {
17371737
use crate::db::identity::Resource;
17381738
use crate::db::model::{ConsoleSession, Organization, Project};
17391739
use crate::db::DataStore;
1740+
use crate::external_api::params;
17401741
use chrono::{Duration, Utc};
1741-
use omicron_common::api::external::{
1742-
Error, IdentityMetadataCreateParams, OrganizationCreateParams,
1743-
ProjectCreateParams,
1744-
};
1742+
use omicron_common::api::external::{Error, IdentityMetadataCreateParams};
17451743
use omicron_test_utils::dev;
17461744
use std::sync::Arc;
17471745
use uuid::Uuid;
@@ -1755,7 +1753,7 @@ mod test {
17551753
let pool = db::Pool::new(&cfg);
17561754
let datastore = DataStore::new(Arc::new(pool));
17571755

1758-
let organization = Organization::new(OrganizationCreateParams {
1756+
let organization = Organization::new(params::OrganizationCreate {
17591757
identity: IdentityMetadataCreateParams {
17601758
name: "org".parse().unwrap(),
17611759
description: "desc".to_string(),
@@ -1766,7 +1764,7 @@ mod test {
17661764

17671765
let project = Project::new(
17681766
organization.id(),
1769-
ProjectCreateParams {
1767+
params::ProjectCreate {
17701768
identity: IdentityMetadataCreateParams {
17711769
name: "project".parse().unwrap(),
17721770
description: "desc".to_string(),

nexus/src/db/model.rs

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use crate::db::schema::{
77
organization, oximeter, project, rack, router_route, sled, vpc, vpc_router,
88
vpc_subnet,
99
};
10+
use crate::external_api::params;
11+
use crate::internal_api;
1012
use chrono::{DateTime, Utc};
1113
use db_macros::{Asset, Resource};
1214
use diesel::backend::{Backend, BinaryRawValue, RawValue};
@@ -343,7 +345,7 @@ pub struct Organization {
343345

344346
impl Organization {
345347
/// Creates a new database Organization object.
346-
pub fn new(params: external::OrganizationCreateParams) -> Self {
348+
pub fn new(params: params::OrganizationCreate) -> Self {
347349
let id = Uuid::new_v4();
348350
Self {
349351
identity: OrganizationIdentity::new(id, params.identity),
@@ -359,12 +361,6 @@ impl DatastoreCollection<Project> for Organization {
359361
type CollectionIdColumn = project::dsl::organization_id;
360362
}
361363

362-
impl Into<external::Organization> for Organization {
363-
fn into(self) -> external::Organization {
364-
external::Organization { identity: self.identity() }
365-
}
366-
}
367-
368364
/// Describes a set of updates for the [`Organization`] model.
369365
#[derive(AsChangeset)]
370366
#[table_name = "organization"]
@@ -374,8 +370,8 @@ pub struct OrganizationUpdate {
374370
pub time_modified: DateTime<Utc>,
375371
}
376372

377-
impl From<external::OrganizationUpdateParams> for OrganizationUpdate {
378-
fn from(params: external::OrganizationUpdateParams) -> Self {
373+
impl From<params::OrganizationUpdate> for OrganizationUpdate {
374+
fn from(params: params::OrganizationUpdate) -> Self {
379375
Self {
380376
name: params.identity.name.map(|n| n.into()),
381377
description: params.identity.description,
@@ -396,26 +392,14 @@ pub struct Project {
396392

397393
impl Project {
398394
/// Creates a new database Project object.
399-
pub fn new(
400-
organization_id: Uuid,
401-
params: external::ProjectCreateParams,
402-
) -> Self {
395+
pub fn new(organization_id: Uuid, params: params::ProjectCreate) -> Self {
403396
Self {
404397
identity: ProjectIdentity::new(Uuid::new_v4(), params.identity),
405398
organization_id: organization_id,
406399
}
407400
}
408401
}
409402

410-
impl Into<external::Project> for Project {
411-
fn into(self) -> external::Project {
412-
external::Project {
413-
identity: self.identity(),
414-
organization_id: self.organization_id,
415-
}
416-
}
417-
}
418-
419403
/// Describes a set of updates for the [`Project`] model.
420404
#[derive(AsChangeset)]
421405
#[table_name = "project"]
@@ -425,8 +409,8 @@ pub struct ProjectUpdate {
425409
pub time_modified: DateTime<Utc>,
426410
}
427411

428-
impl From<external::ProjectUpdateParams> for ProjectUpdate {
429-
fn from(params: external::ProjectUpdateParams) -> Self {
412+
impl From<params::ProjectUpdate> for ProjectUpdate {
413+
fn from(params: params::ProjectUpdate) -> Self {
430414
Self {
431415
name: params.identity.name.map(Name),
432416
description: params.identity.description,
@@ -852,7 +836,7 @@ pub struct OximeterInfo {
852836
}
853837

854838
impl OximeterInfo {
855-
pub fn new(info: &internal::nexus::OximeterInfo) -> Self {
839+
pub fn new(info: &internal_api::params::OximeterInfo) -> Self {
856840
let now = Utc::now();
857841
Self {
858842
id: info.collector_id,

0 commit comments

Comments
 (0)