Skip to content

Commit

Permalink
Fixes #38019 - Add hammer support for flatpak remotes
Browse files Browse the repository at this point in the history
  • Loading branch information
sjha4 committed Nov 21, 2024
1 parent f96ac21 commit f250881
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/hammer_cli_katello.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ def self.exception_handler_class
'hammer_cli_katello/docker'
)

HammerCLI::MainCommand.lazy_subcommand!("flatpak-remote", _("Manipulate flatpak remotes"),
'HammerCLIKatello::FlatpakRemoteCommand',
'hammer_cli_katello/flatpak_remote'
)
# subcommands to hammer_cli_foreman commands
require 'hammer_cli_katello/host'
require 'hammer_cli_katello/hostgroup'
Expand Down
75 changes: 75 additions & 0 deletions lib/hammer_cli_katello/flatpak_remote.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
require 'hammer_cli_katello/flatpak_remote_repository'
module HammerCLIKatello
class FlatpakRemoteCommand < HammerCLIKatello::Command
resource :flatpak_remotes

class ListCommand < HammerCLIKatello::ListCommand
include OrganizationOptions
output do
field :id, _('ID')
field :name, _('Name')
field :url, _('URL')
field :description, _('Description')
field :username, _('User')
field :token, _('Token')
field :registry_url, _('Registry URL')
end

build_options
end

class InfoCommand < HammerCLIKatello::InfoCommand
output do
field :id, _('ID')
field :name, _('Name')
field :label, _('Label')
field :description, _('Description'), Fields::Field, :hide_blank => true
field :url, _('Flatpak index URL')
field :username, _('Username'), Fields::Field, :hide_blank => true
field :token, _('Token'), Fields::Field, :hide_blank => true
field :registry_url, _('Registry URL')
end

build_options
end

class CreateCommand < HammerCLIKatello::CreateCommand
success_message _('Flatpak Remote created.')
failure_message _('Could not create the Flatpak Remote.')

build_options
end

class UpdateCommand < HammerCLIKatello::UpdateCommand
success_message _('Flatpak Remote updated.')
failure_message _('Could not update the Flatpak Remote.')

build_options
end

class DeleteCommand < HammerCLIKatello::DeleteCommand
success_message _('Flatpak Remote deleted.')
failure_message _('Could not delete the Flatpak Remote.')

build_options
end

class ScanCommand < HammerCLIKatello::SingleResourceCommand
include HammerCLIForemanTasks::Async

action :scan
command_name 'scan'

success_message _("Flatpak remote is being scanned in task %<id>s.")
failure_message _('Could not scan the Flatpak remote')

build_options
end

autoload_subcommands

subcommand HammerCLIKatello::FlatpakRemoteRepository.command_name,
HammerCLIKatello::FlatpakRemoteRepository.desc,
HammerCLIKatello::FlatpakRemoteRepository
end
end
53 changes: 53 additions & 0 deletions lib/hammer_cli_katello/flatpak_remote_repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
module HammerCLIKatello
class FlatpakRemoteRepository < HammerCLIKatello::Command
resource :flatpak_remote_repositories
command_name 'remote-repository'
desc _('View and manage flatpak remote repositories')

class ListCommand < HammerCLIKatello::ListCommand
output do
field :id, _("Id")
field :name, _("Name")
field :label, _("Label")
end
build_options do |o|
o.expand(:all).including(:flatpak_remotes, :organizations)
end
end

class InfoCommand < HammerCLIKatello::InfoCommand
output do
field :id, _("Id")
field :name, _("Name")
field :label, _("Label")
from :flatpak_remote do
field :id, _("Flatpak Remote ID")
field :name, _("Flatpak Remote Name")
field :url, _("Flatpak Remote URL")
end
collection :manifests, _("Manifests"), hide_blank: true, hide_empty: true do
field :name, _("Manifest Name")
field :digest, _("Manifest Digest")
field :tags, _("Manifest tags")
end
end
build_options do |o|
o.expand(:all).including(:flatpak_remotes, :organizations)
end
end

class MirrorCommand < HammerCLIKatello::SingleResourceCommand
include HammerCLIForemanTasks::Async

action :mirror
command_name 'mirror'

success_message _("Flatpak remote repository is being mirrored to product in task %<id>s.")
failure_message _('Could not mirror the Flatpak remote repository')

build_options
end

autoload_subcommands
end
end
2 changes: 1 addition & 1 deletion test/data/4.14/foreman_api.json

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions test/functional/flatpak_remote/create_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require File.join(File.dirname(__FILE__), '../test_helper')

describe 'create flatpak remote' do
before do
@cmd = %w(flatpak-remote create)
end

let(:remote_name) { 'pizza' }
let(:url) { 'http://proxy.example.com' }
let(:organization_id) { 1 }

it 'Creates a flatpak remote' do
params = ["--name=#{remote_name}", "--url=#{url}",
"--organization-id=#{organization_id}"]

api_expects(:flatpak_remotes, :create, 'Create a Flatpak remote')

expected_result = success_result("Flatpak Remote created.\n")
result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end

it 'Creates a flatpak remote ' do
params = ["--name=#{remote_name}", "--url=#{url}",
"--organization-id=#{organization_id}"]

api_expects(:flatpak_remotes, :create, 'Create a Flatpak remote')

expected_result = success_result("Flatpak Remote created.\n")
result = run_cmd(@cmd + params)
assert_cmd(expected_result, result)
end
end

0 comments on commit f250881

Please sign in to comment.