]> git.ipfire.org Git - pakfire.git/commitdiff
buildservice: Implement listing repositories
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 13:12:34 +0000 (13:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 20 Oct 2023 13:12:34 +0000 (13:12 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
Makefile.am
src/cli/lib/repo.c
src/cli/lib/repo.h
src/cli/lib/repo_list.c [new file with mode: 0644]
src/cli/lib/repo_list.h [new file with mode: 0644]
src/cli/pakfire-client.c
src/libpakfire/buildservice.c
src/libpakfire/include/pakfire/buildservice.h

index a98ec3f56cfb582ce2eb6ec51bf1fcbf917cccf0..1fe3ae71daee230a1135351069449b903bea0b57 100644 (file)
@@ -497,6 +497,8 @@ libcli_la_SOURCES = \
        src/cli/lib/repo.h \
        src/cli/lib/repo_compose.c \
        src/cli/lib/repo_compose.h \
+       src/cli/lib/repo_list.c \
+       src/cli/lib/repo_list.h \
        src/cli/lib/repolist.c \
        src/cli/lib/repolist.h \
        src/cli/lib/requires.c \
index 71cb1b83992471c97a4fccda124bcfe211dc256b..a0c6839646f641d77822c5008889e762dbfddddc 100644 (file)
@@ -21,6 +21,7 @@
 #include "command.h"
 #include "repo.h"
 #include "repo_compose.h"
+#include "repo_list.h"
 
 int cli_repo(void* data, int argc, char* argv[]) {
        static const struct command commands[] = {
@@ -30,3 +31,12 @@ int cli_repo(void* data, int argc, char* argv[]) {
 
        return cli_parse(NULL, commands, NULL, NULL, NULL, argc, argv, data);
 }
+
+int cli_repo_client(void* data, int argc, char* argv[]) {
+       static const struct command commands[] = {
+               { "list", cli_repo_list, 0, 0, 0 },
+               { NULL },
+       };
+
+       return cli_parse(NULL, commands, NULL, NULL, NULL, argc, argv, data);
+}
index b97cab8c5ebc9ff98fcd60f348d7e00f070d1711..5dc684423bd4e1a368aa84f9d470eca25b2c40b2 100644 (file)
@@ -23,4 +23,6 @@
 
 int cli_repo(void* data, int argc, char* argv[]);
 
+int cli_repo_client(void* data, int argc, char* argv[]);
+
 #endif /* PAKFIRE_CLI_REPO_H */
diff --git a/src/cli/lib/repo_list.c b/src/cli/lib/repo_list.c
new file mode 100644 (file)
index 0000000..091e461
--- /dev/null
@@ -0,0 +1,66 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program 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 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#include <json.h>
+
+#include <pakfire/buildservice.h>
+
+#include "command.h"
+#include "dump.h"
+#include "pakfire.h"
+#include "repo_list.h"
+
+static const char* doc = "Lists all repositories";
+
+int cli_repo_list(void* data, int argc, char* argv[]) {
+       struct pakfire_buildservice* service = NULL;
+       struct json_object* repos = NULL;
+       int r;
+
+       struct cli_config* cli_config = data;
+
+       // Parse the command line
+       r = cli_parse(NULL, NULL, NULL, doc, NULL, argc, argv, NULL);
+       if (r)
+               goto ERROR;
+
+       // Connect to the build service
+       r = pakfire_buildservice_create(&service, cli_config->ctx);
+       if (r)
+               goto ERROR;
+
+       // List repos
+       r = pakfire_buildservice_list_repos(service, cli_config->distro, &repos);
+       if (r)
+               goto ERROR;
+
+       // Dump everything
+       r = cli_dump_json(repos);
+       if (r)
+               goto ERROR;
+
+ERROR:
+       if (service)
+               pakfire_buildservice_unref(service);
+       if (repos)
+               json_object_put(repos);
+
+       return r;
+}
diff --git a/src/cli/lib/repo_list.h b/src/cli/lib/repo_list.h
new file mode 100644 (file)
index 0000000..a035417
--- /dev/null
@@ -0,0 +1,26 @@
+/*#############################################################################
+#                                                                             #
+# Pakfire - The IPFire package management system                              #
+# Copyright (C) 2023 Pakfire development team                                 #
+#                                                                             #
+# This program 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 3 of the License, or           #
+# (at your option) any later version.                                         #
+#                                                                             #
+# This program 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 this program.  If not, see <http://www.gnu.org/licenses/>.       #
+#                                                                             #
+#############################################################################*/
+
+#ifndef PAKFIRE_CLI_REPO_LIST_H
+#define PAKFIRE_CLI_REPO_LIST_H
+
+int cli_repo_list(void* data, int argc, char* argv[]);
+
+#endif /* PAKFIRE_CLI_REPO_LIST_H */
index 06f1533d757888816414cd42e93d010365e7476e..934cc419a8a210c49569954bfec0fc44f9281270 100644 (file)
 #include "lib/config.h"
 #include "lib/pakfire.h"
 #include "lib/progressbar.h"
+#include "lib/repo.h"
 #include "lib/upload.h"
 
 const char* argp_program_version = PACKAGE_VERSION;
 
 static const struct command commands[] = {
        { "build",  cli_client_build, 1, -1, 0 },
+       { "repo",   cli_repo_client, -1, -1, 0 },
        { "upload", cli_upload,      -1, -1, 0 },
        { NULL },
 };
 
 static const char* args_doc =
+       "repo ...\n"
        "upload ...";
 
 static const char* doc = "The Pakfire Build Service Client Tool";
index a0c5d8ff1f3fb090f9c6ec2a759b33c60f89a5b0..09bf12e1eb1f6d8fa030a97b281142968987df46 100644 (file)
@@ -710,3 +710,72 @@ ERROR:
 
        return r;
 }
+
+// Repositories
+
+PAKFIRE_EXPORT int pakfire_buildservice_list_repos(struct pakfire_buildservice* service,
+               const char* distro, struct json_object** p) {
+       struct pakfire_transfer* transfer = NULL;
+       struct json_object* response = NULL;
+       struct json_object* repos = NULL;
+       char url[PATH_MAX];
+       char* buffer = NULL;
+       size_t length = 0;
+       int r;
+
+       // Check inputs
+       if (!distro)
+               return -EINVAL;
+
+       // Compose path
+       r = pakfire_string_format(url, "/api/v1/repos/%s", distro);
+       if (r)
+               goto ERROR;
+
+       // Create a new transfer
+       r = pakfire_buildservice_create_transfer(&transfer, service, url);
+       if (r)
+               goto ERROR;
+
+       // Enable authentication
+       r = pakfire_downloader_transfer_auth(transfer);
+       if (r)
+               goto ERROR;
+
+       // Write the response to the buffer
+       r = pakfire_downloader_transfer_set_output_buffer(transfer, &buffer, &length);
+       if (r)
+               goto ERROR;
+
+       // Run the transfer
+       r = pakfire_downloader_transfer_run(transfer, PAKFIRE_TRANSFER_NO_PROGRESS);
+       if (r)
+               goto ERROR;
+
+       // Parse the response
+       r = pakfire_buildservice_parse_response(service, transfer, buffer, length, &response);
+       if (r) {
+               CTX_ERROR(service->ctx, "Could not parse the response: %s\n", strerror(-r));
+               goto ERROR;
+       }
+
+       // Fetch the repos
+       if (!json_object_object_get_ex(response, "repos", &repos)) {
+               CTX_ERROR(service->ctx, "Malformed response\n");
+               r = -EBADMSG;
+               goto ERROR;
+       }
+
+       // Return the pointer
+       *p = json_object_get(repos);
+
+ERROR:
+       if (transfer)
+               pakfire_downloader_transfer_unref(transfer);
+       if (response)
+               json_object_put(response);
+       if (buffer)
+               free(buffer);
+
+       return r;
+}
index b134877ea71ad3a0d1827cc1469939b20c605737..0f370a4ee040016c46cc50708c46280fbce71d12 100644 (file)
@@ -50,4 +50,9 @@ int pakfire_buildservice_list_uploads(
 int pakfire_buildservice_delete_upload(
        struct pakfire_buildservice* service, const char* uuid);
 
+// Repositories
+
+int pakfire_buildservice_list_repos(struct pakfire_buildservice* service,
+       const char* distro, struct json_object** repos);
+
 #endif /* PAKFIRE_BUILDSERVICE_H */