-
Notifications
You must be signed in to change notification settings - Fork 151
refactor / enable Trakt API keys from environment variables #692
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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,11 @@ | ||
| # -*- coding: utf-8 -*- | ||
|
|
||
| def deobfuscate(data): | ||
| if not data or not isinstance(data, list): | ||
| return "" | ||
| return "".join(chr(b ^ 0x42) for b in data) | ||
|
|
||
| def obfuscate(data): | ||
| if not data: | ||
| return [] | ||
| return [ord(c) ^ 0x42 for c in data] |
This file contains hidden or 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
This file contains hidden or 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,47 @@ | ||
| import os | ||
| import sys | ||
|
|
||
| # Add the parent directory to sys.path to allow importing from resources | ||
| sys.path.append(os.path.join(os.path.dirname(__file__), "..")) | ||
|
|
||
| from resources.lib.obfuscation import deobfuscate, obfuscate | ||
|
|
||
| def main(): | ||
| client_id = os.environ.get("TRAKT_CLIENT_ID") | ||
| client_secret = os.environ.get("TRAKT_CLIENT_SECRET") | ||
|
|
||
| if not client_id or not client_secret: | ||
| print("Error: TRAKT_CLIENT_ID or TRAKT_CLIENT_SECRET not set.") | ||
| sys.exit(1) | ||
|
|
||
| obfuscated_id = obfuscate(client_id) | ||
| obfuscated_secret = obfuscate(client_secret) | ||
|
|
||
| # Verify logic | ||
| assert deobfuscate(obfuscated_id) == client_id | ||
| assert deobfuscate(obfuscated_secret) == client_secret | ||
|
|
||
| target_file = "resources/lib/traktapi.py" | ||
| with open(target_file, "r") as f: | ||
| content = f.read() | ||
|
|
||
| # Replace placeholders | ||
| new_content = content.replace( | ||
| '"TRAKT_CLIENT_ID_PLACEHOLDER"', | ||
| str(obfuscated_id), | ||
| ).replace( | ||
| '"TRAKT_CLIENT_SECRET_PLACEHOLDER"', | ||
| str(obfuscated_secret), | ||
| ) | ||
|
|
||
| if new_content == content: | ||
| print("Error: Could not find placeholders in target file.") | ||
| sys.exit(1) | ||
|
|
||
| with open(target_file, "w") as f: | ||
| f.write(new_content) | ||
|
|
||
| print(f"Successfully injected obfuscated keys into {target_file}") | ||
|
|
||
| if __name__ == "__main__": | ||
| main() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.