diff --git a/nss_cache/sources/httpsource.py b/nss_cache/sources/httpsource.py index 9fa1564f..c9f9549c 100644 --- a/nss_cache/sources/httpsource.py +++ b/nss_cache/sources/httpsource.py @@ -33,6 +33,7 @@ from nss_cache.maps import netgroup from nss_cache.maps import passwd from nss_cache.maps import shadow +from nss_cache.maps import sshkey from nss_cache.sources import source from nss_cache.util import file_formats from nss_cache.util import curl @@ -50,6 +51,7 @@ class HttpFilesSource(source.Source): GROUP_URL = '' AUTOMOUNT_BASE_URL = '' NETGROUP_URL = '' + SSHKEY_URL = '' RETRY_DELAY = 5 RETRY_MAX = 3 TLS_CACERTFILE = '/etc/ssl/certs/ca-certificates.crt' @@ -90,6 +92,8 @@ def _SetDefaults(self, configuration): configuration['group_url'] = self.GROUP_URL if not 'netgroup_url' in configuration: configuration['netgroup_url'] = self.GROUP_URL + if not 'sshkey_url' in configuration: + configuration['sshkey_url'] = self.SSHKEY_URL if not 'retry_delay' in configuration: configuration['retry_delay'] = self.RETRY_DELAY if not 'retry_max' in configuration: @@ -191,6 +195,19 @@ def GetAutomountMasterMap(self): return master_map + def GetSshkeyMap(self, since=None): + """Return the sshkey map from this source. + + Args: + since: Get data only changed since this timestamp (inclusive) or None + for all data. + + Returns: + instance of sshkey.SshkeyMap + """ + return SshkeyUpdateGetter().GetUpdates(self, self.conf['sshkey_url'], since) + + class UpdateGetter(object): """Base class that gets updates over http.""" @@ -373,3 +390,14 @@ def GetParser(self): def CreateMap(self): """Returns a new NetgroupMap instance to have GroupMapEntries added to it.""" return netgroup.NetgroupMap() + +class SshkeyUpdateGetter(UpdateGetter): + """Get sshkey updates.""" + + def GetParser(self): + """Returns a MapParser to parse FilesSshkey cache.""" + return file_formats.FilesSshkeyMapParser() + + def CreateMap(self): + """Returns a new SshkeyMap instance to have SshkeyMapEntries added to it.""" + return sshkey.SshkeyMap() diff --git a/nss_cache/sources/httpsource_test.py b/nss_cache/sources/httpsource_test.py index 01fecb27..e1f13764 100644 --- a/nss_cache/sources/httpsource_test.py +++ b/nss_cache/sources/httpsource_test.py @@ -31,6 +31,7 @@ from nss_cache.maps import netgroup from nss_cache.maps import passwd from nss_cache.maps import shadow +from nss_cache.maps import sshkey from nss_cache.sources import httpsource from nss_cache.util import file_formats @@ -44,6 +45,7 @@ def setUp(self): self.config = {'passwd_url': 'PASSWD_URL', 'shadow_url': 'SHADOW_URL', 'group_url': 'GROUP_URL', + 'sshkey_url': 'SSHKEY_URL', 'retry_delay': 'TEST_RETRY_DELAY', 'retry_max': 'TEST_RETRY_MAX', 'tls_cacertfile': 'TEST_TLS_CACERTFILE', @@ -58,6 +60,8 @@ def testDefaultConfiguration(self): httpsource.HttpFilesSource.SHADOW_URL) self.assertEquals(source.conf['group_url'], httpsource.HttpFilesSource.GROUP_URL) + self.assertEquals(source.conf['sshkey_url'], + httpsource.HttpFilesSource.SSHKEY_URL) self.assertEquals(source.conf['retry_max'], httpsource.HttpFilesSource.RETRY_MAX) self.assertEquals(source.conf['retry_delay'], @@ -71,6 +75,7 @@ def testOverrideDefaultConfiguration(self): self.assertEquals(source.conf['passwd_url'], 'PASSWD_URL') self.assertEquals(source.conf['group_url'], 'GROUP_URL') self.assertEquals(source.conf['shadow_url'], 'SHADOW_URL') + self.assertEquals(source.conf['sshkey_url'], 'SSHKEY_URL') self.assertEquals(source.conf['retry_delay'], 'TEST_RETRY_DELAY') self.assertEquals(source.conf['retry_max'], 'TEST_RETRY_MAX') self.assertEquals(source.conf['tls_cacertfile'], 'TEST_TLS_CACERTFILE') @@ -305,5 +310,21 @@ def testCreateMap(self): automount.AutomountMap)) +class TestSshkeyUpdateGetter(unittest.TestCase): + + def setUp(self): + super(TestSshkeyUpdateGetter, self).setUp() + self.updater = httpsource.SshkeyUpdateGetter() + + def testGetParser(self): + parser = self.updater.GetParser() + self.assertTrue(isinstance(self.updater.GetParser(), + file_formats.FilesSshkeyMapParser)) + + def testCreateMap(self): + self.assertTrue(isinstance(self.updater.CreateMap(), + sshkey.SshkeyMap)) + + if __name__ == '__main__': unittest.main()