Skip to content

validate plotly_(api)_domain - HTTPS, not HTTP #997

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 11 commits into from
May 4, 2018
37 changes: 35 additions & 2 deletions plotly/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,36 @@
ALTERNATIVE_HISTNORM = 'probability'


http_msg = (
"The plotly_domain and plotly_api_domain of your config file must start "
"with 'https', 'http'.\n If you are not using On-Prem then run the "
"following code to ensure your plotly_domain and plotly_api_domain start "
"with 'https':\n\n\n"
"import plotly\n"
"plotly.tools.set_config_file(\n"
" plotly_domain='https://plot.ly',\n"
" plotly_api_domain='https://api.plot.ly'\n"
")\n\n\n"
"If you are using On-Prem then you will need to use your company's "
"domain and api_domain urls:\n\n\n"
"import plotly\n"
"plotly.tools.set_config_file(\n"
" plotly_domain='https://plotly.your-company.com',\n"
" plotly_api_domain='https://plotly.your-company.com'\n"
")\n\n\n"
"Make sure to replace `your-company.com` with the URL of your Plotly "
"On-Premise server.\nSee "
"https://plot.ly/python/getting-started/#special-instructions-for-plotly-onpremise-users "
"for more help with getting started with On-Prem."
)


def validate_config_file(*domains):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is really just validating domains - what do you think about renaming this as validate_domains?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

for d in domains:
if not d.lower().startswith('https'):
warnings.warn(http_msg)


# Warning format
def warning_on_one_line(message, category, filename, lineno,
file=None, line=None):
Expand Down Expand Up @@ -194,6 +224,7 @@ def set_config_file(plotly_domain=None,
'sharing': sharing, 'world_readable': world_readable})
settings = get_config_file()
if isinstance(plotly_domain, six.string_types):
validate_config_file(plotly_domain)
settings['plotly_domain'] = plotly_domain
elif plotly_domain is not None:
raise TypeError('plotly_domain should be a string')
Expand All @@ -202,6 +233,7 @@ def set_config_file(plotly_domain=None,
elif plotly_streaming_domain is not None:
raise TypeError('plotly_streaming_domain should be a string')
if isinstance(plotly_api_domain, six.string_types):
validate_config_file(plotly_api_domain)
settings['plotly_api_domain'] = plotly_api_domain
elif plotly_api_domain is not None:
raise TypeError('plotly_api_domain should be a string')
Expand Down Expand Up @@ -244,9 +276,10 @@ def get_config_file(*args):
"""
if check_file_permissions():
ensure_local_plotly_files() # make sure what's there is OK
return utils.load_json_dict(CONFIG_FILE, *args)
returned_obj = utils.load_json_dict(CONFIG_FILE, *args)
else:
return FILE_CONTENT[CONFIG_FILE]
returned_obj = FILE_CONTENT[CONFIG_FILE]
return returned_obj
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change necessary? Could you add it to a separate commit with a commit msg that explains why if so?



def reset_config_file():
Expand Down