Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup: Use policy name to fetch status #1105

Merged
merged 2 commits into from
Oct 5, 2023
Merged

cleanup: Use policy name to fetch status #1105

merged 2 commits into from
Oct 5, 2023

Conversation

JAORMX
Copy link
Contributor

@JAORMX JAORMX commented Oct 4, 2023

This uses the policy name in order to fetch the status. This is a lot
more user friendly than relying on the ID.

To enable this, I added a constraint for a combination of project ID and name
to be unique in the database.

This uses the policy name in order to fetch the status. This is a lot
more user friendly than relying on the ID.

To enable this, I added a constraint for a combination of project ID and name
to be unique in the database.
It's redundant as we provided the name when getting the status for it
option (google.api.http) = {
get: "/api/v1/policy/{policy_id}/status"
get: "/api/v1/policy/name/{name}/status"
Copy link
Member

Choose a reason for hiding this comment

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

Why is it necessary to have name explicitly as part of the path?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Else the JSON API wouldn't work. We probably want to revisit our API and clean this all up as well

Copy link
Member

Choose a reason for hiding this comment

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

Wait -- why wouldn't the JSON API work? Was there a conflict?

It feels like we should adjust GetPolicyById and DeletePolicy to use the same name format.

Copy link
Member

@evankanderson evankanderson left a comment

Choose a reason for hiding this comment

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

A few comments, but don't let me stand in the way of progress.

I am somewhat concerned about the patterns in our REST API -- for example, creating a policy is POST /api/v1/policy, while listing the things you just created is GET /api/v1/policies (note the plural). I know that Kubernetes did the pluralization thing and it's really cute, but I think it's probably also fundamentally a mistake (certainly, the Kubernetes layer for getting this right is way more complex than you'd hope for).

@@ -188,6 +188,8 @@ CREATE TABLE policies (
FOREIGN KEY (project_id, provider) REFERENCES providers(project_id, name) ON DELETE CASCADE
);

CREATE UNIQUE INDEX ON policies(project_id, name);
Copy link
Member

Choose a reason for hiding this comment

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

I had a preference for UNIQUE (project_id, name), but reading https://www.postgresql.org/docs/current/sql-altertable.html#SQL-ALTERTABLE-DESC-ADD-TABLE-CONSTRAINT-USING-INDEX suggests that we may need care to use ALTER TABLE ADD UNIQUE (project_id, name) later.

Copy link
Member

Choose a reason for hiding this comment

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

I seem to recall that previously we implicitly had this through the provider, name index implicitly including the project_id in the provider. Are we intentionally breaking that now? And, do we need defensive code in the application to ensure that provider.project_id is a parent (or self) of project_id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@evankanderson I don't see how that breaks, just above you can still see the:

    FOREIGN KEY (project_id, provider) REFERENCES providers(project_id, name) ON DELETE CASCADE

option (google.api.http) = {
get: "/api/v1/policy/{policy_id}/status"
get: "/api/v1/policy/name/{name}/status"
Copy link
Member

Choose a reason for hiding this comment

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

Wait -- why wouldn't the JSON API work? Was there a conflict?

It feels like we should adjust GetPolicyById and DeletePolicy to use the same name format.

@JAORMX
Copy link
Contributor Author

JAORMX commented Oct 5, 2023

A few comments, but don't let me stand in the way of progress.

I am somewhat concerned about the patterns in our REST API -- for example, creating a policy is POST /api/v1/policy, while listing the things you just created is GET /api/v1/policies (note the plural). I know that Kubernetes did the pluralization thing and it's really cute, but I think it's probably also fundamentally a mistake (certainly, the Kubernetes layer for getting this right is way more complex than you'd hope for).

I'm not super keen on those inconsistencies either and I have more concerns on the complete randomness of the API. That's actually what brought my comment from yesterday about downgrading to v1beta1 or even v1alpha1`. We really need a dedicated time to sit down, rethink and plan these.

@JAORMX
Copy link
Contributor Author

JAORMX commented Oct 5, 2023

Wait -- why wouldn't the JSON API work? Was there a conflict?
It feels like we should adjust GetPolicyById and DeletePolicy to use the same name format.

I needed to remove policy_id from the URL since it's no longer used, and buf wouldn't compile the open API spec. In reality, we also need to figure out what the name-driven approach will mean in our APIs.

@JAORMX
Copy link
Contributor Author

JAORMX commented Oct 5, 2023

@evankanderson in the meantime, I'll merge this and will follow up on a more general API cleanup approach.

@JAORMX JAORMX merged commit a26cba3 into main Oct 5, 2023
13 checks passed
@JAORMX JAORMX deleted the status-pol-name branch October 5, 2023 05:20
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.

3 participants