def __init__(self, store_api): LOG.info(_LI("Initializing scrubber with configuration: %s"), six.text_type({'registry_host': CONF.registry_host, 'registry_port': CONF.registry_port})) self.store_api = store_api registry.configure_registry_client() registry.configure_registry_admin_creds() # Here we create a request context with credentials to support # delayed delete when using multi-tenant backend storage admin_user = CONF.admin_user admin_tenant = CONF.admin_tenant_name if CONF.send_identity_headers: # When registry is operating in trusted-auth mode roles = [CONF.admin_role] self.admin_context = context.RequestContext(user=admin_user, tenant=admin_tenant, auth_token=None, roles=roles) self.registry = registry.get_registry_client(self.admin_context) else: ctxt = context.RequestContext() self.registry = registry.get_registry_client(ctxt) auth_token = self.registry.auth_token self.admin_context = context.RequestContext(user=admin_user, tenant=admin_tenant, auth_token=auth_token) self.db_queue = get_scrub_queue() self.pool = eventlet.greenpool.GreenPool(CONF.scrub_pool_size)
def __init__(self, store_api): LOG.info(_LI("Initializing scrubber with configuration: %s") % six.text_type({'registry_host': CONF.registry_host, 'registry_port': CONF.registry_port})) self.store_api = store_api registry.configure_registry_client() registry.configure_registry_admin_creds() # Here we create a request context with credentials to support # delayed delete when using multi-tenant backend storage admin_user = CONF.admin_user admin_tenant = CONF.admin_tenant_name if CONF.send_identity_headers: # When registry is operating in trusted-auth mode roles = [CONF.admin_role] self.admin_context = context.RequestContext(user=admin_user, tenant=admin_tenant, auth_token=None, roles=roles) self.registry = registry.get_registry_client(self.admin_context) else: ctxt = context.RequestContext() self.registry = registry.get_registry_client(ctxt) auth_token = self.registry.auth_token self.admin_context = context.RequestContext(user=admin_user, tenant=admin_tenant, auth_token=auth_token) self.db_queue = get_scrub_queue() self.pool = eventlet.greenpool.GreenPool(CONF.scrub_pool_size)
def __init__(self, store_api): LOG.info( _LI("Initializing scrubber with configuration: %s") % six.text_type({ 'scrubber_datadir': CONF.scrubber_datadir, 'cleanup': CONF.cleanup_scrubber, 'cleanup_time': CONF.cleanup_scrubber_time, 'registry_host': CONF.registry_host, 'registry_port': CONF.registry_port })) utils.safe_mkdirs(CONF.scrubber_datadir) self.store_api = store_api registry.configure_registry_client() registry.configure_registry_admin_creds() self.registry = registry.get_registry_client(context.RequestContext()) # Here we create a request context with credentials to support # delayed delete when using multi-tenant backend storage admin_tenant = CONF.admin_tenant_name auth_token = self.registry.auth_token self.admin_context = context.RequestContext(user=CONF.admin_user, tenant=admin_tenant, auth_token=auth_token) (self.file_queue, self.db_queue) = get_scrub_queues()
def __init__(self, store_api): LOG.info(_LI("Initializing scrubber with configuration: %s") % six.text_type({'scrubber_datadir': CONF.scrubber_datadir, 'cleanup': CONF.cleanup_scrubber, 'cleanup_time': CONF.cleanup_scrubber_time, 'registry_host': CONF.registry_host, 'registry_port': CONF.registry_port})) utils.safe_mkdirs(CONF.scrubber_datadir) self.store_api = store_api registry.configure_registry_client() registry.configure_registry_admin_creds() self.registry = registry.get_registry_client(context.RequestContext()) # Here we create a request context with credentials to support # delayed delete when using multi-tenant backend storage admin_tenant = CONF.admin_tenant_name auth_token = self.registry.auth_token self.admin_context = context.RequestContext(user=CONF.admin_user, tenant=admin_tenant, auth_token=auth_token) (self.file_queue, self.db_queue) = get_scrub_queues()
def __init__(self): self.datadir = CONF.scrubber_datadir self.cleanup = CONF.cleanup_scrubber self.cleanup_time = CONF.cleanup_scrubber_time # configs for registry API store auth self.admin_user = CONF.admin_user self.admin_tenant = CONF.admin_tenant_name host, port = CONF.registry_host, CONF.registry_port LOG.info( _("Initializing scrubber with conf: %s") % { 'datadir': self.datadir, 'cleanup': self.cleanup, 'cleanup_time': self.cleanup_time, 'registry_host': host, 'registry_port': port }) registry.configure_registry_client() registry.configure_registry_admin_creds() ctx = context.RequestContext() self.registry = registry.get_registry_client(ctx) utils.safe_mkdirs(self.datadir)
def add_location(self, image_id, location, user_context=None): """Adding image location to scrub queue. :param image_id: The opaque image identifier :param location: The opaque image location :param user_context: The user's request context :retval A boolean value to indicate success or not """ if user_context is not None: registry_client = registry.get_registry_client(user_context) else: registry_client = self.registry with lockutils.lock("scrubber-%s" % image_id, lock_file_prefix='glance-', external=True): # NOTE(zhiyan): make sure scrubber does not cleanup # 'pending_delete' images concurrently before the code # get lock and reach here. try: image = registry_client.get_image(image_id) if image['status'] == 'deleted': return True except exception.NotFound as e: LOG.warn(_LW("Failed to find image to delete: %s"), utils.exception_to_str(e)) return False loc_id = location.get('id', '-') if self.metadata_encryption_key: uri = crypt.urlsafe_encrypt(self.metadata_encryption_key, location['url'], 64) else: uri = location['url'] delete_time = time.time() + self.scrub_time file_path = os.path.join(self.scrubber_datadir, str(image_id)) if os.path.exists(file_path): # Append the uri of location to the queue file with open(file_path, 'a') as f: f.write('\n') f.write('\n'.join( [str(loc_id), uri, str(int(delete_time))])) else: # NOTE(zhiyan): Protect the file before we write any data. open(file_path, 'w').close() os.chmod(file_path, 0o600) with open(file_path, 'w') as f: f.write('\n'.join( [str(loc_id), uri, str(int(delete_time))])) os.utime(file_path, (delete_time, delete_time)) return True
def add_location(self, image_id, location, user_context=None): """Adding image location to scrub queue. :param image_id: The opaque image identifier :param location: The opaque image location :param user_context: The user's request context :retval A boolean value to indicate success or not """ if user_context is not None: registry_client = registry.get_registry_client(user_context) else: registry_client = self.registry with lockutils.lock("scrubber-%s" % image_id, lock_file_prefix='glance-', external=True): # NOTE(zhiyan): make sure scrubber does not cleanup # 'pending_delete' images concurrently before the code # get lock and reach here. try: image = registry_client.get_image(image_id) if image['status'] == 'deleted': return True except exception.NotFound as e: LOG.warn(_LW("Failed to find image to delete: %s"), utils.exception_to_str(e)) return False loc_id = location.get('id', '-') if self.metadata_encryption_key: uri = crypt.urlsafe_encrypt(self.metadata_encryption_key, location['url'], 64) else: uri = location['url'] delete_time = time.time() + self.scrub_time file_path = os.path.join(self.scrubber_datadir, str(image_id)) if os.path.exists(file_path): # Append the uri of location to the queue file with open(file_path, 'a') as f: f.write('\n') f.write('\n'.join([str(loc_id), uri, str(int(delete_time))])) else: # NOTE(zhiyan): Protect the file before we write any data. open(file_path, 'w').close() os.chmod(file_path, 0o600) with open(file_path, 'w') as f: f.write('\n'.join([str(loc_id), uri, str(int(delete_time))])) os.utime(file_path, (delete_time, delete_time)) return True
def __init__(self): self.scrub_time = CONF.scrub_time self.metadata_encryption_key = CONF.metadata_encryption_key registry.configure_registry_client() registry.configure_registry_admin_creds() self.registry = registry.get_registry_client(context.RequestContext()) admin_tenant_name = CONF.admin_tenant_name admin_token = self.registry.auth_token self.admin_context = context.RequestContext(user=CONF.admin_user, tenant=admin_tenant_name, auth_token=admin_token)
def test_get_registry_client_with_identity_headers(self): self.config(send_identity_headers=True) expected_identity_headers = { "X-User-Id": self.context.user, "X-Tenant-Id": self.context.tenant, "X-Roles": ",".join(self.context.roles), "X-Identity-Status": "Confirmed", "X-Service-Catalog": "null", } actual_client = rapi.get_registry_client(self.context) self.assertEqual(actual_client.identity_headers, expected_identity_headers)
def test_get_registry_client_with_identity_headers(self): self.config(send_identity_headers=True) expected_identity_headers = { 'X-User-Id': '', 'X-Tenant-Id': '', 'X-Roles': ','.join(self.context.roles), 'X-Identity-Status': 'Confirmed', 'X-Service-Catalog': 'null', } actual_client = rapi.get_registry_client(self.context) self.assertEqual(expected_identity_headers, actual_client.identity_headers)
def test_get_registry_client_with_identity_headers(self): self.config(send_identity_headers=True) expected_identity_headers = { 'X-User-Id': self.context.user, 'X-Tenant-Id': self.context.tenant, 'X-Roles': ','.join(self.context.roles), 'X-Identity-Status': 'Confirmed', 'X-Service-Catalog': 'null', } actual_client = rapi.get_registry_client(self.context) self.assertEqual(expected_identity_headers, actual_client.identity_headers)
def __init__(self): self.scrub_time = CONF.scrub_time self.metadata_encryption_key = CONF.metadata_encryption_key registry.configure_registry_client() registry.configure_registry_admin_creds() admin_user = CONF.admin_user admin_tenant = CONF.admin_tenant_name if CONF.send_identity_headers: # When registry is operating in trusted-auth mode roles = [CONF.admin_role] self.admin_context = context.RequestContext(user=admin_user, tenant=admin_tenant, auth_token=None, roles=roles) self.registry = registry.get_registry_client(self.admin_context) else: ctxt = context.RequestContext() self.registry = registry.get_registry_client(ctxt) admin_token = self.registry.auth_token self.admin_context = context.RequestContext(user=admin_user, tenant=admin_tenant, auth_token=admin_token)
def __init__(self, store_api): LOG.info(_("Initializing scrubber with configuration: %s") % unicode({'scrubber_datadir': CONF.scrubber_datadir, 'cleanup': CONF.cleanup_scrubber, 'cleanup_time': CONF.cleanup_scrubber_time, 'registry_host': CONF.registry_host, 'registry_port': CONF.registry_port})) utils.safe_mkdirs(CONF.scrubber_datadir) self.store_api = store_api registry.configure_registry_client() registry.configure_registry_admin_creds() self.registry = registry.get_registry_client(context.RequestContext()) (self.file_queue, self.db_queue) = get_scrub_queues()
def __init__(self, store_api): LOG.info( _("Initializing scrubber with configuration: %s") % unicode({ 'scrubber_datadir': CONF.scrubber_datadir, 'cleanup': CONF.cleanup_scrubber, 'cleanup_time': CONF.cleanup_scrubber_time, 'registry_host': CONF.registry_host, 'registry_port': CONF.registry_port })) utils.safe_mkdirs(CONF.scrubber_datadir) self.store_api = store_api registry.configure_registry_client() registry.configure_registry_admin_creds() self.registry = registry.get_registry_client(context.RequestContext()) (self.file_queue, self.db_queue) = get_scrub_queues()
def __init__(self): self.datadir = CONF.scrubber_datadir self.cleanup = CONF.cleanup_scrubber self.cleanup_time = CONF.cleanup_scrubber_time # configs for registry API store auth self.admin_user = CONF.admin_user self.admin_tenant = CONF.admin_tenant_name host, port = CONF.registry_host, CONF.registry_port LOG.info(_("Initializing scrubber with conf: %s") % {'datadir': self.datadir, 'cleanup': self.cleanup, 'cleanup_time': self.cleanup_time, 'registry_host': host, 'registry_port': port}) registry.configure_registry_client() registry.configure_registry_admin_creds() ctx = context.RequestContext() self.registry = registry.get_registry_client(ctx) utils.safe_mkdirs(self.datadir)
def test_get_registry_client(self): actual_client = rapi.get_registry_client(self.context) self.assertIsNone(actual_client.identity_headers)
def __init__(self): registry.configure_registry_client() registry.configure_registry_admin_creds() self.registry = registry.get_registry_client(context.RequestContext())
def __init__(self): self.scrub_time = CONF.scrub_time self.metadata_encryption_key = CONF.metadata_encryption_key registry.configure_registry_client() registry.configure_registry_admin_creds() self.registry = registry.get_registry_client(context.RequestContext())