-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SimplyVanilla/feature/init
Init
- Loading branch information
Showing
11 changed files
with
232 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
trim_trailing_whitespace = true | ||
insert_final_newline = true | ||
indent_size = 2 | ||
indent_style = space | ||
|
||
[Makefile] | ||
indent_size = 4 | ||
indent_style = tab | ||
|
||
[*.py] | ||
indent_size = 4 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
version: 2 | ||
updates: | ||
|
||
- package-ecosystem: "github-actions" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" | ||
|
||
- package-ecosystem: "pip" | ||
directory: "/" | ||
schedule: | ||
interval: "daily" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
name: build and publish | ||
|
||
permissions: | ||
id-token: write | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
tags: | ||
- '*' | ||
pull_request: | ||
branches: | ||
- main | ||
|
||
env: | ||
TERM: xterm-256color | ||
|
||
jobs: | ||
build-and-publish: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ['3.8', '3.9', '3.10', '3.11', '3.12'] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
|
||
- name: Build | ||
run: make build | ||
env: | ||
PYTHON_VERSION: ${{ matrix.python-version }} | ||
|
||
- name: Test | ||
run: make test | ||
env: | ||
PYTHON_VERSION: ${{ matrix.python-version }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
|
||
- name: Publish to PyPI | ||
if: matrix.python-version == '3.11' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | ||
uses: pypa/gh-action-pypi-publish@release/v1 | ||
with: | ||
user: __token__ | ||
password: ${{ secrets.PYPI_API_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: "CodeQL" | ||
|
||
on: | ||
push: | ||
branches: [ "main" ] | ||
pull_request: | ||
branches: [ "main" ] | ||
schedule: | ||
- cron: "21 17 * * 3" | ||
|
||
jobs: | ||
analyze: | ||
name: Analyze | ||
runs-on: ubuntu-latest | ||
permissions: | ||
actions: read | ||
contents: read | ||
security-events: write | ||
|
||
strategy: | ||
fail-fast: false | ||
matrix: | ||
language: [ python ] | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Initialize CodeQL | ||
uses: github/codeql-action/init@v3 | ||
with: | ||
languages: ${{ matrix.language }} | ||
queries: +security-and-quality | ||
|
||
- name: Autobuild | ||
uses: github/codeql-action/autobuild@v3 | ||
|
||
- name: Perform CodeQL Analysis | ||
uses: github/codeql-action/analyze@v3 | ||
with: | ||
category: "/language:${{ matrix.language }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.DS_Store | ||
/.idea/ | ||
/.venv/ | ||
|
||
__pycache__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
# votifier.py | ||
# votifier.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from votifier import VoteV1, Client | ||
|
||
v = VoteV1('EliteToplist.net', 'Netherwhal', 'player-ip') | ||
c = Client('server-ip', 'public-key') | ||
c.vote(v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
coveralls | ||
flake8 | ||
setuptools | ||
twine | ||
wheel | ||
rsa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from setuptools import setup, find_packages | ||
|
||
|
||
def find_description(): | ||
with open('README.md') as fh: | ||
return fh.read() | ||
|
||
|
||
setup( | ||
name='votifier', | ||
version='0.0.1', | ||
author='Netherwhal', | ||
author_email='[email protected]', | ||
description='Votifier v1 Client.', | ||
long_description=find_description(), | ||
long_description_content_type='text/markdown', | ||
url='https://github.com/SimplyVanilla/votifier.py', | ||
packages=find_packages(exclude=['tests*']), | ||
classifiers=[ | ||
'Programming Language :: Python :: 3', | ||
'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)', | ||
'Operating System :: OS Independent', | ||
], | ||
python_requires='>=3', | ||
install_requires=[ | ||
'rsa', | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .votifier import VoteV1, Client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
from datetime import datetime, timezone | ||
import socket | ||
import rsa | ||
|
||
|
||
class VoteV1: | ||
def __init__( | ||
self, | ||
service_name: str, | ||
username: str, | ||
address: str, | ||
timestamp: datetime = datetime.now(timezone.utc), | ||
): | ||
self.service_name = service_name | ||
self.username = username | ||
self.address = address | ||
self.timestamp = round(timestamp.timestamp() * 1000) | ||
|
||
def __str__(self) -> str: | ||
return f"""VOTE | ||
{self.service_name} | ||
{self.username} | ||
{self.address} | ||
{self.timestamp} | ||
""" | ||
|
||
|
||
def ensure_pem_format(key_str: str) -> str: | ||
pem_header = "-----BEGIN PUBLIC KEY-----" | ||
pem_footer = "-----END PUBLIC KEY-----" | ||
|
||
if not key_str.startswith(pem_header): | ||
key_str = pem_header + "\n" + key_str | ||
|
||
if not key_str.endswith(pem_footer): | ||
key_str = key_str + "\n" + pem_footer | ||
|
||
return key_str | ||
|
||
|
||
class Client: | ||
def __init__( | ||
self, | ||
host: str, | ||
public_key: str, | ||
port: int = 8192, | ||
timeout: int = 3, | ||
): | ||
self.public_key = public_key | ||
self.address = (host, port) | ||
self.timeout = timeout | ||
|
||
def vote(self, vote: VoteV1): | ||
pub_key = rsa.PublicKey.load_pkcs1_openssl_pem(ensure_pem_format(self.public_key).encode()) | ||
encrypted_message = rsa.encrypt(str(vote).encode(), pub_key) | ||
|
||
# Send the encrypted message | ||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: | ||
s.connect(self.address) | ||
s.settimeout(self.timeout) | ||
header = s.recv(64).decode().split() | ||
if len(header) != 2: | ||
raise Exception("Not a Votifier v1 server") | ||
s.sendall(encrypted_message) |