summaryrefslogtreecommitdiff
path: root/lib/ansible/galaxy/api.py
Commit message (Collapse)AuthorAgeFilesLines
* [2.11 backport] use same timeout for galaxy api interactions (#77088) (#77143)Elijah DeLee2022-03-151-2/+4
| | | | | | | | | | | | | | | | | | | * use same timeout for galaxy api interactions (#77088) Also, bump the default. A number of people have reported problems with this 20 second timeout for a couple of years on https://github.com/ansible/galaxy/issues/2302 It is mentioned in the issue that resolving dns can sometimes take up to 30 seconds, and that this timeout includes dns resolution. Includes a changelog message * fix type hint Co-authored-by: Matt Clay <matt@mystile.com> Co-authored-by: Matt Davis <6775756+nitzmahone@users.noreply.github.com> Co-authored-by: Matt Clay <matt@mystile.com>
* ansible-galaxy - increase page size and add retry decorator for throttling ↵Sloane Hertel2021-05-171-4/+28
| | | | | | | | | | | | | | | | | | | (#74240) (#74648) * Get available collection versions with page_size=100 for v2 and limit=100 for v3 * Update unit tests for larger page sizes * Add a generic retry decorator in module_utils/api.py that accepts an Iterable of delays and a callable to determine if an exception inheriting from Exception should be retried * Use the new decorator to handle Galaxy API rate limiting * Add unit tests for new retry decorator * Preserve the decorated function's metadata with functools.wraps Co-authored-by: Matt Martz <matt@sivel.net> Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua> (cherry picked from commit ee725846f070fc6b0dd79b5e8c5199ec652faf87)
* ansible-galaxy - set the cache file after getting all collection versions ↵Sloane Hertel2021-02-151-2/+2
| | | | | | | | | (#73557) * Manage the in-memory cache in _call_galaxy but let the caller set the file cache after getting paginated results * Add a test for caching successful and not caching unsuccessful paginated results Co-authored-by: Sviatoslav Sydorenko <wk.cvs.github@sydorenko.org.ua>
* Replace the inhouse collection dependency resolver with `resolvelib`Sviatoslav Sydorenko2021-01-271-2/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | PR #72591 This change: * Adds an artifacts manager that abstracts away extracting the metadata from artifacts, downloading and caching them in a temporary location. * Adds `resolvelib` to direct ansible-core dependencies[0]. * Implements a `resolvelib`-based dependency resolver for `collection` subcommands that replaces the legacy in-house code. This is a dependency resolution library that pip 20.3+ uses by default. It's now integrated for use for the collection dependency resolution in ansible-galaxy CLI. * Refactors of the `ansible-galaxy collection` CLI. In particular, it: - reimplements most of the `download`, `install`, `list` and `verify` subcommands from scratch; - reuses helper bits previously moved out into external modules; - replaces the old in-house resolver with a more clear implementation based on the resolvelib library[0][1][2]. * Adds a multi Galaxy API proxy layer that abstracts accessing the version and dependencies via API or local artifacts manager. * Makes `GalaxyAPI` instances sortable. * Adds string representation methods to `GalaxyAPI`. * Adds dev representation to `GalaxyAPI`. * Removes unnecessary integration and unit tests. * Aligns the tests with the new expectations. * Adds more tests, integration ones in particular. [0]: https://pypi.org/p/resolvelib [1]: https://github.com/sarugaku/resolvelib [2]: https://pradyunsg.me/blog/2020/03/27/pip-resolver-testing Co-Authored-By: Jordan Borean <jborean93@gmail.com> Co-Authored-By: Matt Clay <matt@mystile.com> Co-Authored-By: Sam Doran <sdoran@redhat.com> Co-Authored-By: Sloane Hertel <shertel@redhat.com> Co-Authored-By: Sviatoslav Sydorenko <webknjaz@redhat.com> Signed-Off-By: Sviatoslav Sydorenko <webknjaz@redhat.com>
* Galaxy - make versions list consistent across versions (#72932)Jordan Borean2021-01-201-3/+16
| | | | | * Galaxy - make versions list consistent across versions * Fix up unit tests
* Added caching mechanism for Galaxy API requests (#71904)Jordan Borean2020-11-101-10/+208
| | | | | | | | | | | | | | | | | * Added caching mechanism for Galaxy API requests * Add cache options and split up code * Added unit tests * Fix sanity test * Use modified date and fix up caching for explicit servers * Make sure credentials are not in cached server name * Added test for getting updated cache version * Changes from review
* Remove ansible-galaxy login (#72288)Matt Davis2020-10-231-2/+3
| | | | | | | | * GitHub is removing the underlying API used to implement the `login` command. Since the general consensus seems to be that relatively nobody currently uses this command (in favor of explicit token passing), support was simply removed for interactive login. If a future need arises, this command should be reimplemented via OAuth Device Auth Grants. * login or role login commands now produce a fatal error with a descriptive message * updated 2.10 and 2.11 porting guide entries * remove dead code/config, update messages and porting guides
* Test ansible-galaxy against pulp/pulp_ansible (#69605)Matt Martz2020-06-171-6/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | | * Test galaxy cli against pulp * linting fix * Renames and small fixes * Better handling for resetting pulp * Clean up some things, add a comment * I can't spell * Bump fallaxy, use alternate pulp image * Only reset pulp when we're are executing against pulp * Update for updated pulp container * Update some comments with correct URLs and typos * Linting fix * Pin pulp-fedora31 to a digest * Address review comments for documentation
* Add multipart/form-data functionality (#69376)Matt Martz2020-05-201-23/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add multipart/form-data functionality * Fix some linting issues * Fix error message * Allow filename to be provided with content * Add integration test * Update examples * General improvements to multipart handling * Use prepare_multipart for galaxy collection publish * Properly account for py2 vs py3, ensuring no max header length * Address test assumptions * Add unit tests * Add changelog * Ensure to use CRLF instead of NL * Ignore line-endings in fixture * Consolidate code, add comment * Bump fallaxy container version * ci_complete
* Separate the galaxy lib from the cli (#69473)Toshio Kuratomi2020-05-131-4/+3
| | | | | The galaxy lib knew about the cli args in context. This shouldn't be the case as it makes it hard to use the lib in other contexts. Moved the context knowledge into cli/galaxy.py.
* Fix galaxy publish sha256 value format. (#67942)Adrian Likins2020-05-111-0/+1
| | | | | | | | | | | | | | | | | | * Fix galaxy publish sha256 value format. The multipart/form content used for the body of the POST to /api/automation-hub/v3/collections was missing a newline before the line with the value of the sha256. automation-hub/galaxy/django skips the field entirely in that case and automation-hub code will use None for default to indicate that no sha256 is provided (an available option). Fixes ansible/galaxy-dev#246 * Add changelog fragment Co-authored-by: Matt Martz <matt@sivel.net>
* ansible-galaxy - optimise some paths and use fake galaxy int tests (#67685)Jordan Borean2020-02-291-16/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | * ansible-galaxy - optimise some paths and use fake galaxy int tests * Added init, built, and publish tests * Test against both mocked Galaxy and AH server * Finish off writing the install tests * Fix up broken tests * Rename test target and add migrated tests * Use cloud provider for Galaxy implementation * Added blank static config * Use correct alias group * Set release version and fix copy typo * Remove reset step as it is no longer needed * Use sane env var names for test container name
* all: fix all the the duplicate words (#66784)Eitan Adler2020-01-281-1/+1
|
* Don't remove trailing / on galaxy api URLS (#63294)Adrian Likins2020-01-081-2/+2
| | | | | | | | This causes multiple unneeded http redirects. Since each http redirect takes a few hundred milliseconds, handling the redirects starts to take up a significant amount of wall time. Fixes: #63281
* ansible-galaxy - expand User-Agent string for Galaxy endpoints (#65578)Jordan Borean2019-12-061-3/+3
|
* ansible-galaxy - Add User-Agent to requests (#65438)Jordan Borean2019-12-031-1/+2
|
* galaxy - print HTTP reason on unknown error (#65273)Jordan Borean2019-12-031-3/+3
|
* Fix up role version pagination for Galaxy install (#64373)Jordan Borean2019-11-051-3/+15
| | | | | | * Fix up role version pagination for Galaxy install * Fix sanity issue
* AH servers include automation-hub as part of the server configuration. (#63700)Toshio Kuratomi2019-10-191-1/+1
| | | | | | | | | | * AH servers include automation-hub as part of the server configuration. So we don't need to add it here. Fixes #63699 * Update unittests for the fix to galaxy wait_import_task
* Galaxy publish fix (#63580)Toshio Kuratomi2019-10-161-8/+19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Handle galaxy v2/v3 API diffs for artifact publish response For publishing a collection artifact (POST /v3/collections/artifacts/), the response format is different between v2 and v3. For v2 galaxy, the 'task' url returned is a full url with scheme: {"task": "https://galaxy-dev.ansible.com/api/v2/collection-imports/35573/"} For v3 galaxy, the task url is relative: {"task": "/api/automation-hub/v3/imports/collections/838d1308-a8f4-402c-95cb-7823f3806cd8/"} So check which API we are using and update the task url approriately. * Use full url for all wait_for_import messages Update unit tests to parameterize the expected responses and urls. * update explanatory comment * Rename n_url to full_url. * Fix issue with overwrite of the complete path * Fixes overwrite of the complete path in case there's extra path stored in self.api_sever * Normalizes the input to the wait_import_task function so it receives the same value on both v2 and v3 Builds on #63523 * Update unittests for new call signature * Add changelog for ansible-galaxy publish API fixes.
* Ensure we preserve the /api appended URL (#63472)Matt Martz2019-10-141-3/+3
|
* Fix galaxy url use everywhere when url is set in config. (#63286)Adrian Likins2019-10-091-0/+4
| | | | | | | | | In addition to trying the configured url (for ex, a migrated 'https://galaxy.ansible.com/') there is an attempt at that URL with '/api' postpended. If the extended URL works, update GalaxyAPI.api_server to use the extended URL. Previously it only used it for finding the API root info ('available_versions', etc)
* Stop appending '/api' to galaxy server url (#63238)Adrian Likins2019-10-081-4/+18
| | | | | | | | | | | | | | | | | | | | * Stop appending '/api' to configured galaxy server url Since not all galaxy REST api server URLs live at '/api', stop always appending it to the 'url' value loaded from config. * Add note about manually migrated galaxy configs and /api * Add '/api/' to galaxy url and guessing if galaxy API * Fix most unit tests (update to expect /api/) * Fix test_initialise_unknown unit test Since we retry now with an added /api/, mock it as well. * Update fallback default avail_ver to new format
* Add support for automation-hub authentication to ansible-galaxy (#63031)Adrian Likins2019-10-041-26/+6
| | | Adds support for token authentication in Automation Hub. Fixes: ansible/galaxy-dev#96
* Don't truncate the last character from galaxy urls. Fixes #61624 (#61775)Matt Martz2019-09-051-5/+5
|
* Refactor galaxy collection API for v3 support (#61510)Jordan Borean2019-08-301-120/+362
| | | | | | | | | | * Refactor galaxy collection API for v3 support * Added unit tests for GalaxyAPI and starting to fix other failures * finalise tests * more unit test fixes
* Support galaxy v3/autohub API in ansible-galaxy (#60982)Adrian Likins2019-08-281-6/+13
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Add galaxy collections API v3 support Issue: ansible/galaxy-dev#60 - Determine if server supports v3 Use 'available_versions' from `GET /api` to determine if 'v3' api is available on the server. - Support v3 pagination style ie, 'limit/offset style', with the paginated responses based on https://jsonapi.org/format/#fetching-pagination v2 galaxy uses pagination that is more or less 'django rest framework style' or 'page/page_size style', based on the default drf pagination described at https://www.django-rest-framework.org/api-guide/pagination/#pagenumberpagination - Support galaxy v3 style error response The error objects returned by the galaxy v3 api are based on the JSONAPI response/errors format (https://jsonapi.org/format/#errors). This handles that style response. At least for publish_collection for now. Needs extracting/generalizing. Handle HTTPError in CollectionRequirement.from_name() with _handle_http_error(). It will raise AnsibleError based on the json in an error response. - Update unit tests update test/unit/galaxy/test_collection* to paramaterize calls to test against mocked v2 and v3 servers apis. Update artifacts_versions_json() to tale an api version paramater. Add error_json() for generating v3/v3 style error responses. So now, the urls generated and the pagination schema of the response will use the v3 version if the passed in GalaxyAPI 'galaxy_api' instance has 'v3' in it's available_api_versions * Move checking of server avail versions to collections.py collections.py needs to know the server api versions supported before it makes collection related calls, so the 'lazy' server version check in api.GalaxyAPI is never called and isn't set, so 'v3' servers weren't found. Update unit tests to mock the return value of the request instead of GalaxyAPI itself.
* ansible-galaxy - define multiple galaxy instances in ansible.cfg (#60553)Jordan Borean2019-08-211-61/+52
| | | | | | | | | | | | | | | | * ansible-galaxy: support multiple servers on install * Added docs for the server configuration file * Fix up doc string for requirements file format * Fix bugs after testing * Fix kwarg doc and added version * Fix typo and doc improvement * Fix base64 encoding and allow --server to override list
* Made galaxy token file location configurable (#59387)Brian Coca2019-08-141-1/+14
| | | | | | | | | | * Made galaxy token file location configurable also made file handling 'unicode safe' * only create a token on demand * convert into decorator in case other funcs need
* Allow for no role_versions to be present (#56519)Brian Coca2019-07-171-3/+4
| | | | | | | | | | * Allow for no role_versions to be present fixes #46650 better info on fetch, ensure list return * use correct to_
* Save the command line arguments into a global contextToshio Kuratomi2019-01-031-3/+4
| | | | | | | | | | | | | | * Once cli args are parsed, they're constant. So, save the parsed args into the global context for everyone else to use them from now on. * Port cli scripts to use the CLIARGS in the context * Refactor call to parse cli args into the run() method * Fix unittests for changes to the internals of CLI arg parsing * Port callback plugins to use context.CLIARGS * Got rid of the private self._options attribute * Use context.CLIARGS in the individual callback plugins instead. * Also output positional arguments in default and unixy plugins * Code has been simplified since we're now dealing with a dict rather than Optparse.Value
* Update bare exceptions to specify Exception.Toshio Kuratomi2018-12-161-2/+2
| | | | | This will keep us from accidentally catching program-exiting exceptions like KeyboardInterupt and SystemExit.
* Add a Singleton metaclass, use it with Display (#48935)Matt Martz2018-11-201-5/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | * Add a Singleton class, use it with Display * update six import * Move remaining failes to display singleton * Fix rebase issues * Singleton improvements * Add code-smell for 'from __main__ import display'. ci_complete * s/self/cls/g * Add docs for no-main-display * Address linting issues * Add changelog fragment. ci_complete * Implement reentrant lock for class instantiation in Singleton * Add Display singleton porting guide
* Do not use str() on exceptions (#46950)Martin Krizek2018-11-091-1/+1
|
* ansible-galaxy: fix searching with unicodeMartin Krizek2018-10-181-3/+3
|
* Fix galaxy client executing queries with invalid http method (#42201)Alexander Saprykin2018-07-021-2/+2
| | | Fixes: ansible/galaxy#796
* Allow the galaxy client to fetch from a url in role version data (#39396)David Davis2018-04-301-1/+1
| | | | | | Currently if the ansible-galaxy client fetches a role from a galaxy server, it then fetches the role from Github. This change allows a galaxy server to provide an alternate source url that points to an archive that contains the role version.
* ansible/galaxy: PEP8 compliancy (#24696)Dag Wieers2017-05-181-5/+5
| | | - Make PEP8 compliant
* Update module_utils.six to latest (#22855)Toshio Kuratomi2017-03-231-3/+3
| | | | | | | | * Update module_utils.six to latest We've been held back on the version of six we could use on the module side to 1.4.x because of python-2.4 compatibility. Now that our minimum is Python-2.6, we can update to the latest version of six in module_utils and get rid of the second copy in lib/ansible/compat.
* Remove unnecessary shebangs and execute bits.Matt Clay2017-02-221-2/+0
|
* Previous fix to this failed to account for open_url returning a filehandle ↵Toshio Kuratomi2017-01-101-4/+4
| | | | | | | | | | | | | | | | | (#20097) * Previous fix to this failed to account for open_url returning a filehandle Fixes the bugs introduced by c6fb355 * read() from HTTPError for python-3.6+ HTTPError is funny. It contains a filehandle to read the response from and also makes it available via a read() method. On earlier versions of python (2 and 3) the read() method was enough to make it work with json.load(). The newer version of json.load() needs a more complete file interface than this and has stopped working. Read the bytes, transform to str and pass it in manually to fix it.
* Convert all results from open_url() into text before deserializing the json. ↵Toshio Kuratomi2017-01-101-4/+4
| | | | | (#20069) Fixes #20012
* Allow setting alternate_role_name for galaxy CLI (#17418)Monty Taylor2016-10-271-4/+8
| | | | | | | | | | | | | | | When using the ansible-galaxy CLI to import roles, it's not possible to specify an alternate_role_name, even though the REST API seems to allow such a thing (at least on investigation of the interactions the web app makes) That makes importing things like: openstack/openstack-ansible-os_cloudkitty wind up with roles named "openstack-ansible-os_cloudkitty" instead of "os_cloudkitty". Also, the web ui is smart and imports "openstack-infra/ansible-role-puppet" as openstack-infra.puppet ... but the CLI imports it as openstack-infra.ansible-role-puppet. Add that filtering as well. Issue ansible/galaxy-issues:#185
* Add warnings when installing container type rolesChris Houseknecht2016-10-091-1/+2
|
* Move uses of to_bytes, to_text, to_native to use the module_utils version ↵Toshio Kuratomi2016-09-061-5/+5
| | | | | | | | (#17423) We couldn't copy to_unicode, to_bytes, to_str into module_utils because of licensing. So once created it we had two sets of functions that did the same things but had different implementations. To remedy that, this change removes the ansible.utils.unicode versions of those functions.
* Enable most unittests on python3 (just some vault unittests and a logging ↵Toshio Kuratomi2016-08-251-6/+5
| | | | | | | | | | one left) (#17240) Make some python3 fixes to make the unittests pass: * galaxy imports * dictionary iteration in role requirements * swap_stdout helper for unittests * Normalize to text string in a facts.py function
* Migrate basestring to a python3 compatible type (#17199)Toshio Kuratomi2016-08-231-9/+11
|
* Fixes #163 in galaxy-issuess-hertel2016-07-211-0/+1
|
* much more fine grained error messagesBrian Coca2016-06-061-4/+14
| | | | fixes #16039
* moved validate info from vvv to debugBrian Coca2016-05-271-1/+1
|