From c87a65024177ed67cd4ec0f7d533d973f8e1f971 Mon Sep 17 00:00:00 2001 From: Endi Sukma Dewata Date: Thu, 21 Feb 2013 19:47:35 -0500 Subject: Added security domain info validation. The installer script has been modified to validate security domain info in both interactive and silent installation. A basic Python API has been added to access the REST interface. Ticket #473 --- base/common/python/pki/__init__.py | 0 base/common/python/pki/account.py | 31 ++++++++++++++++++++++ base/common/python/pki/client.py | 53 ++++++++++++++++++++++++++++++++++++++ base/common/python/pki/system.py | 38 +++++++++++++++++++++++++++ 4 files changed, 122 insertions(+) create mode 100644 base/common/python/pki/__init__.py create mode 100644 base/common/python/pki/account.py create mode 100644 base/common/python/pki/client.py create mode 100644 base/common/python/pki/system.py (limited to 'base/common/python') diff --git a/base/common/python/pki/__init__.py b/base/common/python/pki/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/base/common/python/pki/account.py b/base/common/python/pki/account.py new file mode 100644 index 000000000..84f2d0ef0 --- /dev/null +++ b/base/common/python/pki/account.py @@ -0,0 +1,31 @@ +#!/usr/bin/python +# Authors: +# Endi S. Dewata +# +# 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; version 2 of the License. +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2013 Red Hat, Inc. +# All rights reserved. +# + +class AccountClient: + + def __init__(self, connection): + self.connection = connection + + def login(self): + self.connection.get('account/login') + + def logout(self): + self.connection.get('account/logout') diff --git a/base/common/python/pki/client.py b/base/common/python/pki/client.py new file mode 100644 index 000000000..7635fe879 --- /dev/null +++ b/base/common/python/pki/client.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# Authors: +# Endi S. Dewata +# +# 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; version 2 of the License. +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2013 Red Hat, Inc. +# All rights reserved. +# + +import requests + +class PKIConnection: + + def __init__(self, + protocol='http', + hostname='localhost', + port=80, + subsystem='ca'): + + self.protocol = protocol + self.hostname = hostname + self.port = port + self.subsystem = subsystem + + self.serverURI = self.protocol + '://' +\ + self.hostname + ':' + self.port + '/' + \ + self.subsystem + + self.session = requests.Session() + self.session.headers.update({'Accept': 'application/json'}) + + def authenticate(self, username=None, password=None): + if username is not None and password is not None: + self.session.auth = (username, password) + + def get(self, path): + r = self.session.get( + self.serverURI + '/rest/' + path, + verify=False) + r.raise_for_status() + return r \ No newline at end of file diff --git a/base/common/python/pki/system.py b/base/common/python/pki/system.py new file mode 100644 index 000000000..61ffbb9ff --- /dev/null +++ b/base/common/python/pki/system.py @@ -0,0 +1,38 @@ +#!/usr/bin/python +# Authors: +# Endi S. Dewata +# +# 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; version 2 of the License. +# +# 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, write to the Free Software Foundation, Inc., +# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +# +# Copyright (C) 2013 Red Hat, Inc. +# All rights reserved. +# + +class SecurityDomainInfo: + + def __init__(self): + pass + +class SecurityDomainClient: + + def __init__(self, connection): + self.connection = connection + + def getSecurityDomainInfo(self): + r = self.connection.get('securityDomain/domainInfo') + + info = SecurityDomainInfo() + info.name = r.json['DomainInfo']['@id'] + + return info -- cgit