Skip to content

Instantly share code, notes, and snippets.

@rokibhasansagar
Last active September 25, 2023 04:51
Show Gist options
  • Save rokibhasansagar/f4132a28a7e56d22ce3e41cb7265d212 to your computer and use it in GitHub Desktop.
Save rokibhasansagar/f4132a28a7e56d22ce3e41cb7265d212 to your computer and use it in GitHub Desktop.
Google Service Accounts Randomizer for TTK

To use Service Accounts through script, follow this method

As the Dockerfile defined WORKDIR /torapp, make sure you have /torapp folder in root with user write access.

If you use any other WORKDIR, please change the path mention from this method according to your needs.

Step 1: Put your service account in a folder

I've uploaded 100 SA JSON files in "accounts" folder in a private repo. DO NOT UPLOAD them in a Public Repo.

Clone the Repo with your Personal Access Token (PAT). Always keep the token secret.

git clone https://${PAT}@github.com/USERNAME/PRIVATE_REPONAME --depth 1 /torapp/sa

This will put the JSON files inside /torapp/sa/accounts/ folder.

Step 2: Use pre-defined rclone config

Place your rclone config with this format. Make sure you have this line in the config -

service_account_file = /torapp/sa/accounts/__ServiceAcc__

So, the full rclone config would look like this -

[TeamDriveID]
type = drive
client_id = xxxxx-xxxxxxxxxxx.apps.googleusercontent.com
client_secret = yyyyyyyyyyyyyyyyyyyyyyyy
scope = drive
root_folder_id = 
chunk_size = 128M
token = {"access_token":"zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz","token_type":"Bearer","refresh_token":"nnnnnnnnnnnnnnnnn","expiry":"2021-05-30T20:14:18.276611995+06:00"}
service_account_file = /torapp/sa/accounts/__ServiceAcc__
team_drive = xyz_yxz_010

Step 3: Set the rclone config path and remote name

In ExecVarsSample.py, set DEF_RCLONE_DRIVE as the from rclone config.

Also set the rclone config path in RCLONE_CONFIG. Usually it's ~/.config/rclone/rclone.conf for any user.

Step 4: Modify start.sh file

_randomSA() {
  # Get a list of SA JSON Filenames
  ls /torapp/sa/accounts/ > /torapp/sa.list
  # Change The SA Filename in rclone config file every 30m
  while true; do
    sed -i 's|__ServiceAcc__|'"$(shuf -n 1 /torapp/sa.list)"'|' ~/.config/rclone/rclone.conf
    sleep 30m
  done
}
# Run the randomizer in background
_randomSA & disown
# Run main Bot Start Script
gunicorn tortoolkit:start_server --bind 0.0.0.0:$PORT --worker-class aiohttp.GunicornWebWorker & python3 -m tortoolkit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment