Skip to content
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

Using _unswizzled_password #813

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 19 additions & 8 deletions scripts/tank_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -639,13 +639,6 @@ def shotgun_run_action_auth(install_root, pipeline_config_root, is_localized, ar
login = args[3]
rot13_password = args[4]

# un-swizzle the password
rot13 = string.maketrans(
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm",
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
)
password = string.translate(rot13_password, rot13)

# now, first try to authenticate
core_dm = CoreDefaultsManager()
sa = ShotgunAuthenticator(core_dm)
Expand All @@ -659,7 +652,7 @@ def shotgun_run_action_auth(install_root, pipeline_config_root, is_localized, ar
tank.set_authenticated_user(default_user)
else:
# no default user. Have to authenticate
if password == "-":
if _unswizzled_password(rot13_password) == "-":
# no password given from shotgun. Try to use a stored session token
try:
user = sa.create_session_user(login)
Expand Down Expand Up @@ -1655,6 +1648,24 @@ def _extract_credentials(cmd_line):
return cmd_line, {}


def _unswizzled_password(rot13_password): # type: (str) -> str
"""Translate the original rot13 password string.

Falls back to use ``string.maketrans`` for older versions of Python when
``str.maketrans`` isn't available.
"""
maketrans = getattr(str, "maketrans", getattr(string, "maketrans", None))
translate = getattr(str, "translate", getattr(string, "translate", None))
fatal_message = "No password translate methods available!"
assert maketrans is not None and translate is not None, fatal_message

rot13 = maketrans(
"NOPQRSTUVWXYZnopqrstuvwxyzABCDEFGHIJKLMabcdefghijklm",
"ABCDEFGHIJKLMabcdefghijklmNOPQRSTUVWXYZnopqrstuvwxyz",
)
return translate(rot13_password, rot13)


if __name__ == "__main__":

# set up std toolkit logging to file
Expand Down