コード例 #1
0
    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 = GrokAppConfig(mode=GrokAppConfig.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
 def tearDown(self):
   config = GrokAppConfig(mode=GrokAppConfig.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()
コード例 #3
0
ファイル: pavement.py プロジェクト: sergius/numenta-apps
def configure_grok(options):
    """ Initialize Grok's baseline and long-lasting ("override") configuration
  objects
  NOTE: called by jenkins-ec2 / jenkins-ci / src / run_pipeline.py
  """
    # First, generate Grok's baseline config objects
    call_task("gen_grok_base_config", options={"target": options.target})

    from grok.app import config, GrokAppConfig

    # Delete all configuration override objects
    config.clearAllConfigOverrides()

    # Initialize Grok API key
    apiKey = os.environ.get("GROK_API_KEY")
    if apiKey is None:
        apiKey = "".join(
            random.choice("".join(
                set(string.letters + string.digits) - set('1iLl0Oo')))
            for _ in xrange(5))

    config = GrokAppConfig(mode=GrokAppConfig.MODE_OVERRIDE_ONLY)
    config.add_section("security")
    config.set("security", "apikey", apiKey)
    config.save()
コード例 #4
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 = GrokAppConfig(mode=GrokAppConfig.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
コード例 #5
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 = GrokAppConfig(mode=GrokAppConfig.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
コード例 #6
0
        self.assertNotIn(key, result)
      else:
        self.assertIn(key, result)


 # handling Assertionerror as TestApp throws
 # AssertionError: Content-Type header found in a 204 response,
 # which must not return content.
  def testPostTSection(self):
    try:
      self.app.post("/aws", json.dumps(
        {"aws_access_key_id" : "dummy_value_aws_key"}), headers=self.headers)
    except AssertionError, ae:
      print ae.message
    finally:
      config = GrokAppConfig()
      self.assertEqual(config.get("aws", "aws_access_key_id"),
        "dummy_value_aws_key")


 # handling Assertionerror as TestApp throws
 # AssertionError: Content-Type header found in a 204 response,
 # which must not return content.
  def testPostAll(self):
    try:
      self.app.post("/", json.dumps(
        { "aws" : {"aws_secret_access_key" : "dummy_value_aws_secret",
          "aws_access_key_id" : "dummy_value_aws_key_id"}
         }), headers=self.headers)
    except AssertionError, ae:
      print ae.message