-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #38019 - Add hammer support for flatpak remotes
- Loading branch information
Showing
10 changed files
with
334 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
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') | ||
collection :organization, _('Organization') do | ||
field :id, _('Id') | ||
field :name, _('Name') | ||
field :label, _('Label') | ||
end | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
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 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require File.join(File.dirname(__FILE__), '../test_helper') | ||
|
||
describe 'delete a flatpak remote' do | ||
let(:id) { 1 } | ||
|
||
it 'by id' do | ||
api_expects(:flatpak_remotes, :destroy, 'delete acs'). | ||
with_params('id' => id) | ||
|
||
command = %W(flatpak-remote delete --id #{id}) | ||
assert_equal(0, run_cmd(command).exit_code) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
require File.join(File.dirname(__FILE__), '../test_helper') | ||
|
||
describe 'get flatpak remote info' do | ||
before do | ||
@cmd = %w(flatpak-remote info) | ||
end | ||
|
||
it 'shows flatpak remote info by id' do | ||
params = ['--id=12'] | ||
ex = api_expects(:flatpak_remotes, :show, 'Get info') | ||
ex.returns( | ||
'id' => 12, | ||
'name' => 'Fedora flatpak', | ||
'url' => 'https://registry.fedoraproject.org/', | ||
'username' => nil, | ||
'token' => nil, | ||
'seeded' => true, | ||
'organization_id' => 1, | ||
'registry_url' => 'https://registry.fedoraproject.org/', | ||
'organization' => { | ||
'id' => 1, | ||
'name' => 'Default Organization', | ||
'label' => 'Default_Organization' | ||
} | ||
) | ||
result = run_cmd(@cmd + params) | ||
expected_fields = [['ID', '12'], | ||
['Name', 'Fedora flatpak'], | ||
['URL', 'https://registry.fedoraproject.org/'], | ||
['Registry URL', 'https://registry.fedoraproject.org/'], | ||
['Organization', ''], | ||
['Id', '1'], | ||
['Name', 'Default Organization'], | ||
['Label', 'Default_Organization'], | ||
] | ||
|
||
expected_results = expected_fields.map { |field| success_result(FieldMatcher.new(*field)) } | ||
expected_results.each { |expected| assert_cmd(expected, result) } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
require File.join(File.dirname(__FILE__), '../test_helper') | ||
|
||
describe 'listing flatpak remotes' do | ||
before do | ||
@cmd = %w(flatpak-remote list) | ||
end | ||
|
||
let(:empty_response) do | ||
{ | ||
"total" => 0, | ||
"subtotal" => 0, | ||
"page" => "1", | ||
"per_page" => "1000", | ||
"error" => nil, | ||
"search" => nil, | ||
"sort" => { | ||
"by" => nil, | ||
"order" => nil | ||
}, | ||
"results" => [] | ||
} | ||
end | ||
|
||
let(:flatpak_response) do | ||
{ | ||
'id' => 1, | ||
'name' => 'Fedora flatpak', | ||
'url' => 'https://registry.fedoraproject.org/', | ||
'organization_id' => 1, | ||
'username' => nil, | ||
'token' => nil, | ||
} | ||
end | ||
|
||
it "lists acs and returns empty response" do | ||
ex = api_expects(:flatpak_remotes, :index, 'flatpak list') do |par| | ||
par['page'] == 1 && par['per_page'] == 1000 | ||
end | ||
|
||
ex.returns(empty_response) | ||
|
||
expected_result = success_result("---|------|-----|-------------|------|-------|------------- | ||
ID | NAME | URL | DESCRIPTION | USER | TOKEN | REGISTRY URL | ||
---|------|-----|-------------|------|-------|------------- | ||
") | ||
|
||
result = run_cmd(@cmd) | ||
assert_cmd(expected_result, result) | ||
end | ||
|
||
it "lists acs and returns response" do | ||
ex = api_expects(:flatpak_remotes, :index, 'flatpak list') do |par| | ||
par['page'] == 1 && par['per_page'] == 1000 | ||
end | ||
|
||
ex.returns(flatpak_response) | ||
# rubocop:disable Layout/LineLength | ||
expected_result = success_result("1 | Fedora flatpak | https://registry.fedoraproject.org/ | | | ||
---|----------------|-------------------------------------|------|------\n") | ||
# rubocop:enable Layout/LineLength | ||
result = run_cmd(@cmd) | ||
assert_cmd(expected_result, result) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
require File.join(File.dirname(__FILE__), '../test_helper') | ||
|
||
describe 'Scan a flatpak remote' do | ||
include ForemanTaskHelpers | ||
|
||
before do | ||
@cmd = %w(flatpak-remote scan) | ||
end | ||
|
||
let(:org_id) { 1 } | ||
let(:remote_id) { 1 } | ||
let(:task_id) { 3 } | ||
let(:scan_response) do | ||
{ | ||
'id' => remote_id.to_s, | ||
'state' => 'planned' | ||
} | ||
end | ||
|
||
it "scans a repository" do | ||
params = ["--id=#{remote_id}"] | ||
|
||
ex = api_expects(:flatpak_remotes, :scan, 'Remote is scanned') do |par| | ||
par['id'] == remote_id | ||
end | ||
|
||
ex.returns(scan_response) | ||
|
||
expect_foreman_task(task_id) | ||
|
||
result = run_cmd(@cmd + params) | ||
assert_equal(result.exit_code, 0) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require File.join(File.dirname(__FILE__), '../test_helper') | ||
|
||
describe 'Updating flatpak remotes' do | ||
before do | ||
@cmd = %w(flatpak-remote update) | ||
end | ||
|
||
let(:id) { 1 } | ||
let(:desc) { 'A flatpak remote for Fedora registry' } | ||
|
||
it 'updates flatpak remote' do | ||
params = ["--id=#{id}", "--description=#{desc}"] | ||
|
||
ex = api_expects(:flatpak_remotes, :update, 'flatpak remote update') do |par| | ||
par['id'] == 1 && par['description'] == 'A flatpak remote for Fedora registry' | ||
end | ||
|
||
ex.returns({}) | ||
|
||
result = run_cmd(@cmd + params) | ||
assert_equal(result.exit_code, 0) | ||
end | ||
end |