mirror of
https://github.com/openSUSE/osc.git
synced 2024-11-09 22:36:14 +01:00
Use makeurl instead of manual URL construction in do_token
The use of makeurl makes the code more readable/maintainable (IMHO) and it also does proper percentage encoding of the query string (not that the osc codebase cares much about it, though:/).
This commit is contained in:
parent
9b6b398016
commit
9eea35eda0
@ -791,17 +791,18 @@ class Osc(cmdln.Cmdln):
|
||||
args = slash_split(args)
|
||||
|
||||
apiurl = self.get_api_url()
|
||||
url = apiurl + "/person/" + conf.get_apiurl_usr(apiurl) + "/token"
|
||||
url_path = ['person', conf.get_apiurl_usr(apiurl), 'token']
|
||||
|
||||
if opts.create:
|
||||
print("Create a new token")
|
||||
url += "?cmd=create"
|
||||
query = {'cmd': 'create'}
|
||||
if opts.operation:
|
||||
url += "&operation=" + opts.operation
|
||||
query['operation'] = opts.operation
|
||||
if len(args) > 1:
|
||||
url += "&project=" + args[0]
|
||||
url += "&package=" + args[1]
|
||||
query['project'] = args[0]
|
||||
query['package'] = args[1]
|
||||
|
||||
url = makeurl(apiurl, url_path, query)
|
||||
f = http_POST(url)
|
||||
while True:
|
||||
buf = f.read(16384)
|
||||
@ -811,15 +812,17 @@ class Osc(cmdln.Cmdln):
|
||||
|
||||
elif opts.delete:
|
||||
print("Delete token")
|
||||
url += "/" + opts.delete
|
||||
url_path.append(opts.delete)
|
||||
url = makeurl(apiurl, url_path)
|
||||
http_DELETE(url)
|
||||
elif opts.trigger:
|
||||
print("Trigger token")
|
||||
operation = opts.operation or "runservice"
|
||||
url = apiurl + "/trigger/" + operation
|
||||
query = {}
|
||||
if len(args) > 1:
|
||||
url += "?project=" + args[0]
|
||||
url += "&package=" + args[1]
|
||||
query['project'] = args[0]
|
||||
query['package'] = args[1]
|
||||
url = makeurl(apiurl, ['trigger', operation], query)
|
||||
req = URLRequest(url)
|
||||
req.get_method = lambda: "POST"
|
||||
req.add_header('Content-Type', 'application/octet-stream')
|
||||
@ -830,6 +833,7 @@ class Osc(cmdln.Cmdln):
|
||||
if args and args[0] in ['create', 'delete', 'trigger']:
|
||||
raise oscerr.WrongArgs("Did you mean --" + args[0] + "?")
|
||||
# just list token
|
||||
url = makeurl(apiurl, url_path)
|
||||
for data in streamfile(url, http_GET):
|
||||
sys.stdout.write(decode_it(data))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user