Merge lp:~toolpart/openerp-client-lib/xmlrpcs into lp:openerp-client-lib

Proposed by ViktorNagy
Status: Merged
Merged at revision: 35
Proposed branch: lp:~toolpart/openerp-client-lib/xmlrpcs
Merge into: lp:openerp-client-lib
Diff against target: 133 lines (+30/-16)
1 file modified
openerplib/main.py (+30/-16)
To merge this branch: bzr merge lp:~toolpart/openerp-client-lib/xmlrpcs
Reviewer Review Type Date Requested Status
Nicolas Vanhoren (OpenERP) Pending
Review via email: mp+76899@code.launchpad.net

Description of the change

Added secure xmlrpc (XML-RPC-S) connector.

To post a comment you must log in.
Revision history for this message
Nicolas Vanhoren (OpenERP) (niv-openerp) wrote :

Ok, I will discuss this with the rest of the team and see if we merge this.

But, please, in the future could you avoid automatic formatters? It makes an ugly diff.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'openerplib/main.py'
2--- openerplib/main.py 2011-09-22 15:45:57 +0000
3+++ openerplib/main.py 2011-09-25 12:25:23 +0000
4@@ -5,16 +5,16 @@
5 # Copyright (C) 2011 Nicolas Vanhoren
6 # Copyright (C) 2011 OpenERP s.a. (<http://openerp.com>).
7 # All rights reserved.
8-#
9+#
10 # Redistribution and use in source and binary forms, with or without
11-# modification, are permitted provided that the following conditions are met:
12-#
13+# modification, are permitted provided that the following conditions are met:
14+#
15 # 1. Redistributions of source code must retain the above copyright notice, this
16-# list of conditions and the following disclaimer.
17+# list of conditions and the following disclaimer.
18 # 2. Redistributions in binary form must reproduce the above copyright notice,
19 # this list of conditions and the following disclaimer in the documentation
20-# and/or other materials provided with the distribution.
21-#
22+# and/or other materials provided with the distribution.
23+#
24 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
25 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27@@ -25,7 +25,7 @@
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31-#
32+#
33 ##############################################################################
34
35 """
36@@ -36,7 +36,7 @@
37 """
38
39 import xmlrpclib
40-import logging
41+import logging
42 import socket
43
44 try:
45@@ -75,7 +75,7 @@
46 A type of connector that uses the XMLRPC protocol.
47 """
48 PROTOCOL = 'xmlrpc'
49-
50+
51 __logger = _getChildLogger(_logger, 'connector.xmlrpc')
52
53 def __init__(self, hostname, port=8069):
54@@ -92,6 +92,18 @@
55 service = xmlrpclib.ServerProxy(url)
56 return getattr(service, method)(*args)
57
58+class XmlRPCSConnector(XmlRPCConnector):
59+ """
60+ A type of connector that uses the secured XMLRPC protocol.
61+ """
62+ PROTOCOL = 'xmlrpcs'
63+
64+ __logger = _getChildLogger(_logger, 'connector.xmlrpcs')
65+
66+ def __init__(self, hostname, port=8071):
67+ super(XmlRPCSConnector, self).__init__(hostname, port)
68+ self.url = 'https://%s:%d/xmlrpc' % (self.hostname, self.port)
69+
70 class NetRPC_Exception(Exception):
71 """
72 Exception for NetRPC errors.
73@@ -171,7 +183,7 @@
74 """
75
76 PROTOCOL = 'netrpc'
77-
78+
79 __logger = _getChildLogger(_logger, 'connector.netrpc')
80
81 def __init__(self, hostname, port=8070):
82@@ -202,7 +214,7 @@
83 self.connector = connector
84 self.service_name = service_name
85 self.__logger = _getChildLogger(_getChildLogger(_logger, 'service'),service_name)
86-
87+
88 def __getattr__(self, method):
89 """
90 :param method: The name of the method to execute on the service.
91@@ -259,7 +271,7 @@
92 self.database, self.login, self.password = database, login, password
93
94 self.user_id = user_id
95-
96+
97 def check_login(self, force=True):
98 """
99 Checks that the login information is valid. Throws an AuthenticationError if the
100@@ -270,15 +282,15 @@
101 """
102 if self.user_id and not force:
103 return
104-
105+
106 if not self.database or not self.login or self.password is None:
107 raise AuthenticationError("Creditentials not provided")
108-
109+
110 self.user_id = self.get_service("common").login(self.database, self.login, self.password)
111 if not self.user_id:
112 raise AuthenticationError("Authentication failure")
113 self.__logger.debug("Authenticated with user id %s", self.user_id)
114-
115+
116 def get_model(self, model_name):
117 """
118 Returns a Model instance to allow easy remote manipulation of an OpenERP model.
119@@ -375,6 +387,8 @@
120 port = 8069 if protocol=="xmlrpc" else 8070
121 if protocol == "xmlrpc":
122 return XmlRPCConnector(hostname, port)
123+ elif protocol == "xmlrpcs":
124+ return XmlRPCSConnector(hostname, port)
125 elif protocol == "netrpc":
126 return NetRPCConnector(hostname, port)
127 else:
128@@ -396,4 +410,4 @@
129 already know it, in most cases you don't need to specify it.
130 """
131 return Connection(get_connector(hostname, protocol, port), database, login, password, user_id)
132-
133+

Subscribers

People subscribed via source and target branches