def updateSettings(self, section=None):
        if section != "usertrack":
            # Everything but usertrack requires authentication...
            apikey = AuthenticatedBaseHandler.extractAuthHeader()
            authResult = AuthenticatedBaseHandler.compareAuthorization(apikey)

            if authResult is False:
                AuthenticatedBaseHandler.raiseAuthFailure()

        dirty = False
        data = web.data()
        if data:
            sections = {}
            if section:
                sections = {section: utils.jsonDecode(data)}
            else:
                sections = utils.jsonDecode(data)

            config = HTMItAppConfig(mode=HTMItAppConfig.MODE_OVERRIDE_ONLY)

            for s in sections:
                if s in self.validSections():
                    for key in sections[s]:
                        if not config.has_section(s):
                            config.add_section(s)
                        config.set(s, key, sections[s][key])
                        dirty = True
                else:
                    return False
            if dirty:
                config.save()

            return dirty
コード例 #2
0
ファイル: settings_api.py プロジェクト: AmitShah/numenta-apps
  def updateSettings(self, section=None):
    if section != "usertrack":
      # Everything but usertrack requires authentication...
      apikey = AuthenticatedBaseHandler.extractAuthHeader()
      authResult = AuthenticatedBaseHandler.compareAuthorization(apikey)

      if authResult is False:
        AuthenticatedBaseHandler.raiseAuthFailure()

    dirty = False
    data = web.data()
    if data:
      sections = {}
      if section:
        sections = {section: utils.jsonDecode(data)}
      else:
        sections = utils.jsonDecode(data)

      config = HTMItAppConfig(mode=HTMItAppConfig.MODE_OVERRIDE_ONLY)

      for s in sections:
        if s in self.validSections():
          for key in sections[s]:
            if not config.has_section(s):
              config.add_section(s)
            config.set(s, key, sections[s][key])
            dirty = True
        else:
          return False
      if dirty:
        config.save()

      return dirty
コード例 #3
0
    def testPOSTSection(self):
        """
    Test for POST for '/_settings', Set some setting
    resoponse is validated for appropriate headers and body
    """
        # IMPORTANT: functions are executed in reverse order from when they are
        # added so we need to add config.save first.
        configBackup = HTMItAppConfig(mode=HTMItAppConfig.MODE_OVERRIDE_ONLY)
        self.addCleanup(configBackup.save)
        del configBackup

        try:
            self.app.post("/aws",
                          app_utils.jsonEncode(
                              {"aws_access_key_id": "dummy_aws_key1"}),
                          headers=self.headers)
        except AssertionError, ae:
            print ae.message
コード例 #4
0
    def testPOSTAll(self):
        """
    Test for POST for '/_settings', Set All Settings
    resoponse is validated for appropriate headers and body
    """
        # Set up cleanup calls for resetting the config values
        # IMPORTANT: functions are executed in reverse order from when they are
        # added so we need to add config.save first.
        configBackup = HTMItAppConfig(mode=HTMItAppConfig.MODE_OVERRIDE_ONLY)
        self.addCleanup(configBackup.save)
        del configBackup

        try:
            # Make the POST request
            self.app.post("/",
                          app_utils.jsonEncode({
                              "aws": {
                                  "aws_access_key_id": "dummy_aws_key3",
                                  "aws_secret_access_key": "dummy_aws_secret3"
                              }
                          }),
                          headers=self.headers)
        except AssertionError, ae:
            print ae.message
コード例 #5
0
    """
        # IMPORTANT: functions are executed in reverse order from when they are
        # added so we need to add config.save first.
        configBackup = HTMItAppConfig(mode=HTMItAppConfig.MODE_OVERRIDE_ONLY)
        self.addCleanup(configBackup.save)
        del configBackup

        try:
            self.app.post("/aws",
                          app_utils.jsonEncode(
                              {"aws_access_key_id": "dummy_aws_key1"}),
                          headers=self.headers)
        except AssertionError, ae:
            print ae.message
        finally:
            config = HTMItAppConfig()
            self.assertEqual(config.get("aws", "aws_access_key_id"),
                             "dummy_aws_key1")

    def testPOSTSectionInvalid(self):
        """
    Test for POST for '/_settings', Set some invalid setting
    resoponse is validated for appropriate headers and body
    """
        with self.assertRaises(AppError) as e:
            self.app.post("/foo",
                          app_utils.jsonEncode(
                              {"aws_access_key_id": "dummy_aws_key2"}),
                          headers=self.headers)
        self.assertIn(
            "Bad response: 400 Bad Request (not 200 OK or 3xx redirect"
コード例 #6
0
    Test for POST for '/_settings', Set some setting
    resoponse is validated for appropriate headers and body
    """
    # IMPORTANT: functions are executed in reverse order from when they are
    # added so we need to add config.save first.
    configBackup = HTMItAppConfig(mode=HTMItAppConfig.MODE_OVERRIDE_ONLY)
    self.addCleanup(configBackup.save)
    del configBackup

    try:
      self.app.post("/aws", app_utils.jsonEncode(
        {"aws_access_key_id" : "dummy_aws_key1"}), headers=self.headers)
    except AssertionError, ae:
      print ae.message
    finally:
      config = HTMItAppConfig()
      self.assertEqual(config.get("aws", "aws_access_key_id"),
                       "dummy_aws_key1")


  def testPOSTSectionInvalid(self):
    """
    Test for POST for '/_settings', Set some invalid setting
    resoponse is validated for appropriate headers and body
    """
    with self.assertRaises(AppError) as e:
      self.app.post("/foo", app_utils.jsonEncode(
        {"aws_access_key_id" : "dummy_aws_key2"}), headers=self.headers)
    self.assertIn("Bad response: 400 Bad Request (not 200 OK or 3xx redirect"
    " for /foo)\nFailed to update configuration settings", str(e.exception))
 def tearDown(self):
   config = HTMItAppConfig(mode=HTMItAppConfig.MODE_OVERRIDE_ONLY)
   if not config.has_section("aws"):
     config.add_section("aws")
   config.set("aws", "aws_secret_access_key", self.default_aws_secret_key)
   config.set("aws", "aws_access_key_id", self.default_aws_access_key)
   config.save()