Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnf5daemon: Introduce enabling repositories in Repo interface #1266

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions dnf5daemon-client/commands/repo/repo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
Copyright Contributors to the libdnf project.

This file is part of libdnf: https://github.com/rpm-software-management/libdnf/

Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "repo.hpp"

#include "repo_disable.hpp"
#include "repo_enable.hpp"

namespace dnfdaemon::client {

void RepoCommand::set_parent_command() {
auto * arg_parser_parent_cmd = get_session().get_argument_parser().get_root_command();
auto * arg_parser_this_cmd = get_argument_parser_command();
arg_parser_parent_cmd->register_command(arg_parser_this_cmd);
arg_parser_parent_cmd->get_group("subcommands").register_argument(arg_parser_this_cmd);
}

void RepoCommand::set_argument_parser() {
get_argument_parser_command()->set_description("Manage repositories");
}

void RepoCommand::register_subcommands() {
auto * config_commands_repo = get_context().get_argument_parser().add_new_group("repo_config_commands");
config_commands_repo->set_header("Configuration Commands:");
get_argument_parser_command()->register_group(config_commands_repo);
register_subcommand(std::make_unique<RepoEnableCommand>(get_context()), config_commands_repo);
register_subcommand(std::make_unique<RepoDisableCommand>(get_context()), config_commands_repo);
}

void RepoCommand::pre_configure() {
throw_missing_command();
}

} // namespace dnfdaemon::client
40 changes: 40 additions & 0 deletions dnf5daemon-client/commands/repo/repo.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright Contributors to the libdnf project.

This file is part of libdnf: https://github.com/rpm-software-management/libdnf/

Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_REPO_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_REPO_HPP

#include "commands/command.hpp"
#include "context.hpp"

namespace dnfdaemon::client {

class RepoCommand : public DaemonCommand {
public:
explicit RepoCommand(Context & context) : DaemonCommand(context, "repo") {}
void set_parent_command() override;
void set_argument_parser() override;
void register_subcommands() override;
void pre_configure() override;
};

} // namespace dnfdaemon::client


#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_REPO_HPP
35 changes: 35 additions & 0 deletions dnf5daemon-client/commands/repo/repo_disable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright Contributors to the libdnf project.

This file is part of libdnf: https://github.com/rpm-software-management/libdnf/

Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_DISABLE_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_DISABLE_HPP

#include "commands/command.hpp"
#include "repo_enable_disable.hpp"

namespace dnfdaemon::client {

class RepoDisableCommand : public RepoEnableDisableCommand {
public:
explicit RepoDisableCommand(Context & context) : RepoEnableDisableCommand(context, "disable") {}
};

} // namespace dnfdaemon::client

#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_DISABLE_HPP
35 changes: 35 additions & 0 deletions dnf5daemon-client/commands/repo/repo_enable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
Copyright Contributors to the libdnf project.

This file is part of libdnf: https://github.com/rpm-software-management/libdnf/

Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_HPP

#include "commands/command.hpp"
#include "repo_enable_disable.hpp"

namespace dnfdaemon::client {

class RepoEnableCommand : public RepoEnableDisableCommand {
public:
explicit RepoEnableCommand(Context & context) : RepoEnableDisableCommand(context, "enable") {}
};

} // namespace dnfdaemon::client

#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_HPP
62 changes: 62 additions & 0 deletions dnf5daemon-client/commands/repo/repo_enable_disable.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copyright Contributors to the libdnf project.

This file is part of libdnf: https://github.com/rpm-software-management/libdnf/

Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#include "repo_enable_disable.hpp"

#include <fmt/format.h>

namespace dnfdaemon::client {

using namespace libdnf5::cli;

void RepoEnableDisableCommand::set_argument_parser() {
auto & parser = get_context().get_argument_parser();
auto & cmd = *get_argument_parser_command();

patterns_options = parser.add_new_values();
auto repos = parser.add_new_positional_arg(
"repo_ids",
libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED,
parser.add_init_value(std::unique_ptr<libdnf5::Option>(new libdnf5::OptionString(nullptr))),
patterns_options);

repos->set_description(fmt::format("List of repos to be {}d", command));
cmd.set_description(fmt::format("{} given repositories", command));
cmd.register_positional_arg(repos);
}

void RepoEnableDisableCommand::run() {
auto & ctx = get_context();

std::vector<std::string> patterns;
if (!patterns_options->empty()) {
patterns.reserve(patterns_options->size());
for (auto & pattern : *patterns_options) {
auto option = dynamic_cast<libdnf5::OptionString *>(pattern.get());
patterns.emplace_back(option->get_value());
}
}

ctx.session_proxy->callMethod(command)
.onInterface(dnfdaemon::INTERFACE_REPO)
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(patterns);
}

} // namespace dnfdaemon::client
42 changes: 42 additions & 0 deletions dnf5daemon-client/commands/repo/repo_enable_disable.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright Contributors to the libdnf project.

This file is part of libdnf: https://github.com/rpm-software-management/libdnf/

Libdnf is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.

Libdnf is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/

#ifndef DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_DISABLE_HPP
#define DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_DISABLE_HPP

#include "commands/command.hpp"

namespace dnfdaemon::client {

class RepoEnableDisableCommand : public DaemonCommand {
public:
explicit RepoEnableDisableCommand(Context & context, const std::string & command)
: DaemonCommand(context, command),
command(command) {}
void set_argument_parser() override;
void run() override;

private:
std::vector<std::unique_ptr<libdnf5::Option>> * patterns_options{nullptr};
const std::string command;
};

} // namespace dnfdaemon::client

#endif // DNF5DAEMON_CLIENT_COMMANDS_REPO_ENABLE_DISABLE_HPP
3 changes: 3 additions & 0 deletions dnf5daemon-client/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
#include "commands/install/install.hpp"
#include "commands/reinstall/reinstall.hpp"
#include "commands/remove/remove.hpp"
#include "commands/repo/repo.hpp"
#include "commands/repolist/repolist.hpp"
#include "commands/repoquery/repoquery.hpp"
#include "commands/upgrade/upgrade.hpp"
Expand Down Expand Up @@ -202,6 +203,8 @@ static void add_commands(Context & context) {

context.add_and_initialize_command(std::make_unique<GroupCommand>(context));

context.add_and_initialize_command(std::make_unique<RepoCommand>(context));

context.add_and_initialize_command(std::make_unique<RepolistCommand>(context, "repolist"));
context.add_and_initialize_command(std::make_unique<RepolistCommand>(context, "repoinfo"));

Expand Down
6 changes: 3 additions & 3 deletions dnf5daemon-server/dbus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ const char * const DBUS_OBJECT_PATH = "/org/rpm/dnf/v0";
// interfaces
const char * const INTERFACE_BASE = "org.rpm.dnf.v0.Base";
const char * const INTERFACE_REPO = "org.rpm.dnf.v0.rpm.Repo";
const char * const INTERFACE_REPOCONF = "org.rpm.dnf.v0.rpm.RepoConf";
const char * const INTERFACE_RPM = "org.rpm.dnf.v0.rpm.Rpm";
const char * const INTERFACE_GOAL = "org.rpm.dnf.v0.Goal";
const char * const INTERFACE_GROUP = "org.rpm.dnf.v0.comps.Group";
Expand Down Expand Up @@ -87,14 +86,15 @@ const char * const SIGNAL_TRANSACTION_ELEM_PROGRESS = "transaction_elem_progress
const char * const SIGNAL_TRANSACTION_FINISHED = "transaction_finished";

// polkit actions
const char * const POLKIT_REPOCONF_WRITE = "org.rpm.dnf.v0.rpm.RepoConf.write";
const char * const POLKIT_REPOCONF_WRITE = "org.rpm.dnf.v0.rpm.Repo.conf_write";
const char * const POLKIT_EXECUTE_RPM_TRANSACTION = "org.rpm.dnf.v0.rpm.execute_transaction";
const char * const POLKIT_CONFIRM_KEY_IMPORT = "org.rpm.dnf.v0.rpm.Repo.confirm_key";
const char * const POLKIT_CONFIG_OVERRIDE = "org.rpm.dnf.v0.base.Config.override";

// errors
const char * const ERROR = "org.rpm.dnf.v0.Error";
const char * const ERROR_REPOCONF = "org.rpm.dnf.v0.rpm.RepoConf.Error";
const char * const ERROR_REPOCONF = "org.rpm.dnf.v0.rpm.Repo.ConfError";
const char * const ERROR_REPO_ID_UNKNOWN = "org.rpm.dnf.v0.rpm.Repo.NoMatchingIdError";
const char * const ERROR_RESOLVE = "org.rpm.dnf.v0.rpm.Rpm.ResolveError";
const char * const ERROR_TRANSACTION = "org.rpm.dnf.v0.rpm.Rpm.TransactionError";

Expand Down
20 changes: 20 additions & 0 deletions dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.rpm.Repo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,26 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
<arg name="confirmed" type="b" direction="in"/>
</method>

<!--
enable:
@ids: array of strings containing all repo ids to be enabled

Enable repositories based on the list of given ids.
-->
<method name="enable">
<arg name="ids" type="as" direction="in"/>
</method>

<!--
disable:
@ids: array of strings containing all repo ids to be disabled

Disable repositories based on the list of given ids.
-->
<method name="disable">
<arg name="ids" type="as" direction="in"/>
</method>

</interface>

</node>
2 changes: 1 addition & 1 deletion dnf5daemon-server/polkit/org.rpm.dnf.v0.policy
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<vendor>Dnf</vendor>
<vendor_url>https://github.com/rpm-software-management/libdnf/</vendor_url>

<action id="org.rpm.dnf.v0.rpm.RepoConf.write">
<action id="org.rpm.dnf.v0.rpm.Repo.conf_write">
<description>Write repository configuration file</description>
<message>Writing changes to repository configuration file requires authentication.</message>
<defaults>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
*/


#ifndef DNF5DAEMON_SERVER_SERVICES_REPOCONF_CONFIGURATION_HPP
#define DNF5DAEMON_SERVER_SERVICES_REPOCONF_CONFIGURATION_HPP
#ifndef DNF5DAEMON_SERVER_SERVICES_REPO_CONFIGURATION_HPP
#define DNF5DAEMON_SERVER_SERVICES_REPO_CONFIGURATION_HPP

#include "session.hpp"

Expand Down
Loading
Loading