Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sshkey maps to http source. #75

Merged
merged 1 commit into from
Oct 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions nss_cache/sources/httpsource.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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."""

Expand Down Expand Up @@ -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()
21 changes: 21 additions & 0 deletions nss_cache/sources/httpsource_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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',
Expand All @@ -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'],
Expand All @@ -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')
Expand Down Expand Up @@ -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()