Skip to content

Commit 88b4e48

Browse files
committed
playready
1 parent f9d13b7 commit 88b4e48

32 files changed

+2242
-738
lines changed

alembic.ini

+117
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
# A generic, single database configuration.
2+
3+
[alembic]
4+
# path to migration scripts
5+
# Use forward slashes (/) also on windows to provide an os agnostic path
6+
script_location = alembic
7+
8+
# template used to generate migration file names; The default value is %%(rev)s_%%(slug)s
9+
# Uncomment the line below if you want the files to be prepended with date and time
10+
# see https://alembic.sqlalchemy.org/en/latest/tutorial.html#editing-the-ini-file
11+
# for all available tokens
12+
# file_template = %%(year)d_%%(month).2d_%%(day).2d_%%(hour).2d%%(minute).2d-%%(rev)s_%%(slug)s
13+
14+
# sys.path path, will be prepended to sys.path if present.
15+
# defaults to the current working directory.
16+
prepend_sys_path = .
17+
18+
# timezone to use when rendering the date within the migration file
19+
# as well as the filename.
20+
# If specified, requires the python>=3.9 or backports.zoneinfo library.
21+
# Any required deps can installed by adding `alembic[tz]` to the pip requirements
22+
# string value is passed to ZoneInfo()
23+
# leave blank for localtime
24+
# timezone =
25+
26+
# max length of characters to apply to the "slug" field
27+
# truncate_slug_length = 40
28+
29+
# set to 'true' to run the environment during
30+
# the 'revision' command, regardless of autogenerate
31+
# revision_environment = false
32+
33+
# set to 'true' to allow .pyc and .pyo files without
34+
# a source .py file to be detected as revisions in the
35+
# versions/ directory
36+
# sourceless = false
37+
38+
# version location specification; This defaults
39+
# to alembic/versions. When using multiple version
40+
# directories, initial revisions must be specified with --version-path.
41+
# The path separator used here should be the separator specified by "version_path_separator" below.
42+
# version_locations = %(here)s/bar:%(here)s/bat:alembic/versions
43+
44+
# version path separator; As mentioned above, this is the character used to split
45+
# version_locations. The default within new alembic.ini files is "os", which uses os.pathsep.
46+
# If this key is omitted entirely, it falls back to the legacy behavior of splitting on spaces and/or commas.
47+
# Valid values for version_path_separator are:
48+
#
49+
# version_path_separator = :
50+
# version_path_separator = ;
51+
# version_path_separator = space
52+
# version_path_separator = newline
53+
version_path_separator = os # Use os.pathsep. Default configuration used for new projects.
54+
55+
# set to 'true' to search source files recursively
56+
# in each "version_locations" directory
57+
# new in Alembic version 1.10
58+
# recursive_version_locations = false
59+
60+
# the output encoding used when revision files
61+
# are written from script.py.mako
62+
# output_encoding = utf-8
63+
64+
sqlalchemy.url = driver://user:pass@localhost/dbname
65+
66+
67+
[post_write_hooks]
68+
# post_write_hooks defines scripts or Python functions that are run
69+
# on newly generated revision scripts. See the documentation for further
70+
# detail and examples
71+
72+
# format using "black" - use the console_scripts runner, against the "black" entrypoint
73+
# hooks = black
74+
# black.type = console_scripts
75+
# black.entrypoint = black
76+
# black.options = -l 79 REVISION_SCRIPT_FILENAME
77+
78+
# lint with attempts to fix using "ruff" - use the exec runner, execute a binary
79+
# hooks = ruff
80+
# ruff.type = exec
81+
# ruff.executable = %(here)s/.venv/bin/ruff
82+
# ruff.options = --fix REVISION_SCRIPT_FILENAME
83+
84+
# Logging configuration
85+
[loggers]
86+
keys = root,sqlalchemy,alembic
87+
88+
[handlers]
89+
keys = console
90+
91+
[formatters]
92+
keys = generic
93+
94+
[logger_root]
95+
level = WARNING
96+
handlers = console
97+
qualname =
98+
99+
[logger_sqlalchemy]
100+
level = WARNING
101+
handlers =
102+
qualname = sqlalchemy.engine
103+
104+
[logger_alembic]
105+
level = INFO
106+
handlers =
107+
qualname = alembic
108+
109+
[handler_console]
110+
class = StreamHandler
111+
args = (sys.stderr,)
112+
level = NOTSET
113+
formatter = generic
114+
115+
[formatter_generic]
116+
format = %(levelname)-5.5s [%(name)s] %(message)s
117+
datefmt = %H:%M:%S

alembic/README

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Generic single-database configuration.

alembic/env.py

+86
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import os
2+
from logging.config import fileConfig
3+
4+
import toml
5+
from sqlalchemy import engine_from_config, pool
6+
7+
from alembic import context
8+
from getwvkeys.models import CDM, PRD, APIKey, Base, Key, Shared, User, UserPRD
9+
10+
IS_DEVELOPMENT = bool(os.environ.get("DEVELOPMENT", False))
11+
IS_STAGING = bool(os.environ.get("STAGING", False))
12+
CONFIG = toml.load("config.dev.toml" if IS_DEVELOPMENT else "config.staging.toml" if IS_STAGING else "config.toml")
13+
14+
# this is the Alembic Config object, which provides
15+
# access to the values within the .ini file in use.
16+
config = context.config
17+
18+
# Interpret the config file for Python logging.
19+
# This line sets up loggers basically.
20+
if config.config_file_name is not None:
21+
fileConfig(config.config_file_name)
22+
23+
# add your model's MetaData object here
24+
# for 'autogenerate' support
25+
# from myapp import mymodel
26+
# target_metadata = mymodel.Base.metadata
27+
target_metadata = Base.metadata
28+
29+
# other values from the config, defined by the needs of env.py,
30+
# can be acquired:
31+
# my_important_option = config.get_main_option("my_important_option")
32+
# ... etc.
33+
34+
35+
def run_migrations_offline() -> None:
36+
"""Run migrations in 'offline' mode.
37+
38+
This configures the context with just a URL
39+
and not an Engine, though an Engine is acceptable
40+
here as well. By skipping the Engine creation
41+
we don't even need a DBAPI to be available.
42+
43+
Calls to context.execute() here emit the given string to the
44+
script output.
45+
46+
"""
47+
# url = config.get_main_option("sqlalchemy.url")
48+
url = CONFIG["general"]["database_uri"]
49+
context.configure(
50+
url=url,
51+
target_metadata=target_metadata,
52+
literal_binds=True,
53+
dialect_opts={"paramstyle": "named"},
54+
)
55+
56+
with context.begin_transaction():
57+
context.run_migrations()
58+
59+
60+
def run_migrations_online() -> None:
61+
"""Run migrations in 'online' mode.
62+
63+
In this scenario we need to create an Engine
64+
and associate a connection with the context.
65+
66+
"""
67+
url = CONFIG["general"]["database_uri"]
68+
cfg = config.get_section(config.config_ini_section, {})
69+
cfg["sqlalchemy.url"] = url
70+
connectable = engine_from_config(
71+
cfg,
72+
prefix="sqlalchemy.",
73+
poolclass=pool.NullPool,
74+
)
75+
76+
with connectable.connect() as connection:
77+
context.configure(connection=connection, target_metadata=target_metadata)
78+
79+
with context.begin_transaction():
80+
context.run_migrations()
81+
82+
83+
if context.is_offline_mode():
84+
run_migrations_offline()
85+
else:
86+
run_migrations_online()

alembic/script.py.mako

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
"""${message}
2+
3+
Revision ID: ${up_revision}
4+
Revises: ${down_revision | comma,n}
5+
Create Date: ${create_date}
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
${imports if imports else ""}
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = ${repr(up_revision)}
16+
down_revision: Union[str, None] = ${repr(down_revision)}
17+
branch_labels: Union[str, Sequence[str], None] = ${repr(branch_labels)}
18+
depends_on: Union[str, Sequence[str], None] = ${repr(depends_on)}
19+
20+
21+
def upgrade() -> None:
22+
${upgrades if upgrades else "pass"}
23+
24+
25+
def downgrade() -> None:
26+
${downgrades if downgrades else "pass"}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""create_prd
2+
3+
Revision ID: 51d65f145c1f
4+
Revises: 592b912adf54
5+
Create Date: 2024-12-02 13:40:39.900188
6+
7+
"""
8+
9+
from typing import Sequence, Union
10+
11+
import sqlalchemy as sa
12+
13+
from alembic import op
14+
15+
# revision identifiers, used by Alembic.
16+
revision: str = "51d65f145c1f"
17+
down_revision: Union[str, None] = "592b912adf54"
18+
branch_labels: Union[str, Sequence[str], None] = None
19+
depends_on: Union[str, Sequence[str], None] = "592b912adf54"
20+
21+
22+
def upgrade() -> None:
23+
# ### commands auto generated by Alembic - please adjust! ###
24+
op.create_table(
25+
"prds",
26+
sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
27+
sa.Column("hash", sa.String(length=255), nullable=False),
28+
sa.Column("prd", sa.Text(), nullable=False),
29+
sa.Column("uploaded_by", sa.String(length=255), nullable=False),
30+
sa.ForeignKeyConstraint(
31+
["uploaded_by"],
32+
["users.id"],
33+
),
34+
sa.PrimaryKeyConstraint("id"),
35+
sa.UniqueConstraint("hash"),
36+
)
37+
op.create_table(
38+
"user_prd",
39+
sa.Column("user_id", sa.String(length=255), nullable=False),
40+
sa.Column("device_hash", sa.String(length=255), nullable=False),
41+
sa.ForeignKeyConstraint(["device_hash"], ["prds.hash"], ondelete="CASCADE"),
42+
sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
43+
)
44+
# ### end Alembic commands ###
45+
46+
47+
def downgrade() -> None:
48+
# ### commands auto generated by Alembic - please adjust! ###
49+
op.drop_table("user_prd")
50+
op.drop_table("prds")
51+
# ### end Alembic commands ###

alembic/versions/592b912adf54_init.py

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
"""init
2+
3+
Revision ID: 592b912adf54
4+
Revises:
5+
Create Date: 2024-12-02 13:22:59.911782
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '592b912adf54'
16+
down_revision: Union[str, None] = None
17+
branch_labels: Union[str, Sequence[str], None] = None
18+
depends_on: Union[str, Sequence[str], None] = None
19+
20+
21+
def upgrade() -> None:
22+
# ### commands auto generated by Alembic - please adjust! ###
23+
op.create_table('apikeys',
24+
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
25+
sa.Column('created_at', sa.DateTime(), nullable=False),
26+
sa.Column('api_key', sa.String(length=255), nullable=False),
27+
sa.Column('user_id', sa.String(length=255), nullable=False),
28+
sa.PrimaryKeyConstraint('id'),
29+
sa.UniqueConstraint('id')
30+
)
31+
op.create_table('users',
32+
sa.Column('id', sa.String(length=255), nullable=False),
33+
sa.Column('username', sa.String(length=255), nullable=False),
34+
sa.Column('discriminator', sa.String(length=255), nullable=False),
35+
sa.Column('avatar', sa.String(length=255), nullable=True),
36+
sa.Column('public_flags', sa.Integer(), nullable=False),
37+
sa.Column('api_key', sa.String(length=255), nullable=False),
38+
sa.Column('flags', sa.Integer(), nullable=False),
39+
sa.PrimaryKeyConstraint('id'),
40+
sa.UniqueConstraint('id')
41+
)
42+
op.create_table('cdms',
43+
sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
44+
sa.Column('session_id_type', sa.String(length=255), nullable=False),
45+
sa.Column('security_level', sa.Integer(), nullable=False),
46+
sa.Column('client_id_blob_filename', sa.Text(), nullable=False),
47+
sa.Column('device_private_key', sa.Text(), nullable=False),
48+
sa.Column('code', sa.Text(), nullable=False),
49+
sa.Column('uploaded_by', sa.String(length=255), nullable=True),
50+
sa.ForeignKeyConstraint(['uploaded_by'], ['users.id'], ),
51+
sa.PrimaryKeyConstraint('id')
52+
)
53+
op.create_table('keys_',
54+
sa.Column('kid', sa.String(length=32), nullable=False),
55+
sa.Column('added_at', sa.Integer(), nullable=False),
56+
sa.Column('added_by', sa.String(length=255), nullable=True),
57+
sa.Column('license_url', sa.Text(), nullable=False),
58+
sa.Column('key_', sa.String(length=255), nullable=False),
59+
sa.ForeignKeyConstraint(['added_by'], ['users.id'], ),
60+
sa.PrimaryKeyConstraint('kid')
61+
)
62+
# ### end Alembic commands ###
63+
64+
65+
def downgrade() -> None:
66+
# ### commands auto generated by Alembic - please adjust! ###
67+
op.drop_table('keys_')
68+
op.drop_table('cdms')
69+
op.drop_table('users')
70+
op.drop_table('apikeys')
71+
# ### end Alembic commands ###

getwvkeys/config.py

+2
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
MAX_SESSIONS = CONFIG["general"].get("max_sessions", 60)
5252
PROXY = {}
5353
DEFAULT_CDMS = CONFIG["general"].get("default_cdms", []) # list of build infos to use in key rotation
54+
DEFAULT_PRDS = CONFIG["general"].get("default_prds", []) # list of PRDs used in key rotation
5455
APPENDERS = [] # passwords for dumping keys, deprecated in favor of flags
5556
GUILD_ID = CONFIG["general"]["guild_id"] # Discord Guild ID
5657
VERIFIED_ROLE_ID = CONFIG["general"]["verified_role_id"] # Discord Verified role ID
@@ -67,3 +68,4 @@
6768
EXTERNAL_API_BUILD_INFOS = CONFIG.get("external_build_info", [])
6869
# List of CDMs that should use the blacklist, these are considered to be GetWVKeys System CDMs.
6970
SYSTEM_CDMS = CONFIG["general"].get("system_cdms", [])
71+
SYSTEM_PRDS = CONFIG["general"].get("system_prds", [])

0 commit comments

Comments
 (0)