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(client): Implement new api & optimize code structure #63

Merged
merged 42 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
afb5048
test
Aug 6, 2024
f2303e9
refactor
afterimagex Aug 7, 2024
17e5bec
Draft Version
Aug 7, 2024
a567d6d
refactor & add huge_router.py
Aug 7, 2024
7f2e9ce
stash
Aug 7, 2024
c87ddf8
tested version
Aug 8, 2024
1c612a7
fix getEdgeLabel bug
Aug 8, 2024
7a814d0
beta version
Aug 8, 2024
f4db12c
add long
afterimagex Aug 8, 2024
2ff7bd4
hugegraph-python-client: Update for GraphSpace compatibility and API …
afterimagex Aug 8, 2024
b325f3d
log: add a log function in client
imbajin Aug 8, 2024
0277182
fix metric api bug
Aug 9, 2024
bb15f05
fix bug
Aug 9, 2024
6d60a6e
apply log & add pylint: disable=unused-argument
Aug 9, 2024
919536f
add api:rebuild
Aug 9, 2024
e76b65e
add rebuild
Aug 9, 2024
ba0a9cc
add api:services
afterimagex Aug 9, 2024
2fa182f
update & fix some index label bugs
Aug 12, 2024
6744c1a
fix http request bug
Aug 12, 2024
102cf79
update
Aug 12, 2024
f250aa3
update
Aug 12, 2024
ecd3d6d
update
Aug 12, 2024
0d507b4
Merge branch 'py-client-new' into v3t
afterimagex Aug 12, 2024
cc59639
fix dataclass bug
Aug 12, 2024
81d5004
run ci
Aug 13, 2024
79ba9fb
Merge branch 'v3' into v3t
afterimagex Aug 13, 2024
0c0070d
update
Aug 13, 2024
47d039e
add registry for router
Aug 13, 2024
1b10627
line-too-long
Aug 13, 2024
bff8f71
fix line-too-long
Aug 13, 2024
7b3d1c2
fix line-too-long
Aug 13, 2024
6e647ae
fix unbound method call
Aug 13, 2024
f96c77a
update README.md
Aug 13, 2024
950a46f
update README.md
Aug 13, 2024
14650f3
update
Aug 13, 2024
542f681
pylint: disable=unbound-method-call-no-value-for-parameter
Aug 13, 2024
ce12d46
disable E1120
Aug 13, 2024
8bfc21c
fix pylint
Aug 13, 2024
8d00f58
fix pylint
Aug 13, 2024
7c3b669
fix pylint
Aug 13, 2024
af1b85e
fix: extra f'str & update README
imbajin Aug 13, 2024
8d3ec49
reorder client args
Aug 13, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion hugegraph-python-client/README.md
afterimagex marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ release soon
```python
from pyhugegraph.client import PyHugeClient

client = PyHugeClient("127.0.0.1", "8080", user="admin", pwd="admin", graph="hugegraph")
client = PyHugeClient("127.0.0.1", "8080", user="admin", pwd="admin", graph="hugegraph", gs="DEFAULT")
Copy link
Member

Choose a reason for hiding this comment

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

  • add a comment for this line (like gs is optional)
  • currently gs compatible with graphspace? (set as alias)


"""system"""
print(client.get_graphinfo())
Expand Down
277 changes: 124 additions & 153 deletions hugegraph-python-client/src/pyhugegraph/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,227 +18,198 @@

import json

from typing import Optional, Dict
from pyhugegraph.api.common import HugeParamsBase
from pyhugegraph.utils.exceptions import NotFoundError
from pyhugegraph.utils import huge_router as router
from pyhugegraph.utils.util import check_if_success


class AuthManager(HugeParamsBase):

@router.http("GET", "auth/users")
def list_users(self, limit=None):
params = {"limit": limit} if limit is not None else {}
response = self._invoke_request(params=params)
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return []
return self._invoke_request(params=params)

@router.http("POST", "auth/users")
def create_user(self, user_name, user_password, user_phone=None, user_email=None):
data = {
"user_name": user_name,
"user_password": user_password,
"user_phone": user_phone,
"user_email": user_email,
}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def create_user(
self, user_name, user_password, user_phone=None, user_email=None
) -> Optional[Dict]:
return self._invoke_request(
data=json.dumps(
{
"user_name": user_name,
"user_password": user_password,
"user_phone": user_phone,
"user_email": user_email,
}
)
)

@router.http("DELETE", "auth/users/{user_id}")
def delete_user(self, user_id):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
if response.status_code != 204:
return response.json()
return {}
def delete_user(self, user_id) -> Optional[Dict]: # pylint: disable=unused-argument
return self._invoke_request()

@router.http("PUT", "auth/users/{user_id}")
def modify_user(
self,
user_id,
user_id, # pylint: disable=unused-argument
user_name=None,
user_password=None,
user_phone=None,
user_email=None,
):
data = {
"user_name": user_name,
"user_password": user_password,
"user_phone": user_phone,
"user_email": user_email,
}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
) -> Optional[Dict]:
return self._invoke_request(
data=json.dumps(
{
"user_name": user_name,
"user_password": user_password,
"user_phone": user_phone,
"user_email": user_email,
}
)
)

@router.http("GET", "auth/users/{user_id}")
def get_user(self, user_id):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def get_user(self, user_id) -> Optional[Dict]: # pylint: disable=unused-argument
return self._invoke_request()

@router.http("GET", "auth/groups")
def list_groups(self, limit=None):
def list_groups(self, limit=None) -> Optional[Dict]:
params = {"limit": limit} if limit is not None else {}
response = self._invoke_request(params=params)
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return []
return self._invoke_request(params=params)

@router.http("POST", "auth/groups")
def create_group(self, group_name, group_description=None):
def create_group(self, group_name, group_description=None) -> Optional[Dict]:
data = {"group_name": group_name, "group_description": group_description}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
return self._invoke_request(data=json.dumps(data))

@router.http("DELETE", "auth/groups/{group_id}")
def delete_group(self, group_id):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
if response.status_code != 204:
return response.json()
return {}
def delete_group(
self, group_id # pylint: disable=unused-argument
) -> Optional[Dict]:
return self._invoke_request()

@router.http("PUT", "auth/groups/{group_id}")
def modify_group(self, group_id, group_name=None, group_description=None):
def modify_group(
self,
group_id, # pylint: disable=unused-argument
group_name=None,
group_description=None,
) -> Optional[Dict]:
data = {"group_name": group_name, "group_description": group_description}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
return self._invoke_request(data=json.dumps(data))

@router.http("GET", "auth/groups/{group_id}")
def get_group(self, group_id):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def get_group(self, group_id) -> Optional[Dict]: # pylint: disable=unused-argument
return self._invoke_request()

@router.http("POST", "auth/accesses")
def grant_accesses(self, group_id, target_id, access_permission):
data = {
"group": group_id,
"target": target_id,
"access_permission": access_permission,
}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def grant_accesses(self, group_id, target_id, access_permission) -> Optional[Dict]:
return self._invoke_request(
data=json.dumps(
{
"group": group_id,
"target": target_id,
"access_permission": access_permission,
}
)
)

@router.http("DELETE", "auth/accesses/{access_id}")
def revoke_accesses(self, access_id):
response = self._invoke_request()
check_if_success(response, NotFoundError(response.content))
def revoke_accesses(
self, access_id # pylint: disable=unused-argument
) -> Optional[Dict]:
return self._invoke_request()

@router.http("PUT", "auth/accesses/{access_id}")
def modify_accesses(self, access_id, access_description):
def modify_accesses(
self, access_id, access_description # pylint: disable=unused-argument
) -> Optional[Dict]:
# The permission of access can\'t be updated
data = {"access_description": access_description}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
return self._invoke_request(data=json.dumps(data))

@router.http("GET", "auth/accesses/{access_id}")
def get_accesses(self, access_id):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def get_accesses(
self, access_id # pylint: disable=unused-argument
) -> Optional[Dict]:
return self._invoke_request()

@router.http("GET", "auth/accesses")
def list_accesses(self):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def list_accesses(self) -> Optional[Dict]:
return self._invoke_request()

@router.http("POST", "auth/targets")
def create_target(self, target_name, target_graph, target_url, target_resources):
data = {
"target_name": target_name,
"target_graph": target_graph,
"target_url": target_url,
"target_resources": target_resources,
}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def create_target(
self, target_name, target_graph, target_url, target_resources
) -> Optional[Dict]:
return self._invoke_request(
data=json.dumps(
{
"target_name": target_name,
"target_graph": target_graph,
"target_url": target_url,
"target_resources": target_resources,
}
)
)

@router.http("DELETE", "auth/targets/{target_id}")
def delete_target(self, target_id):
response = self._invoke_request()
check_if_success(response, NotFoundError(response.content))
def delete_target(self, target_id) -> None: # pylint: disable=unused-argument
return self._invoke_request()

@router.http("PUT", "auth/targets/{target_id}")
def update_target(
self, target_id, target_name, target_graph, target_url, target_resources
):
data = {
"target_name": target_name,
"target_graph": target_graph,
"target_url": target_url,
"target_resources": target_resources,
}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
self,
target_id, # pylint: disable=unused-argument
target_name,
target_graph,
target_url,
target_resources,
) -> Optional[Dict]:
return self._invoke_request(
data=json.dumps(
{
"target_name": target_name,
"target_graph": target_graph,
"target_url": target_url,
"target_resources": target_resources,
}
)
)

@router.http("GET", "auth/targets/{target_id}")
def get_target(self, target_id, response=None):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def get_target(
self, target_id, response=None # pylint: disable=unused-argument
) -> Optional[Dict]:
return self._invoke_request()

@router.http("GET", "auth/targets")
def list_targets(self):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def list_targets(self) -> Optional[Dict]:
return self._invoke_request()

@router.http("POST", "auth/belongs")
def create_belong(self, user_id, group_id):
def create_belong(self, user_id, group_id) -> Optional[Dict]:
data = {"user": user_id, "group": group_id}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
return self._invoke_request(data=json.dumps(data))

@router.http("DELETE", "auth/belongs/{belong_id}")
def delete_belong(self, belong_id):
response = self._invoke_request()
check_if_success(response, NotFoundError(response.content))
def delete_belong(self, belong_id) -> None: # pylint: disable=unused-argument
return self._invoke_request()

@router.http("PUT", "auth/belongs/{belong_id}")
def update_belong(self, belong_id, description):
def update_belong(
self, belong_id, description # pylint: disable=unused-argument
) -> Optional[Dict]:
data = {"belong_description": description}
response = self._invoke_request(data=json.dumps(data))
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
return self._invoke_request(data=json.dumps(data))

@router.http("GET", "auth/belongs/{belong_id}")
def get_belong(self, belong_id):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def get_belong(
self, belong_id # pylint: disable=unused-argument
) -> Optional[Dict]:
return self._invoke_request()

@router.http("GET", "auth/belongs")
def list_belongs(self):
response = self._invoke_request()
if check_if_success(response, NotFoundError(response.content)):
return response.json()
return {}
def list_belongs(self) -> Optional[Dict]:
return self._invoke_request()
Loading
Loading