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

feat: auth project support #1504

Merged
merged 19 commits into from
Jul 7, 2021
Merged

feat: auth project support #1504

merged 19 commits into from
Jul 7, 2021

Conversation

zyxxoo
Copy link
Contributor

@zyxxoo zyxxoo commented Jun 17, 2021

No description provided.

@zyxxoo zyxxoo force-pushed the zy_auth_project branch 4 times, most recently from cf65262 to 59b456f Compare June 17, 2021 11:16
Copy link
Contributor

@javeme javeme left a comment

Choose a reason for hiding this comment

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

address other comments.

@zyxxoo zyxxoo force-pushed the zy_auth_project branch 2 times, most recently from 1a4ce69 to 4728cd4 Compare June 18, 2021 12:03
createProject("test_project", "this is a good project");
}

public String createProject(String name, String desc) {
Copy link
Contributor

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

Copy link
Contributor Author

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

@zyxxoo zyxxoo changed the title feat: add hugeProject java api suppport feat: auth project support Jun 21, 2021
@zyxxoo zyxxoo force-pushed the zy_auth_project branch 2 times, most recently from 8442b8b to 07e9516 Compare June 21, 2021 11:02
@zyxxoo zyxxoo force-pushed the zy_auth_project branch 2 times, most recently from 35458ce to a61006f Compare June 22, 2021 06:58
@zyxxoo zyxxoo force-pushed the zy_auth_project branch 5 times, most recently from 28b7d3c to dafa78e Compare June 22, 2021 11:47
@@ -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
Copy link
Contributor

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",
Copy link
Contributor

Choose a reason for hiding this comment

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

keep the same style

Copy link
Contributor Author

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?

Copy link
Contributor

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"

@@ -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\"," +
Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

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 {
Copy link
Contributor

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");
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

@zyxxoo zyxxoo Jun 24, 2021

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?

@@ -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<>();
Copy link
Contributor

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
Copy link
Contributor

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"

Copy link
Contributor Author

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

@zyxxoo zyxxoo force-pushed the zy_auth_project branch 3 times, most recently from d7aa42b to 534692c Compare June 24, 2021 13:06
@codecov
Copy link

codecov bot commented Jun 24, 2021

Codecov Report

Merging #1504 (d9de8c6) into master (4cb4348) will increase coverage by 0.16%.
The diff coverage is 85.02%.

Impacted file tree graph

@@             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     
Impacted Files Coverage Δ
...in/java/com/baidu/hugegraph/auth/HugeResource.java 79.22% <ø> (ø)
...a/com/baidu/hugegraph/auth/HugeGraphAuthProxy.java 58.03% <70.00%> (+0.69%) ⬆️
.../com/baidu/hugegraph/auth/StandardAuthManager.java 93.06% <84.61%> (-4.44%) ⬇️
...ain/java/com/baidu/hugegraph/auth/HugeProject.java 85.24% <85.24%> (ø)
.../com/baidu/hugegraph/auth/RelationshipManager.java 80.00% <85.71%> (-1.64%) ⬇️
.../java/com/baidu/hugegraph/api/auth/ProjectAPI.java 86.95% <86.95%> (ø)
...n/java/com/baidu/hugegraph/version/ApiVersion.java 75.00% <100.00%> (ø)
...n/java/com/baidu/hugegraph/auth/EntityManager.java 92.20% <100.00%> (+2.06%) ⬆️
...in/java/com/baidu/hugegraph/auth/ResourceType.java 93.61% <100.00%> (+0.13%) ⬆️
...c/main/java/com/baidu/hugegraph/util/LockUtil.java 84.93% <100.00%> (+0.20%) ⬆️
... and 14 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4cb4348...d9de8c6. Read the comment docs.

corgiboygsj
corgiboygsj previously approved these changes Jul 2, 2021
}
project = jsonProject.build(action, project);
if (this.isAddGraph(action)) {
authManager.updateProjectAddGraph(projectId, jsonProject.graph);
Copy link
Contributor

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;
Copy link
Contributor

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;
Copy link
Contributor

Choose a reason for hiding this comment

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

graphs

Copy link
Contributor Author

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

Copy link
Contributor

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

checkUpdate

Copy link
Contributor Author

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

Copy link
Contributor

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

Copy link
Contributor

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

Comment on lines 46 to 51
private String name;
private String desc;
private Id adminGroupId;
private Id opGroupId;
private Set<String> graphs;
private Id targetId;
Copy link
Contributor

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());
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto

Copy link
Contributor Author

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);
Copy link
Contributor

Choose a reason for hiding this comment

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

improve it

Copy link
Contributor Author

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",
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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);
Copy link
Contributor

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;
Copy link
Contributor

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

Comment on lines 86 to 92
public String opGroupName() {
return "op_" + this.name;
}

public String adminGroupName() {
return "admin_" + this.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 move into createProject() method

@zyxxoo zyxxoo force-pushed the zy_auth_project branch 6 times, most recently from 4e51d5f to 27e05b9 Compare July 5, 2021 12:43
@zyxxoo zyxxoo force-pushed the zy_auth_project branch 3 times, most recently from 74835fa to bea69b4 Compare July 7, 2021 05:40
this.action);
E.checkArgument(!CollectionUtils.isEmpty(this.graphs) ||
this.description != null,
"Must specify the fields 'graphs/description' " +
Copy link
Contributor

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

@javeme javeme merged commit 6bff777 into master Jul 7, 2021
@javeme javeme deleted the zy_auth_project branch July 7, 2021 06:35
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.

None yet

3 participants