diff options
author | Lars Wirzenius <liw@liw.fi> | 2017-04-14 15:41:57 +0300 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2017-04-14 15:44:17 +0300 |
commit | 2df653cef7c34bfdebeddfd273ec2a66fcf8a6e9 (patch) | |
tree | 8112ad6ae5b77a66733e1d3a437a95af449d596a | |
parent | e84c04d32dba8a7c7ebd799bc00696a6a6589640 (diff) | |
download | vmdb2-2df653cef7c34bfdebeddfd273ec2a66fcf8a6e9.tar.gz |
Drop YarnHelper entirely
It wasn't being used anymore.
-rw-r--r-- | yarns/yarnhelper.py | 76 | ||||
-rw-r--r-- | yarns/yarnhelper_tests.py | 33 |
2 files changed, 0 insertions, 109 deletions
diff --git a/yarns/yarnhelper.py b/yarns/yarnhelper.py deleted file mode 100644 index 765f697..0000000 --- a/yarns/yarnhelper.py +++ /dev/null @@ -1,76 +0,0 @@ -# Copyright 2016 Lars Wirzenius -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# =*= License: GPL-3+ =*= - - -import email -import imaplib -import os -import subprocess -import urlparse - -import requests -import yaml - - -variables_filename = os.environ.get('VARIABLES', 'vars.yaml') - - -class YarnHelper(object): - - def construct_aliased_http_request( - self, address, method, url, data=None, headers=None): - - if headers is None: - headers = {} - - parts = list(urlparse.urlparse(url)) - headers['Host'] = parts[1] - parts[1] = address - aliased_url = urlparse.urlunparse(parts) - - r = requests.Request(method, aliased_url, data=data, headers=headers) - return r.prepare() - - def http_get(self, address, url): # pragma: no cover - r = self.construct_aliased_http_request(address, 'GET', url) - s = requests.Session() - resp = s.send(r) - return resp.status_code, resp.content - - def get_password_with_pass(self, pass_home, pass_name): # pragma: no cover - p = subprocess.Popen( - ['env', 'HOME={}'.format(pass_home), 'pass', 'show', pass_name], - stdout=subprocess.PIPE) - stdout, stderr = p.communicate() - password = stdout.rstrip() - return password - - def iterate_mails_in_imap_mailbox( - self, address, user, password, callback, exp): # pragma: no cover - m = imaplib.IMAP4_SSL(address) - m.login(user, password) - m.select('INBOX', False) - typ, data = m.search(None, 'ALL') - for num in data[0].split(): - typ, data = m.fetch(num, '(RFC822)') - typ, text = data[0] - msg = email.message_from_string(text) - callback(m, num, msg) - if exp: - m.expunge() - m.close() - m.logout() diff --git a/yarns/yarnhelper_tests.py b/yarns/yarnhelper_tests.py deleted file mode 100644 index 40dc89e..0000000 --- a/yarns/yarnhelper_tests.py +++ /dev/null @@ -1,33 +0,0 @@ -# Copyright 2016 Lars Wirzenius -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# =*= License: GPL-3+ =*= - - -import os -import unittest - -import yarnhelper - - -class HttpTests(unittest.TestCase): - - def test_constructs_aliased_request(self): - h = yarnhelper.YarnHelper() - server = 'new.example.com' - url = 'http://www.example.com/path' - r = h.construct_aliased_http_request(server, 'GET', url) - self.assertEqual(r.url, 'http://new.example.com/path') - self.assertEqual(r.headers['Host'], 'www.example.com') |