Skip to content

Commit

Permalink
feat: Enable the linter in Windows GithubCI (#34)
Browse files Browse the repository at this point in the history
Signed-off-by: Hongli Chen <[email protected]>
  • Loading branch information
Honglichenn authored Dec 13, 2023
1 parent e296ceb commit 305fcad
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 14 deletions.
1 change: 0 additions & 1 deletion .github/workflows/reuse_python_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ jobs:
run: pip install --upgrade -r requirements-development.txt

- name: Run Linting
if: ${{ matrix.os == 'ubuntu-latest'}}
run: hatch run lint

- name: Run Tests Linux
Expand Down
2 changes: 1 addition & 1 deletion src/openjd/adaptor_runtime/_background/frontend_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ def __init__(self, host, **kwargs):
super(UnixHTTPConnection, self).__init__("localhost", **kwargs)

def connect(self):
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) # type: ignore[attr-defined]
sock.settimeout(self.timeout)
sock.connect(self.socket_path)
self.sock = sock
10 changes: 5 additions & 5 deletions src/openjd/adaptor_runtime/_http/request_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,22 +114,22 @@ def _authenticate(self) -> bool:
# Verify we have a UNIX socket.
if not (
isinstance(self.connection, socket.socket)
and self.connection.family == socket.AddressFamily.AF_UNIX
and self.connection.family == socket.AddressFamily.AF_UNIX # type: ignore[attr-defined]
):
raise UnsupportedPlatformException(
"Failed to handle request because it was not made through a UNIX socket"
)

# Get the credentials of the peer process
cred_buffer = self.connection.getsockopt(
socket.SOL_SOCKET,
socket.SO_PEERCRED,
socket.CMSG_SPACE(ctypes.sizeof(UCred)),
socket.SOL_SOCKET, # type: ignore[attr-defined]
socket.SO_PEERCRED, # type: ignore[attr-defined]
socket.CMSG_SPACE(ctypes.sizeof(UCred)), # type: ignore[attr-defined]
)
peer_cred = UCred.from_buffer_copy(cred_buffer)

# Only allow connections from a process running as the same user
return peer_cred.uid == os.getuid()
return peer_cred.uid == os.getuid() # type: ignore[attr-defined]


class UCred(ctypes.Structure):
Expand Down
12 changes: 6 additions & 6 deletions src/openjd/adaptor_runtime_client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, host, **kwargs):
super(UnixHTTPConnection, self).__init__(host, **kwargs)

def connect(self):
sock = _socket.socket(_socket.AF_UNIX, _socket.SOCK_STREAM)
sock = _socket.socket(_socket.AF_UNIX, _socket.SOCK_STREAM) # type: ignore[attr-defined]
sock.settimeout(self.timeout)
sock.connect(self.host)
self.sock = sock
Expand All @@ -55,19 +55,19 @@ def _authenticate(self) -> bool:
# Verify we have a UNIX socket.
if not (
isinstance(self.sock, _socket.socket)
and self.sock.family == _socket.AddressFamily.AF_UNIX
and self.sock.family == _socket.AddressFamily.AF_UNIX # type: ignore[attr-defined]
):
raise NotImplementedError(
"Failed to handle request because it was not made through a UNIX socket"
)

# Get the credentials of the peer process
cred_buffer = self.sock.getsockopt(
_socket.SOL_SOCKET,
_socket.SO_PEERCRED,
_socket.CMSG_SPACE(_ctypes.sizeof(UCred)),
_socket.SOL_SOCKET, # type: ignore[attr-defined]
_socket.SO_PEERCRED, # type: ignore[attr-defined]
_socket.CMSG_SPACE(_ctypes.sizeof(UCred)), # type: ignore[attr-defined]
)
peer_cred = UCred.from_buffer_copy(cred_buffer)

# Only allow connections from a process running as the same user
return peer_cred.uid == _os.getuid()
return peer_cred.uid == _os.getuid() # type: ignore[attr-defined]
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class TestAuthenticate:
@pytest.fixture
def mock_handler(self) -> MagicMock:
mock_socket = MagicMock(spec=socket.socket)
mock_socket.family = socket.AddressFamily.AF_UNIX
mock_socket.family = socket.AddressFamily.AF_UNIX # type: ignore[attr-defined]

mock_handler = MagicMock(spec=RequestHandler)
mock_handler.connection = mock_socket
Expand Down

0 comments on commit 305fcad

Please sign in to comment.