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

[#2235][part-1] feat(api,core): Add the role entity #2772

Merged
merged 42 commits into from
Apr 15, 2024

Conversation

qqqttt123
Copy link
Contributor

@qqqttt123 qqqttt123 commented Apr 2, 2024

What changes were proposed in this pull request?

This pull request adds the role entity and one privilege.
I avoid to create a large pull request. I will add more privileges in the later pull request.

Why are the changes needed?

Fix: #2235

Does this PR introduce any user-facing change?

No.

How was this patch tested?

new ut.

@qqqttt123 qqqttt123 marked this pull request as draft April 2, 2024 07:02
@qqqttt123 qqqttt123 force-pushed the ISSUE-2235_feat branch 4 times, most recently from 3516475 to c76cd2e Compare April 2, 2024 09:20
String simpleString();

/** The name of this privilege. */
enum Name {
Copy link
Contributor Author

@qqqttt123 qqqttt123 Apr 2, 2024

Choose a reason for hiding this comment

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

We only list parts of privileges to avoid a too large pull request. The extra privileges will be submitted by another pull request.

@qqqttt123 qqqttt123 force-pushed the ISSUE-2235_feat branch 6 times, most recently from d567611 to 65a1916 Compare April 2, 2024 10:40
@qqqttt123 qqqttt123 force-pushed the ISSUE-2235_feat branch 2 times, most recently from 5e1f6b1 to 7715876 Compare April 2, 2024 11:40
@qqqttt123 qqqttt123 changed the title [WIP] Add the role entity [#2235][WIP] feat(core): Add the role entity Apr 7, 2024
@qqqttt123 qqqttt123 changed the title [#2235][WIP] feat(core): Add the role entity [#2235][WIP] feat(api,core): Add the role entity Apr 7, 2024
@qqqttt123 qqqttt123 changed the title [#2235][WIP] feat(api,core): Add the role entity [#2235][part-1] feat(api,core): Add the role entity Apr 7, 2024
@qqqttt123 qqqttt123 self-assigned this Apr 7, 2024
@qqqttt123 qqqttt123 requested a review from jerryshao April 7, 2024 12:52
@qqqttt123 qqqttt123 marked this pull request as ready for review April 7, 2024 13:07
Heng Qin added 2 commits April 15, 2024 11:29
* The resource is the entity of the authorization. Gravitino organizes the resources using tree
* structure. The resource may be a catalog, a table or a schema, etc. For example,
* `catalog1.schema1.table1` represents a table named `table1`. It's in the schema named `schema1`.
* The schema is in the catalog named `catalog1`.
Copy link
Contributor

Choose a reason for hiding this comment

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

How do you represent the resources with name "*", would you please add more comments about the different types of resources and how you define them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I moved some comments from other places.

*
* @return The parent resource.
*/
Resource parent();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you tag this method as @Nullable?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

+ " If you want to create an another resource which represents all entities,"
+ " you can use its parent entity, For example,"
+ " if you want to have read table privileges of all tables of `catalog1.schema1`,"
+ " you can use add `read table` privilege for `catalog1.schema1` directly");
Copy link
Contributor

@jerryshao jerryshao Apr 15, 2024

Choose a reason for hiding this comment

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

Frankly saying, It's weird to add table privilege to the schema, it will confuse the users. Why do you hesitate to use "*"?

Copy link
Contributor Author

@qqqttt123 qqqttt123 Apr 15, 2024

Choose a reason for hiding this comment

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

Now, we give a resource a privileges list. It's a little weird to add load catalog and load schema privilege to catalog1.*.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Databricks follows similar style. Parent doesn't use *. https://docs.databricks.com/en/sql/language-manual/sql-ref-privileges.html

* @param names The names of the resource
* @return The created {@link Resource}
*/
public static Resource of(String... names) {
Copy link
Contributor

Choose a reason for hiding this comment

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

How do users use this Resource concept, what is the relationship to the catalogs, schemas, and tables? I think the introduction of Resource increase the understanding burden to users, users may not know how to use it, I was thinking if there's a better way to clearly define it, which will be easy for users to use.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about letting me user pass the names like
ofCatalog. ofCatalog.ofSchema.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Databricks has the similar concept securable objects .
Snowflake use securable object, too. I will change the name to securable object.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@@ -292,6 +292,10 @@ public Catalog createCatalog(
throw new IllegalArgumentException("Can't create a catalog with with reserved name `system`");
}

if (Entity.RESOURCE_ENTITY_RESERVED_NAME.equals(ident.name())) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is the basic name constraint for entities, better to let @mchades know about this and do it using Capability framework.

@qqqttt123 qqqttt123 requested a review from jerryshao April 15, 2024 09:21
@Override
public String toString() {
if (parent != null) {
return parent + "." + name;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you explicitly write like parent.toString() + "." + name to let others know that this method is recursive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Contributor

@jerryshao jerryshao left a comment

Choose a reason for hiding this comment

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

LGTM.

@jerryshao jerryshao merged commit 64bf339 into apache:main Apr 15, 2024
22 checks passed
@qqqttt123 qqqttt123 deleted the ISSUE-2235_feat branch April 15, 2024 11:13
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.

[Subtask] Add a new entity for role
3 participants