def main(unused_args):
    # Allow per platform configuration.
    config_lib.CONFIG.AddContext(
        "Client Context", "Context applied when we run the client process.")

    startup.ClientInit()

    if flags.FLAGS.install:
        installer.RunInstaller()

    errors = config_lib.CONFIG.Validate(["Client", "CA", "Logging"])

    if errors and errors.keys() != ["Client.private_key"]:
        raise config_lib.ConfigFormatError(errors)

    enrollment_necessary = not config_lib.CONFIG.Get("Client.private_key")
    # Instantiating the client will create a private_key so we need to use a flag.
    client = GRRClient()
    if enrollment_necessary:
        logging.info("No private key found, starting enrollment.")
        client.client.InitiateEnrolment(comms.Status())

    if flags.FLAGS.break_on_start:
        pdb.set_trace()
    else:
        client.Run()
Пример #2
0
    def testUpdateConfiguration(self):
        """Test that we can update the config."""
        # A unique name on the filesystem for the writeback.
        self.config_file = os.path.join(self.temp_dir, "ConfigActionTest.yaml")

        # In a real client, the writeback location should be set to something real,
        # but for this test we make it the same as the config file..
        config_lib.CONFIG.SetWriteBack(self.config_file)

        # Make sure the file is gone
        self.assertRaises(IOError, open, self.config_file)

        location = ["http://www.example1.com/", "http://www.example2.com/"]
        request = rdf_protodict.Dict()
        request["Client.control_urls"] = location
        request["Client.foreman_check_frequency"] = 3600

        result = self.RunAction("UpdateConfiguration", request)

        self.assertEqual(result, [])
        self.assertEqual(config_lib.CONFIG["Client.foreman_check_frequency"],
                         3600)

        # Test the config file got written.
        data = open(self.config_file).read()
        self.assertTrue("control_urls: {0}".format(",".join(location)) in data)

        self.urls = []

        # Now test that our location was actually updated.

        def FakeUrlOpen(req, timeout=10):
            _ = timeout
            self.urls.append(req.get_full_url())
            return StringIO.StringIO()

        comms.urllib2.urlopen = FakeUrlOpen
        client_context = comms.GRRHTTPClient(worker=MockClientWorker)
        client_context.MakeRequest("", comms.Status())

        self.assertTrue(location[0] in self.urls[0])
        self.assertTrue(location[1] in self.urls[1])
Пример #3
0
def main(unused_args):
    # Allow per platform configuration.
    config_lib.CONFIG.AddContext(
        "Client Context", "Context applied when we run the client process.")

    startup.ClientInit()

    if flags.FLAGS.install:
        installer.RunInstaller()

    errors = config_lib.CONFIG.Validate(["Client", "CA", "Logging"])

    if not errors:
        client = GRRClient()
    elif errors.keys() == ["Client.private_key"]:
        client = GRRClient()
        client.client.InitiateEnrolment(comms.Status())
    else:
        raise config_lib.ConfigFormatError(errors)

    if flags.FLAGS.break_on_start:
        pdb.set_trace()
    else:
        client.Run()