mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-23 10:51:24 -07:00
Add a User-Agent string to the API request (#38587)
This commit is contained in:
parent
19977e80f0
commit
afc196acf1
3 changed files with 12 additions and 6 deletions
|
@ -1,4 +1,5 @@
|
|||
import json
|
||||
import sys
|
||||
|
||||
from ansible.module_utils.urls import fetch_url
|
||||
|
||||
|
@ -33,9 +34,12 @@ class Response(object):
|
|||
|
||||
class ScalewayAPI(object):
|
||||
|
||||
def __init__(self, module, headers, base_url):
|
||||
def __init__(self, module, base_url, headers=None):
|
||||
self.module = module
|
||||
self.headers = headers
|
||||
self.headers = {'User-Agent': self.get_user_agent_string(module),
|
||||
'Content-type': 'application/json'}
|
||||
if headers is not None:
|
||||
self.headers.update(headers)
|
||||
self.base_url = base_url
|
||||
|
||||
def _url_builder(self, path):
|
||||
|
@ -59,6 +63,10 @@ class ScalewayAPI(object):
|
|||
|
||||
return Response(resp, info)
|
||||
|
||||
@staticmethod
|
||||
def get_user_agent_string(module):
|
||||
return "ansible %s Python %s" % (module.ansible_version, sys.version.split(' ')[0])
|
||||
|
||||
def get(self, path, data=None, headers=None):
|
||||
return self.send('GET', path, data, headers)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue