├── lib └── hammer_cli_katello │ ├── module_stream_profile.rb │ ├── hostgroup.rb │ ├── option_sources.rb │ ├── version.rb │ ├── output │ ├── fields.rb │ └── formatters.rb │ ├── local_helper.rb │ ├── repository_scoped_to_product.rb │ ├── command_extensions.rb │ ├── docker.rb │ ├── host_deb.rb │ ├── i18n.rb │ ├── lifecycle_environment_name_mapping.rb │ ├── host_collection_erratum.rb │ ├── apipie_helper.rb │ ├── status.rb │ ├── host_package_group.rb │ ├── content_view_environment.rb │ ├── content_view_name_resolvable.rb │ ├── command_extensions │ ├── ping.rb │ ├── lifecycle_environments.rb │ ├── content_source.rb │ ├── lifecycle_environment.rb │ └── kickstart_repository.rb │ ├── erratum_info_command.rb │ ├── unsupported_katello_agent_command_helper.rb │ ├── host_traces.rb │ ├── host_bootc.rb │ ├── host_collection_package.rb │ ├── host_collection_package_group.rb │ ├── content_export_complete.rb │ ├── docker_tag.rb │ ├── content_export_incremental.rb │ ├── product_content.rb │ ├── composite_content_view_name_resolvable.rb │ ├── organization_options.rb │ ├── exception_handler.rb │ ├── acs_bulk_actions.rb │ ├── host_errata.rb │ ├── package_group.rb │ ├── docker_manifest.rb │ ├── flatpak_remote_repository.rb │ ├── host.rb │ ├── erratum.rb │ ├── host_package.rb │ ├── module_stream.rb │ └── srpm.rb ├── config └── katello.yml ├── locale ├── bn │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ca │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── de │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── el │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── en │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── es │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── fr │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── gl │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── gu │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── hi │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── id │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── it │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ja │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ka │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── kn │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ko │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── mr │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── or │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── pa │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── pl │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── pt │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ro │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ru │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── sl │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ta │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── te │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── tr │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── vi │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── zh │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── bqi │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── bn_IN │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── cs_CZ │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── de_AT │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── de_DE │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── en_GB │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── en_US │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── et_EE │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── he_IL │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ml_IN │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── nl_NL │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── pl_PL │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── pt_BR │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ro_RO │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── sv_SE │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── ta_IN │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── vi_VN │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── zh_CN │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── zh_TW │ └── LC_MESSAGES │ │ └── hammer_cli_katello.mo ├── Makefile ├── README.md └── zanata.xml ├── test ├── data │ └── Readme.md ├── functional │ ├── capsule │ │ ├── content │ │ │ ├── data │ │ │ │ ├── sync_status_no_counts.json │ │ │ │ ├── empty_counts.json │ │ │ │ ├── sync_status.json │ │ │ │ ├── unsynced_env.json │ │ │ │ └── library_env.json │ │ │ ├── lifecycle_environments_test.rb │ │ │ ├── reclaim_space_test.rb │ │ │ ├── capsule_content_helpers.rb │ │ │ ├── cancel_synchronization_test.rb │ │ │ ├── add_lifecycle_environment_test.rb │ │ │ └── remove_lifecycle_environment_test.rb │ │ ├── capsule_helpers.rb │ │ ├── list_test.rb │ │ └── info_test.rb │ ├── host │ │ ├── host_helpers.rb │ │ ├── errata │ │ │ ├── apply_test.rb │ │ │ ├── recalculate_test.rb │ │ │ ├── info_test.rb │ │ │ └── list_test.rb │ │ ├── traces │ │ │ ├── resolve_test.rb │ │ │ └── list_test.rb │ │ ├── subscription │ │ │ ├── product_content_test.rb │ │ │ ├── unregister_test.rb │ │ │ ├── enabled_repositories_test.rb │ │ │ └── register_test.rb │ │ └── extensions │ │ │ ├── list_test.rb │ │ │ └── info_test.rb │ ├── sync_plan │ │ ├── sync_plan_helpers.rb │ │ ├── list_test.rb │ │ ├── info_test.rb │ │ ├── update_test.rb │ │ └── delete_test.rb │ ├── file │ │ └── file_helpers.rb │ ├── acs │ │ ├── delete_test.rb │ │ ├── update_test.rb │ │ ├── create_test.rb │ │ └── list_test.rb │ ├── flatpak_remote │ │ ├── delete_test.rb │ │ ├── update_test.rb │ │ ├── create_test.rb │ │ ├── scan_test.rb │ │ ├── info_test.rb │ │ └── list_test.rb │ ├── organization │ │ ├── organization_helpers.rb │ │ ├── info_test.rb │ │ ├── delete_test.rb │ │ └── cdn_configuration_test.rb │ ├── filter_rule │ │ └── filter_rule_helpers.rb │ ├── content_import │ │ └── metadata.json │ ├── lifecycle_environment │ │ ├── update_test.rb │ │ ├── create_test.rb │ │ ├── lifecycle_environment_helpers.rb │ │ └── list_test.rb │ ├── repository_set │ │ ├── info_test.rb │ │ ├── list_test.rb │ │ ├── available_repositories_test.rb │ │ ├── repository_set_helpers.rb │ │ ├── enable_test.rb │ │ └── disable_test.rb │ ├── repository │ │ ├── create_test.rb │ │ ├── repository_helpers.rb │ │ ├── republish_test.rb │ │ └── synchronize_test.rb │ ├── search_helpers.rb │ ├── content_view │ │ ├── content_view_helpers.rb │ │ ├── add_repository_test.rb │ │ ├── publish_test.rb │ │ ├── create_test.rb │ │ ├── version │ │ │ ├── republish_repositories_test.rb │ │ │ ├── list_test.rb │ │ │ └── update_test.rb │ │ ├── update_test.rb │ │ ├── component │ │ │ └── list_test.rb │ │ └── copy_test.rb │ ├── product │ │ ├── verify_checksum_test.rb │ │ ├── product_helpers.rb │ │ ├── info_test.rb │ │ ├── remove_sync_plan_test.rb │ │ ├── update_proxy_test.rb │ │ ├── delete_test.rb │ │ ├── update_test.rb │ │ ├── set_sync_plan_test.rb │ │ ├── list_test.rb │ │ └── create_test.rb │ ├── local_helper_test.rb │ ├── activation_key │ │ ├── product_content_test.rb │ │ ├── update_test.rb │ │ ├── create_test.rb │ │ └── data │ │ │ └── activation_key.json │ ├── content_credentials │ │ ├── data │ │ │ └── test_cert.json │ │ ├── create_test.rb │ │ ├── info_test.rb │ │ └── list_test.rb │ ├── host_collection │ │ ├── content_update_test.rb │ │ ├── content_remove_test.rb │ │ ├── content_install_test.rb │ │ ├── hosts_test.rb │ │ ├── create_test.rb │ │ └── list_test.rb │ ├── erratum │ │ └── info_test.rb │ ├── test_helper.rb │ ├── content_units │ │ └── info_test.rb │ ├── apipie_helper_test.rb │ ├── hostgroup │ │ ├── info_test.rb │ │ └── data │ │ │ └── hostgroup.json │ ├── package_group │ │ └── list_test.rb │ ├── content_export │ │ ├── content_export_helpers.rb │ │ ├── generate_listing_test.rb │ │ └── generate_metadata_test.rb │ └── module_stream │ │ └── list_test.rb ├── unit │ ├── messages_test.rb │ └── id_resolver_test.rb ├── task_helper.rb └── test_helper.rb ├── .tx └── config ├── .github └── workflows │ ├── release.yml │ ├── unit-tests.yml │ ├── single-commit.yml │ └── development-container-release.yml ├── .gitignore ├── Gemfile ├── Containerfile-devel ├── Rakefile ├── hammer-devel-container.sh ├── boilerplate └── command_template.rb ├── .rubocop.yml └── .packit.yaml /lib/hammer_cli_katello/module_stream_profile.rb: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /config/katello.yml: -------------------------------------------------------------------------------- 1 | :katello: 2 | :enable_module: true 3 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/hostgroup.rb: -------------------------------------------------------------------------------- 1 | require 'hammer_cli_foreman/hostgroup' 2 | require 'hammer_cli_katello/hostgroup_extensions' 3 | -------------------------------------------------------------------------------- /locale/bn/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/bn/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ca/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ca/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/de/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/de/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/el/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/el/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/en/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/en/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/es/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/es/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/fr/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/fr/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/gl/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/gl/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/gu/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/gu/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/hi/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/hi/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/id/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/id/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/it/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/it/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ja/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ja/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ka/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ka/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/kn/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/kn/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ko/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ko/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/mr/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/mr/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/or/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/or/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/pa/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/pa/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/pl/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/pl/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/pt/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/pt/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ro/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ro/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ru/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ru/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/sl/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/sl/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ta/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ta/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/te/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/te/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/tr/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/tr/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/vi/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/vi/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/zh/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/zh/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/bqi/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/bqi/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /lib/hammer_cli_katello/option_sources.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'hammer_cli_katello/option_sources/lifecycle_environment_params' 4 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/version.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | def self.version 3 | @version ||= Gem::Version.new('1.20.0-main') 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /locale/bn_IN/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/bn_IN/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/cs_CZ/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/cs_CZ/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/de_AT/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/de_AT/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/de_DE/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/de_DE/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/en_GB/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/en_GB/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/en_US/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/en_US/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/et_EE/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/et_EE/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/he_IL/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/he_IL/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ml_IN/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ml_IN/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/nl_NL/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/nl_NL/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/pl_PL/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/pl_PL/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/pt_BR/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/pt_BR/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ro_RO/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ro_RO/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/sv_SE/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/sv_SE/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/ta_IN/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/ta_IN/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/vi_VN/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/vi_VN/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/zh_CN/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/zh_CN/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /locale/zh_TW/LC_MESSAGES/hammer_cli_katello.mo: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Katello/hammer-cli-katello/HEAD/locale/zh_TW/LC_MESSAGES/hammer_cli_katello.mo -------------------------------------------------------------------------------- /test/data/Readme.md: -------------------------------------------------------------------------------- 1 | # Data for tests 2 | 3 | Follow the [hammer-cli-foreman 4 | instructions](https://github.com/theforeman/hammer-cli-foreman/blob/master/test/data/README.md) with the Katello plugin installed in 5 | Foreman. 6 | -------------------------------------------------------------------------------- /test/functional/capsule/content/data/sync_status_no_counts.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_sync_time": "2016-01-10 00:27:51 +0100", 3 | "active_sync_tasks": [], 4 | "last_failed_sync_tasks": [], 5 | "lifecycle_environments": [] 6 | } 7 | -------------------------------------------------------------------------------- /test/functional/capsule/content/data/empty_counts.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_sync_time": "2016-01-10 00:27:51 +0100", 3 | "active_sync_tasks": [], 4 | "last_failed_sync_tasks": [], 5 | "lifecycle_environments": [], 6 | "content_counts": {} 7 | } -------------------------------------------------------------------------------- /locale/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for PO merging and MO generation. More info in the README. 3 | # 4 | # Run make help to list available targets 5 | # 6 | include $(shell bundle exec ruby -e 'require "hammer_cli"; puts HammerCLI::I18n.main_makefile') 7 | -------------------------------------------------------------------------------- /test/functional/host/host_helpers.rb: -------------------------------------------------------------------------------- 1 | module HostHelpers 2 | def expect_host_search(name, id) 3 | ex = api_expects(:hosts, :index, 'Find the host') do |par| 4 | par[:search] == "name = \"#{name}\"" 5 | end 6 | ex.returns(index_response([{'id' => id}])) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /.tx/config: -------------------------------------------------------------------------------- 1 | [main] 2 | host = https://app.transifex.com 3 | 4 | [o:foreman:p:foreman:r:hammer_cli_katello] 5 | file_filter = locale//hammer_cli_katello.edit.po 6 | source_file = locale/hammer_cli_katello.pot 7 | source_lang = en 8 | type = PO 9 | resource_name = hammer_cli_katello 10 | -------------------------------------------------------------------------------- /test/unit/messages_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require 'hammer_cli/testing/messages' 3 | 4 | include HammerCLI::Testing::Messages 5 | describe "message formatting" do 6 | check_all_command_messages(HammerCLI::MainCommand, HammerCLIKatello::Command) 7 | end 8 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/output/fields.rb: -------------------------------------------------------------------------------- 1 | require 'hammer_cli' 2 | 3 | module HammerCLIKatello 4 | module Output 5 | module Fields 6 | class ChecksumFilePair < ::Fields::Field 7 | end 8 | 9 | class Dependency < ::Fields::Field 10 | end 11 | end 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/task_helper.rb: -------------------------------------------------------------------------------- 1 | module ForemanTaskHelpers 2 | def expect_foreman_task(task_id) 3 | ex = api_expects(:foreman_tasks, :show, 'Show task') 4 | ex.returns('id' => task_id, 'state' => 'stopped', 'progress' => 1, 5 | 'humanized' => {'output' => '', 'errors' => ''}) 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /test/functional/sync_plan/sync_plan_helpers.rb: -------------------------------------------------------------------------------- 1 | module SyncPlanHelpers 2 | def expect_sync_plan_search(org_id, name, id) 3 | ex = api_expects(:sync_plans, :index, 'find sync plan') do |par| 4 | par['name'] == name && par['organization_id'] == org_id 5 | end 6 | ex.returns(index_response([{'id' => id}])) 7 | end 8 | end 9 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/local_helper.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module LocalHelper 3 | def parse_subcommand 4 | return super if File.exist?('/usr/share/foreman') 5 | raise "This command can only be run on the same server that Foreman is running on " \ 6 | "and cannot be run remotely." 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /test/functional/file/file_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module FileHelpers 4 | include SearchHelpers 5 | 6 | def expect_file_search(params, returns) 7 | expect_generic_search(:file_units, params: params, returns: returns) 8 | end 9 | 10 | def expect_file_show(params) 11 | api_expects(:file_units, :show).with_params(params) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/repository_scoped_to_product.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module RepositoryScopedToProduct 3 | def validate_repo_name_requires_product_options(name_option = :option_name) 4 | validate_options :before, 'IdResolution' do 5 | any(:option_product_name, :option_product_id).required if option(name_option).exist? 6 | end 7 | end 8 | end 9 | end 10 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | name: Release 3 | 4 | on: 5 | push: 6 | tags: 7 | - '*' 8 | 9 | jobs: 10 | release: 11 | name: Release gem 12 | runs-on: ubuntu-latest 13 | environment: release 14 | if: github.repository_owner == 'theforeman' 15 | 16 | permissions: 17 | id-token: write 18 | 19 | steps: 20 | - uses: voxpupuli/ruby-release@v0 21 | -------------------------------------------------------------------------------- /test/functional/capsule/capsule_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module CapsuleHelpers 4 | include SearchHelpers 5 | 6 | def expect_generic_capsule_search(opts = {params: {}, returns: {}}) 7 | expect_generic_search(:smart_proxies, opts) 8 | end 9 | 10 | def expect_capsule_info(params = {}) 11 | api_expects(:smart_proxies, :show).with_params(params) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/command_extensions.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | require 'hammer_cli_katello/command_extensions/lifecycle_environment' 4 | require 'hammer_cli_katello/command_extensions/lifecycle_environments' 5 | require 'hammer_cli_katello/command_extensions/ping' 6 | require 'hammer_cli_katello/command_extensions/content_source' 7 | require 'hammer_cli_katello/command_extensions/kickstart_repository' 8 | -------------------------------------------------------------------------------- /test/functional/acs/delete_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'delete an acs' do 4 | let(:id) { 1 } 5 | 6 | it 'by id' do 7 | api_expects(:alternate_content_sources, :destroy, 'delete acs'). 8 | with_params('id' => id) 9 | 10 | command = %W(alternate-content-source delete --id #{id}) 11 | assert_equal(0, run_cmd(command).exit_code) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/functional/flatpak_remote/delete_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'delete a flatpak remote' do 4 | let(:id) { 1 } 5 | 6 | it 'by id' do 7 | api_expects(:flatpak_remotes, :destroy, 'delete acs'). 8 | with_params('id' => id) 9 | 10 | command = %W(flatpak-remote delete --id #{id}) 11 | assert_equal(0, run_cmd(command).exit_code) 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /test/functional/organization/organization_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module OrganizationHelpers 4 | include SearchHelpers 5 | 6 | def expect_organization_search(name_or_label, id, field: 'name') 7 | expect_generic_search(:organizations, params: {search: "#{field} = \"#{name_or_label}\""}, 8 | returns: {'id' => id}).at_least_once 9 | end 10 | end 11 | -------------------------------------------------------------------------------- /test/functional/filter_rule/filter_rule_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module FilterRuleHelpers 4 | include SearchHelpers 5 | 6 | def expect_filter_rule_search(name, filter_id, return_id) 7 | expect_generic_search( 8 | :content_view_filter_rules, 9 | params: {search: "name = \"#{name}\"", 'content_view_filter_id' => filter_id}, 10 | returns: {'id' => return_id}) 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /test/functional/content_import/metadata.json: -------------------------------------------------------------------------------- 1 | {"organization":"export-9697","repository_mapping":{"katello-15062":{"repository":"katello","product":"prod","redhat":false},"misc-28137":{"repository":"misc","product":"prod","redhat":false},"candlepin-37918":{"repository":"candlepin","product":"prod","redhat":false}},"content_view":"view","content_view_version":{"major":1,"minor":0},"incremental":false,"toc":"export-24d91ced-3d11-4fa2-b5ea-19a41f7b97a5-20201118_1523-toc.json"} -------------------------------------------------------------------------------- /test/functional/capsule/content/data/sync_status.json: -------------------------------------------------------------------------------- 1 | { 2 | "last_sync_time": "2016-01-10 00:27:51 +0100", 3 | "active_sync_tasks": [], 4 | "last_failed_sync_tasks": [], 5 | "lifecycle_environments": [], 6 | "content_counts": { 7 | "content_view_versions":{ 8 | "2":{"repositories":{"42":{"metadata":{"env_id":4,"product_id":1,"content_type":"yum","library_instance_id":1},"counts":{"rpm":32,"erratum":4}}}}} 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | *.rbc 3 | .bundle 4 | .config 5 | .idea 6 | .vendor 7 | coverage 8 | InstalledFiles 9 | lib/bundler/man 10 | pkg 11 | rdoc 12 | test/reports 13 | test/tmp 14 | test/version_tmp 15 | tmp 16 | Gemfile.lock 17 | Gemfile.local 18 | Gemfile.local.rb 19 | rubocop.xml 20 | metadata* 21 | 22 | # YARD artifacts 23 | .yardoc 24 | _yardoc 25 | doc/ 26 | 27 | # rvm 28 | .rvmrc 29 | .ruby-version 30 | .ruby-gemset 31 | .*.sw? 32 | 33 | # Locale files 34 | locale/*/*.edit.po 35 | locale/*/*.po.time_stamp 36 | -------------------------------------------------------------------------------- /test/functional/lifecycle_environment/update_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/lifecycle_environment' 3 | 4 | module HammerCLIKatello 5 | describe LifecycleEnvironmentCommand::UpdateCommand do 6 | it 'allows minimal options' do 7 | api_expects(:lifecycle_environments, :update) do |p| 8 | p['new_name'] == 'le3' && p['id'] == 3 9 | end 10 | 11 | run_cmd(%w(lifecycle-environment update --id 3 --new-name le3)) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/docker.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class DockerCommand < HammerCLI::AbstractCommand 3 | require 'hammer_cli_katello/docker_manifest' 4 | subcommand 'manifest', 5 | HammerCLIKatello::DockerManifestCommand.desc, 6 | HammerCLIKatello::DockerManifestCommand 7 | 8 | require 'hammer_cli_katello/docker_tag' 9 | subcommand 'tag', 10 | HammerCLIKatello::DockerTagCommand.desc, 11 | HammerCLIKatello::DockerTagCommand 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /.github/workflows/unit-tests.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | 3 | on: pull_request 4 | 5 | concurrency: 6 | group: ${{ github.ref_name }}-${{ github.workflow }} 7 | cancel-in-progress: true 8 | 9 | jobs: 10 | rubocop: 11 | name: Rubocop 12 | uses: theforeman/actions/.github/workflows/rubocop.yml@v0 13 | with: 14 | command: bundle exec rubocop --parallel --format github 15 | 16 | test: 17 | name: Tests 18 | uses: theforeman/actions/.github/workflows/test-gem.yml@v0 19 | with: 20 | command: bundle exec rake test 21 | -------------------------------------------------------------------------------- /.github/workflows/single-commit.yml: -------------------------------------------------------------------------------- 1 | name: Assert Single Commit (non-blocking) 2 | 3 | on: pull_request 4 | 5 | jobs: 6 | build: 7 | steps: 8 | - name: Checkout 9 | uses: actions/checkout@v1 10 | with: 11 | fetch-depth: 30 12 | - name: Checkout main 13 | run: git fetch origin main 14 | - name: create local master branch 15 | run: git branch main origin/main 16 | - name: Commit Count Check 17 | run: test `git log --oneline --no-merges HEAD ^main | wc -l ` = 1 18 | runs-on: ubuntu-latest 19 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_deb.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostDebPackage < HammerCLIKatello::Command 3 | desc "Manage deb packages on your hosts" 4 | 5 | class ListCommand < HammerCLIKatello::ListCommand 6 | resource :host_debs, :index 7 | 8 | output do 9 | field :id, _("Id") 10 | field :name, _("Name") 11 | field :version, _("Version") 12 | field :architecture, _("Arch") 13 | end 14 | 15 | build_options 16 | end 17 | 18 | autoload_subcommands 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/functional/lifecycle_environment/create_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/lifecycle_environment' 3 | 4 | module HammerCLIKatello 5 | describe LifecycleEnvironmentCommand::CreateCommand do 6 | it 'allows minimal options' do 7 | api_expects(:lifecycle_environments, :create) do |p| 8 | p['name'] == 'le1' && p['prior_id'] == 3 && p['organization_id'] == 1 9 | end 10 | 11 | run_cmd(%w(lifecycle-environment create --name le1 --prior-id 3 --organization-id 1)) 12 | end 13 | end 14 | end 15 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/i18n.rb: -------------------------------------------------------------------------------- 1 | require 'hammer_cli/i18n' 2 | 3 | module HammerCLIKatello 4 | module I18n 5 | class LocaleDomain < HammerCLI::I18n::LocaleDomain 6 | def translated_files 7 | Dir.glob(File.join(File.dirname(__FILE__), '../**/*.rb')) 8 | end 9 | 10 | def locale_dir 11 | File.join(File.dirname(__FILE__), '../../locale') 12 | end 13 | 14 | def domain_name 15 | 'hammer_cli_katello' 16 | end 17 | end 18 | end 19 | end 20 | 21 | HammerCLI::I18n.add_domain(HammerCLIKatello::I18n::LocaleDomain.new) 22 | -------------------------------------------------------------------------------- /test/functional/repository_set/info_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/repository_set' 3 | 4 | module HammerCLIKatello 5 | describe RepositorySetCommand::InfoCommand do 6 | it 'allows minimal options' do 7 | api_expects(:repository_sets, :show) 8 | .with_params('id' => 1) 9 | assert_success run_cmd(%w(repository-set info --id 1)) 10 | end 11 | 12 | it 'requires repository set options' do 13 | api_expects_no_call 14 | assert_failure run_cmd(%w(repository-set info)), /id.*name.*required/ 15 | end 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/functional/host/errata/apply_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | describe 'apply an errata' do 3 | before do 4 | @cmd = %w(host errata apply) 5 | end 6 | 7 | it "errors out on errata applies" do 8 | params = ["--help"] 9 | expected = "Not supported. Use the remote execution equivalent "\ 10 | "`hammer job-invocation create --feature katello_errata_install`.\n" 11 | result = run_cmd(@cmd + params) 12 | assert_exit_code_equal(HammerCLI::EX_UNAVAILABLE, result.exit_code) 13 | assert_equal expected, result.out 14 | end 15 | end 16 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "https://rubygems.org" 2 | 3 | gemspec 4 | 5 | # load local gemfile 6 | ['Gemfile.local.rb', 'Gemfile.local'].map do |file_name| 7 | local_gemfile = File.join(File.dirname(__FILE__), file_name) 8 | self.instance_eval(Bundler.read_file(local_gemfile)) if File.exist?(local_gemfile) 9 | end 10 | 11 | gem 'gettext', '>= 3.1.3', '< 4.0.0' 12 | 13 | group :test do 14 | gem 'ci_reporter_minitest', '~> 1.0.0', :require => false 15 | gem 'minitest', '~> 5.18' 16 | gem 'minitest-spec-context', '~> 0.0.5' 17 | gem 'mocha', '~> 2.0' 18 | gem 'rake' 19 | gem 'rubocop' 20 | gem 'thor' 21 | end 22 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/lifecycle_environment_name_mapping.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module LifecycleEnvironmentNameMapping 3 | def self.included(base) 4 | base.extend(ClassMethods) 5 | end 6 | 7 | module ClassMethods 8 | def resource_name_mapping 9 | mapping = Command.resource_name_mapping 10 | mapping[:environment] = :lifecycle_environment 11 | mapping[:environments] = :lifecycle_environments 12 | mapping 13 | end 14 | 15 | def resource_alias_name_mapping 16 | HammerCLIKatello::RESOURCE_ALIAS_NAME_MAPPING 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_collection_erratum.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostCollectionErratumCommand < HammerCLIKatello::Command 3 | command_name "erratum" 4 | desc "Manage errata on your host collections. "\ 5 | "These commands are no longer available. "\ 6 | "Use the remote execution equivalent" 7 | 8 | class InstallCommand < HammerCLIKatello::Command 9 | command_name "install" 10 | def self.rex_feature 11 | "katello_errata_install" 12 | end 13 | 14 | include UnsupportedKatelloAgentCommandHelper 15 | end 16 | 17 | autoload_subcommands 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /test/functional/capsule/content/lifecycle_environments_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require_relative 'capsule_content_helpers' 3 | require 'hammer_cli_katello/capsule' 4 | 5 | module HammerCLIKatello 6 | module Capsule 7 | class Content 8 | describe Content::ListLifecycleEnvironmentsCommand do 9 | include CapsuleContentHelpers 10 | 11 | it 'allows minimal options' do 12 | expect_lifecycle_environments_list(params: {'id' => 1}, returns: {}) 13 | 14 | run_cmd(%w(capsule content lifecycle-environments --id 1)) 15 | end 16 | end 17 | end 18 | end 19 | end 20 | -------------------------------------------------------------------------------- /test/functional/acs/update_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'listing acs' do 4 | before do 5 | @cmd = %w(alternate-content-source update) 6 | end 7 | 8 | let(:id) { 1 } 9 | let(:desc) { 'pizza' } 10 | 11 | it 'update acs' do 12 | params = ["--id=#{id}", "--description=#{desc}"] 13 | 14 | ex = api_expects(:alternate_content_sources, :update, 'acs update') do |par| 15 | par['id'] == 1 && par['description'] == 'pizza' 16 | end 17 | 18 | ex.returns({}) 19 | 20 | result = run_cmd(@cmd + params) 21 | assert_equal(result.exit_code, 0) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /test/functional/capsule/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative 'capsule_helpers' 3 | require 'hammer_cli_katello/capsule' 4 | 5 | module HammerCLIKatello 6 | describe Capsule do 7 | describe ListCommand do 8 | include CapsuleHelpers 9 | 10 | it 'allows minimal options' do 11 | expect_generic_capsule_search 12 | 13 | run_cmd(%w(capsule list)) 14 | end 15 | 16 | it 'allows search' do 17 | expect_generic_capsule_search( 18 | params: { 'search' => 'search' }, returns: {}) 19 | 20 | run_cmd(%w(capsule list --search search)) 21 | end 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /test/functional/repository_set/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/repository_set' 3 | 4 | module HammerCLIKatello 5 | describe RepositorySetCommand::ListCommand do 6 | it 'allows minimal options' do 7 | api_expects(:repository_sets, :index) 8 | .with_params('organization_id' => 1) 9 | .returns(index_response([])) 10 | assert_success run_cmd(%w(repository-set list --organization-id 1)) 11 | end 12 | 13 | it 'requires organization options' do 14 | api_expects_no_call 15 | assert_failure run_cmd(%w(repository-set list)), /organization.*required/ 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/apipie_helper.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module ApipieHelper 3 | def show(resource, options = {}) 4 | call(:show, resource, options) 5 | end 6 | 7 | def index(resource, options = {}) 8 | call(:index, resource, options)['results'] 9 | end 10 | 11 | def update(resource, options = {}) 12 | call(:update, resource, options)['results'] 13 | end 14 | 15 | def destroy(resource, options = {}) 16 | call(:destroy, resource, options) 17 | end 18 | 19 | def call(action, resource, options = {}) 20 | HammerCLIForeman.foreman_resource(resource).call(action, options) 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /test/functional/repository/create_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | 3 | describe "create repository" do 4 | let(:org_id) { 1 } 5 | let(:product_id) { 2 } 6 | let(:repo_name) { "repo1" } 7 | let(:content_type) { "yum" } 8 | 9 | it 'with basic options' do 10 | api_expects(:repositories, :create) 11 | .with_params( 12 | name: repo_name, 13 | product_id: product_id, 14 | content_type: content_type) 15 | 16 | command = %W(repository create --organization-id #{org_id} --product-id #{product_id} 17 | --content-type #{content_type} --name #{repo_name}) 18 | 19 | assert_equal(0, run_cmd(command).exit_code) 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/functional/flatpak_remote/update_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'Updating flatpak remotes' do 4 | before do 5 | @cmd = %w(flatpak-remote update) 6 | end 7 | 8 | let(:id) { 1 } 9 | let(:desc) { 'A flatpak remote for Fedora registry' } 10 | 11 | it 'updates flatpak remote' do 12 | params = ["--id=#{id}", "--description=#{desc}"] 13 | 14 | ex = api_expects(:flatpak_remotes, :update, 'flatpak remote update') do |par| 15 | par['id'] == 1 && par['description'] == 'A flatpak remote for Fedora registry' 16 | end 17 | 18 | ex.returns({}) 19 | 20 | result = run_cmd(@cmd + params) 21 | assert_equal(result.exit_code, 0) 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /test/functional/repository_set/available_repositories_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/repository_set' 3 | 4 | module HammerCLIKatello 5 | describe RepositorySetCommand::AvailableRepositoriesCommand do 6 | it 'allows minimal options' do 7 | api_expects(:repository_sets, :available_repositories) 8 | .with_params('id' => 1) 9 | .returns(index_response([])) 10 | assert_success run_cmd(%w(repository-set available-repositories --id 1)) 11 | end 12 | 13 | it 'requires repository set options' do 14 | api_expects_no_call 15 | assert_failure run_cmd(%w(repository-set available-repositories)), /id.*name.*required/ 16 | end 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /test/functional/search_helpers.rb: -------------------------------------------------------------------------------- 1 | module SearchHelpers 2 | def expect_generic_search(resource, args) 3 | ex = api_expects(resource, :index, "Find the #{resource}").with_params(args[:params]) 4 | ex.returns(index_response([args[:returns]])) 5 | end 6 | 7 | def expect_lenient_search(resource, params:, returns:) 8 | ex = api_expects(resource, :index, "Find the #{resource}") do |p| 9 | params.each do |key, expected| 10 | actual = p[key] || p[key.to_sym] || p[key.to_s] 11 | assert_equal expected.to_s, actual.to_s, "key: '#{key}', resource: #{resource}" 12 | end 13 | end 14 | returns = [returns] unless returns.is_a? Array 15 | ex.returns(index_response(returns)) 16 | end 17 | end 18 | -------------------------------------------------------------------------------- /test/functional/content_view/content_view_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module ContentViewHelpers 4 | include SearchHelpers 5 | 6 | def expect_content_view_search(org_id, name, id) 7 | expect_generic_content_view_search(params: {'name' => name, 'organization_id' => org_id}, 8 | returns: {'id' => id}) 9 | end 10 | 11 | def expect_generic_content_view_search(args) 12 | expect_generic_search(:content_views, args) 13 | end 14 | 15 | def expect_content_view_version_search(params, returns) 16 | expect_lenient_search(:content_view_versions, 17 | params: params, 18 | returns: returns) 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/functional/lifecycle_environment/lifecycle_environment_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module LifecycleEnvironmentHelpers 4 | include SearchHelpers 5 | 6 | def expect_lifecycle_environment_search(org_id, name, id) 7 | expect_lenient_search(:lifecycle_environments, 8 | params: {'name' => name, 'organization_id' => org_id}, 9 | returns: {'id' => id}) 10 | end 11 | 12 | def expect_lifecycle_environments_request(org_id, results) 13 | ex = api_expects(:lifecycle_environments, :index, 'List the lifecycle environments') do |par| 14 | par['organization_id'] == org_id 15 | end 16 | ex.returns(index_response(results)) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /Containerfile-devel: -------------------------------------------------------------------------------- 1 | FROM registry.access.redhat.com/ubi9/ruby-33 2 | RUN mkdir -p .hammer/cli.modules.d 3 | RUN cat < .hammer/cli.modules.d/foreman.yml 4 | :foreman: 5 | :enable_module: true 6 | :host: 'http://localhost:3000/' 7 | :username: 'admin' 8 | :password: 'changeme' 9 | EOF 10 | 11 | RUN cat < .hammer/cli.modules.d/katello.yml 12 | :katello: 13 | :enable_module: true 14 | EOF 15 | 16 | RUN cat < .hammer/cli_config.yml 17 | :reload_cache: true 18 | :log_dir: '~/.hammer/log' 19 | :log_level: 'debug' 20 | EOF 21 | 22 | RUN mkdir hammer-cli-katello 23 | RUN cat < .gitconfig 24 | [safe] 25 | directory = ~/hammer-cli-katello 26 | EOF 27 | WORKDIR hammer-cli-katello 28 | CMD bundle install && bundle exec bash 29 | -------------------------------------------------------------------------------- /test/functional/host/errata/recalculate_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | 3 | describe 'recalculate errata' do 4 | include ForemanTaskHelpers 5 | 6 | before do 7 | @cmd = %w(host errata recalculate) 8 | end 9 | 10 | let(:host_id) { 1 } 11 | 12 | it "recalculates errata for a host" do 13 | params = ["--host-id=#{host_id}"] 14 | 15 | api_expects(:host_errata, :applicability, 'Host errata recalculate') 16 | .with_params('host_id' => host_id) 17 | .returns({}) 18 | 19 | expected_result = success_result( 20 | 'Errata recalculation started. 21 | ' 22 | ) 23 | result = run_cmd(@cmd + params) 24 | assert_cmd(expected_result, result) 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/functional/content_view/add_repository_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/content_view' 3 | 4 | module HammerCLIKatello 5 | describe ContentView do 6 | describe 'AddRepositoryCommand' do 7 | it 'allows adding a repository by ID' do 8 | ex = api_expects(:organizations, :index) do |p| 9 | p[:search] == "name = \"org1\"" 10 | end 11 | ex.returns(index_response([{'id' => 1}])) 12 | 13 | api_expects(:content_views, :index) do |p| 14 | p['name'] == 'cv' && p['organization_id'] == 1 15 | end 16 | 17 | run_cmd(%w(content-view add-repository --organization org1 --name cv --repository-id 1)) 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/functional/capsule/info_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative 'capsule_helpers' 3 | require 'hammer_cli_katello/capsule' 4 | 5 | module HammerCLIKatello 6 | describe Capsule do 7 | describe InfoCommand do 8 | include CapsuleHelpers 9 | 10 | it 'allows minimal options' do 11 | expect_capsule_info('id' => '1') 12 | 13 | run_cmd(%w(capsule info --id 1)) 14 | end 15 | 16 | it 'resolves capsule ID from name' do 17 | expect_generic_capsule_search( 18 | params: { search: "name = \"capsule1\"" }, returns: {'id' => 1}) 19 | expect_capsule_info('id' => 1) 20 | 21 | run_cmd(%w(capsule info --name capsule1)) 22 | end 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/functional/flatpak_remote/create_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'create flatpak remote' do 4 | before do 5 | @cmd = %w(flatpak-remote create) 6 | end 7 | 8 | let(:remote_name) { 'pizza' } 9 | let(:url) { 'http://proxy.example.com' } 10 | let(:organization_id) { 1 } 11 | 12 | it 'Creates a flatpak remote' do 13 | params = ["--name=#{remote_name}", "--url=#{url}", 14 | "--organization-id=#{organization_id}"] 15 | 16 | api_expects(:flatpak_remotes, :create, 'Create a Flatpak remote') 17 | 18 | expected_result = success_result("Flatpak Remote created.\n") 19 | result = run_cmd(@cmd + params) 20 | assert_cmd(expected_result, result) 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /test/functional/host/traces/resolve_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | 3 | describe 'host trace resolve' do 4 | include ForemanTaskHelpers 5 | 6 | before do 7 | @cmd = %w(host traces resolve) 8 | end 9 | 10 | let(:host_id) { '2' } 11 | let(:task_id) { '5' } 12 | let(:response) do 13 | { 14 | 'id' => task_id, 15 | 'state' => 'stopped' 16 | } 17 | end 18 | 19 | it "resolves traces on a host" do 20 | trace_ids = [3] 21 | params = ["--host-id=#{host_id}", "--trace-ids=#{trace_ids}"] 22 | 23 | ex = api_expects(:host_tracer, :resolve) 24 | 25 | ex.returns(response) 26 | 27 | expect_foreman_task(task_id) 28 | 29 | run_cmd(@cmd + params) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rake/testtask' 2 | require 'bundler/gem_tasks' 3 | require 'ci/reporter/rake/minitest' 4 | 5 | Rake::TestTask.new do |t| 6 | t.libs << "lib" 7 | t.test_files = Dir.glob('test/**/*_test.rb') 8 | t.verbose = true 9 | t.warning = false 10 | end 11 | 12 | begin 13 | require 'rubocop/rake_task' 14 | RuboCop::RakeTask.new 15 | rescue => _ 16 | puts "Rubocop not loaded." 17 | end 18 | 19 | task :default do 20 | Rake::Task['rubocop'].execute 21 | Rake::Task['test'].execute 22 | end 23 | 24 | require "hammer_cli_katello/version" 25 | require "hammer_cli_katello/i18n" 26 | require "hammer_cli/i18n/find_task" 27 | HammerCLI::I18n::FindTask.define( 28 | HammerCLIKatello::I18n::LocaleDomain.new, 29 | HammerCLIKatello.version.to_s 30 | ) 31 | -------------------------------------------------------------------------------- /test/functional/repository_set/repository_set_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module RepositorySetHelpers 4 | include SearchHelpers 5 | 6 | def expect_repository_set_search(name, id, organization_id: nil, product_id: nil) 7 | params = {'name' => name} 8 | params.merge(organization_id: organization_id) if organization_id.nil? 9 | params.merge(product_id: product_id) if product_id.nil? 10 | expect_generic_repository_sets_search( 11 | params: params, 12 | returns: {'id' => id}) 13 | end 14 | 15 | def expect_generic_repository_sets_search(params: {}, returns: []) 16 | api_expects(:repository_sets, :index, 'Find repository sets') 17 | .with_params(params) 18 | .returns(index_response(returns)) 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/status.rb: -------------------------------------------------------------------------------- 1 | require 'hammer_cli_foreman/status' 2 | 3 | module HammerCLIKatello 4 | class StatusCommand < HammerCLIKatello::Command 5 | resource :ping, :server_status 6 | 7 | output do 8 | field :version, _('Version') 9 | field :timeUTC, _('Time UTC'), Fields::Date 10 | end 11 | 12 | def request_options 13 | { with_authentication: false } 14 | end 15 | end 16 | 17 | HammerCLIForeman::StatusCommand.subcommand 'katello', 18 | HammerCLIKatello::StatusCommand.desc, 19 | HammerCLIKatello::StatusCommand 20 | HammerCLIForeman::StatusCommand::ForemanCommand.extend_with( 21 | HammerCLIKatello::CommandExtensions::Ping.new 22 | ) 23 | end 24 | -------------------------------------------------------------------------------- /test/functional/repository/repository_helpers.rb: -------------------------------------------------------------------------------- 1 | module RepositoryHelpers 2 | def expect_repository_search(product_id, name, id) 3 | api_expects(:repositories, :index, 'Find a repository') 4 | .with_params('name' => name, 'product_id' => product_id) 5 | .returns(index_response([{'id' => id}])) 6 | end 7 | 8 | def expect_repositories_search(org_id, names, ids) 9 | expect_generic_repositories_search({'names' => names, 'organization_id' => org_id}, 10 | ids.zip(names).map { |id, name| { 'id' => id, 'name' => name } }) 11 | end 12 | 13 | def expect_generic_repositories_search(params = {}, returns = []) 14 | api_expects(:repositories, :index, 'Find repositories') 15 | .with_params(params) 16 | .returns(index_response(returns)) 17 | end 18 | end 19 | -------------------------------------------------------------------------------- /test/functional/product/verify_checksum_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'verify checksum on a product' do 4 | include ForemanTaskHelpers 5 | 6 | before do 7 | @cmd = %w(product verify-checksum) 8 | end 9 | 10 | let(:sync_response) do 11 | { 12 | 'id' => '1', 13 | 'state' => 'planned' 14 | } 15 | end 16 | 17 | it 'verifies products ' do 18 | params = [ 19 | '--ids=1' 20 | ] 21 | 22 | ex = api_expects(:products_bulk_actions, :verify_checksum_products, 'verify checksum') 23 | .with_params('ids' => [1]) 24 | ex.returns(sync_response) 25 | 26 | expect_foreman_task('3') 27 | 28 | result = run_cmd(@cmd + params) 29 | assert_equal(HammerCLI::EX_OK, result.exit_code) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /test/functional/capsule/content/reclaim_space_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require_relative 'capsule_content_helpers' 3 | require 'hammer_cli_katello/capsule' 4 | 5 | module HammerCLIKatello 6 | module Capsule 7 | class Content 8 | describe Content::ReclaimSpaceCommand do 9 | include CapsuleContentHelpers 10 | 11 | it 'allows minimal options' do 12 | api_expects(:capsule_content, :reclaim_space, 'Reclaim space').with_params('id' => 1) 13 | run_cmd(%w(capsule content reclaim-space --id 1)) 14 | end 15 | 16 | it 'fails on missing ID' do 17 | api_expects_no_call 18 | assert_failure run_cmd(%w(capsule content reclaim-space)), "Missing arguments for '--id'." 19 | end 20 | end 21 | end 22 | end 23 | end 24 | -------------------------------------------------------------------------------- /locale/README.md: -------------------------------------------------------------------------------- 1 | Updating the translations 2 | ------------------------- 3 | 4 | 1. Check if there are any new languages with progress more than 50% on [transifex](https://www.transifex.com/projects/p/katello/resource/hammer-cli-katello/). If so, do the following for each of the new languages: 5 | 6 | ``` 7 | mkdir locale/ 8 | cp locale/hammer-cli-katello.pot locale//hammer-cli-katello.po 9 | ``` 10 | 2. Make sure you have `transifex-client` installed 11 | 12 | 3. Update the translations. From GIT repo root directory run: 13 | 14 | ``` 15 | make -C locale tx-update 16 | ``` 17 | 18 | It will download translations from transifex, generates `mo` files, updates strings in `pot` file and wraps all the changes in a new commit. Transifex automatically updates its strings when the commit is pushed to Github. 19 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_package_group.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostPackageGroup < HammerCLIKatello::Command 3 | desc "Manage package-groups on your hosts. These commands are no longer available"\ 4 | "\n Use the remote execution equivalent" 5 | 6 | class InstallCommand < HammerCLIKatello::SingleResourceCommand 7 | command_name "install" 8 | def self.rex_feature 9 | "katello_group_install" 10 | end 11 | 12 | include UnsupportedKatelloAgentCommandHelper 13 | end 14 | 15 | class RemoveCommand < HammerCLIKatello::SingleResourceCommand 16 | command_name "remove" 17 | def self.rex_feature 18 | "katello_group_remove" 19 | end 20 | 21 | include UnsupportedKatelloAgentCommandHelper 22 | end 23 | 24 | autoload_subcommands 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/functional/content_view/publish_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/content_view' 3 | 4 | module HammerCLIKatello 5 | describe ContentView do 6 | it 'allows major & minor' do 7 | ex = api_expects(:organizations, :index) do |p| 8 | p[:search] == "name = \"org1\"" 9 | end 10 | ex.returns(index_response([{'id' => 1}])) 11 | 12 | ex = api_expects(:content_views, :index) do |p| 13 | p['name'] == 'cv' && p['organization_id'] == 1 14 | end 15 | ex.returns(index_response([{'id' => 3}])) 16 | 17 | api_expects(:content_views, :publish) do |p| 18 | p['id'] == 3 && p['major'] == 5 && p['minor'] == 1 19 | end 20 | 21 | run_cmd(%w(content-view publish --major 5 --minor 1 --organization org1 --name cv --async)) 22 | end 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /test/functional/flatpak_remote/scan_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'Scan a flatpak remote' do 4 | include ForemanTaskHelpers 5 | 6 | before do 7 | @cmd = %w(flatpak-remote scan) 8 | end 9 | 10 | let(:org_id) { 1 } 11 | let(:remote_id) { 1 } 12 | let(:task_id) { 3 } 13 | let(:scan_response) do 14 | { 15 | 'id' => remote_id.to_s, 16 | 'state' => 'planned' 17 | } 18 | end 19 | 20 | it "scans a repository" do 21 | params = ["--id=#{remote_id}"] 22 | 23 | ex = api_expects(:flatpak_remotes, :scan, 'Remote is scanned') do |par| 24 | par['id'] == remote_id 25 | end 26 | 27 | ex.returns(scan_response) 28 | 29 | expect_foreman_task(task_id) 30 | 31 | result = run_cmd(@cmd + params) 32 | assert_equal(result.exit_code, 0) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /test/test_helper.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), './task_helper.rb') 2 | require 'minitest/autorun' 3 | require 'minitest/spec' 4 | require 'mocha/minitest' 5 | require 'hammer_cli' 6 | require 'ostruct' 7 | 8 | KATELLO_VERSION = Gem::Version.new(ENV['TEST_API_VERSION'] || '4.14') 9 | 10 | if HammerCLI.context[:api_connection] 11 | HammerCLI.context[:api_connection].create('foreman') do 12 | HammerCLI::Apipie::ApiConnection.new( 13 | :apidoc_cache_dir => 'test/data/' + KATELLO_VERSION.to_s, 14 | :apidoc_cache_name => 'foreman_api', 15 | :dry_run => true 16 | ) 17 | end 18 | else 19 | HammerCLIForeman.stubs(:resource_config).returns( 20 | :apidoc_cache_dir => 'test/data/' + KATELLO_VERSION.to_s, 21 | :apidoc_cache_name => 'foreman_api', 22 | :dry_run => true 23 | ) 24 | end 25 | 26 | require 'hammer_cli_katello' 27 | -------------------------------------------------------------------------------- /test/functional/local_helper_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'local helper' do 4 | before do 5 | class SuperLocalTestHelper 6 | def parse_subcommand 7 | true 8 | end 9 | end 10 | 11 | class LocalTestHelper < SuperLocalTestHelper 12 | include HammerCLIKatello::LocalHelper 13 | end 14 | 15 | @local_helper = LocalTestHelper.new 16 | end 17 | 18 | it "does not fail if /usr/share/foreman exists" do 19 | File.expects(:exist?).with('/usr/share/foreman').returns(true) 20 | assert @local_helper.parse_subcommand 21 | end 22 | 23 | it "fails if /usr/share/foreman does not exist" do 24 | File.expects(:exist?).with('/usr/share/foreman').returns(false) 25 | 26 | assert_raises RuntimeError do 27 | @local_helper.parse_subcommand 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /test/functional/activation_key/product_content_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'listing available product content' do 4 | let(:activation_key_id) { 1 } 5 | let(:empty_response_table) do 6 | < id}) 8 | end 9 | 10 | def expect_lifecycle_environments_list(args = {params: {}, returns: []}) 11 | api_expects(:capsule_content, :lifecycle_environments) 12 | .with_params(args[:params]).returns(index_response(args[:returns])) 13 | end 14 | 15 | def expect_lifecycle_environment_add(params = {}) 16 | api_expects(:capsule_content, :add_lifecycle_environment) 17 | .with_params(params) 18 | end 19 | 20 | def expect_lifecycle_environment_remove(params = {}) 21 | api_expects(:capsule_content, :remove_lifecycle_environment) 22 | .with_params(params) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /test/functional/host_collection/content_update_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/host_collection' 3 | 4 | module HammerCLIKatello 5 | describe 'update Content on a host-collection' do 6 | { "package" => "katello_package_update", 7 | "package-group" => "katello_group_update" 8 | }.each do |command, feature| 9 | it "errors out on #{command} update" do 10 | cmd = ["host-collection", command, "update"] 11 | params = ["--help"] 12 | result = run_cmd(cmd + params) 13 | assert_exit_code_equal(HammerCLI::EX_UNAVAILABLE, result.exit_code) 14 | assert_match(/Not supported. Use the remote execution equivalent/, result.out) 15 | assert_match(/feature #{feature}/, result.out) 16 | assert_match(/Specify the host collection with the --search-query/, result.out) 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /test/functional/erratum/info_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative 'erratum_helpers' 3 | 4 | describe 'Erratum Info' do 5 | include ErratumHelpers 6 | 7 | before do 8 | @cmd = %w(erratum info) 9 | end 10 | 11 | it "prints module package info on run" do 12 | api_expects(:errata, :show) 13 | .with_params('id' => erratum_id) 14 | .returns(make_erratum_response) 15 | params = ["--id=#{erratum_id}"] 16 | result = run_cmd(@cmd + params) 17 | verify_module_packages_and_orphan_packages(result) 18 | end 19 | 20 | it "prints package info on run" do 21 | api_expects(:errata, :show) 22 | .with_params('id' => erratum_id) 23 | .returns(make_erratum_response(true, false)) 24 | 25 | params = ["--id=#{erratum_id}"] 26 | result = run_cmd(@cmd + params) 27 | verify_no_modules_packages_with_orphan_packages(result) 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /test/functional/host_collection/content_remove_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/host_collection' 3 | 4 | module HammerCLIKatello 5 | describe 'Remove Content on a host-collection' do 6 | { "package" => "katello_package_remove", 7 | "package-group" => "katello_group_remove" 8 | }.each do |command, feature| 9 | it "errors out on #{command} install" do 10 | cmd = ["host-collection", command, "remove"] 11 | params = ["--help"] 12 | result = run_cmd(cmd + params) 13 | assert_exit_code_equal(HammerCLI::EX_UNAVAILABLE, result.exit_code) 14 | assert_match(/Not supported. Use the remote execution equivalent/, result.out) 15 | assert_match(/feature #{feature}/, result.out) 16 | assert_match(/Specify the host collection with the --search-query/, result.out) 17 | end 18 | end 19 | end 20 | end 21 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/content_view_name_resolvable.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module ContentViewNameResolvable 3 | class ContentViewParamSource < HammerCLI::Options::Sources::Base 4 | def initialize(command) 5 | @command = command 6 | end 7 | 8 | def get_options(_defined_options, result) 9 | if result['option_content_view_name'] && result['option_content_view_id'].nil? 10 | result['option_content_view_id'] = @command.resolver.content_view_id( 11 | @command.resolver.scoped_options('content_view', result, :single)) 12 | end 13 | result 14 | end 15 | end 16 | 17 | def option_sources 18 | sources = super 19 | sources.find_by_name('IdResolution').insert_relative( 20 | :after, 21 | 'IdParams', 22 | ContentViewParamSource.new(self) 23 | ) 24 | sources 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /hammer-devel-container.sh: -------------------------------------------------------------------------------- 1 | #/bin/bash 2 | shopt -s expand_aliases 3 | #set -e 4 | #set -x 5 | 6 | # Check if podman is installed 7 | if ! $(rpm -q --quiet podman) ; then 8 | echo "Error: podman is not installed." 9 | exit 1 10 | fi 11 | 12 | # Check if the HAMMER_DIR environment variable exists and is not empty 13 | if [ -z "${HAMMER_DIR+x}" ]; then 14 | # If the environment variable does not exist, use the current working directory 15 | HAMMER_DIR=$(pwd) 16 | fi 17 | 18 | if [ ! -f "$HAMMER_DIR/hammer_cli_katello.gemspec" ]; then 19 | # Not a hammer cli katello repo. Have the user set it and exit 20 | echo "Error: HAMMER_DIR needs to point to a hammer-cli-katello repo" 21 | exit 1 22 | fi 23 | 24 | chmod 777 $HAMMER_DIR 25 | find $HAMMER_DIR -type d -exec chmod 777 {} + 26 | podman run --rm -it --network=host -v $HAMMER_DIR:/opt/app-root/src/hammer-cli-katello:Z ghcr.io/katello/hammer-cli-katello-devel:latest 27 | -------------------------------------------------------------------------------- /test/functional/activation_key/update_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/activation_key' 3 | 4 | module HammerCLIKatello 5 | describe ActivationKeyCommand do 6 | describe UpdateCommand do 7 | it 'allows promoting a content view' do 8 | ex = api_expects(:organizations, :index) do |p| 9 | p[:search] == "name = \"org1\"" 10 | end 11 | ex.at_least_once.returns(index_response([{'id' => 1}])) 12 | 13 | ex = api_expects(:activation_keys, :index) do |p| 14 | p['name'] == 'ak' && p['organization_id'] == 1 15 | end 16 | ex.returns(index_response([{'id' => 6}])) 17 | 18 | api_expects(:activation_keys, :update) do |p| 19 | p['id'] == 6 && p['organization_id'] == 1 20 | end 21 | 22 | run_cmd(%w(activation-key update --organization org1 --name ak --auto-attach false)) 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/command_extensions/ping.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module CommandExtensions 3 | class Ping < HammerCLI::CommandExtensions 4 | before_print do |data| 5 | unless data['results']['katello'].nil? 6 | data['results']['katello']['services'].each do |_, service| 7 | service['_response'] = get_server_response(service) 8 | end 9 | data['results'].merge!(data['results']['katello']) 10 | end 11 | end 12 | 13 | output do |definition| 14 | definition.append(HammerCLIKatello::PingCommand.output_definition.fields) 15 | end 16 | 17 | def self.get_server_response(service_hash) 18 | if service_hash['duration_ms'] 19 | _("Duration: %sms") % service_hash['duration_ms'] 20 | elsif service_hash['message'] 21 | _("Message: %s") % service_hash['message'] 22 | end 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/erratum_info_command.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class ErratumInfoCommand < HammerCLIKatello::InfoCommand 3 | command_name "info" 4 | 5 | output do 6 | field :title, _("Title") 7 | field :version, _("Version") 8 | field :description, _("Description") 9 | field :status, _("Status") 10 | field :id, _("Id") 11 | field :errata_id, _("Errata ID") 12 | field :reboot_suggested, _("Reboot Suggested") 13 | field :updated, _("Updated") 14 | field :issued, _("Issued") 15 | field :release, _("Release") 16 | field :solution, _("Solution") 17 | field :packages, _("Packages"), Fields::List, :hide_blank => true 18 | 19 | collection :module_streams, _("Module Streams"), :hide_blank => true do 20 | field :name, _("Name") 21 | field :stream, _("Stream") 22 | field :packages, _("Packages"), Fields::List 23 | end 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /test/functional/host_collection/content_install_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/host_collection' 3 | 4 | module HammerCLIKatello 5 | describe 'Install Content on a host-collection' do 6 | { "package" => "katello_package_install", 7 | "package-group" => "katello_group_install", 8 | "erratum" => "katello_errata_install" 9 | }.each do |command, feature| 10 | it "errors out on #{command} install" do 11 | cmd = ["host-collection", command, "install"] 12 | params = ["--help"] 13 | result = run_cmd(cmd + params) 14 | assert_exit_code_equal(HammerCLI::EX_UNAVAILABLE, result.exit_code) 15 | assert_match(/Not supported. Use the remote execution equivalent/, result.out) 16 | assert_match(/feature #{feature}/, result.out) 17 | assert_match(/Specify the host collection with the --search-query/, result.out) 18 | end 19 | end 20 | end 21 | end 22 | -------------------------------------------------------------------------------- /test/functional/sync_plan/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/sync_plan' 3 | require_relative 'sync_plan_helpers' 4 | require_relative '../organization/organization_helpers' 5 | 6 | module HammerCLIKatello 7 | describe SyncPlan::ListCommand do 8 | include SyncPlanHelpers 9 | include OrganizationHelpers 10 | 11 | it 'allows minimal options' do 12 | expect_sync_plan_search(1, nil, nil) 13 | 14 | run_cmd(%w(sync-plan list --organization-id 1)) 15 | end 16 | 17 | it 'allows org name' do 18 | expect_organization_search('org1', 1) 19 | expect_sync_plan_search(1, nil, nil) 20 | 21 | run_cmd(%w(sync-plan list --organization org1)) 22 | end 23 | 24 | it 'allows org label' do 25 | expect_organization_search('org1', 1, field: 'label') 26 | expect_sync_plan_search(1, nil, nil) 27 | 28 | run_cmd(%w(sync-plan list --organization-label org1)) 29 | end 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /test/functional/product/product_helpers.rb: -------------------------------------------------------------------------------- 1 | module ProductHelpers 2 | def expect_generic_product_search(params = {}, returns = {}) 3 | api_expects(:products, :index, 'Find the Product') 4 | .with_params(params).returns(index_response([returns])) 5 | end 6 | 7 | def expect_product_search(org_id, name, id) 8 | expect_generic_product_search({'name' => name, 'organization_id' => org_id}, 'id' => id) 9 | end 10 | 11 | def expect_product_show(options = {}) 12 | raise "#{__method__} must be called with :id" unless (options.keys & [:id]).size == 1 13 | 14 | if options[:name] 15 | raise "#{__method__} used with :name also requires :org_id" unless options[:org_id] 16 | expect_product_search(options[:org_id], options[:name], options[:id]) 17 | end 18 | 19 | ex = api_expects(:products, :show, 'Show a Product') do |par| 20 | par['id'] == options[:id] 21 | end 22 | ex.returns(index_response([{'id' => options[:id]}])) 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /test/functional/test_helper.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | require 'hammer_cli/testing/output_matchers' 4 | require 'hammer_cli/testing/command_assertions' 5 | require 'hammer_cli/testing/data_helpers' 6 | require 'hammer_cli_foreman/testing/api_expectations' 7 | 8 | include HammerCLI::Testing::OutputMatchers 9 | include HammerCLI::Testing::CommandAssertions 10 | include HammerCLI::Testing::DataHelpers 11 | include HammerCLIForeman::Testing::APIExpectations 12 | 13 | def assert_success(command_run_result) 14 | assert command_run_result.exit_code.zero?, 15 | "Nonzero exit code (#{command_run_result.exit_code}): #{command_run_result.err}" 16 | end 17 | 18 | def assert_failure(command_run_result, msg = nil) 19 | assert !command_run_result.exit_code.zero?, "Success exit code (0) when expecting failure" 20 | if msg 21 | assert command_run_result.err[msg], 22 | "Actual:\n#{command_run_result.err}\nExpected:\n#{msg.inspect}" 23 | end 24 | end 25 | -------------------------------------------------------------------------------- /test/functional/host/subscription/product_content_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require File.join(File.dirname(__FILE__), '../host_helpers') 3 | require 'hammer_cli_katello/host_subscription' 4 | 5 | describe 'listing available product content' do 6 | include HostHelpers 7 | 8 | let(:host_id) { 1 } 9 | let(:empty_response_table) do 10 | < 0, 12 | "subtotal" => 0, 13 | "page" => "1", 14 | "per_page" => "1000", 15 | "error" => nil, 16 | "search" => nil, 17 | "sort" => { 18 | "by" => nil, 19 | "order" => nil 20 | }, 21 | "results" => [] 22 | } 23 | end 24 | 25 | it 'allows listing by host' do 26 | params = ["--host-id=#{host_id}"] 27 | ex = api_expects(:host_tracer, :index, 'host traces list') 28 | 29 | ex.returns(empty_response) 30 | expected_result = success_result("---------|-------------|--------|----- 31 | TRACE ID | APPLICATION | HELPER | TYPE 32 | ---------|-------------|--------|----- 33 | ") 34 | result = run_cmd(@cmd + params) 35 | assert_cmd(expected_result, result) 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/functional/host/errata/info_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require_relative '../../erratum/erratum_helpers' 3 | 4 | describe 'host Erratum Info' do 5 | include ErratumHelpers 6 | before do 7 | @cmd = %w(host errata info) 8 | end 9 | 10 | it "prints module package info on run" do 11 | api_expects(:host_errata, :show) 12 | .with_params('id' => erratum_id, 'host_id' => host_id) 13 | .returns(make_erratum_response) 14 | params = ["--id=#{erratum_id}", "--host-id=#{host_id}"] 15 | result = run_cmd(@cmd + params) 16 | verify_module_packages_and_orphan_packages(result) 17 | end 18 | 19 | it "prints package info on run" do 20 | api_expects(:host_errata, :show) 21 | .with_params('id' => erratum_id, 'host_id' => host_id) 22 | .returns(make_erratum_response(true, false)) 23 | params = ["--id=#{erratum_id}", "--host-id=#{host_id}"] 24 | result = run_cmd(@cmd + params) 25 | verify_no_modules_packages_with_orphan_packages(result) 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/output/formatters.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module Output 3 | module Formatters 4 | class ChecksumFormatter < HammerCLI::Output::Formatters::FieldFormatter 5 | def required_features 6 | [:rich_text] 7 | end 8 | 9 | def format(items, _ = {}) 10 | "%s %s" % items.reverse 11 | end 12 | end 13 | 14 | class DependencyFormatter < HammerCLI::Output::Formatters::FieldFormatter 15 | def format(dependency, _ = {}) 16 | name = dependency[:name] || dependency['name'] 17 | version = dependency[:version_requirement] || dependency['version_requirement'] 18 | if version 19 | "%s ( %s )" % [name, version] 20 | else 21 | name 22 | end 23 | end 24 | end 25 | 26 | HammerCLI::Output::Output.register_formatter(ChecksumFormatter.new, :ChecksumFilePair) 27 | HammerCLI::Output::Output.register_formatter(DependencyFormatter.new, :Dependency) 28 | end 29 | end 30 | end 31 | -------------------------------------------------------------------------------- /test/functional/host/subscription/unregister_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require File.join(File.dirname(__FILE__), '../host_helpers') 3 | 4 | describe 'host subscription unregister' do 5 | include HostHelpers 6 | 7 | before do 8 | @cmd = %w(host subscription unregister) 9 | end 10 | 11 | it "unregisters the host" do 12 | params = ['--host-id=3'] 13 | ex = api_expects(:host_subscriptions, :destroy, 'Host unregister') do |par| 14 | par['host_id'] == 3 15 | end 16 | ex.returns({}) 17 | 18 | expected_result = success_result( 19 | 'Host unregistered. 20 | ' 21 | ) 22 | 23 | result = run_cmd(@cmd + params) 24 | assert_cmd(expected_result, result) 25 | end 26 | 27 | it "resolves id from name" do 28 | params = ['--host=host1'] 29 | 30 | api_expects(:host_subscriptions, :destroy, 'Host unregister') do |par| 31 | par['host_id'].to_i == 3 32 | end 33 | expect_host_search('host1', '3') 34 | 35 | run_cmd(@cmd + params) 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/functional/organization/info_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/organization' 3 | require 'hammer_cli_katello/associating_commands' 4 | 5 | describe HammerCLIKatello::Organization::InfoCommand do 6 | before do 7 | @cmd = %w(organization info) 8 | end 9 | 10 | let(:cdn_configuration) do 11 | { "type" => 'network_sync' } 12 | end 13 | 14 | it "includes cdn configuration attributes" do 15 | org_id = 2 16 | params = ["--id=#{org_id}"] 17 | api_expects(:organizations, :index).returns(index_response([{'id' => org_id}])) 18 | 19 | cdn_configuration = { 20 | "url" => "https://cdn.redhat.com", 21 | "type" => "redhat_cdn" 22 | } 23 | 24 | api_expects(:organizations, :show) 25 | .with_params('id' => org_id.to_s) 26 | .returns("cdn_configuration" => cdn_configuration, "id" => org_id) 27 | result = run_cmd(@cmd + params) 28 | expected = success_result(FieldMatcher.new('URL', cdn_configuration["url"])) 29 | assert_cmd(expected, result) 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/unsupported_katello_agent_command_helper.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module UnsupportedKatelloAgentCommandHelper 3 | def execute 4 | print_message(failure_message) 5 | HammerCLI::EX_UNAVAILABLE 6 | end 7 | 8 | def self.host_collection_help_text 9 | "Specify the host collection with the --search-query " \ 10 | "parameter, e.g. `--search-query \"host_collection = MyCollection\"` or " \ 11 | "`--search-query \"host_collection_id=6\"`" 12 | end 13 | 14 | def self.included(base) 15 | alternate_command = "hammer job-invocation create --feature #{base.rex_feature}" 16 | message = "Use the remote execution equivalent `#{alternate_command}`." 17 | if base.name =~ /HostCollection/ 18 | message = "#{message} #{host_collection_help_text}" 19 | end 20 | base.desc "Not supported. #{message}" 21 | base.failure_message "Not supported. #{message}" 22 | base.option ["-h", "--help"], :flag, "Unsupported Operation - #{message}" 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/functional/organization/delete_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | 3 | module HammerCLIKatello 4 | describe 'Organization::DeleteCommand' do 5 | it 'it requires the organization ID and must be resolved from name' do 6 | api_expects(:organizations, :index).with_params( 7 | :search => "name = \"my_org\"", :per_page => 1000, :page => 1 8 | ) 9 | run_cmd(%w(organization delete --name my_org)) 10 | end 11 | 12 | it 'it requires the organization ID and must be resolved from name' do 13 | api_expects(:organizations, :index).with_params( 14 | :search => "label = \"my_org\"", :per_page => 1000, :page => 1 15 | ) 16 | run_cmd(%w(organization delete --label my_org)) 17 | end 18 | 19 | it 'it requires the organization ID and must be resolved from name' do 20 | api_expects(:organizations, :index).with_params( 21 | :search => "title = \"my_org\"", :per_page => 1000, :page => 1 22 | ) 23 | run_cmd(%w(organization delete --title my_org)) 24 | end 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_traces.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostTraces < HammerCLIKatello::Command 3 | desc "List traces on your hosts" 4 | 5 | class ListCommand < HammerCLIKatello::ListCommand 6 | resource :host_tracer, :index 7 | command_name "list" 8 | 9 | output do 10 | field :id, _("Trace ID") 11 | field :application, _("Application") 12 | field :helper, _("Helper") 13 | field :app_type, _("Type") 14 | end 15 | build_options 16 | end 17 | 18 | class ResolveCommand < HammerCLIKatello::SingleResourceCommand 19 | include HammerCLIForemanTasks::Async 20 | resource :host_tracer, :resolve 21 | command_name "resolve" 22 | 23 | success_message _("Traces are being resolved with task %{id}.") 24 | failure_message _("Could not resolve traces") 25 | 26 | validate_options do 27 | option(:option_trace_ids).required 28 | option(:option_host_id).required 29 | end 30 | 31 | build_options 32 | end 33 | 34 | autoload_subcommands 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_bootc.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostBootc < HammerCLIKatello::Command 3 | resource :host_bootc_images 4 | desc "Manage bootc images on your hosts" 5 | 6 | class ImagesCommand < HammerCLIKatello::ListCommand 7 | action :bootc_images 8 | command_name "images" 9 | 10 | output do 11 | field :bootc_booted_image, _("Running image") 12 | field :bootc_booted_digest, _("Running image digest") 13 | field :host_count, _("Host count") 14 | end 15 | 16 | def send_request 17 | self.class.parse_data(super) 18 | end 19 | 20 | def self.parse_data(data_collection) 21 | data = data_collection.inject([]) do |list, item| 22 | list + item["digests"].collect do |digest| 23 | digest.merge(:bootc_booted_image => item["bootc_booted_image"]) 24 | end 25 | end 26 | HammerCLI::Output::RecordCollection.new(data, :meta => data_collection.meta) 27 | end 28 | 29 | build_options 30 | end 31 | 32 | autoload_subcommands 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /test/functional/content_units/info_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper.rb' 2 | require_relative '../organization/organization_helpers' 3 | require_relative '../content_view/content_view_helpers' 4 | require_relative '../repository/repository_helpers' 5 | require_relative '../product/product_helpers' 6 | require 'hammer_cli_katello/content_units' 7 | 8 | module HammerCLIKatello 9 | describe ContentUnitsCommand::InfoCommand do 10 | include ContentViewHelpers 11 | include RepositoryHelpers 12 | include ProductHelpers 13 | include OrganizationHelpers 14 | 15 | it 'allows minimal options' do 16 | api_expects(:generic_content_units, :show) 17 | .with_params('content_type' => 'python_package', 'id' => '1492') 18 | 19 | run_cmd(%w(content-units info --content-type python_package --id 1492)) 20 | end 21 | 22 | it 'requires content_type param' do 23 | api_expects_no_call 24 | 25 | r = run_cmd(%w(content-units info --id 1492)) 26 | assert(r.err.include?("Missing arguments for '--content-type'"), "Invalid error message") 27 | end 28 | end 29 | end 30 | -------------------------------------------------------------------------------- /test/functional/product/info_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../organization/organization_helpers') 3 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 4 | 5 | describe "get product info" do 6 | include OrganizationHelpers 7 | include ProductHelpers 8 | 9 | it 'by ID' do 10 | expect_product_show(:id => 1) 11 | assert_equal( 12 | 0, 13 | run_cmd(%w(product info --id 1)).exit_code 14 | ) 15 | end 16 | 17 | it 'by organization id and product name' do 18 | expect_product_show(:name => 'product1', :org_id => 1, :id => 1) 19 | assert_equal( 20 | 0, 21 | run_cmd(%w(product info --organization-id 1 --name product1)).exit_code 22 | ) 23 | end 24 | 25 | it 'by organization name and product name' do 26 | expect_organization_search('org1', 1) 27 | expect_product_show(:name => 'product1', :org_id => 1, :id => 1) 28 | assert_equal( 29 | 0, 30 | run_cmd(%w(product info --organization org1 --name product1)).exit_code 31 | ) 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /test/functional/repository/republish_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), './repository_helpers') 3 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 4 | 5 | describe 'Republish a repository' do 6 | include RepositoryHelpers 7 | include ForemanTaskHelpers 8 | include ProductHelpers 9 | 10 | before do 11 | @cmd = %w(repository republish) 12 | end 13 | 14 | let(:repo_id) { 1 } 15 | let(:sync_response) do 16 | { 17 | 'id' => repo_id.to_s, 18 | 'label' => 'Actions::Katello::Repository::MetadataGenerate', 19 | 'state' => 'planned' 20 | } 21 | end 22 | 23 | it "republishes a repository" do 24 | params = ["--id=#{repo_id}", "--force=true"] 25 | 26 | ex = api_expects(:repositories, :republish, 'Repository republished.') do |par| 27 | par['id'] == repo_id && par['force'] == true 28 | end 29 | 30 | ex.returns(sync_response) 31 | 32 | expect_foreman_task('3') 33 | 34 | result = run_cmd(@cmd + params) 35 | assert_equal(result.exit_code, 0) 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /locale/zanata.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | https://translate.zanata.org/zanata/ 4 | satellite6-hammer-cli-katello 5 | 6.0 6 | podir 7 | 8 | fr 9 | it 10 | ja 11 | ko 12 | gu 13 | hi 14 | mr 15 | or 16 | ru 17 | te 18 | pa 19 | kn 20 | de-DE 21 | es-ES 22 | pt-BR 23 | bn-IN 24 | ta-IN 25 | zh-Hans-CN 26 | zh-Hant-TW 27 | 28 | 29 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_collection_package.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostCollectionPackageCommand < HammerCLIKatello::Command 3 | command_name "package" 4 | desc "Manage packages on your host collections. "\ 5 | "These commands are no longer available. "\ 6 | "Use the remote execution equivalent" 7 | 8 | class InstallCommand < HammerCLIKatello::Command 9 | command_name "install" 10 | def self.rex_feature 11 | "katello_package_install" 12 | end 13 | 14 | include UnsupportedKatelloAgentCommandHelper 15 | end 16 | 17 | class UpdateCommand < HammerCLIKatello::Command 18 | command_name "update" 19 | def self.rex_feature 20 | "katello_package_update" 21 | end 22 | 23 | include UnsupportedKatelloAgentCommandHelper 24 | end 25 | 26 | class RemoveCommand < HammerCLIKatello::Command 27 | command_name "remove" 28 | def self.rex_feature 29 | "katello_package_remove" 30 | end 31 | 32 | include UnsupportedKatelloAgentCommandHelper 33 | end 34 | 35 | autoload_subcommands 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/functional/content_view/create_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | 3 | describe 'content-view create' do 4 | before do 5 | @cmd = %w(content-view create) 6 | @base_params = ["--organization-id=#{org_id}", "--name=#{cv_name}"] 7 | end 8 | let(:error_heading) { "Could not create the content view" } 9 | let(:cv_name) { 'test-cv' } 10 | let(:org_id) { 1 } 11 | let(:repositories) do 12 | [ 13 | {'id' => '1'}, 14 | {'id' => '2'}, 15 | {'id' => '3'} 16 | ] 17 | end 18 | 19 | it 'creates the content view with repositories specified by ids' do 20 | wanted = repositories.take(2) 21 | ids = wanted.map { |repo| repo['id'] } 22 | params = %W(--repository-ids=#{ids.join(',')}) 23 | 24 | api_expects(:content_views, :create, 'Create content view') do |par| 25 | par['name'] == cv_name && 26 | par['repository_ids'] == ids && 27 | par['organization_id'] == org_id 28 | end 29 | 30 | expected_result = success_result("Content view created.\n") 31 | result = run_cmd(@cmd + @base_params + params) 32 | assert_cmd(expected_result, result) 33 | end 34 | end 35 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_collection_package_group.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostCollectionPackageGroupCommand < HammerCLIKatello::Command 3 | command_name "package-group" 4 | desc "Manage package-groups on your host collections. "\ 5 | "These commands are no longer available. "\ 6 | "Use the remote execution equivalent" 7 | 8 | class InstallCommand < HammerCLIKatello::Command 9 | command_name "install" 10 | def self.rex_feature 11 | "katello_group_install" 12 | end 13 | 14 | include UnsupportedKatelloAgentCommandHelper 15 | end 16 | 17 | class UpdateCommand < HammerCLIKatello::Command 18 | command_name "update" 19 | def self.rex_feature 20 | "katello_group_update" 21 | end 22 | 23 | include UnsupportedKatelloAgentCommandHelper 24 | end 25 | 26 | class RemoveCommand < HammerCLIKatello::Command 27 | command_name "remove" 28 | def self.rex_feature 29 | "katello_group_remove" 30 | end 31 | 32 | include UnsupportedKatelloAgentCommandHelper 33 | end 34 | 35 | autoload_subcommands 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/content_export_complete.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class ContentExportComplete < HammerCLIKatello::Command 3 | desc "Prepare content for a full export to a disconnected Katello" 4 | resource :content_exports 5 | command_name 'complete' 6 | 7 | class VersionCommand < HammerCLIKatello::SingleResourceCommand 8 | desc _('Performs a full export a content view version') 9 | command_name "version" 10 | 11 | include HammerCLIForemanTasks::Async 12 | include ContentExportHelper 13 | end 14 | 15 | class LibraryCommand < HammerCLIKatello::SingleResourceCommand 16 | desc _("Performs a full export of the organization's library environment") 17 | command_name "library" 18 | 19 | include HammerCLIForemanTasks::Async 20 | include ContentExportHelper 21 | end 22 | 23 | class RepositoryCommand < HammerCLIKatello::SingleResourceCommand 24 | desc _("Performs a full export of a repository") 25 | command_name "repository" 26 | 27 | include HammerCLIForemanTasks::Async 28 | include ContentExportHelper 29 | end 30 | 31 | autoload_subcommands 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/docker_tag.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class DockerTagCommand < HammerCLIForeman::Command 3 | resource :docker_tags 4 | command_name 'tag' 5 | desc _('Manage docker tags') 6 | 7 | class ListCommand < HammerCLIKatello::ListCommand 8 | include HammerCLIKatello::LifecycleEnvironmentNameMapping 9 | 10 | output do 11 | field :id, _("ID") 12 | field :name, _("Tag") 13 | field :repository_id, _("Repository ID") 14 | end 15 | 16 | build_options do |o| 17 | o.expand.including(:products, :organizations, :content_views) 18 | end 19 | 20 | extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new) 21 | end 22 | 23 | class InfoCommand < HammerCLIKatello::InfoCommand 24 | output do 25 | field :id, _("ID") 26 | field :name, _("Tag") 27 | field :repository_id, _("Repository ID") 28 | 29 | from :manifest do 30 | field :id, _("Docker Manifest ID") 31 | field :name, _("Docker Manifest Name") 32 | end 33 | end 34 | 35 | build_options 36 | end 37 | 38 | autoload_subcommands 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /test/functional/apipie_helper_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'apipie helper' do 4 | before do 5 | class ApipieTestHelper 6 | include HammerCLIKatello::ApipieHelper 7 | end 8 | 9 | @apipie_helper = ApipieTestHelper.new 10 | end 11 | 12 | it "calls show method apipie resource" do 13 | api_expects(:repositories, :show).with_params('id' => '1').returns({}) 14 | assert @apipie_helper.show(:repositories, 'id' => '1') 15 | end 16 | 17 | it "calls index method apipie resource" do 18 | api_expects(:repositories, :index).with_params('name' => 'foo').returns('results' => []) 19 | assert @apipie_helper.index(:repositories, 'name' => 'foo') 20 | end 21 | 22 | it "calls destroy method apipie resource" do 23 | api_expects(:repositories, :destroy).with_params('id' => '1').returns({}) 24 | assert @apipie_helper.destroy(:repositories, 'id' => '1') 25 | end 26 | 27 | it "call method for apipie resources works" do 28 | api_expects(:repositories, :index).with_params('name' => 'foo').returns('results' => []) 29 | assert @apipie_helper.call(:index, :repositories, 'name' => 'foo') 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /test/functional/product/remove_sync_plan_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../organization/organization_helpers') 3 | require File.join(File.dirname(__FILE__), '../sync_plan/sync_plan_helpers') 4 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 5 | 6 | describe "remove a product's sync plan" do 7 | include OrganizationHelpers 8 | include SyncPlanHelpers 9 | include ProductHelpers 10 | 11 | it "by product ID" do 12 | api_expects(:products, :update, "set sync plan") do |params| 13 | params['id'] == 1 && params['sync_plan_id'].nil? 14 | end 15 | 16 | assert_equal( 17 | 0, 18 | run_cmd(%w(product remove-sync-plan --id 1)).exit_code 19 | ) 20 | end 21 | 22 | it "by product name" do 23 | expect_product_search(1, 'product1', 1) 24 | api_expects(:products, :update, "set sync plan") do |params| 25 | params['id'] == 1 && params['sync_plan_id'].nil? 26 | end 27 | 28 | assert_equal( 29 | 0, 30 | run_cmd(%w(product remove-sync-plan 31 | --organization-id 1 32 | --name product1)).exit_code 33 | ) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/command_extensions/lifecycle_environments.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module CommandExtensions 3 | class LifecycleEnvironments < HammerCLI::CommandExtensions 4 | # Remove when support of --environments options is ended. 5 | option_family( 6 | format: HammerCLI::Options::Normalizers::List.new, 7 | deprecation: _("Use %s instead") % '--lifecycle-environment[s|-ids]', 8 | deprecated: { '--environments' => _("Use %s instead") % '--lifecycle-environments', 9 | '--environment-ids' => _("Use %s instead") % '--lifecycle-environment-ids'} 10 | ) do 11 | parent '--environment-ids', 'ENVIRONMENT_IDS', _(''), 12 | attribute_name: :option_environment_ids 13 | child '--environments', 'ENVIRONMENT_NAMES', _(''), 14 | attribute_name: :option_environment_names 15 | end 16 | 17 | option_sources do |sources, command| 18 | sources.find_by_name('IdResolution').insert_relative( 19 | :after, 20 | 'IdsParams', 21 | HammerCLIKatello::OptionSources::LifecycleEnvironmentParams.new(command) 22 | ) 23 | sources 24 | end 25 | end 26 | end 27 | end 28 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/content_export_incremental.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class ContentExportIncremental < HammerCLIKatello::Command 3 | desc "Prepare content for an incremental export to a disconnected Katello" 4 | resource :content_export_incrementals 5 | command_name 'incremental' 6 | 7 | class VersionCommand < HammerCLIKatello::SingleResourceCommand 8 | desc _('Performs an incremental export of a content view version') 9 | command_name "version" 10 | 11 | include HammerCLIForemanTasks::Async 12 | include ContentExportHelper 13 | end 14 | 15 | class LibraryCommand < HammerCLIKatello::SingleResourceCommand 16 | desc _("Performs an incremental export of the organization's library environment") 17 | command_name "library" 18 | 19 | include HammerCLIForemanTasks::Async 20 | include ContentExportHelper 21 | end 22 | 23 | class RepositoryCommand < HammerCLIKatello::SingleResourceCommand 24 | desc _("Performs an incremental export of a repository") 25 | command_name "repository" 26 | 27 | include HammerCLIForemanTasks::Async 28 | include ContentExportHelper 29 | end 30 | 31 | autoload_subcommands 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/product_content.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module ProductContentBase 3 | class ProductContentCommand < HammerCLIKatello::ListCommand 4 | def self.setup 5 | desc _("List associated products") 6 | command_name "product-content" 7 | 8 | output do 9 | from :content do 10 | field :id, _("Id") 11 | field :name, _("Name") 12 | field :type, _("Type") 13 | field :contentUrl, _("Url") 14 | field :gpgUrl, _("GPG Key") 15 | field :label, _("Label") 16 | end 17 | field :enabled, _("Default Enabled?"), Fields::Boolean 18 | field :override_description, _("Override") 19 | end 20 | build_options 21 | end 22 | 23 | def extend_data(mod) 24 | formatted_overrides = mod["overrides"].map do |override| 25 | value = override['value'] 26 | if override['name'] == "enabled" 27 | value = override['value'] ? '1' : '0' 28 | end 29 | "#{override['name']}:#{value}" 30 | end 31 | mod["override_description"] = formatted_overrides.join(", ") 32 | mod 33 | end 34 | end 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /test/functional/content_credentials/create_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'create content-credentials' do 4 | before do 5 | @cmd = %w(content-credentials create) 6 | @base_params = ["--organization-id=#{org_id}", "--name=#{cred_name}"] 7 | end 8 | 9 | let(:org_id) { 1 } 10 | let(:cred_name) { 'sslcert' } 11 | let(:cert) { File.join(File.dirname(__FILE__), 'data', 'test_cert.json') } 12 | 13 | it 'Creates a SSL Content Credential' do 14 | params = ["--path=#{cert}", '--content-type=cert'] 15 | 16 | api_expects(:content_credentials, :create, 'Create a Content Credential') 17 | 18 | expected_result = success_result("Content Credential created.\n") 19 | result = run_cmd(@cmd + @base_params + params) 20 | assert_cmd(expected_result, result) 21 | end 22 | 23 | it 'Create a GPG Key Content Credential' do 24 | params = ["--path=#{cert}", '--content-type=gpg_key'] 25 | 26 | api_expects(:content_credentials, :create, 'Create a Content Credential') 27 | 28 | expected_result = success_result("Content Credential created.\n") 29 | result = run_cmd(@cmd + @base_params + params) 30 | assert_cmd(expected_result, result) 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /test/functional/hostgroup/info_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_foreman/hostgroup' 3 | 4 | module HammerCLIForeman 5 | describe Hostgroup do 6 | describe InfoCommand do 7 | before do 8 | @cmd = %w(hostgroup info) 9 | end 10 | 11 | let(:hostgroup_id) { 1 } 12 | 13 | it "Shows information about a hostgroup" do 14 | params = ["--id=#{hostgroup_id}"] 15 | 16 | ex = api_expects(:hostgroups, :show, "Get info") do |par| 17 | par["id"] == hostgroup_id.to_s 18 | end 19 | json_file = File.join(File.dirname(__FILE__), 'data', 'hostgroup.json') 20 | ex.returns(JSON.parse(File.read(json_file))) 21 | 22 | result = run_cmd(@cmd + params) 23 | # rubocop:disable Style/WordArray 24 | expected_fields = [['Name', 'Library'], 25 | ['Name', 'Default Organization View'], 26 | ['Name', 'foreman.example.com'], 27 | ['Name', 'Rhel 7']] 28 | expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) } 29 | expected_results.each { |expected| assert_cmd(expected, result) } 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/composite_content_view_name_resolvable.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module CompositeContentViewNameResolvable 3 | def composite_content_view_resolve_options(options) 4 | { 5 | HammerCLI.option_accessor_name("organization_id") => options["option_organization_id"], 6 | HammerCLI.option_accessor_name("organization_name") => options["option_organization_name"], 7 | HammerCLI.option_accessor_name("organization_label") => 8 | options["option_organization_label"], 9 | HammerCLI.option_accessor_name("name") => options["option_composite_content_view_name"] 10 | } 11 | end 12 | 13 | def options 14 | if super['option_composite_content_view_name'] && 15 | super['option_composite_content_view_id'].nil? 16 | options = composite_content_view_resolve_options(super) 17 | super['option_composite_content_view_id'] = resolver.content_view_id(options) 18 | end 19 | super 20 | end 21 | 22 | def self.included(base) 23 | base.option "--composite-content-view", 24 | "COMPOSITE_CONTENT_VIEW_NAME", _("Name of the composite content view"), 25 | :attribute_name => :option_composite_content_view_name 26 | end 27 | end 28 | end 29 | -------------------------------------------------------------------------------- /test/functional/product/update_proxy_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'update an http proxy on a product' do 4 | include ForemanTaskHelpers 5 | 6 | before do 7 | @cmd = %w(product update-proxy) 8 | end 9 | 10 | let(:sync_response) do 11 | { 12 | 'id' => '1', 13 | 'state' => 'planned' 14 | } 15 | end 16 | 17 | it 'updates product proxy policy' do 18 | params = [ 19 | '--ids=1', 20 | '--http-proxy-policy=use_selected_http_proxy', 21 | '--http-proxy-id=1' 22 | ] 23 | 24 | ex = api_expects(:products_bulk_actions, :update_http_proxy, 'update an http-proxy') 25 | .with_params("ids" => [1], "http_proxy_policy" => "use_selected_http_proxy", 26 | "http_proxy_id" => 1) 27 | ex.returns(sync_response) 28 | 29 | expect_foreman_task('3') 30 | 31 | result = run_cmd(@cmd + params) 32 | assert_equal(HammerCLI::EX_OK, result.exit_code) 33 | end 34 | 35 | it 'fails with missing required params' do 36 | params = ['--http-proxy-id=1'] 37 | api_expects_no_call 38 | result = run_cmd(@cmd + params) 39 | assert(result.err[/--ids is required/], 40 | "ids requirements must be validated") 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /test/functional/activation_key/create_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/activation_key' 3 | 4 | module HammerCLIKatello 5 | describe ActivationKeyCommand do 6 | describe CreateCommand do 7 | it 'allows activation key creation' do 8 | ex = api_expects(:organizations, :index) do |p| 9 | p[:search] == "name = \"org1\"" 10 | end 11 | ex.at_least_once.returns(index_response([{'id' => 1}])) 12 | 13 | ex = api_expects(:lifecycle_environments, :index) do |p| 14 | p['organization_id'] == 1 && p['name'] == 'test' 15 | end 16 | ex.returns(index_response([{'id' => 9}])) 17 | 18 | ex = api_expects(:content_views, :index) do |p| 19 | p['name'] == 'cv' && p['organization_id'] == 1 20 | end 21 | ex.returns(index_response([{'id' => 3}])) 22 | 23 | api_expects(:activation_keys, :create) do |p| 24 | p['name'] == 'ak' && p['environment_id'] == 9 && p['organization_id'] == 1 && 25 | p['content_view_id'] == 3 26 | end 27 | 28 | run_cmd(%w(activation-key create --organization org1 --name ak --content-view cv 29 | --lifecycle-environment test --unlimited-hosts)) 30 | end 31 | end 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/organization_options.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module OrganizationOptions 3 | def self.included(base) 4 | base.option_family do 5 | parent '--organization-id', 'ORGANIZATION_ID', 6 | _('Organization ID to search by'), attribute_name: :option_organization_id 7 | child '--organization', 'ORGANIZATION_NAME', 8 | _('Organization name to search by'), attribute_name: :option_organization_name 9 | child '--organization-label', 'ORGANIZATION_LABEL', 10 | _('Organization label to search by'), attribute_name: :option_organization_label 11 | child '--organization-title', 'ORGANIZATION_TITLE', 12 | _('Organization title to search by'), attribute_name: :option_organization_title 13 | end 14 | end 15 | 16 | def org_options 17 | { 18 | HammerCLI.option_accessor_name("organization_id") => options["option_organization_id"], 19 | HammerCLI.option_accessor_name("organization_name") => options["option_organization_name"], 20 | HammerCLI.option_accessor_name("organization_label") => options["option_organization_label"], 21 | HammerCLI.option_accessor_name("organization_title") => options["option_organization_title"] 22 | } 23 | end 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /test/functional/content_view/version/republish_repositories_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require 'hammer_cli_katello/content_view_version' 3 | 4 | module HammerCLIKatello 5 | describe ContentViewVersion::RepublishRepositoriesCommand do 6 | include ForemanTaskHelpers 7 | include OrganizationHelpers 8 | 9 | it 'allows republishing repositories on a content view version' do 10 | expect_organization_search('org1', 1) 11 | 12 | ex = api_expects(:content_views, :index) do |p| 13 | p['name'] == 'cv' && p['organization_id'] == 1 14 | end 15 | ex.returns(index_response([{'id' => 3}])) 16 | 17 | ex = api_expects(:content_view_versions, :index) do |p| 18 | p['version'] == '1' && p['content_view_id'] == 3 19 | end 20 | ex.returns(index_response([{'id' => 6}])) 21 | 22 | ex = api_expects(:content_view_versions, :republish_repositories) do |p| 23 | p['id'] == 6 24 | end 25 | ex.returns('state' => 'pending', 'id' => '3') 26 | 27 | expect_foreman_task('3') 28 | 29 | result = run_cmd(%w(content-view version republish-repositories --organization org1 30 | --content-view cv --version 1 --force true)) 31 | 32 | assert_equal(result.exit_code, 0) 33 | end 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /test/functional/package_group/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/package_group' 3 | 4 | module HammerCLIKatello 5 | describe PackageGroupCommand::ListCommand do 6 | it 'allows minimal options' do 7 | api_expects(:package_groups, :index) 8 | 9 | run_cmd(%w(package-group list)) 10 | end 11 | 12 | it 'can be provided by repository ID' do 13 | api_expects(:package_groups, :index) do |params| 14 | params['repository_id'] == 1 15 | end 16 | 17 | run_cmd(%w(package-group list --repository-id 1)) 18 | end 19 | 20 | it 'needs product options with repository name' do 21 | cmd = run_cmd(%w(package-group list --repository Repo)) 22 | api_expects_no_call 23 | error_msg = "At least one of options --product, --product-id is required." 24 | assert_match error_msg, cmd.err 25 | end 26 | 27 | it 'can be provided product id and repository name' do 28 | api_expects(:repositories, :index) 29 | .with_params(name: "Repo", product_id: 1) 30 | .returns(index_response([{'id' => 1}])) 31 | 32 | api_expects(:package_groups, :index) 33 | .with_params(repository_id: 1) 34 | 35 | run_cmd(%w(package-group list --repository Repo --product-id 1)) 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /.github/workflows/development-container-release.yml: -------------------------------------------------------------------------------- 1 | name: Container release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | env: 9 | REGISTRY: ghcr.io 10 | IMAGE_NAME: ${{ github.repository }}-devel 11 | 12 | jobs: 13 | build-and-push-image: 14 | runs-on: ubuntu-latest 15 | permissions: 16 | contents: read 17 | packages: write 18 | strategy: 19 | fail-fast: false 20 | steps: 21 | - name: Checkout repository 22 | uses: actions/checkout@v4 23 | - name: Log in to the Container registry 24 | uses: docker/login-action@v3 25 | with: 26 | registry: ${{ env.REGISTRY }} 27 | username: ${{ github.actor }} 28 | password: ${{ secrets.GITHUB_TOKEN }} 29 | - name: Extract metadata (tags, labels) for Docker 30 | id: meta 31 | uses: docker/metadata-action@v5 32 | with: 33 | images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} 34 | tags: | 35 | type=raw,value=latest 36 | - name: Build and push Docker image 37 | uses: docker/build-push-action@v5 38 | with: 39 | context: . 40 | file: Containerfile-devel 41 | push: true 42 | tags: ${{ steps.meta.outputs.tags }} 43 | labels: ${{ steps.meta.outputs.labels }} 44 | -------------------------------------------------------------------------------- /test/functional/sync_plan/info_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/sync_plan' 3 | require_relative 'sync_plan_helpers' 4 | require_relative '../organization/organization_helpers' 5 | module HammerCLIKatello 6 | describe SyncPlan::InfoCommand do 7 | include OrganizationHelpers 8 | include SyncPlanHelpers 9 | 10 | it 'allows ID' do 11 | api_expects(:sync_plans, :show).with_params('id' => 1) 12 | 13 | run_cmd(%w(sync-plan info --id 1)) 14 | end 15 | 16 | it 'allows organization id and sync plan name' do 17 | org_id = 1 18 | name = "SyncPlan1" 19 | id = 100 20 | expect_sync_plan_search(org_id, name, id) 21 | api_expects(:sync_plans, :show).with_params('id' => id) 22 | run_cmd("sync-plan info --organization-id #{org_id} --name #{name}".split) 23 | end 24 | 25 | it 'allows organization name and sync plan name' do 26 | org_id = 1 27 | org_label = "org" 28 | name = "SyncPlan1" 29 | id = 100 30 | 31 | expect_organization_search(org_label, org_id, field: 'label') 32 | expect_sync_plan_search(org_id, name, id) 33 | api_expects(:sync_plans, :show).with_params('id' => id) 34 | run_cmd("sync-plan info --organization-label #{org_label} --name #{name}".split) 35 | end 36 | end 37 | end 38 | -------------------------------------------------------------------------------- /test/functional/host/extensions/list_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | 3 | describe 'host list' do 4 | before do 5 | @cmd = %w(host list) 6 | end 7 | 8 | it "list hosts" do 9 | ex = api_expects(:hosts, :index, 'Host index') 10 | 11 | json_file = File.join(File.dirname(__FILE__), 'data', 'host_list.json') 12 | ex.returns(JSON.parse(File.read(json_file))) 13 | 14 | result = run_cmd(@cmd) 15 | 16 | fields = ['CONTENT VIEW ENVIRONMENTS', 'MULTI CONTENT VIEW ENVIRONMENT', 'TRACE STATUS'] 17 | values = ['Library', 'no', 'updated'] 18 | expected_result = success_result(IndexMatcher.new([fields, values])) 19 | assert_cmd(expected_result, result) 20 | end 21 | 22 | it "list hosts bootc" do 23 | ex = api_expects(:hosts, :index, 'Host index') 24 | 25 | json_file = File.join(File.dirname(__FILE__), 'data', 'host_list.json') 26 | ex.returns(JSON.parse(File.read(json_file))) 27 | 28 | result = run_cmd(['host', 'list', "--fields=\"Running image\",\"Running image digest\""]) 29 | 30 | fields = ['RUNNING IMAGE', 'RUNNING IMAGE DIGEST'] 31 | values = ['sha256:a68293b8402890ba802f11fc2fab26e23c665be9e645836c3f32cbfe9e07f9ae'] 32 | expected_result = success_result(IndexMatcher.new([fields, values])) 33 | assert_cmd(expected_result, result) 34 | end 35 | end 36 | -------------------------------------------------------------------------------- /test/functional/product/delete_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../organization/organization_helpers') 3 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 4 | 5 | describe 'delete a product' do 6 | include OrganizationHelpers 7 | include ProductHelpers 8 | 9 | it 'by ID' do 10 | api_expects(:products, :destroy, 'delete a product') do |par| 11 | par['id'] == 1 12 | end 13 | assert_equal( 14 | 0, 15 | run_cmd(%w(product delete --id 1)).exit_code 16 | ) 17 | end 18 | 19 | it 'by organization ID and product name' do 20 | expect_product_search(1, 'product1', 1) 21 | api_expects(:products, :destroy, 'delete a product') do |par| 22 | par['id'] == 1 23 | end 24 | assert_equal( 25 | 0, 26 | run_cmd(%w(product delete --organization-id 1 --name product1)).exit_code 27 | ) 28 | end 29 | 30 | it 'by organization name and product name' do 31 | expect_organization_search('org1', 1) 32 | expect_product_search(1, 'product1', 1) 33 | api_expects(:products, :destroy, 'delete a product') do |par| 34 | par['id'] == 1 35 | end 36 | assert_equal( 37 | 0, 38 | run_cmd(%w(product delete --organization org1 --name product1)).exit_code 39 | ) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /test/functional/content_export/content_export_helpers.rb: -------------------------------------------------------------------------------- 1 | require_relative '../search_helpers' 2 | 3 | module ContentExportHelpers 4 | include SearchHelpers 5 | def expects_repository(repository_id, returns = {}) 6 | ex = api_expects(:repositories, :show, "Find Repo #{repository_id}") do |p| 7 | assert_equal p[:id].to_s, repository_id.to_s 8 | end 9 | ex.returns(returns) 10 | end 11 | 12 | def expects_repositories_in_library(organization_id, returns = []) 13 | expect_lenient_search(:repositories, 14 | params: { 15 | organization_id: organization_id, 16 | library: true, 17 | search: "download_policy != immediate", 18 | content_type: 'yum' 19 | }, 20 | returns: returns) 21 | end 22 | 23 | def expects_repositories_in_version(version_id, returns = []) 24 | expect_lenient_search(:repositories, 25 | params: { 26 | content_view_version_id: version_id, 27 | library: true, 28 | search: "download_policy != immediate", 29 | content_type: 'yum' 30 | }, 31 | returns: returns) 32 | end 33 | end 34 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/command_extensions/content_source.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module CommandExtensions 3 | class ContentSource < HammerCLI::CommandExtensions 4 | option_family associate: 'content_source' do 5 | child '--content-source', 'CONTENT_SOURCE_NAME', _('Content Source name'), 6 | attribute_name: :option_content_source, 7 | referenced_resource: :smart_proxy 8 | end 9 | 10 | request_params do |params, cmd_obj| 11 | begin 12 | resource_name = cmd_obj.resource.singular_name 13 | if cmd_obj.option_content_source && !cmd_obj.option_content_source_id 14 | resource_hash = if resource_name == 'hostgroup' 15 | params[resource_name] 16 | else 17 | params[resource_name]['content_facet_attributes'] 18 | end 19 | 20 | proxy_options = { 21 | HammerCLI.option_accessor_name('name') => cmd_obj.option_content_source 22 | } 23 | resource_hash['content_source_id'] = cmd_obj.resolver.smart_proxy_id(proxy_options) 24 | end 25 | rescue HammerCLIForeman::ResolverError => e 26 | e.message.gsub!('smart_proxy', _('Content Source')) 27 | raise e 28 | end 29 | end 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /test/functional/capsule/content/cancel_synchronization_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require File.join(File.dirname(__FILE__), './capsule_content_helpers') 3 | 4 | describe 'capsule content cancel-synchronization' do 5 | include CapsuleContentHelpers 6 | 7 | before do 8 | @cmd = ['capsule', 'content', 'cancel-synchronization'] 9 | end 10 | 11 | MESSAGE = "There's no running synchronization for this capsule.".freeze 12 | 13 | it "triggers the cancel" do 14 | expected_result = success_result("#{MESSAGE}\n") 15 | params = ['--id=3'] 16 | 17 | ex = api_expects(:capsule_content, :cancel_sync, 'Cancel sync') do |par| 18 | par['id'] == 3 19 | end 20 | ex.returns("message" => MESSAGE) 21 | 22 | result = run_cmd(@cmd + params) 23 | assert_cmd(expected_result, result) 24 | end 25 | 26 | it "resolves id from name" do 27 | params = ['--name=capsule1'] 28 | 29 | ex = api_expects(:capsule_content, :cancel_sync, 'Cancel sync') do |par| 30 | par['id'] == 3 31 | end 32 | ex.returns("message" => MESSAGE) 33 | expect_capsule_search('capsule1', 3) 34 | 35 | run_cmd(@cmd + params) 36 | end 37 | 38 | it "is mounted under proxy too" do 39 | result = run_cmd(['proxy', 'content', 'cancel-synchronization', '-h']) 40 | assert_exit_code_equal(HammerCLI::EX_OK, result.exit_code) 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /test/functional/lifecycle_environment/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/lifecycle_environment' 3 | 4 | module HammerCLIKatello 5 | describe LifecycleEnvironmentCommand::ListCommand do 6 | it 'allows minimal options' do 7 | api_expects(:lifecycle_environments, :index) 8 | 9 | run_cmd(%w(lifecycle-environment list)) 10 | end 11 | 12 | describe 'allows organization' do 13 | it 'id' do 14 | api_expects(:lifecycle_environments, :index) { |p| p['organization_id'] == 1 } 15 | 16 | run_cmd(%w(lifecycle-environment list --organization-id 1)) 17 | end 18 | 19 | it 'name' do 20 | api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" } 21 | .at_least_once.returns(index_response([{'id' => 1}])) 22 | 23 | api_expects(:lifecycle_environments, :index) { |p| p['organization_id'] == 1 } 24 | 25 | run_cmd(%w(lifecycle-environment list --organization org1)) 26 | end 27 | 28 | it 'label' do 29 | api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" } 30 | .at_least_once.returns(index_response([{'id' => 1}])) 31 | 32 | api_expects(:lifecycle_environments, :index) { |p| p['organization_id'] == 1 } 33 | 34 | run_cmd(%w(lifecycle-environment list --organization-label org1)) 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /test/functional/hostgroup/data/hostgroup.json: -------------------------------------------------------------------------------- 1 | { 2 | "content_source_id":1, 3 | "content_source_name":"foreman.example.com", 4 | "content_view_id":1, 5 | "content_view_name":"Default Organization View", 6 | "lifecycle_environment_id":1, 7 | "lifecycle_environment_name":"Library", 8 | "kickstart_repository_id":10000, 9 | "kickstart_repository_name":"Rhel 7", 10 | "subnet_id":null, 11 | "subnet_name":null, 12 | "operatingsystem_id":null, 13 | "operatingsystem_name":null, 14 | "domain_id":null, 15 | "domain_name":null, 16 | "environment_id":1, 17 | "environment_name":"Production Env", 18 | "compute_profile_id":null, 19 | "compute_profile_name":null, 20 | "ancestry":null, 21 | "parent_id":null, 22 | "parent_name":null, 23 | "puppet_proxy_id":null, 24 | "puppet_ca_proxy_id":null, 25 | "ptable_id":null, 26 | "ptable_name":null, 27 | "medium_id":null, 28 | "medium_name":null, 29 | "architecture_id":null, 30 | "architecture_name":null, 31 | "realm_id":null, 32 | "realm_name":null, 33 | "created_at":"2016-08-09 04:18:32 UTC", 34 | "updated_at":"2016-08-09 04:18:32 UTC", 35 | "id":1, 36 | "parameters":[], 37 | "template_combinations":[], 38 | "puppetclasses":[], 39 | "config_groups":[], 40 | "all_puppetclasses":[], 41 | "locations":[], 42 | "organizations":[ 43 | { 44 | "id":1, 45 | "name":"Redhat", 46 | "title":"Redhat", 47 | "description":null 48 | } 49 | ] 50 | } 51 | -------------------------------------------------------------------------------- /test/functional/content_view/version/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require 'hammer_cli_katello/content_view_version' 3 | 4 | module HammerCLIKatello 5 | describe ContentViewVersion::ListCommand do 6 | it 'allows minimal options' do 7 | api_expects(:content_view_versions, :index) 8 | 9 | run_cmd(%w(content-view version list)) 10 | end 11 | 12 | describe 'allows organization' do 13 | it 'id' do 14 | api_expects(:content_view_versions, :index) do |p| 15 | p['organization_id'] == 1 16 | end 17 | 18 | run_cmd(%w(content-view version list --organization-id 1)) 19 | end 20 | 21 | it 'name' do 22 | api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" } 23 | .at_least_once.returns(index_response([{'id' => 1}])) 24 | 25 | api_expects(:content_view_versions, :index) do |p| 26 | p['organization_id'] == 1 27 | end 28 | 29 | run_cmd(%w(content-view version list --organization org1)) 30 | end 31 | 32 | it 'label' do 33 | api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" } 34 | .at_least_once.returns(index_response([{'id' => 1}])) 35 | 36 | api_expects(:content_view_versions, :index) do |p| 37 | p['organization_id'] == 1 38 | end 39 | 40 | run_cmd(%w(content-view version list --organization-label org1)) 41 | end 42 | end 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /test/functional/host_collection/hosts_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/host_collection' 3 | 4 | module HammerCLIKatello 5 | describe HostCollection::HostsCommand do 6 | it 'allows host collection id' do 7 | api_expects(:hosts, :index) do |par| 8 | par['search'] == "host_collection_id=1" 9 | end 10 | 11 | run_cmd(%w(host-collection hosts --id 1)) 12 | end 13 | 14 | it 'allows host collection name' do 15 | ex = api_expects(:host_collections, :index) 16 | ex.returns(index_response([{'id' => 2}])) 17 | 18 | api_expects(:hosts, :index) do |par| 19 | par['search'] == "host_collection_id=2" 20 | end 21 | 22 | run_cmd(%w(host-collection hosts --name collection --organization-id 1)) 23 | end 24 | 25 | it 'requires organization with host collection name' do 26 | result = run_cmd(%w(host-collection hosts --name collection)) 27 | expected_error = "Missing options to search organization" 28 | assert_equal(HammerCLI::EX_SOFTWARE, result.exit_code) 29 | assert_equal(expected_error, result.err[/#{expected_error}/]) 30 | end 31 | 32 | it 'requires host collection name or id' do 33 | result = run_cmd(%w(host-collection hosts)) 34 | expected_error = "Error: At least one of options --id, --name is required" 35 | assert_equal(HammerCLI::EX_USAGE, result.exit_code) 36 | assert_equal(expected_error, result.err[/#{expected_error}/]) 37 | end 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /boilerplate/command_template.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class Taco < HammerCLI::Apipie::Command 3 | resource KatelloApi::Resources::Taco 4 | 5 | class ListCommand < HammerCLIKatello::ListCommand 6 | output do 7 | field :id, _("Taco ID") 8 | field :name, _("Name") 9 | end 10 | 11 | build_options 12 | end 13 | 14 | class CreateCommand < HammerCLIKatello::CreateCommand 15 | success_message _("Taco created") 16 | failure_message _("Could not create the taco") 17 | 18 | build_options 19 | end 20 | 21 | class InfoCommand < HammerCLIKatello::InfoCommand 22 | output do 23 | field :id, _("Taco ID") 24 | field :name, _("Name") 25 | field :crunchiness, _("Crunchiness") 26 | field :meat, _("Meat") 27 | end 28 | 29 | build_options 30 | end 31 | 32 | class UpdateCommand < HammerCLIKatello::UpdateCommand 33 | success_message _("Taco updated") 34 | failure_message _("Could not update the taco") 35 | 36 | build_options :without => [:doritos_locos] 37 | option "--meat", "MEAT", _("meat type"), :attribute_name => :option_meat 38 | end 39 | 40 | class DeleteCommand < HammerCLIKatello::DeleteCommand 41 | success_message _("Taco deleted") 42 | failure_message _("Could not delete the taco") 43 | 44 | build_options 45 | end 46 | 47 | autoload_subcommands 48 | end 49 | end 50 | 51 | HammerCLI::MainCommand.subcommand "taco", _("Manipulate tacos"), HammerCLIKatello::Taco 52 | -------------------------------------------------------------------------------- /test/functional/host/subscription/enabled_repositories_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | 3 | describe 'host enabled-repositories listing' do 4 | before do 5 | @cmd = %w(host subscription enabled-repositories) 6 | end 7 | 8 | let(:host_id) { 1 } 9 | let(:empty_response) do 10 | { 11 | "total" => 0, 12 | "subtotal" => 0, 13 | "page" => "1", 14 | "per_page" => "1000", 15 | "error" => nil, 16 | "search" => nil, 17 | "sort" => { 18 | "by" => nil, 19 | "order" => nil 20 | }, 21 | "results" => [] 22 | } 23 | end 24 | 25 | it 'allows listing by host' do 26 | params = ["--host-id=#{host_id}"] 27 | ex = api_expects(:host_subscriptions, 28 | :enabled_repositories, 'host subscription enabled-repositories') 29 | ex.returns(empty_response) 30 | # rubocop:disable Layout/LineLength 31 | expected_result = success_result("---|------|-------|--------------|----------|-----------------|-------------------|----------------------|------------------|------------- 32 | ID | NAME | LABEL | CONTENT TYPE | CHECKSUM | CONTENT VIEW ID | CONTENT VIEW NAME | CONTENT VIEW VERSION | ENVIRONMENT NAME | PRODUCT NAME 33 | ---|------|-------|--------------|----------|-----------------|-------------------|----------------------|------------------|------------- 34 | ") 35 | # rubocop:enable Layout/LineLength 36 | result = run_cmd(@cmd + params) 37 | assert_cmd(expected_result, result) 38 | end 39 | end 40 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | # TODO: remove this 2 | inherit_from: .rubocop_todo.yml 3 | 4 | inherit_gem: 5 | theforeman-rubocop: 6 | - lenient.yml 7 | 8 | AllCops: 9 | TargetRubyVersion: 2.7 10 | 11 | MethodLength: 12 | Description: 'Avoid methods longer than 30 lines of code.' 13 | Max: 30 # default is 10 14 | 15 | HashSyntax: 16 | Enabled: false 17 | 18 | SpaceInsideHashLiteralBraces: 19 | Enabled: false 20 | 21 | Encoding: 22 | Enabled: false 23 | 24 | LineLength: 25 | Max: 150 26 | 27 | FormatString: 28 | Enabled: false # we use % for i18n 29 | 30 | IfUnlessModifier: 31 | Enabled: false 32 | 33 | Next: 34 | Enabled: false # don't force next over conditions 35 | 36 | MethodCalledOnDoEndBlock: 37 | Enabled: true 38 | 39 | LeadingCommentSpace: 40 | Enabled: false 41 | 42 | RescueModifier: 43 | Enabled: false 44 | 45 | AssignmentInCondition: 46 | Enabled: false 47 | 48 | ParameterAlignment: 49 | Enabled: false # don't care if parameters are not aligned 50 | 51 | WhileUntilModifier: 52 | Enabled: false 53 | 54 | ParenthesesAroundCondition: 55 | Enabled: false 56 | 57 | DotPosition: 58 | Enabled: false 59 | 60 | Lambda: 61 | Enabled: false # don't require -> for single line lambdas 62 | 63 | RedundantSelf: 64 | Enabled: false 65 | 66 | RedundantReturn: 67 | Enabled: false 68 | 69 | SingleLineBlockParams: 70 | Enabled: false 71 | 72 | Style/MultilineMethodCallBraceLayout: 73 | Enabled: false 74 | 75 | Style/MultilineHashBraceLayout: 76 | Enabled: false 77 | 78 | Style/MultilineArrayBraceLayout: 79 | Enabled: false 80 | -------------------------------------------------------------------------------- /test/functional/flatpak_remote/info_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'get flatpak remote info' do 4 | before do 5 | @cmd = %w(flatpak-remote info) 6 | end 7 | 8 | it 'shows flatpak remote info by id' do 9 | params = ['--id=12'] 10 | ex = api_expects(:flatpak_remotes, :show, 'Get info') 11 | ex.returns( 12 | 'id' => 12, 13 | 'name' => 'Fedora flatpak', 14 | 'url' => 'https://registry.fedoraproject.org/', 15 | 'username' => nil, 16 | 'token' => nil, 17 | 'seeded' => true, 18 | 'organization_id' => 1, 19 | 'registry_url' => 'https://registry.fedoraproject.org/', 20 | 'organization' => { 21 | 'id' => 1, 22 | 'name' => 'Default Organization', 23 | 'label' => 'Default_Organization' 24 | } 25 | ) 26 | result = run_cmd(@cmd + params) 27 | expected_fields = [['ID', '12'], 28 | ['Name', 'Fedora flatpak'], 29 | ['URL', 'https://registry.fedoraproject.org/'], 30 | ['Registry URL', 'https://registry.fedoraproject.org/'], 31 | ['Organization', ''], 32 | ['Id', '1'], 33 | ['Name', 'Default Organization'], 34 | ['Label', 'Default_Organization'], 35 | ] 36 | 37 | expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) } 38 | expected_results.each { |expected| assert_cmd(expected, result) } 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/exception_handler.rb: -------------------------------------------------------------------------------- 1 | 2 | module HammerCLIKatello 3 | class ExceptionHandler < HammerCLIForeman::ExceptionHandler 4 | def mappings 5 | super + [ 6 | [RestClient::InternalServerError, :handle_internal_error], 7 | [RestClient::BadRequest, :handle_bad_request] 8 | ] 9 | end 10 | 11 | protected 12 | 13 | def handle_internal_error(e) 14 | handle_katello_error(e) 15 | HammerCLI::EX_SOFTWARE 16 | end 17 | 18 | def handle_unprocessable_entity(e) 19 | handle_katello_error(e) 20 | HammerCLI::EX_DATAERR 21 | end 22 | 23 | def handle_not_found(e) 24 | handle_katello_error(e) 25 | HammerCLI::EX_NOT_FOUND 26 | end 27 | 28 | def handle_bad_request(e) 29 | handle_katello_error(e) 30 | HammerCLI::EX_NOT_FOUND 31 | end 32 | 33 | def handle_katello_error(e) 34 | begin 35 | response = JSON.parse(e.response) 36 | response = HammerCLIForeman.record_to_common_format(response) 37 | # Check multiple possible keys that can contain error message: 38 | # - displayMessage for katello specific messages 39 | # - full_messages for for messages that come from rails 40 | # - message for foreman specific messages 41 | msg = response["displayMessage"] || response["full_messages"] || response["message"] 42 | rescue JSON::ParserError 43 | msg = e.message 44 | ensure 45 | msg ||= e.message 46 | end 47 | print_error(msg) 48 | log_full_error(e) 49 | end 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/acs_bulk_actions.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class AcsBulkActionsCommand < HammerCLIKatello::Command 3 | desc 'Modify alternate content sources in bulk' 4 | resource :alternate_content_sources_bulk_actions 5 | 6 | class RefreshAllCommand < HammerCLIKatello::SingleResourceCommand 7 | action :refresh_all_alternate_content_sources 8 | command_name 'refresh-all' 9 | desc _("Refresh all alternate content sources") 10 | success_message _("Successfully refreshed all alternate content sources") 11 | failure_message _("Could not refresh all alternate content sources") 12 | 13 | build_options 14 | end 15 | 16 | class RefreshCommand < HammerCLIKatello::SingleResourceCommand 17 | action :refresh_alternate_content_sources 18 | command_name 'refresh' 19 | desc _("Refresh alternate content sources") 20 | success_message _("Successfully refreshed specified alternate content sources") 21 | failure_message _("Could not refresh the specified alternate content sources") 22 | 23 | build_options 24 | end 25 | 26 | class DestroyCommand < HammerCLIKatello::SingleResourceCommand 27 | action :destroy_alternate_content_sources 28 | command_name 'destroy' 29 | desc _("Destroy alternate content sources") 30 | success_message _("Sucessfully destroyed specified alternate content sources") 31 | failure_message _("Could not destroy the specified alternate content sources") 32 | 33 | build_options 34 | end 35 | 36 | autoload_subcommands 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_errata.rb: -------------------------------------------------------------------------------- 1 | require 'hammer_cli_katello/erratum_info_command' 2 | 3 | module HammerCLIKatello 4 | class HostErrata < HammerCLIKatello::Command 5 | desc "Manage errata on your hosts" 6 | 7 | class ApplyCommand < HammerCLIKatello::SingleResourceCommand 8 | command_name "apply" 9 | 10 | def self.rex_feature 11 | "katello_errata_install" 12 | end 13 | 14 | include UnsupportedKatelloAgentCommandHelper 15 | end 16 | 17 | class ListCommand < HammerCLIKatello::ListCommand 18 | include OrganizationOptions 19 | include LifecycleEnvironmentNameMapping 20 | resource :host_errata, :index 21 | command_name "list" 22 | 23 | output do 24 | field :id, _("Id") 25 | field :errata_id, _("Erratum ID") 26 | field :type, _("Type") 27 | field :title, _("Title") 28 | field :installable, _("Installable") 29 | end 30 | 31 | build_options 32 | extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new) 33 | end 34 | 35 | class InfoCommand < HammerCLIKatello::ErratumInfoCommand 36 | resource :host_errata, :show 37 | build_options 38 | end 39 | 40 | class RecalculateCommand < HammerCLIKatello::SingleResourceCommand 41 | resource :host_errata, :applicability 42 | command_name "recalculate" 43 | success_message _("Errata recalculation started.") 44 | failure_message _("Could not recalculate errata") 45 | 46 | build_options 47 | end 48 | 49 | autoload_subcommands 50 | end 51 | end 52 | -------------------------------------------------------------------------------- /test/functional/host/extensions/info_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | 3 | describe 'host info' do 4 | before do 5 | @cmd = %w(host info) 6 | end 7 | 8 | it "includes katello attributes" do 9 | params = ['--id', '1'] 10 | ex = api_expects(:hosts, :show, 'Host show') do |par| 11 | par['id'] == '1' 12 | end 13 | 14 | json_file = File.join(File.dirname(__FILE__), 'data', 'host.json') 15 | ex.returns(JSON.parse(File.read(json_file))) 16 | 17 | result = run_cmd(@cmd + params) 18 | # rubocop:disable Style/WordArray 19 | expected_fields = [['Name', 'robot.example.com'], 20 | ['Release Version', '7Server'], 21 | ['Name', 'Rhel 7'], 22 | ['Name', 'capsule'], 23 | ['Bug Fix', '0'], 24 | ['Name', 'my host collection'], 25 | ['Applicable Packages', '5'], 26 | ['Upgradable Packages', '4'], 27 | ['Purpose Usage', 'Production'], 28 | ['Purpose Role', 'Role'], 29 | ['Trace Status', 'Updated'], 30 | ['Running image', 'potato'], 31 | ['Running image digest', 32 | 'sha256:a68293b8402890ba802f11fc2fab26e23c665be9e645836c3f32cbfe9e07f9ae']] 33 | expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) } 34 | expected_results.each { |expected| assert_cmd(expected, result) } 35 | end 36 | end 37 | -------------------------------------------------------------------------------- /test/functional/acs/list_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | 3 | describe 'listing acs' do 4 | before do 5 | @cmd = %w(alternate-content-source list) 6 | end 7 | 8 | let(:empty_response) do 9 | { 10 | "total" => 0, 11 | "subtotal" => 0, 12 | "page" => "1", 13 | "per_page" => "1000", 14 | "error" => nil, 15 | "search" => nil, 16 | "sort" => { 17 | "by" => nil, 18 | "order" => nil 19 | }, 20 | "results" => [] 21 | } 22 | end 23 | 24 | let(:acs_response) do 25 | { 26 | 'id' => 1, 27 | 'name' => 'pizza', 28 | 'alternate_content_source_type' => 'custom' 29 | } 30 | end 31 | 32 | it "lists acs and returns empty response" do 33 | ex = api_expects(:alternate_content_sources, :index, 'acs list') do |par| 34 | par['page'] == 1 && par['per_page'] == 1000 35 | end 36 | 37 | ex.returns(empty_response) 38 | 39 | expected_result = success_result("---|------|----- 40 | ID | NAME | TYPE 41 | ---|------|----- 42 | ") 43 | 44 | result = run_cmd(@cmd) 45 | assert_cmd(expected_result, result) 46 | end 47 | 48 | it "lists acs and returns response" do 49 | ex = api_expects(:alternate_content_sources, :index, 'acs list') do |par| 50 | par['page'] == 1 && par['per_page'] == 1000 51 | end 52 | 53 | ex.returns(acs_response) 54 | 55 | expected_result = success_result("1 | pizza | custom 56 | ---|-------|------- 57 | ") 58 | 59 | result = run_cmd(@cmd) 60 | assert_cmd(expected_result, result) 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /test/functional/content_credentials/info_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 3 | 4 | def expect_credentials_search(org_id, name, id) 5 | api_expects(:content_credentials, :index, 'List content credentials') 6 | .with_params('name' => name, 'organization_id' => org_id) 7 | .returns(index_response([{'id' => id}])) 8 | end 9 | 10 | describe "get content-credentials info" do 11 | include ProductHelpers 12 | 13 | before do 14 | @cmd = %w(content-credentials info) 15 | end 16 | 17 | let(:org_id) { 1 } 18 | let(:product_id) { 2 } 19 | let(:key_id) { 3 } 20 | 21 | it "Shows information about a content credental" do 22 | params = ["--organization-id=#{org_id}", "--name=test_key"] 23 | 24 | expect_credentials_search(org_id, 'test_key', key_id) 25 | 26 | ex = api_expects(:content_credentials, :show, "Get info") do |par| 27 | par["id"] == key_id 28 | end 29 | 30 | ex.returns({}) 31 | 32 | result = run_cmd(@cmd + params) 33 | assert_equal(result.exit_code, 0) 34 | end 35 | 36 | it "Shows information about a key with organization-id and key name" do 37 | params = ["--name=test_key", "--organization-id=#{org_id}"] 38 | 39 | expect_credentials_search(org_id, "test_key", key_id) 40 | 41 | ex2 = api_expects(:content_credentials, :show, "Get info") do |par| 42 | par["id"] == key_id 43 | end 44 | 45 | ex2.returns({}) 46 | 47 | result = run_cmd(@cmd + params) 48 | assert_equal(result.exit_code, 0) 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /test/functional/organization/cdn_configuration_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative './organization_helpers' 3 | require 'hammer_cli_katello/organization' 4 | require 'hammer_cli_katello/associating_commands' 5 | 6 | describe HammerCLIKatello::Organization::ConfigureCdnCommand do 7 | include OrganizationHelpers 8 | before do 9 | @cmd = %w(organization configure-cdn) 10 | end 11 | 12 | it 'by updates with the right params' do 13 | org_id = '100' 14 | org_label = 'org1' 15 | ssl_cred_id = '1' 16 | password = "pass" 17 | username = "foo" 18 | url = "https://goo.com" 19 | upstream_label = "GreatOrg" 20 | type = 'network_sync' 21 | params = ["--label=#{org_label}", 22 | "--url=#{url}", 23 | "--username=#{username}", 24 | "--upstream-organization-label=#{upstream_label}", 25 | "--password=#{password}", 26 | "--ssl-ca-credential-id=#{ssl_cred_id}", 27 | "--type=#{type}" 28 | ] 29 | expect_organization_search(org_label, org_id, field: 'label') 30 | 31 | api_expects(:organizations, :cdn_configuration) do |par| 32 | par['id'].to_s == org_id && 33 | par['username'] == username && 34 | par['url'] == url && 35 | par['password'] == password && 36 | par['ssl_ca_credential_id'].to_s == ssl_cred_id && 37 | par['upstream_organization_label'] == upstream_label && 38 | par['type'] == type 39 | end 40 | 41 | assert_equal( 42 | 0, 43 | run_cmd(@cmd + params).exit_code 44 | ) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /test/functional/host/errata/list_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require_relative '../../lifecycle_environment/lifecycle_environment_helpers' 3 | 4 | describe 'host errata listing' do 5 | include LifecycleEnvironmentHelpers 6 | 7 | before do 8 | @cmd = %w(host errata list) 9 | end 10 | 11 | let(:org_id) { 1 } 12 | let(:host_id) { 2 } 13 | let(:lifecycle_env_id) { 3 } 14 | let(:empty_response) do 15 | { 16 | "total" => 0, 17 | "subtotal" => 0, 18 | "page" => "1", 19 | "per_page" => "1000", 20 | "error" => nil, 21 | "search" => nil, 22 | "sort" => { 23 | "by" => nil, 24 | "order" => nil 25 | }, 26 | "results" => [] 27 | } 28 | end 29 | 30 | it "lists the host errata belonging to a lifecycle-environment by name" do 31 | params = ["--host-id=#{host_id}", "--organization-id=#{org_id}", '--lifecycle-environment=test'] 32 | 33 | expect_lifecycle_environment_search(org_id.to_s, 'test', lifecycle_env_id) 34 | 35 | ex = api_expects(:host_errata, :index, 'host errata list'). 36 | with_params('host_id': host_id, 37 | 'environment_id': lifecycle_env_id, 38 | 'page': 1, 39 | 'per_page': 1000) 40 | 41 | ex.returns(empty_response) 42 | expected_result = success_result("---|------------|------|-------|------------ 43 | ID | ERRATUM ID | TYPE | TITLE | INSTALLABLE 44 | ---|------------|------|-------|------------ 45 | ") 46 | result = run_cmd(@cmd + params) 47 | assert_cmd(expected_result, result) 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/functional/repository_set/enable_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative './repository_set_helpers' 3 | require 'hammer_cli_katello/repository_set' 4 | 5 | module HammerCLIKatello 6 | describe RepositorySetCommand::EnableCommand do 7 | include RepositorySetHelpers 8 | 9 | it 'allows minimal options' do 10 | api_expects(:repository_sets, :enable) 11 | .with_params('id' => 1) 12 | assert_success run_cmd(%w(repository-set enable --id 1)) 13 | end 14 | 15 | it 'requires repository set options' do 16 | api_expects_no_call 17 | assert_failure run_cmd(%w(repository-set enable)), /id.*name.*required/ 18 | end 19 | 20 | describe 'resolves repository set ID' do 21 | it 'by requiring organization or product options' do 22 | api_expects_no_call 23 | assert_failure run_cmd(%w(repository-set enable --name reposet1)), 24 | /organization.*product.*required/ 25 | end 26 | 27 | it 'from organization options' do 28 | expect_repository_set_search('reposet1', 1, organization_id: 2) 29 | api_expects(:repository_sets, :enable) 30 | .with_params('id' => 1) 31 | assert_success run_cmd(%w(repository-set enable --name reposet1 --organization-id 2)) 32 | end 33 | 34 | it 'from product options' do 35 | expect_repository_set_search('reposet1', 1, product_id: 3) 36 | api_expects(:repository_sets, :enable) 37 | .with_params('id' => 1) 38 | assert_success run_cmd(%w(repository-set enable --name reposet1 --product-id 3)) 39 | end 40 | end 41 | end 42 | end 43 | -------------------------------------------------------------------------------- /test/functional/activation_key/data/activation_key.json: -------------------------------------------------------------------------------- 1 | { 2 | "service_level": null, 3 | "id": "1", 4 | "organization_id": "1", 5 | "name": "test key2", 6 | "description": "Activation key", 7 | "unlimited_hosts": true, 8 | "auto_attach": true, 9 | "release_version": null, 10 | "purpose_usage": "Usage", 11 | "purpose_role": "Role", 12 | "environment": { 13 | "name": "Library", 14 | "id": 1 15 | }, 16 | "multi_content_view_environment": true, 17 | "organization": { 18 | "name": "Default Organization", 19 | "label": "Default_Organization", 20 | "id": 1 21 | }, 22 | "content_view_environments": [ 23 | { 24 | "content_view": { 25 | "id": 2, 26 | "name": "RHEL-8", 27 | "composite": false, 28 | "content_view_version": "1.0", 29 | "content_view_version_id": 4, 30 | "content_view_version_latest": true, 31 | "content_view_default": false 32 | }, 33 | "lifecycle_environment": { 34 | "id": 1, 35 | "name": "Library", 36 | "lifecycle_environment_library": true 37 | }, 38 | "label": "Library/RHEL-8" 39 | }, 40 | { 41 | "content_view": { 42 | "id": 4, 43 | "name": "Zoo", 44 | "composite": false, 45 | "content_view_version": "1.0", 46 | "content_view_version_id": 2, 47 | "content_view_version_latest": true, 48 | "content_view_default": false 49 | }, 50 | "lifecycle_environment": { 51 | "id": 2, 52 | "name": "Dev", 53 | "lifecycle_environment_library": false 54 | }, 55 | "label": "Dev/Zoo" 56 | } 57 | ] 58 | } -------------------------------------------------------------------------------- /test/functional/capsule/content/add_lifecycle_environment_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require_relative 'capsule_content_helpers' 3 | require_relative '../../lifecycle_environment/lifecycle_environment_helpers' 4 | require_relative '../../organization/organization_helpers' 5 | require 'hammer_cli_katello/capsule' 6 | 7 | module HammerCLIKatello 8 | module Capsule 9 | class Content 10 | describe Content::AddLifecycleEnvironmentCommand do 11 | include CapsuleContentHelpers 12 | include LifecycleEnvironmentHelpers 13 | include OrganizationHelpers 14 | 15 | it 'allows minimal options' do 16 | expect_lifecycle_environment_add('id' => 1, 'environment_id' => 2) 17 | 18 | run_cmd(%w(capsule content add-lifecycle-environment --id 1 --environment-id 2)) 19 | end 20 | 21 | it 'resolves environment ID from name' do 22 | expect_lifecycle_environment_search('3', 'env2', 2) 23 | expect_lifecycle_environment_add('id' => 1, 'environment_id' => 2) 24 | 25 | run_cmd(%w(capsule content add-lifecycle-environment --id 1 --environment env2 26 | --organization-id 3)) 27 | end 28 | 29 | it 'resolves organization ID from name' do 30 | expect_organization_search('org3', 3) 31 | expect_lifecycle_environment_search(3, 'env2', 2) 32 | expect_lifecycle_environment_add('id' => 1, 'environment_id' => 2) 33 | 34 | run_cmd(%w(capsule content add-lifecycle-environment --id 1 --environment env2 35 | --organization org3)) 36 | end 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/package_group.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class PackageGroupCommand < HammerCLIKatello::Command 3 | resource :package_groups 4 | 5 | class ListCommand < HammerCLIKatello::ListCommand 6 | extend RepositoryScopedToProduct 7 | 8 | validate_repo_name_requires_product_options(:option_repository_name) 9 | 10 | output do 11 | field :id, _("Id") 12 | field :name, _("Package Group Name") 13 | field :repo_name, _("Repository Name") 14 | field :uuid, _("Uuid") 15 | end 16 | 17 | def extend_data(data) 18 | data["repo_name"] = data["repository"]["name"] 19 | data 20 | end 21 | 22 | build_options do |o| 23 | o.expand.including(:products, :organizations, :content_views) 24 | end 25 | end 26 | 27 | class InfoCommand < HammerCLIKatello::InfoCommand 28 | output do 29 | field :id, _("Id") 30 | field :name, _("Package Group Name") 31 | field :repo_name, _("Repository Name") 32 | field :uuid, _("Uuid") 33 | field :description, _("Description") 34 | field :default_package_names, _("Default Packages"), Fields::List 35 | field :mandatory_package_names, _("Mandatory Packages"), Fields::List 36 | field :conditional_package_names, _("Conditional Packages"), Fields::List 37 | field :optional_package_names, _("Optional Packages"), Fields::List 38 | end 39 | 40 | def extend_data(data) 41 | data["repo_name"] = data["repository"]["name"] 42 | data 43 | end 44 | 45 | build_options 46 | end 47 | 48 | autoload_subcommands 49 | end 50 | end 51 | -------------------------------------------------------------------------------- /test/functional/repository/synchronize_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 3 | require File.join(File.dirname(__FILE__), './repository_helpers') 4 | 5 | describe 'Synchronize a repository' do 6 | include ForemanTaskHelpers 7 | include ProductHelpers 8 | include RepositoryHelpers 9 | 10 | before do 11 | @cmd = %w(repository synchronize) 12 | end 13 | 14 | let(:org_id) { 1 } 15 | let(:repo_id) { 2 } 16 | let(:product_id) { 3 } 17 | let(:sync_response) do 18 | { 19 | 'id' => repo_id.to_s, 20 | 'state' => 'planned' 21 | } 22 | end 23 | 24 | it "synchronizes a repository" do 25 | params = ["--id=#{repo_id}"] 26 | 27 | ex = api_expects(:repositories, :sync, 'Repository is synced') do |par| 28 | par['id'] == repo_id 29 | end 30 | 31 | ex.returns(sync_response) 32 | 33 | expect_foreman_task('3') 34 | 35 | result = run_cmd(@cmd + params) 36 | assert_equal(result.exit_code, 0) 37 | end 38 | 39 | it "synchronizes a repository with a repository name" do 40 | params = ["--name=test_repo", "--product=test_product", "--organization-id=#{org_id}"] 41 | 42 | expect_product_search(org_id, "test_product", product_id) 43 | 44 | expect_repository_search(product_id, "test_repo", repo_id) 45 | 46 | ex = api_expects(:repositories, :sync, 'Repository is synced') do |par| 47 | par['id'] == repo_id 48 | end 49 | 50 | ex.returns(sync_response) 51 | 52 | expect_foreman_task('3') 53 | 54 | result = run_cmd(@cmd + params) 55 | assert_equal(result.exit_code, 0) 56 | end 57 | end 58 | -------------------------------------------------------------------------------- /test/functional/product/update_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../organization/organization_helpers') 3 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 4 | 5 | describe 'update a product' do 6 | include OrganizationHelpers 7 | include ProductHelpers 8 | 9 | it 'by product ID' do 10 | api_expects(:products, :update, 'update a product') do |par| 11 | par['id'] == 1 && 12 | par['description'] == 'new_description' 13 | end 14 | assert_equal( 15 | 0, 16 | run_cmd(%w(product update --organization-id 1 --id 1 --description new_description)).exit_code 17 | ) 18 | end 19 | 20 | it 'by organization ID and product name' do 21 | expect_product_search(1, 'product1', 1) 22 | api_expects(:products, :update, 'update a product') do |par| 23 | par['id'] == 1 && 24 | par['description'] == 'new_description' 25 | end 26 | command = %w(product update --organization-id 1 --name product1 --description new_description) 27 | assert_equal( 28 | 0, 29 | run_cmd(command).exit_code 30 | ) 31 | end 32 | 33 | it 'by organization name and product name' do 34 | expect_organization_search('org1', 1) 35 | expect_product_search(1, 'product1', 1) 36 | api_expects(:products, :update, 'update a product') do |par| 37 | par['id'] == 1 && 38 | par['description'] == 'new_description' 39 | end 40 | command = %w(product update --organization org1 --name product1 --description new_description) 41 | assert_equal( 42 | 0, 43 | run_cmd(command).exit_code 44 | ) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /test/functional/capsule/content/remove_lifecycle_environment_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require_relative 'capsule_content_helpers' 3 | require_relative '../../lifecycle_environment/lifecycle_environment_helpers' 4 | require_relative '../../organization/organization_helpers' 5 | require 'hammer_cli_katello/capsule' 6 | 7 | module HammerCLIKatello 8 | module Capsule 9 | class Content 10 | describe Content::RemoveLifecycleEnvironmentCommand do 11 | include CapsuleContentHelpers 12 | include LifecycleEnvironmentHelpers 13 | include OrganizationHelpers 14 | 15 | it 'allows minimal options' do 16 | expect_lifecycle_environment_remove('id' => 1, 'environment_id' => 2) 17 | 18 | run_cmd(%w(capsule content remove-lifecycle-environment --id 1 --environment-id 2)) 19 | end 20 | 21 | it 'resolves environment ID from name' do 22 | expect_lifecycle_environment_search('3', 'env2', 2) 23 | expect_lifecycle_environment_remove('id' => 1, 'environment_id' => 2) 24 | 25 | run_cmd(%w(capsule content remove-lifecycle-environment --id 1 --environment env2 26 | --organization-id 3)) 27 | end 28 | 29 | it 'resolves organization ID from name' do 30 | expect_organization_search('org3', 3) 31 | expect_lifecycle_environment_search(3, 'env2', 2) 32 | expect_lifecycle_environment_remove('id' => 1, 'environment_id' => 2) 33 | 34 | run_cmd(%w(capsule content remove-lifecycle-environment --id 1 --environment env2 35 | --organization org3)) 36 | end 37 | end 38 | end 39 | end 40 | end 41 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/docker_manifest.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class DockerManifestCommand < HammerCLIForeman::Command 3 | resource :docker_manifests 4 | command_name 'manifest' 5 | desc _('Manage docker manifests') 6 | 7 | class ListCommand < HammerCLIKatello::ListCommand 8 | include HammerCLIKatello::LifecycleEnvironmentNameMapping 9 | 10 | output do 11 | field :id, _("ID") 12 | field :name, _("Name") 13 | field :schema_version, _("Schema Version") 14 | field :digest, _("Digest") 15 | field :downloaded, _("Downloaded"), Fields::Boolean 16 | field :_tags, _("Tags") 17 | end 18 | 19 | def extend_data(manifest) 20 | manifest['_tags'] = manifest['tags'].map { |e| e["name"] }.join(", ") 21 | manifest 22 | end 23 | 24 | build_options do |o| 25 | o.expand.including(:products, :organizations, :content_views) 26 | end 27 | 28 | extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new) 29 | end 30 | 31 | class InfoCommand < HammerCLIKatello::InfoCommand 32 | output do 33 | field :id, _("ID") 34 | field :name, _("Name") 35 | field :schema_version, _("Schema Version") 36 | field :digest, _("Digest") 37 | field :downloaded, _("Downloaded"), Fields::Boolean 38 | collection :tags, _("Tags") do 39 | field :name, _("Name") 40 | end 41 | end 42 | 43 | def extend_data(manifest) 44 | manifest['_tags'] = manifest['tags'].map { |e| { name: e["name"] } }.join(", ") 45 | manifest 46 | end 47 | 48 | build_options 49 | end 50 | 51 | autoload_subcommands 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /test/functional/product/set_sync_plan_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../organization/organization_helpers') 3 | require File.join(File.dirname(__FILE__), '../sync_plan/sync_plan_helpers') 4 | require File.join(File.dirname(__FILE__), '../product/product_helpers') 5 | 6 | describe "set a product's sync plan" do 7 | include OrganizationHelpers 8 | include SyncPlanHelpers 9 | include ProductHelpers 10 | 11 | it "by product ID and sync-plan ID" do 12 | api_expects(:products, :update, "set sync plan") do |params| 13 | params['id'] == 1 && params['sync_plan_id'] == 1 14 | end 15 | 16 | assert_equal( 17 | 0, 18 | run_cmd(%w(product set-sync-plan --id 1 --sync-plan-id 1)).exit_code 19 | ) 20 | end 21 | 22 | it "by product ID and sync-plan name (requires org ID)" do 23 | expect_sync_plan_search(1, 'syncplan1', 1) 24 | api_expects(:products, :update, "set sync plan") do |params| 25 | params['id'] == 1 && params['sync_plan_id'] == 1 26 | end 27 | 28 | assert_equal( 29 | 0, 30 | run_cmd(%w(product set-sync-plan --organization-id 1 --id 1 --sync-plan syncplan1)).exit_code 31 | ) 32 | end 33 | 34 | it "by product name and sync-plan name (both requiring org ID)" do 35 | expect_product_search(1, 'product1', 1) 36 | expect_sync_plan_search(1, 'syncplan1', 1) 37 | api_expects(:products, :update, "set sync plan") do |params| 38 | params['id'] == 1 && params['sync_plan_id'] == 1 39 | end 40 | 41 | assert_equal( 42 | 0, 43 | run_cmd(%w(product set-sync-plan 44 | --organization-id 1 45 | --name product1 46 | --sync-plan syncplan1)).exit_code 47 | ) 48 | end 49 | end 50 | -------------------------------------------------------------------------------- /test/functional/sync_plan/update_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative 'sync_plan_helpers' 3 | require_relative '../organization/organization_helpers' 4 | 5 | describe 'update a sync plan' do 6 | include OrganizationHelpers 7 | include SyncPlanHelpers 8 | 9 | let(:org_id) { 1 } 10 | let(:id) { 1 } 11 | let(:sync_plan_name) { "sync_plan1" } 12 | let(:org_name) { "org1" } 13 | let(:desc) { "New Description" } 14 | 15 | it 'with organization id and sync plan ID' do 16 | api_expects(:sync_plans, :update, 'update a sync plan'). 17 | with_params('description' => desc, 18 | 'id' => id) 19 | command = %W(sync-plan update --organization-id #{org_id} --id #{id} 20 | --description #{desc}) 21 | assert_equal(0, run_cmd(command).exit_code) 22 | end 23 | 24 | it 'with organization ID and sync plan name' do 25 | expect_sync_plan_search(org_id, sync_plan_name, id) 26 | api_expects(:sync_plans, :update, 'update a sync plan'). 27 | with_params('description' => desc, 28 | 'id' => id) 29 | command = %W(sync-plan update --organization-id #{org_id} --name #{sync_plan_name} 30 | --description #{desc}) 31 | assert_equal(0, run_cmd(command).exit_code) 32 | end 33 | 34 | it 'with organization name and sync plan name' do 35 | expect_organization_search(org_name, org_id) 36 | expect_sync_plan_search(org_id, sync_plan_name, id) 37 | api_expects(:sync_plans, :update, 'update a sync plan'). 38 | with_params('description' => desc, 39 | 'id' => id) 40 | command = %W(sync-plan update --organization #{org_name} --name #{sync_plan_name} 41 | --description #{desc}) 42 | assert_equal(0, run_cmd(command).exit_code) 43 | end 44 | end 45 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/command_extensions/lifecycle_environment.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module CommandExtensions 3 | class LifecycleEnvironment < HammerCLI::CommandExtensions 4 | # Remove when support of --environment options is ended. 5 | option_family( 6 | deprecated: { '--environment' => _("Use %s instead") % '--lifecycle-environment', 7 | '--environment-id' => _("Use %s instead") % '--lifecycle-environment-id'} 8 | ) do 9 | child '--environment', 'ENVIRONMENT_NAME', _('Lifecycle environment name to search by'), 10 | attribute_name: :option_environment_name 11 | parent '--environment-id', 'ENVIRONMENT_ID', _(''), 12 | format: HammerCLI::Options::Normalizers::Number.new, 13 | attribute_name: :option_environment_id 14 | end 15 | 16 | # Add explicitly defined options since option builder won't be 17 | # able to create options automatically in case there is missing resource 18 | # in API docs or if the resource name is different 19 | # (e.g. environment instead of lifecycle_environment) 20 | # This can happen if API docs contain a param which cannot be mapped 21 | # via param_name to resource_name mapping 22 | option_family associate: 'lifecycle_environment' do 23 | child '--lifecycle-environment', 'ENVIRONMENT_NAME', 24 | _('Lifecycle environment name to search by'), 25 | attribute_name: :option_environment_name 26 | end 27 | 28 | option_sources do |sources, command| 29 | sources.find_by_name('IdResolution').insert_relative( 30 | :after, 31 | 'IdParams', 32 | HammerCLIKatello::OptionSources::LifecycleEnvironmentParams.new(command) 33 | ) 34 | sources 35 | end 36 | end 37 | end 38 | end 39 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/flatpak_remote_repository.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class FlatpakRemoteRepository < HammerCLIKatello::Command 3 | resource :flatpak_remote_repositories 4 | command_name 'remote-repository' 5 | desc _('View and manage flatpak remote repositories') 6 | 7 | class ListCommand < HammerCLIKatello::ListCommand 8 | output do 9 | field :id, _("Id") 10 | field :name, _("Name") 11 | field :label, _("Label") 12 | end 13 | build_options do |o| 14 | o.expand(:all).including(:flatpak_remotes, :organizations) 15 | end 16 | end 17 | 18 | class InfoCommand < HammerCLIKatello::InfoCommand 19 | output do 20 | field :id, _("Id") 21 | field :name, _("Name") 22 | field :label, _("Label") 23 | from :flatpak_remote do 24 | field :id, _("Flatpak Remote ID") 25 | field :name, _("Flatpak Remote Name") 26 | field :url, _("Flatpak Remote URL") 27 | end 28 | collection :manifests, _("Manifests"), hide_blank: true, hide_empty: true do 29 | field :name, _("Manifest Name") 30 | field :digest, _("Manifest Digest") 31 | field :tags, _("Manifest tags") 32 | end 33 | end 34 | build_options do |o| 35 | o.expand(:all).including(:flatpak_remotes, :organizations) 36 | end 37 | end 38 | 39 | class MirrorCommand < HammerCLIKatello::SingleResourceCommand 40 | include HammerCLIForemanTasks::Async 41 | 42 | action :mirror 43 | command_name 'mirror' 44 | 45 | success_message _("Flatpak remote repository is being mirrored to product in task %s.") 46 | failure_message _('Could not mirror the Flatpak remote repository') 47 | 48 | build_options 49 | end 50 | 51 | autoload_subcommands 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /.packit.yaml: -------------------------------------------------------------------------------- 1 | # See the documentation for more information: 2 | # https://packit.dev/docs/configuration/ 3 | 4 | specfile_path: rubygem-hammer_cli_katello.spec 5 | 6 | # add or remove files that should be synced 7 | files_to_sync: 8 | - rubygem-hammer_cli_katello.spec 9 | - .packit.yaml 10 | 11 | # name in upstream package repository or registry (e.g. in PyPI) 12 | upstream_package_name: hammer_cli_katello 13 | # downstream (Fedora) RPM package name 14 | downstream_package_name: rubygem-hammer_cli_katello 15 | 16 | actions: 17 | post-upstream-clone: 18 | - "wget https://raw.githubusercontent.com/theforeman/foreman-packaging/rpm/develop/packages/katello/rubygem-hammer_cli_katello/rubygem-hammer_cli_katello.spec -O rubygem-hammer_cli_katello.spec" 19 | - "sed -i '/^%global prereleasesource pre.develop$/d' rubygem-hammer_cli_katello.spec" 20 | - "sed -i '/^%global prerelease %{?prereleasesource:.}%{?prereleasesource}$/d' rubygem-hammer_cli_katello.spec" 21 | get-current-version: 22 | - ruby -rrubygems -e 'puts Gem::Specification::load(Dir.glob("*.gemspec").first).version' 23 | create-archive: 24 | - gem build hammer_cli_katello.gemspec 25 | - bash -c "ls -1t ./hammer_cli_katello-*.gem | head -n 1" 26 | 27 | jobs: 28 | - &copr 29 | job: copr_build 30 | trigger: pull_request 31 | targets: 32 | rhel-9: 33 | additional_modules: "foreman-devel:el9" 34 | additional_repos: 35 | - https://yum.theforeman.org/releases/nightly/el9/x86_64/ 36 | - https://yum.theforeman.org/plugins/nightly/el9/x86_64/ 37 | - https://yum.theforeman.org/katello/nightly/katello/el9/x86_64/ 38 | module_hotfixes: true 39 | 40 | - <<: *copr 41 | trigger: commit 42 | branch: main 43 | owner: '@theforeman' 44 | project: develop 45 | 46 | srpm_build_deps: 47 | - wget 48 | - rubygems 49 | -------------------------------------------------------------------------------- /test/functional/sync_plan/delete_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative 'sync_plan_helpers' 3 | require_relative '../organization/organization_helpers' 4 | 5 | describe 'delete a sync plan' do 6 | include OrganizationHelpers 7 | include SyncPlanHelpers 8 | 9 | let(:org_id) { 1 } 10 | let(:id) { 1 } 11 | let(:sync_plan_name) { "sync_plan1" } 12 | let(:org_name) { "org1" } 13 | 14 | it 'by organization ID and sync plan id' do 15 | api_expects(:sync_plans, :destroy, 'delete a sync plan'). 16 | with_params('organization_id' => org_id, 17 | 'id' => id) 18 | command = %W(sync-plan delete --organization-id #{org_id} --id #{id}) 19 | assert_equal(0, run_cmd(command).exit_code) 20 | end 21 | 22 | it 'by organization ID and sync plan name' do 23 | expect_sync_plan_search(1, 'sync_plan1', 1) 24 | api_expects(:sync_plans, :destroy, 'delete a sync plan'). 25 | with_params('id' => id) 26 | command = %W(sync-plan delete --organization-id #{org_id} --name #{sync_plan_name}) 27 | assert_equal(0, run_cmd(command).exit_code) 28 | end 29 | 30 | it 'by organization name and sync plan name' do 31 | expect_organization_search('org1', 1) 32 | expect_sync_plan_search(1, 'sync_plan1', 1) 33 | api_expects(:sync_plans, :destroy, 'delete a sync plan'). 34 | with_params('id' => id) 35 | command = %W(sync-plan delete --organization #{org_name} --name #{sync_plan_name}) 36 | assert_equal(0, run_cmd(command).exit_code) 37 | end 38 | 39 | it 'by organization name and sync plan id' do 40 | expect_organization_search(org_name, org_id) 41 | api_expects(:sync_plans, :destroy, 'delete a sync plan'). 42 | with_params('id' => id) 43 | command = %W(sync-plan delete --organization #{org_name} --id #{id}) 44 | assert_equal(0, run_cmd(command).exit_code) 45 | end 46 | end 47 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host.rb: -------------------------------------------------------------------------------- 1 | require 'hammer_cli_foreman/host' 2 | require 'hammer_cli_katello/host_extensions' 3 | require 'hammer_cli_katello/host_errata' 4 | require 'hammer_cli_katello/host_subscription' 5 | require 'hammer_cli_katello/host_package' 6 | require 'hammer_cli_katello/host_deb' 7 | require 'hammer_cli_katello/host_package_group' 8 | require 'hammer_cli_katello/host_traces' 9 | require 'hammer_cli_katello/host_bootc' 10 | 11 | module HammerCLIKatello 12 | HammerCLIForeman::Host.subcommand "errata", 13 | HammerCLIKatello::HostErrata.desc, 14 | HammerCLIKatello::HostErrata 15 | 16 | HammerCLIForeman::Host.subcommand "package", 17 | HammerCLIKatello::HostPackage.desc, 18 | HammerCLIKatello::HostPackage 19 | 20 | HammerCLIForeman::Host.subcommand "deb-package", 21 | HammerCLIKatello::HostDebPackage.desc, 22 | HammerCLIKatello::HostDebPackage 23 | 24 | HammerCLIForeman::Host.subcommand "package-group", 25 | HammerCLIKatello::HostPackageGroup.desc, 26 | HammerCLIKatello::HostPackageGroup 27 | 28 | HammerCLIForeman::Host.subcommand "subscription", 29 | HammerCLIKatello::HostSubscription.desc, 30 | HammerCLIKatello::HostSubscription 31 | 32 | HammerCLIForeman::Host.subcommand "traces", 33 | HammerCLIKatello::HostTraces.desc, 34 | HammerCLIKatello::HostTraces 35 | 36 | HammerCLIForeman::Host.subcommand "bootc", 37 | HammerCLIKatello::HostBootc.desc, 38 | HammerCLIKatello::HostBootc 39 | end 40 | -------------------------------------------------------------------------------- /test/functional/repository_set/disable_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative './repository_set_helpers' 3 | require 'hammer_cli_katello/repository_set' 4 | 5 | module HammerCLIKatello 6 | describe RepositorySetCommand::DisableCommand do 7 | include RepositorySetHelpers 8 | 9 | it 'allows minimal options' do 10 | api_expects(:repository_sets, :disable) 11 | .with_params('id' => 1) 12 | assert_success run_cmd(%w(repository-set disable --id 1)) 13 | end 14 | 15 | it 'requires repository set options' do 16 | api_expects_no_call 17 | assert_failure run_cmd(%w(repository-set disable)), /id.*name.*required/ 18 | end 19 | 20 | describe 'resolves repository set ID' do 21 | it 'by requiring organization or product options' do 22 | api_expects_no_call 23 | assert_failure run_cmd(%w(repository-set disable --name reposet1)), 24 | /organization.*product.*required/ 25 | end 26 | 27 | it 'from organization options' do 28 | expect_repository_set_search('reposet1', 1, organization_id: 2) 29 | api_expects(:repository_sets, :disable) 30 | .with_params('id' => 1) 31 | assert_success run_cmd(%w(repository-set disable --name reposet1 --organization-id 2)) 32 | end 33 | 34 | it 'from product options' do 35 | repo_id = 1001 36 | product_id = 3 37 | api_expects(:repositories, :index, 'Find a repository') 38 | .with_params('product_id' => product_id) 39 | .returns(index_response([{'id' => repo_id}])) 40 | 41 | expect_repository_set_search('reposet1', 1, product_id: 3) 42 | api_expects(:repository_sets, :disable) 43 | .with_params('id' => 1, 'repository_id' => repo_id) 44 | assert_success run_cmd(%w(repository-set disable --name reposet1 --product-id 3)) 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /test/functional/product/list_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), 'product_helpers') 3 | 4 | describe "listing products" do 5 | include ProductHelpers 6 | 7 | let(:empty_response_table) do 8 | < 0, 11 | "subtotal" => 0, 12 | "page" => "1", 13 | "per_page" => "1000", 14 | "error" => nil, 15 | "search" => nil, 16 | "sort" => { 17 | "by" => nil, 18 | "order" => nil 19 | }, 20 | "results" => [] 21 | } 22 | end 23 | 24 | let(:flatpak_response) do 25 | { 26 | 'id' => 1, 27 | 'name' => 'Fedora flatpak', 28 | 'url' => 'https://registry.fedoraproject.org/', 29 | 'organization_id' => 1, 30 | 'username' => nil, 31 | 'token' => nil, 32 | } 33 | end 34 | 35 | it "lists flatpak remotes and returns empty response" do 36 | ex = api_expects(:flatpak_remotes, :index, 'flatpak list') do |par| 37 | par['page'] == 1 && par['per_page'] == 1000 38 | end 39 | 40 | ex.returns(empty_response) 41 | 42 | expected_result = success_result("---|------|-----|-------------|----------|------------- 43 | ID | NAME | URL | DESCRIPTION | USERNAME | REGISTRY URL 44 | ---|------|-----|-------------|----------|------------- 45 | ") 46 | 47 | result = run_cmd(@cmd) 48 | assert_cmd(expected_result, result) 49 | end 50 | 51 | it "lists flatpak remotes and returns response" do 52 | ex = api_expects(:flatpak_remotes, :index, 'flatpak list') do |par| 53 | par['page'] == 1 && par['per_page'] == 1000 54 | end 55 | 56 | ex.returns(flatpak_response) 57 | expected_result = success_result("1 | Fedora flatpak | https://registry.fedoraproject.org/ |" + " " + " 58 | ---|----------------|-------------------------------------|---------\n" 59 | ) 60 | result = run_cmd(@cmd) 61 | assert_cmd(expected_result, result) 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /test/functional/content_credentials/list_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../test_helper') 2 | require File.join(File.dirname(__FILE__), '../lifecycle_environment/lifecycle_environment_helpers') 3 | 4 | describe 'listing content credentials' do 5 | include LifecycleEnvironmentHelpers 6 | 7 | before do 8 | @cmd = %w(content-credentials list) 9 | end 10 | 11 | let(:org_id) { 1 } 12 | let(:lifecycle_env_id) { 1 } 13 | let(:empty_response) do 14 | { 15 | "total" => 0, 16 | "subtotal" => 0, 17 | "page" => "1", 18 | "per_page" => "1000", 19 | "error" => nil, 20 | "search" => nil, 21 | "sort" => { 22 | "by" => nil, 23 | "order" => nil 24 | }, 25 | "results" => [] 26 | } 27 | end 28 | 29 | it "lists an organizations keys" do 30 | params = ["--organization-id=#{org_id}"] 31 | 32 | ex = api_expects(:content_credentials, :index, 'Organization content credentials list') do |par| 33 | par['organization_id'] == org_id && par['page'] == 1 && 34 | par['per_page'] == 1000 35 | end 36 | 37 | ex.returns(empty_response) 38 | 39 | expected_result = success_result("---|------|------------- 40 | ID | NAME | CONTENT TYPE 41 | ---|------|------------- 42 | ") 43 | 44 | result = run_cmd(@cmd + params) 45 | assert_cmd(expected_result, result) 46 | end 47 | 48 | it "lists the keys by content-type" do 49 | params = ['--content-type=gpg', "--organization-id=#{org_id}"] 50 | 51 | ex = api_expects(:content_credentials, :index, 'content-type') do |par| 52 | par['organization_id'] == org_id && par['page'] == 1 && 53 | par['per_page'] == 1000 54 | end 55 | 56 | ex.returns(empty_response) 57 | 58 | expected_result = CommandExpectation.new("---|------|------------- 59 | ID | NAME | CONTENT TYPE 60 | ---|------|------------- 61 | ") 62 | 63 | result = run_cmd(@cmd + params) 64 | assert_cmd(expected_result, result) 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/erratum.rb: -------------------------------------------------------------------------------- 1 | require 'hammer_cli_katello/erratum_info_command' 2 | 3 | module HammerCLIKatello 4 | class ErratumCommand < HammerCLIKatello::Command 5 | resource :errata 6 | 7 | class ListCommand < HammerCLIKatello::ListCommand 8 | extend RepositoryScopedToProduct 9 | include LifecycleEnvironmentNameMapping 10 | 11 | validate_repo_name_requires_product_options(:option_repository_name) 12 | 13 | output do 14 | field :id, _("Id") 15 | field :errata_id, _("Errata ID") 16 | field :type, _("Type") 17 | field :title, _("Title") 18 | field :issued, _("Issued") 19 | field :updated, _("Updated") 20 | end 21 | 22 | validate_options :before, 'IdResolution' do 23 | organization_options = [:option_organization_id, :option_organization_name, \ 24 | :option_organization_label] 25 | content_view_options = [:option_content_view_id, :option_content_view_name] 26 | 27 | if option(:option_product_name).exist? || option(:option_content_view_name).exist? 28 | any(*organization_options).required 29 | end 30 | 31 | if option(:option_content_view_version_version).exist? 32 | any(*content_view_options).required 33 | end 34 | 35 | if any(*content_view_options).exist? 36 | any(:option_content_view_version_id, 37 | :option_content_view_version_version, 38 | :option_environment_id, 39 | :option_environment_name).required 40 | end 41 | end 42 | 43 | build_options do |o| 44 | o.expand.including(:products, :organizations, :content_views) 45 | end 46 | extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new) 47 | end 48 | 49 | class InfoCommand < HammerCLIKatello::ErratumInfoCommand 50 | resource :errata 51 | build_options 52 | end 53 | 54 | autoload_subcommands 55 | end 56 | end 57 | -------------------------------------------------------------------------------- /test/unit/id_resolver_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/id_resolver' 3 | 4 | module HammerCLIKatello 5 | describe IdResolver do 6 | let(:api) { mock('api') } 7 | let(:searchables) { mock('searchables') } 8 | let(:id_resolver) { IdResolver.new api, searchables } 9 | 10 | before(:each) do 11 | api.stubs(:resources).returns([]) 12 | api.stubs(:resource).returns([]) 13 | end 14 | 15 | describe '#repository_ids' do 16 | it 'accepts nil repository_names' do 17 | id_resolver.stubs(:find_resources).returns([]) 18 | id_resolver.repository_ids({}).must_equal(nil) 19 | end 20 | 21 | it 'accepts repository_ids' do 22 | id_resolver.repository_ids( 23 | 'option_repository_ids' => [1, 2] 24 | ).must_equal [1, 2] 25 | end 26 | 27 | it 'accepts repository_names' do 28 | id_resolver.stubs(:find_resources).returns( 29 | [ 30 | {'id' => 1, 'name' => 'repo1'}, 31 | {'id' => 2, 'name' => 'repo2'} 32 | ] 33 | ) 34 | id_resolver.repository_ids( 35 | 'option_names' => %w(repo1 repo2) 36 | ).must_equal [1, 2] 37 | end 38 | end 39 | 40 | describe '#repository_id' do 41 | it 'resolves ID from name' do 42 | id_resolver.expects(:find_resource).with(:repositories, name: 'repo1').returns('id' => 5) 43 | options = {name: 'repo1'} 44 | id_resolver.repository_id(options).must_equal 5 45 | end 46 | end 47 | 48 | describe '#content_view_version_id' do 49 | it 'resolves ID from version number' do 50 | options = {'option_version' => '2.0', 'option_content_view_id' => 4} 51 | id_resolver.expects(:find_resources) 52 | .with(:content_view_versions, options) 53 | .returns(['id' => 5]) 54 | id_resolver.content_view_version_id(options).must_equal 5 55 | end 56 | end 57 | end 58 | end 59 | -------------------------------------------------------------------------------- /test/functional/content_view/update_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative '../organization/organization_helpers' 3 | require_relative '../content_view/content_view_helpers' 4 | require 'hammer_cli_katello/content_view' 5 | 6 | module HammerCLIKatello 7 | describe ContentView::UpdateCommand do 8 | include OrganizationHelpers 9 | include ContentViewHelpers 10 | 11 | it 'allows minimal options' do 12 | api_expects(:content_views, :update) do |p| 13 | p['id'] == 2 14 | end 15 | run_cmd(%w(content-view update --id 2)) 16 | end 17 | 18 | describe 'OrganizationOptions' do 19 | it 'requires organization if content view name is supplied' do 20 | api_expects_no_call 21 | result = run_cmd(%w(content-view update --name cv2)) 22 | assert(result.err[/--organization-id, --organization, --organization-label is required/], 23 | "Organization option requirements are validated") 24 | end 25 | 26 | it 'allows organization id' do 27 | expect_content_view_search('1', 'cv2', 2) 28 | api_expects(:content_views, :update) do |p| 29 | p['id'] == 2 30 | end 31 | run_cmd(%w(content-view update --name cv2 --organization-id 1)) 32 | end 33 | 34 | it 'allows organization name' do 35 | expect_organization_search('org1', 1) 36 | expect_content_view_search(1, 'cv2', 2) 37 | api_expects(:content_views, :update) do |p| 38 | p['id'] == 2 39 | end 40 | run_cmd(%w(content-view update --name cv2 --organization org1)) 41 | end 42 | 43 | it 'allows organization label' do 44 | expect_organization_search('org1', 1, field: 'label') 45 | expect_content_view_search(1, 'cv2', 2) 46 | api_expects(:content_views, :update) do |p| 47 | p['id'] == 2 48 | end 49 | run_cmd(%w(content-view update --name cv2 --organization-label org1)) 50 | end 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /test/functional/module_stream/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/module_stream' 3 | 4 | module HammerCLIKatello 5 | describe ModuleStreamCommand::ListCommand do 6 | it 'allows minimal options' do 7 | api_expects(:module_streams, :index) 8 | 9 | run_cmd(%w(module-stream list)) 10 | end 11 | 12 | it 'can be provided by repository ID' do 13 | api_expects(:module_streams, :index).with_params(repository_id: 1) 14 | 15 | run_cmd(%w(module-stream list --repository-id 1)) 16 | end 17 | 18 | it 'product params needed with repository name' do 19 | cmd = run_cmd(%w(module-stream list --repository Repo)) 20 | error_msg = "At least one of options --product, --product-id is required." 21 | api_expects_no_call 22 | assert_match error_msg, cmd.err 23 | end 24 | 25 | it 'can be provided by repository name and product id' do 26 | api_expects(:repositories, :index) 27 | .with_params(name: "Repo", product_id: 1) 28 | .returns(index_response([{'id' => 1}])) 29 | 30 | api_expects(:module_streams, :index).with_params(repository_id: 1) 31 | 32 | run_cmd(%w(module-stream list --repository Repo --product-id 1)) 33 | end 34 | 35 | it 'can be provided by repository id and organization id' do 36 | api_expects(:module_streams, :index) 37 | .with_params(repository_id: 1, organization_id: 1) 38 | 39 | run_cmd(%w(module-stream list --repository-id 1 --organization-id 1)) 40 | end 41 | 42 | it 'can be provided by repository name, product id, and organization id' do 43 | api_expects(:repositories, :index) 44 | .with_params(name: "Repo", product_id: 1) 45 | .returns(index_response([{'id' => 1}])) 46 | 47 | api_expects(:module_streams, :index) 48 | .with_params(repository_id: 1, organization_id: 1) 49 | 50 | run_cmd(%w(module-stream list --repository Repo --product-id 1 --organization-id 1)) 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /test/functional/content_export/generate_listing_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require 'hammer_cli_katello/content_export' 3 | 4 | describe('content-export generate-listing') do 5 | include ForemanTaskHelpers 6 | 7 | before do 8 | @cmd = %w(content-export generate-listing) 9 | @params = [] 10 | @export_history_id = 100 11 | @path = '/tmp' 12 | @export_history = { 13 | 'id' => @export_history_id, 14 | 'path' => @path, 15 | 'metadata' => {'format' => 'syncable'} 16 | } 17 | @task_id = SecureRandom.uuid 18 | end 19 | 20 | let(:cmd) { @cmd + @params } 21 | let(:result) { run_cmd(cmd) } 22 | 23 | describe('given an export history id') do 24 | it('loads export history by id') do 25 | @params = ["--id=#{@export_history_id}"] 26 | 27 | HammerCLIKatello::ContentExport::GenerateListingCommand. 28 | any_instance. 29 | expects(:fetch_export_history). 30 | returns(@export_history) 31 | assert_match(/Generated/, result.out) 32 | assert_match(@path, result.out) 33 | end 34 | end 35 | 36 | describe('given a task id') do 37 | it('loads export history based on the task') do 38 | @params = ["--task-id=#{@task_id}"] 39 | 40 | HammerCLIKatello::ContentExport::GenerateListingCommand. 41 | any_instance. 42 | expects(:reload_task). 43 | returns('id' => 'taskid') 44 | 45 | HammerCLIKatello::ContentExport::GenerateListingCommand. 46 | any_instance. 47 | expects(:fetch_export_history). 48 | returns(@export_history) 49 | 50 | assert_match(/Generated/, result.out) 51 | assert_match(@path, result.out) 52 | end 53 | end 54 | 55 | describe('given no arguments') do 56 | it('tells the user to verify the arguments') do 57 | expected = "Error: No export history was found. Verify the value given for "\ 58 | + "--task-id or --id\n" 59 | assert_equal(expected, result.err) 60 | end 61 | end 62 | end 63 | -------------------------------------------------------------------------------- /test/functional/host/subscription/register_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require File.join(File.dirname(__FILE__), '../../content_view/content_view_helpers') 3 | require File.join(File.dirname(__FILE__), '../../organization/organization_helpers') 4 | require File.join(File.dirname(__FILE__), 5 | '../../lifecycle_environment/lifecycle_environment_helpers') 6 | 7 | describe 'host subscription register' do 8 | include OrganizationHelpers 9 | include ContentViewHelpers 10 | include LifecycleEnvironmentHelpers 11 | 12 | before do 13 | @cmd = %w(host subscription register) 14 | end 15 | 16 | it "subscribe a host" do 17 | params = ['--name=trump.wall.com', '--content-view-id=1', '--lifecycle-environment-id=2'] 18 | ex = api_expects(:host_subscriptions, :create, 'Host subscription register') do |par| 19 | par['name'] == 'trump.wall.com' && par['content_view_id'] == 1 && 20 | par['lifecycle_environment_id'] == 2 21 | end 22 | ex.returns({}) 23 | 24 | expected_result = success_result( 25 | 'Host successfully registered. 26 | ' 27 | ) 28 | 29 | result = run_cmd(@cmd + params) 30 | assert_cmd(expected_result, result) 31 | end 32 | 33 | it "resolves ids from names" do 34 | params = ['--name=trump.wall.com', '--content-view=someview', '--lifecycle-environment=someenv', 35 | '--organization=trumporg'] 36 | 37 | api_expects(:host_subscriptions, :create, 'Host subscription register') do |par| 38 | par['name'] == 'trump.wall.com' && par['content_view_id'] == 1 && 39 | par['lifecycle_environment_id'] == 2 40 | end 41 | 42 | expect_organization_search('trumporg', 3) 43 | expect_content_view_search(3, 'someview', 1) 44 | expect_lifecycle_environment_search(3, 'someenv', 2) 45 | 46 | expected_result = success_result( 47 | 'Host successfully registered. 48 | ' 49 | ) 50 | result = run_cmd(@cmd + params) 51 | assert_cmd(expected_result, result) 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /test/functional/content_export/generate_metadata_test.rb: -------------------------------------------------------------------------------- 1 | require File.join(File.dirname(__FILE__), '../../test_helper') 2 | require 'hammer_cli_katello/content_export' 3 | 4 | describe('content-export generate-metadata') do 5 | include ForemanTaskHelpers 6 | 7 | before do 8 | @cmd = %w(content-export generate-metadata) 9 | @params = [] 10 | @export_history_id = 100 11 | @export_history = { 12 | 'id' => @export_history_id, 13 | 'path' => '/tmp', 14 | 'metadata' => {} 15 | } 16 | @task_id = SecureRandom.uuid 17 | end 18 | 19 | let(:cmd) { @cmd + @params } 20 | let(:result) { run_cmd(cmd) } 21 | 22 | describe('given an export history id') do 23 | it('loads export history by id') do 24 | @params = ["--id=#{@export_history_id}"] 25 | 26 | HammerCLIKatello::ContentExport::GenerateMetadataCommand. 27 | any_instance. 28 | expects(:fetch_export_history). 29 | returns(@export_history) 30 | 31 | expected = success_result("Generated /tmp/metadata.json\n") 32 | 33 | assert_cmd(expected, result) 34 | end 35 | end 36 | 37 | describe('given a task id') do 38 | it('loads export history based on the task') do 39 | @params = ["--task-id=#{@task_id}"] 40 | 41 | HammerCLIKatello::ContentExport::GenerateMetadataCommand. 42 | any_instance. 43 | expects(:reload_task). 44 | returns('id' => 'taskid') 45 | 46 | HammerCLIKatello::ContentExport::GenerateMetadataCommand. 47 | any_instance. 48 | expects(:fetch_export_history). 49 | returns(@export_history) 50 | 51 | expected = success_result("Generated /tmp/metadata.json\n") 52 | 53 | assert_cmd(expected, result) 54 | end 55 | end 56 | 57 | describe('given no arguments') do 58 | it('tells the user to verify the arguments') do 59 | expected = "Error: No export history was found. Verify the value given for "\ 60 | + "--task-id or --id\n" 61 | assert_equal(expected, result.err) 62 | end 63 | end 64 | end 65 | -------------------------------------------------------------------------------- /test/functional/host_collection/create_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/host_collection' 3 | 4 | module HammerCLIKatello 5 | describe HostCollection::CreateCommand do 6 | it 'requires organization options' do 7 | result = run_cmd(%w(host-collection create --name hc1)) 8 | expected_error = "Could not find organization" 9 | assert_equal(result.exit_code, HammerCLI::EX_SOFTWARE) 10 | assert_equal(result.err[/#{expected_error}/], expected_error) 11 | end 12 | 13 | it 'allows organization id' do 14 | api_expects(:host_collections, :create) do |par| 15 | par['organization_id'].to_i == 1 16 | end 17 | 18 | run_cmd(%w(host-collection create --name hc1 --organization-id 1)) 19 | end 20 | 21 | it 'allows organization name' do 22 | api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" } 23 | .returns(index_response([{'id' => 1}])) 24 | 25 | api_expects(:host_collections, :create) do |par| 26 | par['organization_id'].to_i == 1 27 | end 28 | 29 | run_cmd(%w(host-collection create --name hc1 --organization org1)) 30 | end 31 | 32 | it 'allows unlimited-hosts flag with no arguments' do 33 | api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" } 34 | .returns(index_response([{'id' => 1}])) 35 | 36 | api_expects(:host_collections, :create) do |par| 37 | par['unlimited_hosts'] == true 38 | end 39 | 40 | run_cmd(%w(host-collection create --name hc1 --organization org1 --unlimited-hosts)) 41 | end 42 | 43 | it 'allows organization label' do 44 | api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" } 45 | .returns(index_response([{'id' => 1}])) 46 | 47 | api_expects(:host_collections, :create) do |par| 48 | par['organization_id'].to_i == 1 49 | end 50 | 51 | run_cmd(%w(host-collection create --name hc1 --organization-label org1)) 52 | end 53 | end 54 | end 55 | -------------------------------------------------------------------------------- /test/functional/host_collection/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require 'hammer_cli_katello/host_collection' 3 | 4 | module HammerCLIKatello 5 | describe HostCollection::ListCommand do 6 | it 'does not require organization options' do 7 | api_expects(:host_collections, :index) 8 | 9 | run_cmd(%w(host-collection list)) 10 | end 11 | 12 | it 'allows organization id' do 13 | api_expects(:host_collections, :index) do |par| 14 | par['organization_id'].to_i == 1 15 | end 16 | 17 | run_cmd(%w(host-collection list --organization-id 1)) 18 | end 19 | 20 | it 'allows organization name' do 21 | api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" } 22 | .returns(index_response([{'id' => 1}])) 23 | 24 | api_expects(:host_collections, :index) do |par| 25 | par['organization_id'].to_i == 1 26 | end 27 | 28 | run_cmd(%w(host-collection list --organization org1)) 29 | end 30 | 31 | it 'allows organization label' do 32 | api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" } 33 | .returns(index_response([{'id' => 1}])) 34 | 35 | api_expects(:host_collections, :index) do |par| 36 | par['organization_id'].to_i == 1 37 | end 38 | 39 | run_cmd(%w(host-collection list --organization-label org1)) 40 | end 41 | 42 | it 'allows host id' do 43 | api_expects(:host_collections, :index) do |par| 44 | par['host_id'] == 1 45 | end 46 | 47 | run_cmd(%w(host-collection list --host-id 1 --organization-id 1)) 48 | end 49 | 50 | it 'allows host name' do 51 | ex = api_expects(:hosts, :index) do |par| 52 | par[:search] == "name = \"host1\"" 53 | end 54 | ex.returns(index_response([{'id' => 1}])) 55 | 56 | api_expects(:host_collections, :index) do |par| 57 | par['host_id'] == 1 58 | end 59 | 60 | run_cmd(%w(host-collection list --host host1 --organization-id 1)) 61 | end 62 | end 63 | end 64 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/host_package.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class HostPackage < HammerCLIKatello::Command 3 | desc "Manage packages on your hosts" 4 | 5 | class ListCommand < HammerCLIKatello::ListCommand 6 | resource :host_packages, :index 7 | 8 | output do 9 | field :nvra, _("Nvra") 10 | field :persistence, _("Persistence"), nil, :sets => ['ALL'] 11 | end 12 | 13 | build_options 14 | end 15 | 16 | class InstallCommand < HammerCLIKatello::Command 17 | command_name "install" 18 | 19 | def self.rex_feature 20 | "katello_package_install" 21 | end 22 | 23 | include UnsupportedKatelloAgentCommandHelper 24 | end 25 | 26 | class UpgradeCommand < HammerCLIKatello::Command 27 | command_name "upgrade" 28 | def self.rex_feature 29 | "katello_package_update" 30 | end 31 | 32 | include UnsupportedKatelloAgentCommandHelper 33 | end 34 | 35 | class UpgradeAllCommand < HammerCLIKatello::Command 36 | command_name "upgrade-all" 37 | 38 | def self.rex_feature 39 | "katello_package_update" 40 | end 41 | 42 | include UnsupportedKatelloAgentCommandHelper 43 | end 44 | 45 | class RemoveCommand < HammerCLIKatello::Command 46 | command_name "remove" 47 | 48 | def self.rex_feature 49 | "katello_package_remove" 50 | end 51 | 52 | include UnsupportedKatelloAgentCommandHelper 53 | end 54 | 55 | class ContainerfileInstallCommand < HammerCLIKatello::Command 56 | desc _("Generate a Containerfile RUN command from transiently installed packages on image mode hosts") 57 | resource :host_packages, :containerfile_install_command 58 | command_name "containerfile-install-command" 59 | 60 | output do 61 | field :command, nil, Fields::Field, :hide_blank => true 62 | field :message, _("Message"), Fields::Field, :hide_blank => true 63 | end 64 | 65 | build_options 66 | end 67 | 68 | autoload_subcommands 69 | end 70 | end 71 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/module_stream.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class ModuleStreamCommand < HammerCLIKatello::Command 3 | resource :module_streams 4 | 5 | class ListCommand < HammerCLIKatello::ListCommand 6 | extend RepositoryScopedToProduct 7 | 8 | desc "List module streams" 9 | 10 | validate_repo_name_requires_product_options(:option_repository_name) 11 | 12 | output do 13 | field :id, _("Id") 14 | field :name, _("Module Stream Name") 15 | field :stream, _("Stream") 16 | field :uuid, _("Uuid") 17 | field :version, _("Version") 18 | field :arch, _("Architecture") 19 | field :context, _("Context") 20 | end 21 | 22 | build_options do |o| 23 | o.expand.including(:products) 24 | end 25 | end 26 | 27 | class InfoCommand < HammerCLIKatello::InfoCommand 28 | extend RepositoryScopedToProduct 29 | 30 | validate_repo_name_requires_product_options(:option_repository_name) 31 | 32 | output do 33 | field :id, _("Id") 34 | field :name, _("Module Stream Name") 35 | field :stream, _("Stream") 36 | field :uuid, _("Uuid") 37 | field :version, _("Version") 38 | field :arch, _("Architecture") 39 | field :context, _("Context") 40 | 41 | collection :repositories, _("Repositories") do 42 | field :id, _("Id") 43 | field :name, _("Name") 44 | field :label, _("Label") 45 | end 46 | 47 | collection :artifacts, _("Artifacts") do 48 | field :id, _("Id") 49 | field :name, _("Name") 50 | end 51 | 52 | collection :profiles, _("Profiles") do 53 | field :id, _("Id") 54 | field :name, _("Name") 55 | collection :rpms, _("RPMs") do 56 | field :id, _("Id") 57 | field :name, _("Name") 58 | end 59 | end 60 | end 61 | 62 | build_options do |o| 63 | o.expand.including(:products, :organizations) 64 | end 65 | end 66 | 67 | autoload_subcommands 68 | end 69 | end 70 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/command_extensions/kickstart_repository.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | module CommandExtensions 3 | class KickstartRepository < HammerCLI::CommandExtensions 4 | option_family associate: 'kickstart_repository' do 5 | child '--kickstart-repository', 'REPOSITORY_NAME', _('Kickstart repository name'), 6 | attribute_name: :option_kickstart_repository 7 | end 8 | 9 | request_params do |params, cmd_obj| 10 | resource_name = cmd_obj.resource.singular_name 11 | if cmd_obj.option_kickstart_repository && !cmd_obj.option_kickstart_repository_id 12 | resource_hash = if resource_name == 'hostgroup' 13 | params[resource_name] 14 | else 15 | params[resource_name]['content_facet_attributes'] 16 | end 17 | 18 | resource_hash ||= {} 19 | 20 | env_id = resource_hash['lifecycle_environment_id'] 21 | cv_id = resource_hash['content_view_id'] 22 | 23 | raise _('Please provide --lifecycle-environment-id') unless env_id 24 | 25 | raise _('Please provide --content-view-id') unless cv_id 26 | resource_hash['kickstart_repository_id'] = HammerCLIKatello::CommandExtensions::KickstartRepository.fetch_repo_id( 27 | cv_id, env_id, cmd_obj.option_kickstart_repository 28 | ) 29 | end 30 | end 31 | 32 | def self.fetch_repo_id(cv_id, env_id, repo_name) 33 | repo_resource = HammerCLIForeman.foreman_resource(:repositories) 34 | index_options = { 35 | content_view_id: cv_id, 36 | environment_id: env_id, 37 | name: repo_name 38 | } 39 | repos = repo_resource.call(:index, index_options)['results'] 40 | if repos.empty? 41 | raise _("No such repository with name %{name}, in lifecycle environment"\ 42 | " %{environment_id} and content view %{content_view_id}") % index_options 43 | end 44 | repos.first['id'] 45 | end 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /test/functional/content_view/version/update_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require 'hammer_cli_katello/content_view_version' 3 | 4 | module HammerCLIKatello 5 | describe ContentViewVersion::UpdateCommand do 6 | include OrganizationHelpers 7 | it 'allows minimal options' do 8 | ex = api_expects(:content_view_versions, :update).with_params('description' => 'pizza') 9 | ex.returns('id' => '2', 'description' => 'pizza') 10 | 11 | result = run_cmd(%w(content-view version update --id 2 --description pizza)) 12 | assert_equal(result.exit_code, 0) 13 | end 14 | end 15 | 16 | describe 'content view options' do 17 | it 'allows content view id with one version' do 18 | ex = api_expects(:content_view_versions, :index) 19 | ex.returns('id' => '1', 'content_view' => [{'id' => '2'}]) 20 | 21 | ex = api_expects(:content_view_versions, :update).with_params('description' => 'pizza') 22 | ex.returns('id' => '1', 'description' => 'pizza', 'content_view' => [{'id' => '2'}]) 23 | 24 | result = run_cmd(%w(content-view version update --description pizza --content-view-id 2)) 25 | assert_equal(result.exit_code, 0) 26 | end 27 | 28 | it 'allows content view id with multiple versions' do 29 | ex = api_expects(:content_view_versions, :index) 30 | ex.returns('id' => '2', 'content_view' => [{'id' => '3'}]) 31 | 32 | ex = api_expects(:content_view_versions, :update).with_params('description' => 'pizza') 33 | ex.returns('id' => '2', 'description' => 'pizza', 'content_view' => [{'id' => '3'}]) 34 | 35 | result = run_cmd(%w(content-view version update --description pizza 36 | --content-view-id 3 --version 2)) 37 | assert_equal(result.exit_code, 0) 38 | end 39 | 40 | it 'blocks update without description' do 41 | ex = api_expects(:content_view_versions, :index) 42 | ex.returns('id' => '1', 'content_view' => [{'id' => '2'}]) 43 | 44 | result = run_cmd(%w(content-view version update --content-view-id 2)) 45 | assert_equal(result.exit_code, 64) 46 | end 47 | end 48 | end 49 | -------------------------------------------------------------------------------- /test/functional/content_view/component/list_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../../test_helper' 2 | require 'hammer_cli_katello/content_view_component' 3 | module HammerCLIKatello 4 | describe ContentViewComponent::ListCommand do 5 | before do 6 | @cmd = %w(content-view component list) 7 | end 8 | 9 | it 'expects composite_content_view_id as minimal options' do 10 | api_expects(:content_view_components, :index, "component list") do |p| 11 | p["composite_content_view_id"].to_s == "1" 12 | end 13 | run_cmd(@cmd + ["--composite-content-view-id=1"]) 14 | end 15 | 16 | it 'expects composite_content_view and organization_id as other options' do 17 | api_expects(:content_views, :index) do |p| 18 | p['name'] == "lol" && p["organization_id"].to_s == "1" 19 | end 20 | run_cmd(@cmd + %w(--composite-content-view=lol --organization-id=1)) 21 | end 22 | 23 | it 'label' do 24 | api_expects(:organizations, :index) { |par| par[:search] == "label = \"org1\"" } 25 | .at_least_once.returns(index_response([{'id' => 1}])) 26 | 27 | api_expects(:content_view_components, :index) do |p| 28 | p["composite_content_view_id"].to_s == "1" 29 | end 30 | 31 | api_expects(:content_views, :index). 32 | at_least_once.returns(index_response([{'id' => 1}])) do |p| 33 | p['name'] == "lol" && p["organization_id"].to_s == "1" 34 | end 35 | 36 | run_cmd(@cmd + %w(--composite-content-view=lol --organization-label=org1)) 37 | end 38 | 39 | it 'name' do 40 | api_expects(:organizations, :index) { |par| par[:search] == "name = \"org1\"" } 41 | .at_least_once.returns(index_response([{'id' => 1}])) 42 | 43 | api_expects(:content_view_components, :index) do |p| 44 | p["composite_content_view_id"].to_s == "1" 45 | end 46 | 47 | api_expects(:content_views, :index). 48 | at_least_once.returns(index_response([{'id' => 1}])) do |p| 49 | p['name'] == "lol" && p["organization_id"].to_s == "1" 50 | end 51 | 52 | run_cmd(@cmd + %w(--composite-content-view=lol --organization=org1)) 53 | end 54 | end 55 | end 56 | -------------------------------------------------------------------------------- /test/functional/content_view/copy_test.rb: -------------------------------------------------------------------------------- 1 | require_relative '../test_helper' 2 | require_relative '../organization/organization_helpers' 3 | require_relative '../content_view/content_view_helpers' 4 | require 'hammer_cli_katello/content_view' 5 | 6 | module HammerCLIKatello 7 | describe ContentView::CopyCommand do 8 | include OrganizationHelpers 9 | include ContentViewHelpers 10 | 11 | it 'allows minimal options' do 12 | api_expects(:content_views, :copy) do |p| 13 | p['id'] == 2 && p['name'] == 'cv2-dup' 14 | end 15 | run_cmd(%w(content-view copy --id 2 --new-name cv2-dup)) 16 | end 17 | 18 | describe 'OrganizationOptions' do 19 | it 'requires organization if content view name is supplied' do 20 | api_expects_no_call 21 | result = run_cmd(%w(content-view copy --new-name cv2-dup --name cv2)) 22 | assert(result.err[/--organization-id, --organization, --organization-label is required/], 23 | "Organization option requirements are validated") 24 | end 25 | 26 | it 'allows organization id' do 27 | expect_content_view_search('1', 'cv2', 2) 28 | api_expects(:content_views, :copy) do |p| 29 | p['id'] == 2 && p['name'] == 'cv2-dup' 30 | end 31 | run_cmd(%w(content-view copy --name cv2 --new-name cv2-dup --organization-id 1)) 32 | end 33 | 34 | it 'allows organization name' do 35 | expect_organization_search('org1', 1) 36 | expect_content_view_search(1, 'cv2', 2) 37 | api_expects(:content_views, :copy) do |p| 38 | p['id'] == 2 && p['name'] == 'cv2-dup' 39 | end 40 | run_cmd(%w(content-view copy --name cv2 --new-name cv2-dup --organization org1)) 41 | end 42 | 43 | it 'allows organization label' do 44 | expect_organization_search('org1', 1, field: 'label') 45 | expect_content_view_search(1, 'cv2', 2) 46 | api_expects(:content_views, :copy) do |p| 47 | p['id'] == 2 && p['name'] == 'cv2-dup' 48 | end 49 | run_cmd(%w(content-view copy --name cv2 --new-name cv2-dup --organization-label org1)) 50 | end 51 | end 52 | end 53 | end 54 | -------------------------------------------------------------------------------- /lib/hammer_cli_katello/srpm.rb: -------------------------------------------------------------------------------- 1 | module HammerCLIKatello 2 | class SrpmCommand < HammerCLIKatello::Command 3 | resource :srpms 4 | 5 | class ListCommand < HammerCLIKatello::ListCommand 6 | include LifecycleEnvironmentNameMapping 7 | output do 8 | field :id, _("Id") 9 | field :name, _("Name") 10 | field :filename, _("Filename") 11 | end 12 | 13 | validate_options :before, 'IdResolution' do 14 | organization_options = [:option_organization_id, :option_organization_name, \ 15 | :option_organization_label] 16 | product_options = [:option_product_id, :option_product_name] 17 | content_view_options = [:option_content_view_id, :option_content_view_name] 18 | 19 | if option(:option_product_name).exist? || option(:option_content_view_name).exist? 20 | any(*organization_options).required 21 | end 22 | 23 | if option(:option_repository_name).exist? 24 | any(*product_options).required 25 | end 26 | 27 | if option(:option_content_view_version_version).exist? 28 | any(*content_view_options).required 29 | end 30 | 31 | if any(*content_view_options).exist? 32 | any(:option_content_view_version_id, 33 | :option_content_view_version_version, 34 | :option_environment_id, 35 | :option_environment_name).required 36 | end 37 | end 38 | 39 | build_options do |o| 40 | o.expand.including(:products, :content_views) 41 | end 42 | 43 | extend_with(HammerCLIKatello::CommandExtensions::LifecycleEnvironment.new) 44 | end 45 | 46 | class InfoCommand < HammerCLIKatello::InfoCommand 47 | output do 48 | field :id, _("Id") 49 | field :name, _("Name") 50 | field :version, _("Version") 51 | field :arch, _("Architecture") 52 | field :epoch, _("Epoch") 53 | field :release, _("Release") 54 | field :filename, _("Filename") 55 | field :summary, _("Description") 56 | end 57 | 58 | build_options 59 | end 60 | 61 | autoload_subcommands 62 | end 63 | end 64 | --------------------------------------------------------------------------------