diff options
author | Simo Sorce <simo@redhat.com> | 2014-04-11 15:42:54 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2014-04-11 17:25:54 -0400 |
commit | c3a2716985604564d46bc5367cf0be5e45d7f14a (patch) | |
tree | fc0061bcf5c5d6bc3a2f2ffb3dde9ad6d8d67113 | |
parent | 5bca20d28896ef9f89a7740996b1e13194fb9cb9 (diff) | |
download | ipsilon.git-c3a2716985604564d46bc5367cf0be5e45d7f14a.tar.gz ipsilon.git-c3a2716985604564d46bc5367cf0be5e45d7f14a.tar.xz ipsilon.git-c3a2716985604564d46bc5367cf0be5e45d7f14a.zip |
Store full path immediately
Allows to query .key and .cert to e used to find the files on the system
directly w/o having to know what path was previously used to initialize the
class.
Signed-off-by: Simo Sorce <simo@redhat.com>
-rwxr-xr-x | ipsilon/tools/certs.py | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/ipsilon/tools/certs.py b/ipsilon/tools/certs.py index a4b0f11..3a60488 100755 --- a/ipsilon/tools/certs.py +++ b/ipsilon/tools/certs.py @@ -34,21 +34,20 @@ class Certificate(object): self.path = os.getcwd() def generate(self, prefix, subject): - self.key = '%s.key' % prefix - self.cert = '%s.pem' % prefix + self.key = os.path.join(self.path, '%s.key' % prefix) + self.cert = os.path.join(self.path, '%s.pem' % prefix) self.subject = '/CN=%s' % subject command = ['openssl', 'req', '-x509', '-batch', '-days', '1825', '-newkey', 'rsa:2048', '-nodes', '-subj', self.subject, - '-keyout', os.path.join(self.path, self.key), - '-out', os.path.join(self.path, self.cert)] + '-keyout', self.key, '-out', self.cert] proc = Popen(command) proc.wait() def get_cert(self): if not self.cert: - raise NameError('Invalid certificate name: %s' % self.cert) - with open(os.path.join(self.path, self.cert), 'r') as f: + raise ValueError('Certificate unavailable') + with open(self.cert, 'r') as f: cert = f.readlines() #poor man stripping of BEGIN/END lines |