def test03Expire(self): """Tests the expire mechanism.""" s = utils.FastStore(max_size=100) key = "test1" s.Put(key, 1) # This should not raise self.assertEqual(s.Get(key), 1) s.ExpireObject(key) self.assertRaises(KeyError, s.Get, key)
def setUp(self): super(TestTransfer, self).setUp() # Set suitable defaults for testing self.old_window_size = transfer.GetFile.WINDOW_SIZE self.old_chunk_size = transfer.GetFile.CHUNK_SIZE transfer.GetFile.WINDOW_SIZE = 10 transfer.GetFile.CHUNK_SIZE = 600 * 1024 # We wiped the data_store so we have to retransmit all blobs. standard.HASH_CACHE = utils.FastStore(100)
def test02StoreRefresh(self): """Test that store keeps recently gotten objects fresh.""" s = utils.FastStore(max_size=5) keys = [] for i in range(0, 5): keys.append(s.Put(i, i)) # This should not raise because keys[0] should be refreshed each time its # gotten for i in range(0, 1000): s.Get(keys[0]) s.Put(i, i)
def test01StoreExpiration(self): """Testing store removes objects when full.""" s = utils.FastStore(max_size=5) keys = [] for i in range(0, 100): keys.append(s.Put(i, i)) # This should not raise s.Get(keys[-1]) # This should raise though self.assertRaises(KeyError, s.Get, keys[0])
def __init__(self): self.client_id_re = aff4_grr.VFSGRRClient.CLIENT_ID_RE self.acl_cache = utils.AgeBasedCache( max_size=10000, max_age=config_lib.CONFIG["ACL.cache_age"]) self.flow_cache = utils.FastStore(max_size=10000) self.super_token = access_control.ACLToken(username="******").SetUID() self.write_access_helper = self._CreateWriteAccessHelper() self.read_access_helper = self._CreateReadAccessHelper() self.query_access_helper = self._CreateQueryAccessHelper() super(FullAccessControlManager, self).__init__()
def __init__(self, certificate=None, private_key=None): """Creates a communicator. Args: certificate: Our own certificate. private_key: Our own private key. """ self.private_key = private_key self.certificate = certificate self._ClearServerCipherCache() # A cache for encrypted ciphers self.encrypted_cipher_cache = utils.FastStore(max_size=50000)
def __init__(self, certificate=None, private_key=None): """Creates a communicator. Args: certificate: Our own certificate. private_key: Our own private key. """ self.private_key = private_key self.certificate = certificate self.server_cipher = None self.server_cipher_age = rdfvalue.RDFDatetime().FromSecondsFromEpoch(0) # A cache for encrypted ciphers self.encrypted_cipher_cache = utils.FastStore(max_size=50000)
def __init__(self, certificate=None, private_key=None): """Creates a communicator. Args: certificate: Our own certificate in string form (as PEM). private_key: Our own private key in string form (as PEM). """ # A cache of cipher objects. self.cipher_cache = utils.TimeBasedCache(max_age=24 * 3600) self.private_key = private_key self.certificate = certificate # A cache for encrypted ciphers self.encrypted_cipher_cache = utils.FastStore(max_size=50000)
def MockClientMountPointsWithImage(self, image_path, fs_type="ext2"): """Mock the client to run off a test image. Args: image_path: The path to the image file. fs_type: The filesystem in the image. Returns: A context manager which ensures that client actions are served off the test image. """ def MockGetMountpoints(): return {"/": (image_path, fs_type)} return utils.MultiStubber( (client_utils_linux, "GetMountpoints", MockGetMountpoints), (client_utils_osx, "GetMountpoints", MockGetMountpoints), (standard, "HASH_CACHE", utils.FastStore(100)))
# Set and write the certificate to the client record. client.Set(client.Schema.CERT, cert) client.Set(client.Schema.FIRST_SEEN, rdfvalue.RDFDatetime.Now()) index = client_index.CreateClientIndex(token=self.token) index.AddClient(client) client.Close(sync=True) # Publish the client enrollment message. self.Publish("ClientEnrollment", self.client_id) self.Log("Enrolled %s successfully", self.client_id) enrolment_cache = utils.FastStore(5000) class Enroler(flow.WellKnownFlow): """Manage enrolment requests.""" well_known_session_id = rdfvalue.SessionID(queue=queues.ENROLLMENT, flow_name="Enrol") def ProcessMessage(self, message): """Begins an enrollment flow for this client. Args: message: The Certificate sent by the client. Note that this message is not authenticated. """ cert = rdf_crypto.Certificate(message.payload)
def __init__(self): self.pub_key_cache = utils.FastStore(max_size=50000)
offset = fd.Tell() data = fd.Read(args.length) except (IOError, OSError), e: self.SetStatus(rdf_flows.GrrStatus.ReturnedStatus.IOERROR, e) return # Now return the data to the server self.SendReply(offset=offset, data=data, length=len(data), pathspec=fd.pathspec) HASH_CACHE = utils.FastStore(100) class TransferBuffer(actions.ActionPlugin): """Reads a buffer from a file and returns it to the server efficiently.""" in_rdfvalue = rdf_client.BufferReference out_rdfvalue = rdf_client.BufferReference def Run(self, args): """Reads a buffer on the client and sends it to the server.""" # Make sure we limit the size of our output if args.length > MAX_BUFFER_SIZE: raise RuntimeError("Can not read buffers this large.") data = vfs.ReadVFS(args.pathspec, args.offset,
# Copyright 2010 Google Inc. All Rights Reserved. """Implements VFSHandlers for files on the client.""" import logging import os import re import sys import threading from grr.client import client_utils from grr.client import vfs from grr.lib import rdfvalue from grr.lib import utils # File handles are cached here. FILE_HANDLE_CACHE = utils.FastStore() class LockedFileHandle(object): """An object which encapsulates access to a file.""" def __init__(self, filename): self.lock = threading.RLock() self.fd = open(filename, "rb") self.filename = filename def Seek(self, offset, whence=0): self.fd.seek(offset, whence) def Read(self, length): return self.fd.read(length)
def __init__(self): self._routing_maps_cache = utils.FastStore()
def __init__(self, certificate, private_key): super(RelationalServerCommunicator, self).__init__(certificate=certificate, private_key=private_key) self.pub_key_cache = utils.FastStore(max_size=50000) self.common_name = self.certificate.GetCN()
def __init__(self): super(IPResolver, self).__init__() self.cache = utils.FastStore(max_size=100)