Fix nodeId type
This commit is contained in:
parent
343f88b61f
commit
51c0b09014
|
@ -1 +0,0 @@
|
||||||
- fix types for nodeId, ideally it should be an int
|
|
|
@ -33,7 +33,7 @@ class HSAPICall:
|
||||||
self.base_path = f"{
|
self.base_path = f"{
|
||||||
self.api_settings.server}{self.api_settings.api_path}/{self.objectPath}"
|
self.api_settings.server}{self.api_settings.api_path}/{self.objectPath}"
|
||||||
|
|
||||||
def call(self, method, call_path: str = "", data=None, query: dict = {}):
|
def call(self, method, call_path: Union[str, int] = "", data=None, query: dict = {}):
|
||||||
headers = {
|
headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Accept": "application/json",
|
"Accept": "application/json",
|
||||||
|
|
|
@ -45,7 +45,7 @@ class Node(HSAPICall):
|
||||||
response = self.call('get')
|
response = self.call('get')
|
||||||
return v1ListNodesResponse(**response.json())
|
return v1ListNodesResponse(**response.json())
|
||||||
|
|
||||||
def get(self, nodeId: str) -> v1Node:
|
def get(self, nodeId: int) -> v1Node:
|
||||||
# There is a bug in headscale API
|
# There is a bug in headscale API
|
||||||
# retrieving a specific node does not return the tags
|
# retrieving a specific node does not return the tags
|
||||||
# so we get the full list of nodes and extract the node with the
|
# so we get the full list of nodes and extract the node with the
|
||||||
|
@ -55,7 +55,7 @@ class Node(HSAPICall):
|
||||||
node = next((n for n in nodelist.nodes if n.id == nodeId), v1Node())
|
node = next((n for n in nodelist.nodes if n.id == nodeId), v1Node())
|
||||||
return node # type: ignore
|
return node # type: ignore
|
||||||
|
|
||||||
def _get(self, nodeId: str) -> v1Node:
|
def _get(self, nodeId: int) -> v1Node:
|
||||||
# There is a bug in headscale API
|
# There is a bug in headscale API
|
||||||
# retrieving a specific node does not return the tags
|
# retrieving a specific node does not return the tags
|
||||||
# This does a real get
|
# This does a real get
|
||||||
|
@ -69,25 +69,25 @@ class Node(HSAPICall):
|
||||||
|
|
||||||
return v1ListNodesResponse(nodes=byUser)
|
return v1ListNodesResponse(nodes=byUser)
|
||||||
|
|
||||||
def delete(self, nodeId: str) -> None:
|
def delete(self, nodeId: int) -> None:
|
||||||
self.call('delete', call_path=nodeId)
|
self.call('delete', call_path=nodeId)
|
||||||
|
|
||||||
def expire(self, nodeId: str) -> None:
|
def expire(self, nodeId: int) -> None:
|
||||||
self.call('post', f'{nodeId}/expire')
|
self.call('post', f'{nodeId}/expire')
|
||||||
|
|
||||||
def rename(self, nodeId: str, newName: str) -> v1NodeResponse:
|
def rename(self, nodeId: int, newName: str) -> v1NodeResponse:
|
||||||
response = self.call('post', f'{nodeId}/rename/{newName}')
|
response = self.call('post', f'{nodeId}/rename/{newName}')
|
||||||
return v1NodeResponse(**response.json())
|
return v1NodeResponse(**response.json())
|
||||||
|
|
||||||
def move(self, nodeId: str, data: v1MoveNodeRequest) -> v1NodeResponse:
|
def move(self, nodeId: int, data: v1MoveNodeRequest) -> v1NodeResponse:
|
||||||
response = self.call('post', f'{nodeId}/user', data)
|
response = self.call('post', f'{nodeId}/user', data)
|
||||||
return v1NodeResponse(**response.json())
|
return v1NodeResponse(**response.json())
|
||||||
|
|
||||||
def routes(self, nodeId: str) -> v1GetNodeRoutesResponse:
|
def routes(self, nodeId: int) -> v1GetNodeRoutesResponse:
|
||||||
response = self.call('get', f'{nodeId}/routes')
|
response = self.call('get', f'{nodeId}/routes')
|
||||||
return v1GetNodeRoutesResponse(**response.json())
|
return v1GetNodeRoutesResponse(**response.json())
|
||||||
|
|
||||||
def setTags(self, nodeId: str, data: v1SetTagsNodeRequest) -> v1NodeResponse:
|
def setTags(self, nodeId: int, data: v1SetTagsNodeRequest) -> v1NodeResponse:
|
||||||
response = self.call('post', f'{nodeId}/tags', data)
|
response = self.call('post', f'{nodeId}/tags', data)
|
||||||
return v1NodeResponse(**response.json())
|
return v1NodeResponse(**response.json())
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ class v1ApiKey(BaseModel):
|
||||||
def expired(self) -> bool:
|
def expired(self) -> bool:
|
||||||
tzinfo = timezone(timedelta(hours=0)) # UTC
|
tzinfo = timezone(timedelta(hours=0)) # UTC
|
||||||
now = datetime.now(tzinfo)
|
now = datetime.now(tzinfo)
|
||||||
return self.expiration < now # type: ignore
|
return self.expiration < now
|
||||||
|
|
||||||
|
|
||||||
class v1PreAuthKey(BaseModel):
|
class v1PreAuthKey(BaseModel):
|
||||||
|
|
Loading…
Reference in New Issue