-
Notifications
You must be signed in to change notification settings - Fork 64
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
Create Maps API key automagically in Kuviz #1082
Merged
Merged
Changes from all commits
Commits
Show all changes
42 commits
Select commit
Hold shift + click to select a range
3978545
publish use the same credentials
simon-contreras-deel 68634e3
publish structure
simon-contreras-deel cc94622
instantiate KuvizPublisher with all info
simon-contreras-deel 5165782
auth api client
simon-contreras-deel d218ce3
kuviz refactor
simon-contreras-deel 8728491
easy publish
simon-contreras-deel acc1e94
kuviz easy get and set layers
simon-contreras-deel 3cc0d76
updating kuviz delete and creation layers
simon-contreras-deel 93f58de
update kuviz
simon-contreras-deel 8075113
using new update
simon-contreras-deel 2ac70dc
fix tables usage
simon-contreras-deel 22db554
setting api key naming
simon-contreras-deel 149875f
test auth api client
simon-contreras-deel 25ff832
udating kuviz test
simon-contreras-deel 3afa59a
table_name is optional
simon-contreras-deel dedf194
remove tests testing mocks
simon-contreras-deel a4e3f3e
test naming
simon-contreras-deel def0bc3
remove needless mocks
simon-contreras-deel c38d945
test publish method
simon-contreras-deel fcbb38e
test update and delete
simon-contreras-deel 3676ff1
ensuring working with layer copy
simon-contreras-deel 2f0d06a
unique name for api key
simon-contreras-deel 01d228c
ensure table name
simon-contreras-deel 7eeeb0e
saving and changing branch
simon-contreras-deel 3837ce8
Merge branch 'develop' into feature/magic-apikey-kuviz
simon-contreras-deel 96be37a
tests several geoms columns and geodataframes
simon-contreras-deel 0bc118b
final notebook
simon-contreras-deel f264a8c
updating map test behaviour
simon-contreras-deel dbc9b69
updating doc
simon-contreras-deel e16663a
hound
simon-contreras-deel d477c00
removeing forgotten line
simon-contreras-deel 4343a16
more hound happiness
simon-contreras-deel 89619f4
updating guides
simon-contreras-deel d31e7f7
needless import
simon-contreras-deel 98c087d
messaging in Kuviz publication and update
simon-contreras-deel a57fa18
improve message
simon-contreras-deel 884ad08
Merge branch 'feature/magic-apikey-kuviz' of github.com:CartoDB/carto…
simon-contreras-deel 82199f8
Improve message 2
simon-contreras-deel 9e271b9
Merge branch 'feature/magic-apikey-kuviz' of github.com:CartoDB/carto…
simon-contreras-deel 43adc4f
Improve message 3
simon-contreras-deel b42afd9
Merge branch 'develop' into feature/magic-apikey-kuviz
simon-contreras-deel aa7784b
Update docs/guides/kuviz.rst
alrocar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from __future__ import absolute_import | ||
|
||
from carto.api_keys import APIKeyManager | ||
|
||
from ...auth import get_default_credentials | ||
|
||
|
||
class AuthAPIClient(object): | ||
"""AuthAPIClient class is a client of the CARTO Auth API. | ||
More info: https://carto.com/developers/auth-api/ | ||
|
||
Args: | ||
credentials (:py:class:`Credentials <cartoframes.auth.Credentials>`, optional): | ||
credentials of user account to send Dataset to. If not provided, | ||
a default credentials (if set with :py:meth:`set_default_credentials | ||
<cartoframes.auth.set_default_credentials>`) will attempted to be | ||
used. | ||
""" | ||
def __init__(self, credentials=None): | ||
credentials = credentials or get_default_credentials() | ||
self._api_key_manager = _get_api_key_manager(credentials) | ||
|
||
def create_api_key(self, datasets, name, apis=['sql', 'maps'], permissions=['select']): | ||
tables = [] | ||
for dataset in datasets: | ||
table_names = dataset.get_table_names() | ||
for table_name in table_names: | ||
tables.append(_get_table_dict(dataset.schema, table_name, permissions)) | ||
|
||
api_key = self._api_key_manager.create( | ||
name=name, | ||
apis=apis, | ||
tables=tables) | ||
|
||
return api_key.token | ||
|
||
|
||
def _get_table_dict(schema, table, permissions): | ||
return { | ||
"schema": schema, | ||
"name": table, | ||
"permissions": permissions | ||
} | ||
|
||
|
||
def _get_api_key_manager(credentials): | ||
auth_client = credentials.get_api_key_auth_client() | ||
return APIKeyManager(auth_client) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should raise an error if we are not receiving the master API key here, because otherwise it won't work the API key creation. It could be responsibility of carto-python.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering the API keys with the one provided by the user to check if it is the master one? This also applies to the Kuviz creation, the user should use the master one.
I am not sure about it. Maybe we can catch
Access denied
exceptions and remembering the user about using the master key?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Anyway, the validation of the credentials is something to work on because we are not validating if the credentials are defined or not (we are doing the classical
credentials or get_default_credentials()
, but not checking if we have credentials or not after that). Maybe we can create a task with both objectivesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#1097