- Add timeout param.
 - Some improvement on params description.
This commit is contained in:
Slezhuk Yevgeniy 2017-02-27 15:56:58 +04:00 committed by John R Barker
parent 2cd6e56dc2
commit ea2b27f931

View file

@ -35,7 +35,7 @@ options:
uri:
required: true
description:
- Base URI for the JIRA instance
- Base URI for the JIRA instance.
operation:
required: true
@ -99,25 +99,32 @@ options:
required: false
version_added: 2.3
description:
- Set type of link, when action 'link' selected
- Set type of link, when action 'link' selected.
inwardissue:
required: false
version_added: 2.3
description:
- set issue from which link will be created
- Set issue from which link will be created.
outwardissue:
required: false
version_added: 2.3
description:
- set issue to which link will be created
- Set issue to which link will be created.
fields:
required: false
description:
- This is a free-form data structure that can contain arbitrary data. This is passed directly to the JIRA REST API (possibly after merging with other required data, as when passed to create). See examples for more information, and the JIRA REST API for the structure required for various fields.
timeout:
required: false
version_added: 2.3
description:
- Set timeout, in seconds, on requests to JIRA API.
default: 10
notes:
- "Currently this only works with basic-auth."
@ -237,7 +244,7 @@ from ansible.module_utils.basic import *
from ansible.module_utils.urls import *
from ansible.module_utils.pycompat24 import get_exception
def request(url, user, passwd, data=None, method=None):
def request(url, user, passwd, timeout, data=None, method=None):
if data:
data = json.dumps(data)
@ -249,7 +256,7 @@ def request(url, user, passwd, data=None, method=None):
# inject the basic-auth header up-front to ensure that JIRA treats
# the requests as authorized for this user.
auth = base64.encodestring('%s:%s' % (user, passwd)).replace('\n', '')
response, info = fetch_url(module, url, data=data, method=method,
response, info = fetch_url(module, url, data=data, method=method, timeout=timeout,
headers={'Content-Type':'application/json',
'Authorization':"Basic %s" % auth})
@ -263,14 +270,14 @@ def request(url, user, passwd, data=None, method=None):
else:
return {}
def post(url, user, passwd, data):
return request(url, user, passwd, data=data, method='POST')
def post(url, user, passwd, timeout, data):
return request(url, user, passwd, timeout, data=data, method='POST')
def put(url, user, passwd, data):
return request(url, user, passwd, data=data, method='PUT')
def put(url, user, passwd, timeout, data):
return request(url, user, passwd, timeout, data=data, method='PUT')
def get(url, user, passwd):
return request(url, user, passwd)
def get(url, user, passwd, timeout):
return request(url, user, passwd, timeout)
def create(restbase, user, passwd, params):
@ -288,7 +295,7 @@ def create(restbase, user, passwd, params):
url = restbase + '/issue/'
ret = post(url, user, passwd, data)
ret = post(url, user, passwd, params['timeout'], data)
return ret
@ -300,7 +307,7 @@ def comment(restbase, user, passwd, params):
url = restbase + '/issue/' + params['issue'] + '/comment'
ret = post(url, user, passwd, data)
ret = post(url, user, passwd, params['timeout'], data)
return ret
@ -312,21 +319,21 @@ def edit(restbase, user, passwd, params):
url = restbase + '/issue/' + params['issue']
ret = put(url, user, passwd, data)
ret = put(url, user, passwd, params['timeout'],data)
return ret
def fetch(restbase, user, passwd, params):
url = restbase + '/issue/' + params['issue']
ret = get(url, user, passwd)
ret = get(url, user, passwd, params['timeout'])
return ret
def transition(restbase, user, passwd, params):
# Find the transition id
turl = restbase + '/issue/' + params['issue'] + "/transitions"
tmeta = get(turl, user, passwd)
tmeta = get(turl, user, passwd, params['timeout'])
target = params['status']
tid = None
@ -343,7 +350,7 @@ def transition(restbase, user, passwd, params):
data = { 'transition': { "id" : tid },
'fields': params['fields']}
ret = post(url, user, passwd, data)
ret = post(url, user, passwd, params['timeout'], data)
return ret
@ -356,7 +363,7 @@ def link(restbase, user, passwd, params):
url = restbase + '/issueLink/'
ret = post(url, user, passwd, data)
ret = post(url, user, passwd, params['timeout'], data)
return ret
@ -390,6 +397,7 @@ def main():
linktype=dict(),
inwardissue=dict(),
outwardissue=dict(),
timeout=dict(type='float', default=10),
),
supports_check_mode=False
)