Skip to content

Instantly share code, notes, and snippets.

@jfboismenu
Last active July 13, 2020 20:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jfboismenu/5f704ddf7c90dd9c14e01baee5dc7b09 to your computer and use it in GitHub Desktop.
Save jfboismenu/5f704ddf7c90dd9c14e01baee5dc7b09 to your computer and use it in GitHub Desktop.
Allows to detect whether a bundles from the AppStore can be downloaded through s3-proxy.shotgunstudio.com
#!/usr/bin/env python
# Copyright (c) 2020 Shotgun Software Inc.
#
# CONFIDENTIAL AND PROPRIETARY
#
# This work is provided "AS IS" and subject to the Shotgun Pipeline Toolkit
# Source Code License included in this distribution package. See LICENSE.
# By accessing, using, copying or modifying this work you indicate your
# agreement to the Shotgun Pipeline Toolkit Source Code License. All rights
# not expressly granted therein are reserved by Shotgun Software Inc.
doc = """
This script allows to detect whether Toolkit will be able to download updates from the
Shotgun AppStore once all media is served through s3-proxy.shotgunstudio.com on August 3rd.
To do this, an attempt to download tk-config-basic v1.3.10, which is served through
the s3-proxy.shotgunstudio.com URL, will be made.
You need to run this test on a computer that sits behind the firewall, proxy or
gateway that puts traffic restrictions in place. If you don't have
any network restrictions, this script should always work.
It can be executed from:
- The Shotgun Desktop in the Toolkit Python Console, which is accessible after launching a project,
from the down arrow button at the upper right.
- By pasting it when running the `tank shell` command.
- From a standalone Python interpreter either as a command line argument or by pasting
it in the Python console.
"""
import tempfile
import shutil
import sys
import os
def _try(message):
print(message)
# Ensures the output is flushed to the screen right away. Python doesn't now print
# things to the screen straight away if no end of line is present.
sys.stdout.flush()
def _success(message=None):
print("Success!")
if message:
print(message)
else:
print("")
def main(bundle_cache):
print(doc.strip())
print("")
# Remove env var so we can download from the appstore if it was set.
if "SHOTGUN_DISABLE_APPSTORE_ACCESS" in os.environ:
del os.environ["SHOTGUN_DISABLE_APPSTORE_ACCESS"]
# If we can't import Toolkit we can't do much!
_try("Importing Toolkit...")
try:
import sgtk
except:
print("""
It appears Toolkit could not be imported. Please make sure that Toolkit is in your
PYTHONPATH before launching this script.
""")
return
_success()
# Check if we're already authenticated
_try("Authenticating...")
user = sgtk.get_authenticated_user()
# If we're not, we're going to have to ask for some credentials.
if not user:
sg_auth = sgtk.authentication.ShotgunAuthenticator()
user = sg_auth.get_user()
_success()
# We will now connect to the apptore to resolve on descriptor
# pointing to the Toolkit bundle we want to use for our test.
_try("Resolving a Toolkit bundle stored on S3...")
descriptor = sgtk.descriptor.create_descriptor(
user.create_sg_connection(),
sgtk.descriptor.Descriptor.CONFIG,
"sgtk:descriptor:app_store?name=tk-config-basic&version=v1.3.10",
# Override the global bundle cache location to make sure the
# script does not pick up an already cached location by mistake.
bundle_cache_root_override=bundle_cache
)
_success()
# Try to download the bundle from the AppStore. This is when the s3-proxy.shotgunstudio.com
# will be pulled from.
_try("Attempting to download through the S3 Proxy. This may up to 30 seconds depending on your connection speed...")
try:
descriptor.download_local()
except Exception as e:
print("""
There was a problem downloading the configuration from the AppStore.
Please review your proxy, gateway or firewall settings. They need to allow traffic to either:
- s3-proxy.shotgunstudio.com in addition to your site, appstore and S3 urls
OR
- the Shotgun IPs documented at https://support.shotgunsoftware.com/hc/en-us/articles/115000073013-Shotgun-ecosystem
Please note that a HTTP redirect happens as part of the download process. Toolkit pulls media from
from https://tank.shotgunstudio.com/file_serve/attachment/... but the connection is redirected to
https://s3-proxy.shotgunstudio.com/.... This may have an impact on your proxy configuration in some cases.
Detailed error message will follow:
""")
raise
else:
_success("""
It appears you can download Toolkit bundles through s3-proxy.shotgunstudio.com. As a next step,
we recommend that you set up a site configuration restricted to you only to download tk-config-basic
v1.3.10 from the AppStore as documented here:
https://developer.shotgunsoftware.com/c186b05d/?title=Offline+usage+and+disabling+auto+updates#upgrading
""")
# Create a temporary location to download the Toolkit bundle. This ensures
# that we're actually downloading it from the AppStore and not pulling
# it from a cached location. It also ensures that after being download
# it can't be reused when testing the connection to the AppStore
# from Shotgun Desktop.
bundle_cache = tempfile.mkdtemp()
try:
main(bundle_cache)
finally:
shutil.rmtree(bundle_cache)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment