Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def populate_connections(self, workbook_item):
if not workbook_item.id:
error = "Workbook item missing ID. Workbook must be retrieved from server first."
raise MissingRequiredFieldError(error)
def connection_fetcher():
return self._get_workbook_connections(workbook_item)
workbook_item._set_connections(connection_fetcher)
logger.info('Populated connections for workbook (ID: {0})'.format(workbook_item.id))
def populate_connections(self, datasource_item):
if not datasource_item.id:
error = 'Datasource item missing ID. Datasource must be retrieved from server first.'
raise MissingRequiredFieldError(error)
def connections_fetcher():
return self._get_datasource_connections(datasource_item)
datasource_item._set_connections(connections_fetcher)
logger.info('Populated connections for datasource (ID: {0})'.format(datasource_item.id))
def run(self, task_item):
if not task_item.id:
error = "User item missing ID."
raise MissingRequiredFieldError(error)
url = "{0}/{1}/runNow".format(self.baseurl, task_item.id)
run_req = RequestFactory.Task.run_req(task_item)
server_response = self.post_request(url, run_req)
return server_response.content
def populate(self, item):
if not item.id:
error = "Server item is missing ID. Item must be retrieved from server first."
raise MissingRequiredFieldError(error)
def permission_fetcher():
return self._get_permissions(item)
item._set_permissions(permission_fetcher)
logger.info('Populated permissions for item (ID: {0})'.format(item.id))
def populate_views(self, workbook_item, usage=False):
if not workbook_item.id:
error = "Workbook item missing ID. Workbook must be retrieved from server first."
raise MissingRequiredFieldError(error)
def view_fetcher():
return self._get_views_for_workbook(workbook_item, usage)
workbook_item._set_views(view_fetcher)
logger.info('Populated views for workbook (ID: {0}'.format(workbook_item.id))
def update(self, site_item):
if not site_item.id:
error = "Site item missing ID."
raise MissingRequiredFieldError(error)
if site_item.admin_mode:
if site_item.admin_mode == SiteItem.AdminMode.ContentOnly and site_item.user_quota:
error = 'You cannot set admin_mode to ContentOnly and also set a user quota'
raise ValueError(error)
url = "{0}/{1}".format(self.baseurl, site_item.id)
update_req = RequestFactory.Site.update_req(site_item)
server_response = self.put_request(url, update_req)
logger.info('Updated site item (ID: {0})'.format(site_item.id))
update_site = copy.copy(site_item)
return update_site._parse_common_tags(server_response.content, self.parent_srv.namespace)
def update(self, project_item):
if not project_item.id:
error = "Project item missing ID."
raise MissingRequiredFieldError(error)
url = "{0}/{1}".format(self.baseurl, project_item.id)
update_req = RequestFactory.Project.update_req(project_item)
server_response = self.put_request(url, update_req)
logger.info('Updated project item (ID: {0})'.format(project_item.id))
updated_project = ProjectItem.from_response(server_response.content, self.parent_srv.namespace)[0]
return updated_project
def update(self, datasource_item):
if not datasource_item.id:
error = 'Datasource item missing ID. Datasource must be retrieved from server first.'
raise MissingRequiredFieldError(error)
self._resource_tagger.update_tags(self.baseurl, datasource_item)
# Update the datasource itself
url = "{0}/{1}".format(self.baseurl, datasource_item.id)
update_req = RequestFactory.Datasource.update_req(datasource_item)
server_response = self.put_request(url, update_req)
logger.info('Updated datasource item (ID: {0})'.format(datasource_item.id))
updated_datasource = copy.copy(datasource_item)
return updated_datasource._parse_common_elements(server_response.content, self.parent_srv.namespace)
def add_user(self, group_item, user_id):
if not group_item.id:
error = "Group item missing ID."
raise MissingRequiredFieldError(error)
if not user_id:
error = "User ID undefined."
raise ValueError(error)
url = "{0}/{1}/users".format(self.baseurl, group_item.id)
add_req = RequestFactory.Group.add_user_req(user_id)
server_response = self.post_request(url, add_req)
return UserItem.from_response(server_response.content, self.parent_srv.namespace).pop()
logger.info('Added user (id: {0}) to group (ID: {1})'.format(user_id, group_item.id))
def populate_preview_image(self, view_item):
if not view_item.id or not view_item.workbook_id:
error = "View item missing ID or workbook ID."
raise MissingRequiredFieldError(error)
def image_fetcher():
return self._get_preview_for_view(view_item)
view_item._set_preview_image(image_fetcher)
logger.info('Populated preview image for view (ID: {0})'.format(view_item.id))