-
Notifications
You must be signed in to change notification settings - Fork 504
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
feat: auth project support #1504
Conversation
cf65262
to
59b456f
Compare
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeProject.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeProject.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
address other comments.
1a4ce69
to
4728cd4
Compare
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
createProject("test_project", "this is a good project"); | ||
} | ||
|
||
public String createProject(String name, String desc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
set private static and move the method to the bottom of the class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this method need use client that is a field of object, so may i replace public to private
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/api/ProjectApiTest.java
Outdated
Show resolved
Hide resolved
8442b8b
to
07e9516
Compare
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeProject.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/api/ProjectApiTest.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java
Outdated
Show resolved
Hide resolved
35458ce
to
a61006f
Compare
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeProject.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
28b7d3c
to
dafa78e
Compare
@@ -76,7 +76,8 @@ public String create(@Context GraphManager manager, | |||
HugeGraph g = graph(manager, graph); | |||
HugeProject project = jsonTarget.build(); | |||
Id projectId = manager.authManager().createProject(project); | |||
// Some fields of project be known must be after create | |||
// Some fields of project(like admin_group ) can only be known after | |||
// created |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect "/*" for comment with multi lines
@@ -557,7 +557,7 @@ public Id updateProject(HugeProject project) { | |||
E.checkArgumentNotNull(project.id(), | |||
"The project's id can't be null"); | |||
E.checkArgument(project.description() != null, | |||
"the project's '%s' description can't be null", | |||
"The project's '%s' description can't be null", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep the same style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean use "The project's '%s' " this style to other places?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
common style is "The description of project '%s' can't be null"
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/StandardAuthManager.java
Outdated
Show resolved
Hide resolved
@@ -46,8 +46,9 @@ public void testCreate() { | |||
} | |||
|
|||
private String createProject(String name, String desc) { | |||
String reqBody = String.format("{\"name\": \"%s\",\"desc\": \"%s\"}", | |||
name, desc); | |||
String reqBody = String.format("{\"project_name\": \"%s\"," + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to body or request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this params is a request body, so i named it reqBody
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
refer to VertexApiTest/EdgeApiTest
return ACTION_DELETE_GRAPH.equals(action); | ||
} | ||
|
||
private static class JsonTarget implements Checkable { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JsonTarget => JsonProject
@Override | ||
public void checkCreate(boolean isBatch) { | ||
E.checkArgumentNotNull(this.name, | ||
"The project's name can't be null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this code already aligned here, Do you mean something else?
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/auth/HugeProject.java
Outdated
Show resolved
Hide resolved
@@ -54,6 +54,7 @@ | |||
private final HugeGraphParams graph; | |||
private final String label; | |||
private final Function<Edge, T> deser; | |||
private final ThreadLocal<Boolean> shouldCommitTrans = new ThreadLocal<>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rename to autoCommit
E.checkArgumentNotNull(oldProject, | ||
"The project with id '%s' " + | ||
"can't be found", id); | ||
// Check not graph bind this project |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve "Check not graph bind this project"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Check whether there are any graph binding this project, throw ForbiddenException, if it is
d7aa42b
to
534692c
Compare
Codecov Report
@@ Coverage Diff @@
## master #1504 +/- ##
============================================
+ Coverage 59.65% 59.82% +0.16%
- Complexity 6153 6209 +56
============================================
Files 410 412 +2
Lines 33272 33603 +331
Branches 4590 4618 +28
============================================
+ Hits 19850 20104 +254
- Misses 11349 11400 +51
- Partials 2073 2099 +26
Continue to review full report at Codecov.
|
} | ||
project = jsonProject.build(action, project); | ||
if (this.isAddGraph(action)) { | ||
authManager.updateProjectAddGraph(projectId, jsonProject.graph); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add method jsonProject.graph()
private static class JsonProject implements Checkable { | ||
|
||
@JsonProperty("project_description") | ||
private String description; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to line 187
@JsonProperty("project_name") | ||
private String name; | ||
@JsonProperty("project_graph") | ||
private String graph; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
graphs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently only one graph needs to be updated or deleted, so here is singular
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep consistency between server response and client request
} else if (this.isRemoveGraph(action)) { | ||
authManager.updateProjectRemoveGraph(projectId, jsonProject.graph); | ||
} else { | ||
authManager.updateProject(project); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
checkUpdate
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The check logic is in the method "JsonProject.build", so there is no need to call the method "checkUpdate" here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect to check params for each action
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the action param is empty
private String name; | ||
private String desc; | ||
private Id adminGroupId; | ||
private Id opGroupId; | ||
private Set<String> graphs; | ||
private Id targetId; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve order
this.graph.name(), | ||
"localhost:8080", | ||
ImmutableList.of(resource)); | ||
target.creator(project.creator()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"creator" is a parameter. I see that when other places are created, the method "AuthManagerProxy.updateCreator" is called, so to be consistent, I also update "creator" when I create it.
|
||
HugeProject oldProject = this.project.get(id); | ||
E.checkArgumentNotNull(oldProject, | ||
"The project '%s' can't be found", id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
improve it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe change to "The project '%s' not found"?
id); | ||
E.checkArgument(project.adminGroupId() != null, | ||
"Failed to delete the project '%s'," + | ||
"the admin group id of project can't be null", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the admin group of project
id); | ||
E.checkArgument(project.opGroupId() != null, | ||
"Failed to delete the project '%s'," + | ||
"the op group id of project can't be null", id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the op group of project
"the op group id of project can't be null", id); | ||
E.checkArgument(project.targetId() != null, | ||
"Failed to delete the project '%s', " + | ||
"the target id of project can't be null", id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the target resource of project
} else if (this.isRemoveGraph(action)) { | ||
authManager.updateProjectRemoveGraph(projectId, jsonProject.graph); | ||
} else { | ||
authManager.updateProject(project); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
expect to check params for each action
} else if (this.isRemoveGraph(action)) { | ||
authManager.updateProjectRemoveGraph(projectId, jsonProject.graph); | ||
} else { | ||
authManager.updateProject(project); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check the action param is empty
@JsonProperty("project_name") | ||
private String name; | ||
@JsonProperty("project_graph") | ||
private String graph; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
keep consistency between server response and client request
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
public String opGroupName() { | ||
return "op_" + this.name; | ||
} | ||
|
||
public String adminGroupName() { | ||
return "admin_" + this.name; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can move into createProject() method
hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/core/AuthTest.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java
Outdated
Show resolved
Hide resolved
hugegraph-test/src/main/java/com/baidu/hugegraph/unit/core/RolePermissionTest.java
Outdated
Show resolved
Hide resolved
4e51d5f
to
27e05b9
Compare
hugegraph-test/src/main/java/com/baidu/hugegraph/api/ProjectApiTest.java
Outdated
Show resolved
Hide resolved
hugegraph-core/src/main/java/com/baidu/hugegraph/util/ObjectUtils.java
Outdated
Show resolved
Hide resolved
hugegraph-api/src/main/java/com/baidu/hugegraph/api/auth/ProjectAPI.java
Outdated
Show resolved
Hide resolved
74835fa
to
bea69b4
Compare
this.action); | ||
E.checkArgument(!CollectionUtils.isEmpty(this.graphs) || | ||
this.description != null, | ||
"Must specify the fields 'graphs/description' " + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
specify 'graphs' or 'description' field
No description provided.