def ssl(): """ For docs, see https://github.com/pkimber/docs.""" if not env.site_info.ssl: abort("'{}' is not set-up for SSL in the Salt pillar".format(env.site_info.domain)) folder_info = FolderInfo(env.site_info) if not exists(folder_info.srv_folder(), use_sudo=True): abort("{} folder does not exist on the server".format(folder_info.srv_folder())) if exists(folder_info.ssl_folder(), use_sudo=True): print(green("SSL folder exists: {}".format(folder_info.ssl_folder()))) else: print(green("Create SSL folder: {}".format(folder_info.ssl_folder()))) sudo('mkdir {}'.format(folder_info.ssl_folder())) sudo('chown www-data:www-data {}'.format(folder_info.ssl_folder())) sudo('chmod 0400 {}'.format(folder_info.ssl_folder())) if exists(folder_info.ssl_cert_folder(), use_sudo=True): print(green("Certificate folder exists: {}".format(folder_info.ssl_cert_folder()))) else: print(green("Create certificate folder: {}".format(folder_info.ssl_cert_folder()))) sudo('mkdir {}'.format(folder_info.ssl_cert_folder())) sudo('chown www-data:www-data {}'.format(folder_info.ssl_cert_folder())) sudo('chmod 0400 {}'.format(folder_info.ssl_cert_folder())) put( env.site_info.ssl_cert(), folder_info.ssl_cert(), use_sudo=True, mode=0400, ) sudo('chown www-data:www-data {}'.format(folder_info.ssl_cert())) print(green(folder_info.ssl_cert())) put( env.site_info.ssl_server_key(), folder_info.ssl_server_key(), use_sudo=True, mode=0400, ) sudo('chown www-data:www-data {}'.format(folder_info.ssl_server_key())) print(green(folder_info.ssl_server_key())) print(yellow("Complete"))
class TestFolderInfo(unittest.TestCase): def _site_info(self): module_folder = os.path.dirname(os.path.realpath(__file__)) folder = os.path.join(module_folder, 'data', 'sites', 'data') folder = os.path.abspath(folder) return SiteInfo('drop-temp', 'csw_web', folder) def _site_info_testing(self): module_folder = os.path.dirname(os.path.realpath(__file__)) folder = os.path.join(module_folder, 'data', 'sites', 'data_testing') folder = os.path.abspath(folder) return SiteInfo('drop-test', 'kb_couk', folder) def setUp(self): self.folder = FolderInfo(self._site_info()) def test_folder_deploy(self): self.assertEquals( '/home/web/repo/project/csw_web/deploy', self.folder.deploy() ) def test_folder_install(self): folder = FolderInfo(self._site_info(), '1.2.34') self.assertIn( '/home/web/repo/project/csw_web/deploy', folder.install() ) def test_folder_install_temp(self): folder = FolderInfo(self._site_info(), '1.2.34') temp_folder = folder.install_temp() self.assertIn('/home/web/repo/project/csw_web/deploy', temp_folder) self.assertIn('temp', temp_folder) def test_folder_install_venv(self): folder = FolderInfo(self._site_info(), '1.2.34') folder_name = folder.install_venv() self.assertIn('/home/web/repo/project/csw_web/deploy', folder_name) self.assertIn('venv', folder_name) def test_folder_live(self): self.assertEquals( '/home/web/repo/project/csw_web/live', self.folder.live() ) def test_folder_site(self): self.assertEquals( '/home/web/repo/project/csw_web', self.folder.site() ) def test_folder_vassals(self): self.assertSequenceEqual( ('/home/web/repo/uwsgi/vassals/csw_web.ini',), self.folder.vassals() ) def test_invalid_folder_version(self): with self.assertRaises(TaskError) as cm: self.folder.install() self.assertIn( "class wasn't constructed with a version number", cm.exception.value ) def test_srv_folder(self): self.assertEquals( '/srv', self.folder.srv_folder() )