Exemplo n.º 1
0
 def upload(self,
            appid,
            return_to=None,
            breadcrumbs=None,
            state=None,
            appfile=None,
            force=None,
            **kw):
     """
     Present a form for direct upload of an app
     """
     if state:
         state = StateDict.unserialize(state)
         breadcrumbs = state.get('breadcrumbs')
     else:
         breadcrumbs = parse_breadcrumbs_string(breadcrumbs)
         breadcrumbs.append([_('Upload app'), None])
         state = StateDict({
             'return_to':
             return_to if return_to else self.make_url(
                 ['manager', splunk.getDefault('namespace')],
                 translate=False),
             'breadcrumbs':
             breadcrumbs
         })
     error = None
     if appfile is not None and cherrypy.request.method == 'POST':
         try:
             force = (force == '1')
             appid = self.processAppUpload(appfile, force)
             module.moduleMapper.resetInstalledModules()
             memoizedViews.clearCachedViews()
             return self.checkstatus(appid, state=state)
         except SBFileUploadException, e:
             error = e.message
 def upload(self, appid, return_to=None, breadcrumbs=None, state=None, appfile=None, force=None, **kw):
     """
     Present a form for direct upload of an app
     """
     if state:
         state = StateDict.unserialize(state)
         breadcrumbs = state.get('breadcrumbs')
     else:
         breadcrumbs = parse_breadcrumbs_string(breadcrumbs)
         breadcrumbs.append([_('Upload app'), None])
         state = StateDict({
             'return_to': return_to if return_to else self.make_url(['manager', splunk.getDefault('namespace'), 'apps','local'], translate=False),
             'breadcrumbs': breadcrumbs
             })
     error = None
     if appfile is not None and cherrypy.request.method == 'POST':
         try:
             force = (force == '1')
             appid = self.processAppUpload(appfile, force)
             module.moduleMapper.resetInstalledModules()
             memoizedViews.clearCachedViews()
             return self.checkstatus(appid, state=state)
         except SBFileUploadException, e:
             error = e.message
         except splunk.RESTException, e:
             error = e.get_extended_message_text()
Exemplo n.º 3
0
                    state.serialize()
                })

        if response.status not in [200, 201]:
            return self.redirect_to_url(
                ['/manager/appinstall', appid],
                _qs={
                    'error':
                    _('An error occurred while installing the app: %s - %s') %
                    (str(response.status), content),
                    'state':
                    state.serialize()
                })

        module.moduleMapper.resetInstalledModules()
        memoizedViews.clearCachedViews()
        logger.info("App %s installed" % appid)
        return self.checkstatus(appid, state=state)

    @route('/:appid/:update=update', methods='POST')
    @expose_page(must_login=True)
    def update(self, appid, state, update=None, **kw):
        """
        Attempt to download and install an app update from Splunkbase
        """
        if not isinstance(state, StateDict):
            state = StateDict.unserialize(state)
        sbSessionKey = self.getSBSessionKey()
        if not sbSessionKey:
            # login required
            return self.render_admin_template(
            if e.statusCode == 403:
                return self.render_admin_template('/admin/appinstall/sb-login.html', {
                    'appid': appid,
                    'breadcrumbs': state['breadcrumbs'],
                    'error': _('SplunkApps login timed out'),
                    'state': state,
                    'next': install
                })
            else:
                return self.redirect_to_url(['/manager/appinstall', appid], _qs={'error': _('An error occurred while downloading the app: %s') % str(e), 'state': state.serialize()})

        if response.status not in [200, 201]:
            return self.redirect_to_url(['/manager/appinstall', appid], _qs={'error': _('An error occurred while installing the app: %s - %s') % (str(response.status), content), 'state': state.serialize()})

        module.moduleMapper.resetInstalledModules()
        memoizedViews.clearCachedViews()
        logger.info("App %s installed" % appid)
        return self.checkstatus(appid, state=state)


    @route('/:appid/:update=update', methods='POST')
    @expose_page(must_login=True)
    def update(self, appid, state, update=None, **kw):
        """
        Attempt to download and install an app update from Splunkbase
        """
        if not isinstance(state, StateDict):
            state = StateDict.unserialize(state)
        sbSessionKey = self.getSBSessionKey()
        if not sbSessionKey:
            # login required