Skip to content

Integrate orgs and projects#325

Merged
teisenbe merged 40 commits into
mainfrom
integrate-orgs-and-projects
Oct 27, 2021
Merged

Integrate orgs and projects#325
teisenbe merged 40 commits into
mainfrom
integrate-orgs-and-projects

Conversation

@teisenbe

Copy link
Copy Markdown
Contributor

Introduce the notion of projects belonging to organizations. This has broad impacts on our API routes, as mentioned in #308.

Resolves #308

@teisenbe teisenbe requested a review from davepacheco October 20, 2021 18:46
@teisenbe

Copy link
Copy Markdown
Contributor Author

Hmm, I did something slightly wrong at least, since it grabbed the authn stuff. I think what happened was I merged main into the CTE branch but forgot to push, and then pushed this branch. I'll see if I can disentangle

@teisenbe teisenbe changed the base branch from child-resource-insert-cte to main October 20, 2021 18:50
@teisenbe teisenbe changed the base branch from main to child-resource-insert-cte October 20, 2021 18:50
@teisenbe

Copy link
Copy Markdown
Contributor Author

Okay, looks good now

Comment thread nexus/src/db/datastore.rs
.await
.map_err(|e| {
let organization_id = project.organization_id;
Organization::insert_resource(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of refactoring noise in this PR so it's easy to miss, but this is really slick. I love that this block is clear for readers, handles the concurrency issues, and produces a useful error for the various cases! Thanks again for doing this.

Comment thread nexus/src/db/datastore.rs
path = "/organizations/{organization_name}/projects/{project_name}",
}]
async fn projects_put_project(
async fn organization_projects_put_project(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make sense to prepend the "organization_" prefix to these endpoints? Kinda seems like we should keep the old naming scheme for these functions - technically everything is nested under "organization", so it gets kinda noisy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine dropping it. I was following the scheme that seemed to already be present on things like instances and disks

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the current scheme is documented in the file. I think it'd be worthwhile that we stick with some consistent, predictable naming scheme, especially since the names show up in the generated clients and changing the names requires clients to make code changes. That scheme doesn't have to match what we do today.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, this was documented as {collection_path}_{verb}_{object}.

It's not clear if "collection_path" is meant to be the whole path, or only the "outermost collection".

  • If it's the full path, we would need to add the organization_ prefix to all endpoints. As an example, we'd want project_disks_post to become organizations_projects_disk_post, but that seems... wordy.
  • If it's the "outermost collection: I think organization_put_project makes more sense than organization_projects_put_project - the inner "project" is implied.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a strong opinion on this? I'd be inclined to leave it to a later refactor (since I think it also has implications for other endpoint names)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I'd make it a separate PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Could do it together with organizations -> orgs)

@teisenbe

Copy link
Copy Markdown
Contributor Author

I think I forgot to ping this last week, this should be ready for review

Comment thread nexus/tests/test_projects.rs Outdated
// child-resource generation number
let org_after_p1_creation =
datastore.organization_fetch(&make_name(org_name)).await.unwrap();
assert!(org_after_p1_creation.rcgen > org_after_creation.rcgen);

@david-crespo david-crespo Oct 26, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could you do without create_datastore by using nexus here

let nexus = &cptestctx.server.apictx.nexus;
let org_after_creation =
    nexus.organization_fetch(&make_name(org_name)).await.unwrap();

On one hand I can see why you'd want to talk to directly to the DB and avoid any indirection the Nexus wrapper might introduce. On the other hand I have a slight bias against doing asserts about internal implementation details from an integration test if possible, and if those were moved elsewhere it makes the question of talking to the DB moot.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'll move this to a test within the datastore.rs I think

Comment thread nexus/src/db/model.rs
type CollectionTimeDeletedColumn = organization::dsl::time_deleted;
type CollectionIdColumn = project::dsl::organization_id;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is so clean 👌 👌 👌 👌

@david-crespo david-crespo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks for doing all this. I don't have a strong opinion about the datastore in integration test comment, just curious about your thoughts.

Base automatically changed from child-resource-insert-cte to main October 27, 2021 17:16
@teisenbe teisenbe merged commit 4466bee into main Oct 27, 2021
@teisenbe teisenbe deleted the integrate-orgs-and-projects branch October 27, 2021 19:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Project endpoints should be hierarchically beneath organization endpoints

4 participants