Skip to content

Commit

Permalink
Remove proxy/ folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tvst committed May 19, 2019
1 parent 862a71d commit 7425f82
Show file tree
Hide file tree
Showing 22 changed files with 325 additions and 396 deletions.
42 changes: 19 additions & 23 deletions lib/Pipfile.locks/python-3.6.6

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions lib/streamlit/ScriptRunner.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@

from streamlit import config
from streamlit import magic
from streamlit import util
from streamlit.LocalSourcesObserver import LocalSourcesObserver
from streamlit.watcher.LocalSourcesWatcher import LocalSourcesWatcher

from streamlit.logger import get_logger
LOGGER = get_logger(__name__)
Expand Down Expand Up @@ -59,7 +58,7 @@ def __init__(self, report):

self._set_state(State.INITIAL)

self._local_sources_observer = LocalSourcesObserver(
self._local_sources_watcher = LocalSourcesWatcher(
self._report, self.maybe_handle_file_changed)

def _set_state(self, new_state):
Expand Down Expand Up @@ -199,7 +198,7 @@ def _run(self):
finally:
self._set_state(State.STOPPED)

self._local_sources_observer.update_watched_modules()
self._local_sources_watcher.update_watched_modules()
_clean_problem_modules()

if rerun:
Expand Down
60 changes: 56 additions & 4 deletions lib/streamlit/Server.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import textwrap
import threading
import urllib

import tornado.concurrent
import tornado.gen
Expand All @@ -20,7 +21,6 @@
from streamlit import util
from streamlit.ReportQueue import ReportQueue
from streamlit.ScriptRunner import State as ScriptState
from streamlit.proxy import proxy_util
from streamlit.storage.S3Storage import S3Storage as Storage

from streamlit.logger import get_logger
Expand Down Expand Up @@ -346,7 +346,7 @@ def set_extra_headers(self, path):

def check_origin(self, origin):
"""Set up CORS."""
return proxy_util.url_is_from_allowed_origins(origin)
return _is_url_from_allowed_origins(origin)


class _HealthHandler(tornado.web.RequestHandler):
Expand All @@ -355,7 +355,7 @@ def initialize(self, server):

def check_origin(self, origin):
"""Set up CORS."""
return proxy_util.url_is_from_allowed_origins(origin)
return _is_url_from_allowed_origins(origin)

def get(self):
self.add_header('Cache-Control', 'no-cache')
Expand All @@ -373,7 +373,7 @@ def initialize(self, server):

def check_origin(self, origin):
"""Set up CORS."""
return proxy_util.url_is_from_allowed_origins(origin)
return _is_url_from_allowed_origins(origin)

def open(self):
self._server._add_browser_connection(self)
Expand Down Expand Up @@ -436,3 +436,55 @@ def _convert_msg_to_exception_msg(msg, e):
msg.delta.id = delta_id

exception_element.marshall(msg.delta.new_element, e)


def _is_url_from_allowed_origins(url):
"""Return True if URL is from allowed origins (for CORS purpose).
Allowed origins:
1. localhost
2. The internal and external IP addresses of the machine where this
functions was called from.
3. The cloud storage domain configured in `s3.bucket`.
If `proxy.enableCORS` is False, this allows all origins.
Parameters
----------
url : str
The URL to check
Returns
-------
bool
True if URL is accepted. False otherwise.
"""
if not config.get_option('proxy.enableCORS'):
# Allow everything when CORS is disabled.
return True

hostname = urllib.parse.urlparse(url).hostname

# Allow connections from bucket.
if hostname == config.get_option('s3.bucket'):
return True

# Allow connections from watcher's machine or localhost.
allowed_domains = [
'localhost',
'127.0.0.1',
util.get_internal_ip(),
util.get_external_ip(),
]

s3_url = config.get_option('s3.url')

if s3_url is not None:
parsed = urllib.parse.urlparse(s3_url)
allowed_domains.append(parsed.hostname)

if config.is_manually_set('browser.proxyAddress'):
allowed_domains.append(config.get_option('browser.proxyAddress'))

return any(hostname == d for d in allowed_domains)
30 changes: 0 additions & 30 deletions lib/streamlit/proxy/__main__.py

This file was deleted.

0 comments on commit 7425f82

Please sign in to comment.