Skip to content

Commit

Permalink
Merge pull request #726 from plotly/secret_fix
Browse files Browse the repository at this point in the history
check that share key is enabled
  • Loading branch information
cldougl authored Apr 7, 2017
2 parents 1e686cf + 6f3280e commit 3efe833
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [2.0.7] - [Unreleased]
## [2.0.7] - 2017-04-07
### Updated
- Updated `plotly.min.js` to version 1.25.0 for `plotly.offline`.
- See [the plotly.js CHANGELOG](https://github.com/plotly/plotly.js/blob/master/CHANGELOG.md) for additional information regarding the updates.

### Added
- Added check to verify the share key is enabled when secret charts are created.

## [2.0.6] - 2017-03-20
### Added
- Added a new mimetype 'text/vnd.plotly.v1+html' for `iplot` outputs.
Expand Down Expand Up @@ -37,8 +40,6 @@ Note: This release's installation was broken. It has been removed from PyPI
See [https://github.com/nteract/nteract/pull/662](https://github.com/nteract/nteract/pull/662)
for the associated PR in nteract.
- As part of the above, plotly output now prints with a [custom mimetype](https://github.com/plotly/plotly.py/blob/f65724f06b894a5db94245ee4889c632b887d8ce/plotly/offline/offline.py#L348) - `application/vnd.plotly.v1+json`

### Added
- `memoize` decorator added to `plotly.utils`

### Changed
Expand Down
20 changes: 17 additions & 3 deletions plotly/plotly/plotly.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,9 +1295,9 @@ def parse_grid_id_args(grid, grid_url):
return grid.id


def add_share_key_to_url(plot_url):
def add_share_key_to_url(plot_url, attempt=0):
"""
Update plot's url to include the secret key
Check that share key is enabled and update url to include the secret key
"""
urlsplit = six.moves.urllib.parse.urlparse(plot_url)
Expand All @@ -1308,7 +1308,21 @@ def add_share_key_to_url(plot_url):
body = {'share_key_enabled': True, 'world_readable': False}
response = v2.files.update(fid, body)

return plot_url + '?share_key=' + response.json()['share_key']
# Sometimes a share key is added, but access is still denied.
# Check that share_key_enabled is set to true and
# retry if this is not the case
# https://github.com/plotly/streambed/issues/4089
if not v2.files.retrieve(fid).json()['share_key_enabled']:
attempt += 1
if attempt == 50:
raise exceptions.PlotlyError(
"The sharekey could not be enabled at this time so the graph "
"is saved as private. Try again to save as 'secret' later."
)
add_share_key_to_url(plot_url, attempt)

url_share_key = plot_url + '?share_key=' + response.json()['share_key']
return url_share_key


def _send_to_plotly(figure, **plot_options):
Expand Down

0 comments on commit 3efe833

Please sign in to comment.