mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Replace categories with tags.
Also added --ignore-certs option for use with install and search commands. Helpful when overriding server and server has self signed cert.
This commit is contained in:
parent
6d8abe84e4
commit
8360a1b3f2
3 changed files with 29 additions and 30 deletions
|
@ -85,9 +85,9 @@ class GalaxyCLI(CLI):
|
||||||
elif self.action == "search":
|
elif self.action == "search":
|
||||||
self.parser.add_option('-P', '--platforms', dest='platforms',
|
self.parser.add_option('-P', '--platforms', dest='platforms',
|
||||||
help='list of OS platforms to filter by')
|
help='list of OS platforms to filter by')
|
||||||
self.parser.add_option('-C', '--categories', dest='categories',
|
self.parser.add_option('-T', '--tags', dest='tags',
|
||||||
help='list of categories to filter by')
|
help='list of tags to filter by')
|
||||||
self.parser.set_usage("usage: %prog search [<search_term>] [-C <category1,category2>] [-P platform]")
|
self.parser.set_usage("usage: %prog search [<search_term>] [-T <tag1,tag2>] [-P platform]")
|
||||||
|
|
||||||
# options that apply to more than one action
|
# options that apply to more than one action
|
||||||
if self.action != "init":
|
if self.action != "init":
|
||||||
|
@ -99,6 +99,8 @@ class GalaxyCLI(CLI):
|
||||||
if self.action in ("info","init","install","search"):
|
if self.action in ("info","init","install","search"):
|
||||||
self.parser.add_option('-s', '--server', dest='api_server', default="https://galaxy.ansible.com",
|
self.parser.add_option('-s', '--server', dest='api_server', default="https://galaxy.ansible.com",
|
||||||
help='The API server destination')
|
help='The API server destination')
|
||||||
|
self.parser.add_option('-c', '--ignore-certs', action='store_false', dest='validate_certs', default=True,
|
||||||
|
help='Ignore SSL certificate validation errors.')
|
||||||
|
|
||||||
if self.action in ("init","install"):
|
if self.action in ("init","install"):
|
||||||
self.parser.add_option('-f', '--force', dest='force', action='store_true', default=False,
|
self.parser.add_option('-f', '--force', dest='force', action='store_true', default=False,
|
||||||
|
@ -251,9 +253,6 @@ class GalaxyCLI(CLI):
|
||||||
platforms = []
|
platforms = []
|
||||||
if not offline and self.api:
|
if not offline and self.api:
|
||||||
platforms = self.api.get_list("platforms") or []
|
platforms = self.api.get_list("platforms") or []
|
||||||
categories = []
|
|
||||||
if not offline and self.api:
|
|
||||||
categories = self.api.get_list("categories") or []
|
|
||||||
|
|
||||||
# group the list of platforms from the api based
|
# group the list of platforms from the api based
|
||||||
# on their names, with the release field being
|
# on their names, with the release field being
|
||||||
|
@ -270,7 +269,6 @@ class GalaxyCLI(CLI):
|
||||||
issue_tracker_url = 'http://example.com/issue/tracker',
|
issue_tracker_url = 'http://example.com/issue/tracker',
|
||||||
min_ansible_version = '1.2',
|
min_ansible_version = '1.2',
|
||||||
platforms = platform_groups,
|
platforms = platform_groups,
|
||||||
categories = categories,
|
|
||||||
)
|
)
|
||||||
rendered_meta = Environment().from_string(self.galaxy.default_meta).render(inject)
|
rendered_meta = Environment().from_string(self.galaxy.default_meta).render(inject)
|
||||||
f = open(main_yml_path, 'w')
|
f = open(main_yml_path, 'w')
|
||||||
|
@ -543,7 +541,7 @@ class GalaxyCLI(CLI):
|
||||||
elif len(self.args) == 1:
|
elif len(self.args) == 1:
|
||||||
search = self.args.pop()
|
search = self.args.pop()
|
||||||
|
|
||||||
response = self.api.search_roles(search, self.options.platforms, self.options.categories)
|
response = self.api.search_roles(search, self.options.platforms, self.options.tags)
|
||||||
|
|
||||||
if 'count' in response:
|
if 'count' in response:
|
||||||
self.galaxy.display.display("Found %d roles matching your search:\n" % response['count'])
|
self.galaxy.display.display("Found %d roles matching your search:\n" % response['count'])
|
||||||
|
|
|
@ -62,7 +62,7 @@ class GalaxyAPI(object):
|
||||||
return 'v1'
|
return 'v1'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
data = json.load(open_url(api_server))
|
data = json.load(open_url(api_server, validate_certs=self.galaxy.options.validate_certs))
|
||||||
return data.get("current_version", 'v1')
|
return data.get("current_version", 'v1')
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# TODO: report error
|
# TODO: report error
|
||||||
|
@ -86,7 +86,7 @@ class GalaxyAPI(object):
|
||||||
url = '%s/roles/?owner__username=%s&name=%s' % (self.baseurl, user_name, role_name)
|
url = '%s/roles/?owner__username=%s&name=%s' % (self.baseurl, user_name, role_name)
|
||||||
self.galaxy.display.vvvv("- %s" % (url))
|
self.galaxy.display.vvvv("- %s" % (url))
|
||||||
try:
|
try:
|
||||||
data = json.load(open_url(url))
|
data = json.load(open_url(url, validate_certs=self.galaxy.options.validate_certs))
|
||||||
if len(data["results"]) != 0:
|
if len(data["results"]) != 0:
|
||||||
return data["results"][0]
|
return data["results"][0]
|
||||||
except:
|
except:
|
||||||
|
@ -103,13 +103,13 @@ class GalaxyAPI(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = '%s/roles/%d/%s/?page_size=50' % (self.baseurl, int(role_id), related)
|
url = '%s/roles/%d/%s/?page_size=50' % (self.baseurl, int(role_id), related)
|
||||||
data = json.load(open_url(url))
|
data = json.load(open_url(url, validate_certs=self.galaxy.options.validate_certs))
|
||||||
results = data['results']
|
results = data['results']
|
||||||
done = (data.get('next', None) == None)
|
done = (data.get('next', None) == None)
|
||||||
while not done:
|
while not done:
|
||||||
url = '%s%s' % (self.baseurl, data['next'])
|
url = '%s%s' % (self.baseurl, data['next'])
|
||||||
self.galaxy.display.display(url)
|
self.galaxy.display.display(url)
|
||||||
data = json.load(open_url(url))
|
data = json.load(open_url(url, validate_certs=self.galaxy.options.validate_certs))
|
||||||
results += data['results']
|
results += data['results']
|
||||||
done = (data.get('next', None) == None)
|
done = (data.get('next', None) == None)
|
||||||
return results
|
return results
|
||||||
|
@ -123,7 +123,7 @@ class GalaxyAPI(object):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
url = '%s/%s/?page_size' % (self.baseurl, what)
|
url = '%s/%s/?page_size' % (self.baseurl, what)
|
||||||
data = json.load(open_url(url))
|
data = json.load(open_url(url, validate_certs=self.galaxy.options.validate_certs))
|
||||||
if "results" in data:
|
if "results" in data:
|
||||||
results = data['results']
|
results = data['results']
|
||||||
else:
|
else:
|
||||||
|
@ -134,27 +134,27 @@ class GalaxyAPI(object):
|
||||||
while not done:
|
while not done:
|
||||||
url = '%s%s' % (self.baseurl, data['next'])
|
url = '%s%s' % (self.baseurl, data['next'])
|
||||||
self.galaxy.display.display(url)
|
self.galaxy.display.display(url)
|
||||||
data = json.load(open_url(url))
|
data = json.load(open_url(url, validate_certs=self.galaxy.options.validate_certs))
|
||||||
results += data['results']
|
results += data['results']
|
||||||
done = (data.get('next', None) == None)
|
done = (data.get('next', None) == None)
|
||||||
return results
|
return results
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
raise AnsibleError("Failed to download the %s list: %s" % (what, str(error)))
|
raise AnsibleError("Failed to download the %s list: %s" % (what, str(error)))
|
||||||
|
|
||||||
def search_roles(self, search, platforms=None, categories=None):
|
def search_roles(self, search, platforms=None, tags=None):
|
||||||
|
|
||||||
search_url = self.baseurl + '/roles/?page=1'
|
search_url = self.baseurl + '/roles/?page=1'
|
||||||
|
|
||||||
if search:
|
if search:
|
||||||
search_url += '&search=' + urlquote(search)
|
search_url += '&search=' + urlquote(search)
|
||||||
|
|
||||||
if categories is None:
|
if tags is None:
|
||||||
categories = []
|
tags = []
|
||||||
elif isinstance(categories, basestring):
|
elif isinstance(tags, basestring):
|
||||||
categories = categories.split(',')
|
tags = tags.split(',')
|
||||||
|
|
||||||
for cat in categories:
|
for tag in tags:
|
||||||
search_url += '&chain__categories__name=' + urlquote(cat)
|
search_url += '&chain__tags__name=' + urlquote(tag)
|
||||||
|
|
||||||
if platforms is None:
|
if platforms is None:
|
||||||
platforms = []
|
platforms = []
|
||||||
|
@ -166,7 +166,7 @@ class GalaxyAPI(object):
|
||||||
|
|
||||||
self.galaxy.display.debug("Executing query: %s" % search_url)
|
self.galaxy.display.debug("Executing query: %s" % search_url)
|
||||||
try:
|
try:
|
||||||
data = json.load(open_url(search_url))
|
data = json.load(open_url(search_url, validate_certs=self.galaxy.options.validate_certs))
|
||||||
except HTTPError as e:
|
except HTTPError as e:
|
||||||
raise AnsibleError("Unsuccessful request to server: %s" % str(e))
|
raise AnsibleError("Unsuccessful request to server: %s" % str(e))
|
||||||
|
|
||||||
|
|
|
@ -28,14 +28,15 @@ galaxy_info:
|
||||||
# - {{ version }}
|
# - {{ version }}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
{%- endfor %}
|
{%- endfor %}
|
||||||
#
|
tags: []
|
||||||
# Below are all categories currently available. Just as with
|
# List tags for your role here, one per line. A tag is
|
||||||
# the platforms above, uncomment those that apply to your role.
|
# a keyword that describes and categorizes the role.
|
||||||
#
|
# Users find roles by searching for tags. Be sure to
|
||||||
#categories:
|
# remove the '[]' above if you add dependencies
|
||||||
{%- for category in categories %}
|
# to this list.
|
||||||
#- {{ category.name }}
|
#
|
||||||
{%- endfor %}
|
# NOTE: A tag is limted to a single word comprised of
|
||||||
|
# alphanumeric characters. Maximum 20 tags per role.
|
||||||
dependencies: []
|
dependencies: []
|
||||||
# List your role dependencies here, one per line.
|
# List your role dependencies here, one per line.
|
||||||
# Be sure to remove the '[]' above if you add dependencies
|
# Be sure to remove the '[]' above if you add dependencies
|
||||||
|
|
Loading…
Add table
Reference in a new issue