Skip to content

Commit c07c97a

Browse files
committed
organizations and projects
1 parent 8b8d018 commit c07c97a

File tree

19 files changed

+187
-161
lines changed

19 files changed

+187
-161
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/mod.rs

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -545,79 +545,6 @@ pub struct IdentityMetadataUpdateParams {
545545
* Specific API resources
546546
*/
547547

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

nexus/Cargo.toml

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

38+
[dependencies.api_identity]
39+
path = "../api_identity"
40+
3841
[dependencies.chrono]
3942
version = "0.4"
4043
features = [ "serde" ]

nexus/src/db/datastore.rs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use super::identity::{Asset, Resource};
2424
use super::Pool;
2525
use crate::authz;
2626
use crate::context::OpContext;
27+
use crate::params;
2728
use async_bb8_diesel::{AsyncRunQueryDsl, ConnectionManager};
2829
use chrono::Utc;
2930
use diesel::{ExpressionMethods, QueryDsl, SelectableHelper};
@@ -320,7 +321,7 @@ impl DataStore {
320321
pub async fn organization_update(
321322
&self,
322323
name: &Name,
323-
update_params: &api::external::OrganizationUpdateParams,
324+
update_params: &params::OrganizationUpdate,
324325
) -> UpdateResult<Organization> {
325326
use db::schema::organization::dsl;
326327
let updates: OrganizationUpdate = update_params.clone().into();
@@ -496,7 +497,7 @@ impl DataStore {
496497
&self,
497498
organization_id: &Uuid,
498499
name: &Name,
499-
update_params: &api::external::ProjectUpdateParams,
500+
update_params: &params::ProjectUpdate,
500501
) -> UpdateResult<Project> {
501502
use db::schema::project::dsl;
502503
let updates: ProjectUpdate = update_params.clone().into();
@@ -1658,11 +1659,9 @@ mod test {
16581659
use crate::db::identity::Resource;
16591660
use crate::db::model::{ConsoleSession, Organization, Project};
16601661
use crate::db::DataStore;
1662+
use crate::params;
16611663
use chrono::{Duration, Utc};
1662-
use omicron_common::api::external::{
1663-
Error, IdentityMetadataCreateParams, OrganizationCreateParams,
1664-
ProjectCreateParams,
1665-
};
1664+
use omicron_common::api::external::{Error, IdentityMetadataCreateParams};
16661665
use omicron_test_utils::dev;
16671666
use std::sync::Arc;
16681667
use uuid::Uuid;
@@ -1676,7 +1675,7 @@ mod test {
16761675
let pool = db::Pool::new(&cfg);
16771676
let datastore = DataStore::new(Arc::new(pool));
16781677

1679-
let organization = Organization::new(OrganizationCreateParams {
1678+
let organization = Organization::new(params::OrganizationCreate {
16801679
identity: IdentityMetadataCreateParams {
16811680
name: "org".parse().unwrap(),
16821681
description: "desc".to_string(),
@@ -1687,7 +1686,7 @@ mod test {
16871686

16881687
let project = Project::new(
16891688
organization.id(),
1690-
ProjectCreateParams {
1689+
params::ProjectCreate {
16911690
identity: IdentityMetadataCreateParams {
16921691
name: "project".parse().unwrap(),
16931692
description: "desc".to_string(),

nexus/src/db/model.rs

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::db::schema::{
66
console_session, disk, instance, metric_producer, network_interface,
77
organization, oximeter, project, rack, sled, vpc, vpc_router, vpc_subnet,
88
};
9+
use crate::params;
910
use chrono::{DateTime, Utc};
1011
use db_macros::{Asset, Resource};
1112
use diesel::backend::{Backend, BinaryRawValue, RawValue};
@@ -339,7 +340,7 @@ pub struct Organization {
339340

340341
impl Organization {
341342
/// Creates a new database Organization object.
342-
pub fn new(params: external::OrganizationCreateParams) -> Self {
343+
pub fn new(params: params::OrganizationCreate) -> Self {
343344
let id = Uuid::new_v4();
344345
Self {
345346
identity: OrganizationIdentity::new(id, params.identity),
@@ -355,12 +356,6 @@ impl DatastoreCollection<Project> for Organization {
355356
type CollectionIdColumn = project::dsl::organization_id;
356357
}
357358

358-
impl Into<external::Organization> for Organization {
359-
fn into(self) -> external::Organization {
360-
external::Organization { identity: self.identity() }
361-
}
362-
}
363-
364359
/// Describes a set of updates for the [`Organization`] model.
365360
#[derive(AsChangeset)]
366361
#[table_name = "organization"]
@@ -370,8 +365,8 @@ pub struct OrganizationUpdate {
370365
pub time_modified: DateTime<Utc>,
371366
}
372367

373-
impl From<external::OrganizationUpdateParams> for OrganizationUpdate {
374-
fn from(params: external::OrganizationUpdateParams) -> Self {
368+
impl From<params::OrganizationUpdate> for OrganizationUpdate {
369+
fn from(params: params::OrganizationUpdate) -> Self {
375370
Self {
376371
name: params.identity.name.map(|n| n.into()),
377372
description: params.identity.description,
@@ -392,26 +387,14 @@ pub struct Project {
392387

393388
impl Project {
394389
/// Creates a new database Project object.
395-
pub fn new(
396-
organization_id: Uuid,
397-
params: external::ProjectCreateParams,
398-
) -> Self {
390+
pub fn new(organization_id: Uuid, params: params::ProjectCreate) -> Self {
399391
Self {
400392
identity: ProjectIdentity::new(Uuid::new_v4(), params.identity),
401393
organization_id: organization_id,
402394
}
403395
}
404396
}
405397

406-
impl Into<external::Project> for Project {
407-
fn into(self) -> external::Project {
408-
external::Project {
409-
identity: self.identity(),
410-
organization_id: self.organization_id,
411-
}
412-
}
413-
}
414-
415398
/// Describes a set of updates for the [`Project`] model.
416399
#[derive(AsChangeset)]
417400
#[table_name = "project"]
@@ -421,8 +404,8 @@ pub struct ProjectUpdate {
421404
pub time_modified: DateTime<Utc>,
422405
}
423406

424-
impl From<external::ProjectUpdateParams> for ProjectUpdate {
425-
fn from(params: external::ProjectUpdateParams) -> Self {
407+
impl From<params::ProjectUpdate> for ProjectUpdate {
408+
fn from(params: params::ProjectUpdate) -> Self {
426409
Self {
427410
name: params.identity.name.map(Name),
428411
description: params.identity.description,

nexus/src/http_entrypoints_external.rs renamed to nexus/src/external_api/http_entrypoints.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
* Handler functions (entrypoints) for external HTTP APIs
33
*/
44

5-
use super::ServerContext;
65
use crate::db;
76
use crate::db::model::Name;
7+
use crate::ServerContext;
88

9+
use super::views::{Organization, Project};
910
use crate::context::OpContext;
11+
use crate::params;
1012
use dropshot::endpoint;
1113
use dropshot::ApiDescription;
1214
use dropshot::HttpError;
@@ -38,13 +40,7 @@ use omicron_common::api::external::DiskAttachment;
3840
use omicron_common::api::external::DiskCreateParams;
3941
use omicron_common::api::external::Instance;
4042
use omicron_common::api::external::InstanceCreateParams;
41-
use omicron_common::api::external::Organization;
42-
use omicron_common::api::external::OrganizationCreateParams;
43-
use omicron_common::api::external::OrganizationUpdateParams;
4443
use omicron_common::api::external::PaginationOrder;
45-
use omicron_common::api::external::Project;
46-
use omicron_common::api::external::ProjectCreateParams;
47-
use omicron_common::api::external::ProjectUpdateParams;
4844
use omicron_common::api::external::Rack;
4945
use omicron_common::api::external::Saga;
5046
use omicron_common::api::external::Sled;
@@ -70,7 +66,7 @@ type NexusApiDescription = ApiDescription<Arc<ServerContext>>;
7066
/**
7167
* Returns a description of the external nexus API
7268
*/
73-
pub fn external_api() -> NexusApiDescription {
69+
pub fn api() -> NexusApiDescription {
7470
fn register_endpoints(api: &mut NexusApiDescription) -> Result<(), String> {
7571
api.register(organizations_get)?;
7672
api.register(organizations_post)?;
@@ -224,7 +220,7 @@ async fn organizations_get(
224220
}]
225221
async fn organizations_post(
226222
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
227-
new_organization: TypedBody<OrganizationCreateParams>,
223+
new_organization: TypedBody<params::OrganizationCreate>,
228224
) -> Result<HttpResponseCreated<Organization>, HttpError> {
229225
let apictx = rqctx.context();
230226
let nexus = &apictx.nexus;
@@ -307,7 +303,7 @@ async fn organizations_delete_organization(
307303
async fn organizations_put_organization(
308304
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
309305
path_params: Path<OrganizationPathParam>,
310-
updated_organization: TypedBody<OrganizationUpdateParams>,
306+
updated_organization: TypedBody<params::OrganizationUpdate>,
311307
) -> Result<HttpResponseOk<Organization>, HttpError> {
312308
let apictx = rqctx.context();
313309
let nexus = &apictx.nexus;
@@ -381,7 +377,7 @@ async fn organization_projects_get(
381377
async fn organization_projects_post(
382378
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
383379
path_params: Path<OrganizationPathParam>,
384-
new_project: TypedBody<ProjectCreateParams>,
380+
new_project: TypedBody<params::ProjectCreate>,
385381
) -> Result<HttpResponseCreated<Project>, HttpError> {
386382
let apictx = rqctx.context();
387383
let nexus = &apictx.nexus;
@@ -470,7 +466,7 @@ async fn organization_projects_delete_project(
470466
async fn organization_projects_put_project(
471467
rqctx: Arc<RequestContext<Arc<ServerContext>>>,
472468
path_params: Path<ProjectPathParam>,
473-
updated_project: TypedBody<ProjectUpdateParams>,
469+
updated_project: TypedBody<params::ProjectUpdate>,
474470
) -> Result<HttpResponseOk<Project>, HttpError> {
475471
let apictx = rqctx.context();
476472
let nexus = &apictx.nexus;

nexus/src/external_api/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
pub mod http_entrypoints;
2+
pub mod views;

nexus/src/external_api/views.rs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*!
2+
* Views are public lenses onto the DB models.
3+
*
4+
* Views let us define what fields from the models will be serialized out in
5+
* API responses.
6+
*/
7+
8+
use crate::db::identity::Resource;
9+
use crate::db::model;
10+
use api_identity::ObjectIdentity;
11+
use omicron_common::api::external::{IdentityMetadata, ObjectIdentity};
12+
use schemars::JsonSchema;
13+
use serde::{Deserialize, Serialize};
14+
use uuid::Uuid;
15+
16+
/*
17+
* ORGANIZATIONS
18+
*/
19+
20+
/**
21+
* Client view of an [`Organization`]
22+
*/
23+
#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)]
24+
#[serde(rename_all = "camelCase")]
25+
pub struct Organization {
26+
#[serde(flatten)]
27+
pub identity: IdentityMetadata,
28+
}
29+
30+
impl Into<Organization> for model::Organization {
31+
fn into(self) -> Organization {
32+
Organization { identity: self.identity() }
33+
}
34+
}
35+
36+
/*
37+
* PROJECTS
38+
*/
39+
40+
/**
41+
* Client view of an [`Project`]
42+
*/
43+
#[derive(ObjectIdentity, Clone, Debug, Deserialize, Serialize, JsonSchema)]
44+
#[serde(rename_all = "camelCase")]
45+
pub struct Project {
46+
/*
47+
* TODO-correctness is flattening here (and in all the other types) the
48+
* intent in RFD 4?
49+
*/
50+
#[serde(flatten)]
51+
pub identity: IdentityMetadata,
52+
pub organization_id: Uuid,
53+
}
54+
55+
impl Into<Project> for model::Project {
56+
fn into(self) -> Project {
57+
Project {
58+
identity: self.identity(),
59+
organization_id: self.organization_id,
60+
}
61+
}
62+
}

nexus/src/http_entrypoints_internal.rs renamed to nexus/src/internal_api/http_entrypoints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
22
* Handler functions (entrypoints) for HTTP APIs internal to the control plane
33
*/
4-
use super::ServerContext;
4+
use crate::ServerContext;
55

66
use dropshot::endpoint;
77
use dropshot::ApiDescription;
@@ -28,7 +28,7 @@ type NexusApiDescription = ApiDescription<Arc<ServerContext>>;
2828
/**
2929
* Returns a description of the internal nexus API
3030
*/
31-
pub fn internal_api() -> NexusApiDescription {
31+
pub fn api() -> NexusApiDescription {
3232
fn register_endpoints(api: &mut NexusApiDescription) -> Result<(), String> {
3333
api.register(cpapi_sled_agents_post)?;
3434
api.register(cpapi_instances_put)?;

nexus/src/internal_api/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub mod http_entrypoints;

0 commit comments

Comments
 (0)