Merge lp:~dpigott/lava-scheduler-tool/fix842524-add-token-file into lp:lava-scheduler-tool

Proposed by Zygmunt Krynicki
Status: Work in progress
Proposed branch: lp:~dpigott/lava-scheduler-tool/fix842524-add-token-file
Merge into: lp:lava-scheduler-tool
Diff against target: 150 lines (+112/-3) (has conflicts)
1 file modified
lava_scheduler_tool/commands.py (+112/-3)
Text conflict in lava_scheduler_tool/commands.py
To merge this branch: bzr merge lp:~dpigott/lava-scheduler-tool/fix842524-add-token-file
Reviewer Review Type Date Requested Status
Zygmunt Krynicki (community) Needs Fixing
Review via email: mp+79961@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Zygmunt Krynicki (zyga) wrote :

Could you look at resolving the merge conflict?

review: Needs Fixing

Unmerged revisions

10. By Dave Pigott

Added authentiaction token file support to cancel-job

9. By Dave Pigott

Added authentiction token file support to submit-job

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lava_scheduler_tool/commands.py'
2--- lava_scheduler_tool/commands.py 2011-10-19 03:11:36 +0000
3+++ lava_scheduler_tool/commands.py 2011-10-20 13:34:26 +0000
4@@ -16,12 +16,36 @@
5 # You should have received a copy of the GNU Lesser General Public License
6 # along with lava-scheduler-tool. If not, see <http://www.gnu.org/licenses/>.
7
8-import xmlrpclib
9+<<<<<<< TREE
10+import xmlrpclib
11+=======
12+import getpass
13+import urlparse
14+import xmlrpclib
15+>>>>>>> MERGE-SOURCE
16
17+<<<<<<< TREE
18 from lava_tool.authtoken import AuthenticatingServerProxy, KeyringAuthBackend
19 from lava_tool.interface import Command, LavaCommandError
20+=======
21+from lava_tool.authtoken import (
22+ AuthenticatingServerProxy,
23+ KeyringAuthBackend,
24+ MemoryAuthBackend,
25+ )
26+from lava_tool.interface import Command, LavaCommandError
27+>>>>>>> MERGE-SOURCE
28 from lava_tool.commands import ExperimentalCommandMixIn
29
30+def normalize_xmlrpc_url(uri):
31+ if '://' not in uri:
32+ uri = 'http://' + uri
33+ if not uri.endswith('/'):
34+ uri += '/'
35+ if not uri.endswith('/RPC2/'):
36+ uri += 'RPC2/'
37+ return uri
38+
39
40 class submit_job(ExperimentalCommandMixIn, Command):
41 """
42@@ -33,11 +57,53 @@
43 super(submit_job, cls).register_arguments(parser)
44 parser.add_argument("SERVER")
45 parser.add_argument("JSON_FILE")
46+ parser.add_argument(
47+ "--token-file", default=None,
48+ help="Read the password from a file rather than prompting for it.")
49
50 def invoke(self):
51 self.print_experimental_notice()
52+
53+ uri = normalize_xmlrpc_url(self.args.SERVER)
54+ parsed_host = urlparse.urlparse(uri)
55+
56+ if parsed_host.username:
57+ username = parsed_host.username
58+ else:
59+ username = getpass.getuser()
60+
61+ host = parsed_host.hostname
62+ if parsed_host.port:
63+ host += ':' + str(parsed_host.port)
64+
65+ uri = '%s://%s@%s%s' % (
66+ parsed_host.scheme, username, host, parsed_host.path)
67+
68+ if self.args.token_file:
69+ if parsed_host.password:
70+ raise LavaCommandError(
71+ "Token specified in url but --token-file also passed.");
72+ else:
73+ try:
74+ token_file = open(self.args.token_file)
75+ except IOError as ex:
76+ raise LavaCommandError(
77+ "opening %r failed: %s" % (self.args.token_file, ex))
78+ token = token_file.read().strip()
79+ else:
80+ if parsed_host.password:
81+ token = parsed_host.password
82+ else:
83+ token = getpass.getpass("Paste token for %s: " % uri)
84+
85+ userless_uri = '%s://%s%s' % (
86+ parsed_host.scheme, host, parsed_host.path)
87+
88+
89 server = AuthenticatingServerProxy(
90- self.args.SERVER, auth_backend=KeyringAuthBackend())
91+ uri, auth_backend = MemoryAuthBackend(
92+ [(username, userless_uri, token)]))
93+
94 with open(self.args.JSON_FILE, 'rb') as stream:
95 command_text = stream.read()
96 try:
97@@ -54,9 +120,52 @@
98 def register_arguments(self, parser):
99 parser.add_argument("SERVER")
100 parser.add_argument("JOB_ID", type=int)
101+ parser.add_argument(
102+ "--token-file", default=None,
103+ help="Read the password from a file rather than prompting for it.")
104
105 def invoke(self):
106 self.print_experimental_notice()
107+
108+ uri = normalize_xmlrpc_url(self.args.SERVER)
109+ parsed_host = urlparse.urlparse(uri)
110+
111+ if parsed_host.username:
112+ username = parsed_host.username
113+ else:
114+ username = getpass.getuser()
115+
116+ host = parsed_host.hostname
117+ if parsed_host.port:
118+ host += ':' + str(parsed_host.port)
119+
120+ uri = '%s://%s@%s%s' % (
121+ parsed_host.scheme, username, host, parsed_host.path)
122+
123+ if self.args.token_file:
124+ if parsed_host.password:
125+ raise LavaCommandError(
126+ "Token specified in url but --token-file also passed.");
127+ else:
128+ try:
129+ token_file = open(self.args.token_file)
130+ except IOError as ex:
131+ raise LavaCommandError(
132+ "opening %r failed: %s" % (self.args.token_file, ex))
133+ token = token_file.read().strip()
134+ else:
135+ if parsed_host.password:
136+ token = parsed_host.password
137+ else:
138+ token = getpass.getpass("Paste token for %s: " % uri)
139+
140+ userless_uri = '%s://%s%s' % (
141+ parsed_host.scheme, host, parsed_host.path)
142+
143+ self.print_experimental_notice()
144+
145 server = AuthenticatingServerProxy(
146- self.args.SERVER, auth_backend=KeyringAuthBackend())
147+ uri, auth_backend = MemoryAuthBackend(
148+ [(username, userless_uri, token)]))
149+
150 server.scheduler.cancel_job(self.args.JOB_ID)

Subscribers

People subscribed via source and target branches