Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
:return:
:raise: CartoException
"""
try:
endpoint = (self.Meta.collection_endpoint
+ "{id}/regenerate_secret"). \
format(id=self.id)
self.send(endpoint, "POST")
except Exception as e:
raise CartoException(e)
class GrantedOauthApp(Resource):
"""
Represents an OAuth app granted to access a CARTO account.
"""
id = CharField()
name = CharField()
icon_url = CharField()
scopes = CharField(many=True)
created_at = DateTimeField()
updated_at = DateTimeField()
class Meta:
collection_endpoint = GRANTED_API_ENDPOINT.format(api_version=API_VERSION)
app_collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)
name_field = "id"
"""
from pyrestcli.fields import CharField, DateTimeField, BooleanField
from .resources import Resource, Manager
from .exceptions import CartoException
from .paginators import CartoPaginator
API_VERSION = "v4"
API_ENDPOINT = "api/{api_version}/oauth_apps/"
GRANTED_API_ENDPOINT = "api/{api_version}/granted_oauth_apps/"
class OauthApp(Resource):
"""
Represents an OAuth app in CARTO.
"""
id = CharField()
name = CharField()
client_id = CharField()
client_secret = CharField()
user_id = CharField()
redirect_uris = CharField(many=True)
icon_url = CharField()
restricted = BooleanField()
created_at = DateTimeField()
updated_at = DateTimeField()
class Meta:
.. moduleauthor:: Jesús Arroyo
"""
from pyrestcli.fields import CharField, FloatField
from .resources import Resource, Manager
from .paginators import CartoPaginator
API_VERSION = "v4"
API_ENDPOINT = "api/{api_version}/do/subscriptions"
class DOSubscription(Resource):
"""
Represents a Data Observatory Subscriptions in CARTO.
"""
dataset = CharField()
id = CharField()
project = CharField()
table = CharField()
type = CharField()
class Meta:
collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)
name_field = "id"
class DOSubscriptionManager(Manager):
API_VERSION = "v3"
API_ENDPOINT = "api/{api_version}/api_keys/"
API_SQL = "sql"
API_MAPS = "maps"
PERMISSION_INSERT = "insert"
PERMISSION_SELECT = "select"
PERMISSION_UPDATE = "update"
PERMISSION_DELETE = "delete"
SERVICE_GEOCODING = "geocoding"
SERVICE_ROUTING = "routing"
SERVICE_ISOLINES = "isolines"
SERVICE_OBSERVATORY = "observatory"
class APIKey(Resource):
"""
Represents an API key in CARTO. API keys are used to grant permissions to
tables and maps. See the Auth API reference for more info: https://carto.com/developers/auth-api/
"""
name = CharField()
token = CharField()
type = CharField()
created_at = DateTimeField()
updated_at = DateTimeField()
grants = GrantsField()
class Meta:
collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)
name_field = "name"
"""
grants = []
if not apis:
raise CartoException("'apis' cannot be empty. Please specify which CARTO APIs you want to grant. Example: ['sql', 'maps']")
grants.append({'type': 'apis', 'apis': apis})
if tables and (len(tables) > 0):
if isinstance(tables[0], dict):
grants.append({'type': 'database', 'tables': tables})
elif isinstance(tables[0], TableGrant):
grants.append({'type': 'database', 'tables': [x.to_json for x in tables]})
if services:
grants.append({'type': 'dataservices', 'services': services})
return super(APIKeyManager, self).create(name=name, grants=grants)
class TableGrant(Resource):
"""
Describes to which tables and which privleges on each table this API Key grants access to trough tables attribute.
This is an internal data type, with no specific API endpoints
See https://carto.com/developers/auth-api/reference/#section/API-Key-format
Example:
.. code::
{
"type": "database",
"tables": [
{
"schema": "public",
"name": "my_table",
.. moduleauthor:: Jesús Arroyo
"""
from pyrestcli.fields import CharField
from .resources import Resource, Manager
from .paginators import CartoPaginator
API_VERSION = "v4"
API_ENDPOINT = "api/{api_version}/do/datasets"
class DODataset(Resource):
"""
Represents a Data Observatory Datasets object in CARTO.
"""
dataset = CharField()
id = CharField()
project = CharField()
table = CharField()
class Meta:
collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)
name_field = "id"
class DODatasetManager(Manager):
"""
]
}
"""
schema = CharField()
name = CharField()
permissions = CharField(many=True)
def to_json(self):
return {
'schema': self.schema,
'name': self.name,
'permissions': self.permissions
}
class Grants(Resource):
apis = CharField(many=True)
tables = TableGrantField(many=True)
services = CharField(many=True)
def get_id(self):
tables = []
if self.tables:
tables = [x.to_json() for x in self.tables]
return [
{
'type': 'apis',
'apis': self.apis or []
},
{
'type': 'database',
'tables': tables
class Meta:
collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)
name_field = "id"
class DOSubscriptionManager(Manager):
"""
Manager for the DOSubscription class.
"""
resource_class = DOSubscription
json_collection_attribute = "subscriptions"
paginator_class = CartoPaginator
class DOCreatedSubscription(Resource):
"""
Represents a Data Observatory Subscriptions in CARTO.
"""
id = CharField()
estimated_delivery_days = FloatField()
subscription_list_price = FloatField()
tos = CharField()
tos_link = CharField()
licenses = CharField()
licenses_link = CharField()
rights = CharField()
type = CharField()
class Meta:
collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)
.. moduleauthor:: Javier Goizueta
"""
from pyrestcli.fields import CharField, FloatField
from .resources import Resource, Manager
from .paginators import CartoPaginator
API_VERSION = "v4"
API_ENDPOINT = "api/{api_version}/do/subscription_info"
class DOSubscriptionInfo(Resource):
"""
Represents a Data Observatory Subscriptions in CARTO.
"""
id = CharField()
estimated_delivery_days = FloatField()
subscription_list_price = FloatField()
tos = CharField()
tos_link = CharField()
licenses = CharField()
licenses_link = CharField()
rights = CharField()
type = CharField()
class Meta:
collection_endpoint = API_ENDPOINT.format(api_version=API_VERSION)