mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
parent
6f6bdf7914
commit
c4a7f64c02
6 changed files with 25 additions and 32 deletions
|
@ -151,7 +151,7 @@ class GalaxyAPI(object):
|
||||||
if role_name:
|
if role_name:
|
||||||
args['alternate_role_name'] = role_name
|
args['alternate_role_name'] = role_name
|
||||||
elif github_repo.startswith('ansible-role'):
|
elif github_repo.startswith('ansible-role'):
|
||||||
args['alternate_role_name'] = github_repo[len('ansible-role')+1:]
|
args['alternate_role_name'] = github_repo[len('ansible-role') + 1:]
|
||||||
data = self.__call_galaxy(url, args=urlencode(args))
|
data = self.__call_galaxy(url, args=urlencode(args))
|
||||||
if data.get('results', None):
|
if data.get('results', None):
|
||||||
return data['results']
|
return data['results']
|
||||||
|
@ -164,9 +164,9 @@ class GalaxyAPI(object):
|
||||||
"""
|
"""
|
||||||
url = '%s/imports/' % self.baseurl
|
url = '%s/imports/' % self.baseurl
|
||||||
if task_id is not None:
|
if task_id is not None:
|
||||||
url = "%s?id=%d" % (url,task_id)
|
url = "%s?id=%d" % (url, task_id)
|
||||||
elif github_user is not None and github_repo is not None:
|
elif github_user is not None and github_repo is not None:
|
||||||
url = "%s?github_user=%s&github_repo=%s" % (url,github_user,github_repo)
|
url = "%s?github_user=%s&github_repo=%s" % (url, github_user, github_repo)
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("Expected task_id or github_user and github_repo")
|
raise AnsibleError("Expected task_id or github_user and github_repo")
|
||||||
|
|
||||||
|
@ -248,7 +248,7 @@ class GalaxyAPI(object):
|
||||||
if search:
|
if search:
|
||||||
search_url += '&autocomplete=' + urlquote(search)
|
search_url += '&autocomplete=' + urlquote(search)
|
||||||
|
|
||||||
tags = kwargs.get('tags',None)
|
tags = kwargs.get('tags', None)
|
||||||
platforms = kwargs.get('platforms', None)
|
platforms = kwargs.get('platforms', None)
|
||||||
page_size = kwargs.get('page_size', None)
|
page_size = kwargs.get('page_size', None)
|
||||||
author = kwargs.get('author', None)
|
author = kwargs.get('author', None)
|
||||||
|
@ -296,6 +296,6 @@ class GalaxyAPI(object):
|
||||||
|
|
||||||
@g_connect
|
@g_connect
|
||||||
def delete_role(self, github_user, github_repo):
|
def delete_role(self, github_user, github_repo):
|
||||||
url = "%s/removerole/?github_user=%s&github_repo=%s" % (self.baseurl,github_user,github_repo)
|
url = "%s/removerole/?github_user=%s&github_repo=%s" % (self.baseurl, github_user, github_repo)
|
||||||
data = self.__call_galaxy(url, headers=self.__auth_header(), method='DELETE')
|
data = self.__call_galaxy(url, headers=self.__auth_header(), method='DELETE')
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -52,12 +52,12 @@ class GalaxyLogin(object):
|
||||||
self.get_credentials()
|
self.get_credentials()
|
||||||
|
|
||||||
def get_credentials(self):
|
def get_credentials(self):
|
||||||
display.display(u'\n\n' + "We need your " + stringc("Github login",'bright cyan') +
|
display.display(u'\n\n' + "We need your " + stringc("Github login", 'bright cyan') +
|
||||||
" to identify you.", screen_only=True)
|
" to identify you.", screen_only=True)
|
||||||
display.display("This information will " + stringc("not be sent to Galaxy",'bright cyan') +
|
display.display("This information will " + stringc("not be sent to Galaxy", 'bright cyan') +
|
||||||
", only to " + stringc("api.github.com.","yellow"), screen_only=True)
|
", only to " + stringc("api.github.com.", "yellow"), screen_only=True)
|
||||||
display.display("The password will not be displayed." + u'\n\n', screen_only=True)
|
display.display("The password will not be displayed." + u'\n\n', screen_only=True)
|
||||||
display.display("Use " + stringc("--github-token",'yellow') +
|
display.display("Use " + stringc("--github-token", 'yellow') +
|
||||||
" if you do not want to enter your password." + u'\n\n', screen_only=True)
|
" if you do not want to enter your password." + u'\n\n', screen_only=True)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -90,7 +90,7 @@ class GalaxyLogin(object):
|
||||||
display.vvvvv('removing token: %s' % token['token_last_eight'])
|
display.vvvvv('removing token: %s' % token['token_last_eight'])
|
||||||
try:
|
try:
|
||||||
open_url('https://api.github.com/authorizations/%d' % token['id'], url_username=self.github_username,
|
open_url('https://api.github.com/authorizations/%d' % token['id'], url_username=self.github_username,
|
||||||
url_password=self.github_password, method='DELETE', force_basic_auth=True,)
|
url_password=self.github_password, method='DELETE', force_basic_auth=True)
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
res = json.load(e)
|
res = json.load(e)
|
||||||
raise AnsibleError(res['message'])
|
raise AnsibleError(res['message'])
|
||||||
|
@ -100,7 +100,7 @@ class GalaxyLogin(object):
|
||||||
Create a personal authorization token with a note of 'ansible-galaxy login'
|
Create a personal authorization token with a note of 'ansible-galaxy login'
|
||||||
'''
|
'''
|
||||||
self.remove_github_token()
|
self.remove_github_token()
|
||||||
args = json.dumps({"scopes":["public_repo"], "note":"ansible-galaxy login"})
|
args = json.dumps({"scopes": ["public_repo"], "note": "ansible-galaxy login"})
|
||||||
try:
|
try:
|
||||||
data = json.load(open_url(self.GITHUB_AUTH, url_username=self.github_username,
|
data = json.load(open_url(self.GITHUB_AUTH, url_username=self.github_username,
|
||||||
url_password=self.github_password, force_basic_auth=True, data=args))
|
url_password=self.github_password, force_basic_auth=True, data=args))
|
||||||
|
|
|
@ -42,12 +42,13 @@ except ImportError:
|
||||||
from ansible.utils.display import Display
|
from ansible.utils.display import Display
|
||||||
display = Display()
|
display = Display()
|
||||||
|
|
||||||
|
|
||||||
class GalaxyRole(object):
|
class GalaxyRole(object):
|
||||||
|
|
||||||
SUPPORTED_SCMS = set(['git', 'hg'])
|
SUPPORTED_SCMS = set(['git', 'hg'])
|
||||||
META_MAIN = os.path.join('meta', 'main.yml')
|
META_MAIN = os.path.join('meta', 'main.yml')
|
||||||
META_INSTALL = os.path.join('meta', '.galaxy_install_info')
|
META_INSTALL = os.path.join('meta', '.galaxy_install_info')
|
||||||
ROLE_DIRS = ('defaults','files','handlers','meta','tasks','templates','vars','tests')
|
ROLE_DIRS = ('defaults', 'files', 'handlers', 'meta', 'tasks', 'templates', 'vars', 'tests')
|
||||||
|
|
||||||
def __init__(self, galaxy, name, src=None, version=None, scm=None, path=None):
|
def __init__(self, galaxy, name, src=None, version=None, scm=None, path=None):
|
||||||
|
|
||||||
|
@ -114,7 +115,6 @@ class GalaxyRole(object):
|
||||||
|
|
||||||
return self._metadata
|
return self._metadata
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def install_info(self):
|
def install_info(self):
|
||||||
"""
|
"""
|
||||||
|
@ -238,7 +238,7 @@ class GalaxyRole(object):
|
||||||
# are no versions in the list, we'll grab the head
|
# are no versions in the list, we'll grab the head
|
||||||
# of the master branch
|
# of the master branch
|
||||||
if len(role_versions) > 0:
|
if len(role_versions) > 0:
|
||||||
loose_versions = [LooseVersion(a.get('name',None)) for a in role_versions]
|
loose_versions = [LooseVersion(a.get('name', None)) for a in role_versions]
|
||||||
loose_versions.sort()
|
loose_versions.sort()
|
||||||
self.version = str(loose_versions[-1])
|
self.version = str(loose_versions[-1])
|
||||||
elif role_data.get('github_branch', None):
|
elif role_data.get('github_branch', None):
|
||||||
|
@ -256,7 +256,6 @@ class GalaxyRole(object):
|
||||||
else:
|
else:
|
||||||
raise AnsibleError("No valid role data found")
|
raise AnsibleError("No valid role data found")
|
||||||
|
|
||||||
|
|
||||||
if tmp_file:
|
if tmp_file:
|
||||||
|
|
||||||
display.debug("installing from %s" % tmp_file)
|
display.debug("installing from %s" % tmp_file)
|
||||||
|
@ -346,7 +345,7 @@ class GalaxyRole(object):
|
||||||
if not local_file:
|
if not local_file:
|
||||||
try:
|
try:
|
||||||
os.unlink(tmp_file)
|
os.unlink(tmp_file)
|
||||||
except (OSError,IOError) as e:
|
except (OSError, IOError) as e:
|
||||||
display.warning("Unable to remove tmp file (%s): %s" % (tmp_file, str(e)))
|
display.warning("Unable to remove tmp file (%s): %s" % (tmp_file, str(e)))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
|
@ -46,9 +46,9 @@ class GalaxyToken(object):
|
||||||
display.vvv('Opened %s' % self.file)
|
display.vvv('Opened %s' % self.file)
|
||||||
return open(self.file, 'r')
|
return open(self.file, 'r')
|
||||||
# config.yml not found, create and chomd u+rw
|
# config.yml not found, create and chomd u+rw
|
||||||
f = open(self.file,'w')
|
f = open(self.file, 'w')
|
||||||
f.close()
|
f.close()
|
||||||
os.chmod(self.file,S_IRUSR|S_IWUSR) # owner has +rw
|
os.chmod(self.file, S_IRUSR | S_IWUSR) # owner has +rw
|
||||||
display.vvv('Created %s' % self.file)
|
display.vvv('Created %s' % self.file)
|
||||||
return open(self.file, 'r')
|
return open(self.file, 'r')
|
||||||
|
|
||||||
|
@ -60,6 +60,5 @@ class GalaxyToken(object):
|
||||||
return self.config.get('token', None)
|
return self.config.get('token', None)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
with open(self.file,'w') as f:
|
with open(self.file, 'w') as f:
|
||||||
yaml.safe_dump(self.config,f,default_flow_style=False)
|
yaml.safe_dump(self.config, f, default_flow_style=False)
|
||||||
|
|
||||||
|
|
|
@ -23,11 +23,6 @@ lib/ansible/executor/process/worker.py
|
||||||
lib/ansible/executor/stats.py
|
lib/ansible/executor/stats.py
|
||||||
lib/ansible/executor/task_executor.py
|
lib/ansible/executor/task_executor.py
|
||||||
lib/ansible/executor/task_queue_manager.py
|
lib/ansible/executor/task_queue_manager.py
|
||||||
lib/ansible/galaxy/__init__.py
|
|
||||||
lib/ansible/galaxy/api.py
|
|
||||||
lib/ansible/galaxy/login.py
|
|
||||||
lib/ansible/galaxy/role.py
|
|
||||||
lib/ansible/galaxy/token.py
|
|
||||||
lib/ansible/inventory/__init__.py
|
lib/ansible/inventory/__init__.py
|
||||||
lib/ansible/inventory/dir.py
|
lib/ansible/inventory/dir.py
|
||||||
lib/ansible/inventory/expand_hosts.py
|
lib/ansible/inventory/expand_hosts.py
|
||||||
|
|
Loading…
Reference in a new issue