From: Michael Tremer Date: Tue, 28 Jan 2025 15:23:44 +0000 (+0000) Subject: buildservice: Simplify how it is being initialized X-Git-Tag: 0.9.30~317 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=950dac5a54050ec836b4a78e2409b2d1d831bd3c;p=pakfire.git buildservice: Simplify how it is being initialized This make this all more re-usable in other places. Signed-off-by: Michael Tremer --- diff --git a/src/cli/lib/client-build.c b/src/cli/lib/client-build.c index e6e98217..d56d1fc1 100644 --- a/src/cli/lib/client-build.c +++ b/src/cli/lib/client-build.c @@ -110,8 +110,8 @@ int cli_client_build(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // Upload all packages diff --git a/src/cli/lib/pakfire.c b/src/cli/lib/pakfire.c index 2764cac6..19e66d41 100644 --- a/src/cli/lib/pakfire.c +++ b/src/cli/lib/pakfire.c @@ -22,6 +22,7 @@ #include #include +#include #include #include #include @@ -138,3 +139,30 @@ ERROR: return r; } + +int cli_setup_buildservice(struct pakfire_buildservice** service, struct cli_global_args* args) { + struct pakfire_config* config = NULL; + const char* url = NULL; + int r; + + // Setup the configuration + r = cli_setup_config(&config, args); + if (r < 0) + goto ERROR; + + // Fetch the URL + url = pakfire_config_get(config, "client", "url", "https://pakfire.ipfire.org/"); + + // Connect to the build service + r = pakfire_buildservice_create(service, args->ctx, url); + if (r < 0) { + fprintf(stderr, "Could not setup the build service: %s\n", strerror(-r)); + goto ERROR; + } + +ERROR: + if (config) + pakfire_config_unref(config); + + return r; +} diff --git a/src/cli/lib/pakfire.h b/src/cli/lib/pakfire.h index 47fef8ce..4dc2cc0d 100644 --- a/src/cli/lib/pakfire.h +++ b/src/cli/lib/pakfire.h @@ -22,6 +22,7 @@ #define PAKFIRE_CLI_PAKFIRE_H #include +#include #include #include #include @@ -48,5 +49,6 @@ struct cli_global_args { int cli_setup_config(struct pakfire_config** config, struct cli_global_args* args); int cli_setup_pakfire(struct pakfire** pakfire, struct cli_global_args* args); int cli_setup_build(struct pakfire_build** build, struct cli_global_args* args, int flags); +int cli_setup_buildservice(struct pakfire_buildservice** service, struct cli_global_args* args); #endif /* PAKFIRE_CLI_PAKFIRE_H */ diff --git a/src/cli/lib/repo_create.c b/src/cli/lib/repo_create.c index ba270f57..c1e46cbc 100644 --- a/src/cli/lib/repo_create.c +++ b/src/cli/lib/repo_create.c @@ -86,8 +86,8 @@ int cli_repo_create(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // List repos diff --git a/src/cli/lib/repo_delete.c b/src/cli/lib/repo_delete.c index 3ad30425..c5eda6cc 100644 --- a/src/cli/lib/repo_delete.c +++ b/src/cli/lib/repo_delete.c @@ -73,8 +73,8 @@ int cli_repo_delete(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // Delete the repository diff --git a/src/cli/lib/repo_list.c b/src/cli/lib/repo_list.c index f3b40e63..8f750042 100644 --- a/src/cli/lib/repo_list.c +++ b/src/cli/lib/repo_list.c @@ -65,8 +65,8 @@ int cli_repo_list(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // List repos diff --git a/src/cli/lib/repo_show.c b/src/cli/lib/repo_show.c index e7794db3..c92a543c 100644 --- a/src/cli/lib/repo_show.c +++ b/src/cli/lib/repo_show.c @@ -71,8 +71,8 @@ int cli_repo_show(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // List repos diff --git a/src/cli/lib/upload_create.c b/src/cli/lib/upload_create.c index 04a7cef5..4df2360d 100644 --- a/src/cli/lib/upload_create.c +++ b/src/cli/lib/upload_create.c @@ -68,8 +68,8 @@ int cli_upload_create(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // List uploads diff --git a/src/cli/lib/upload_delete.c b/src/cli/lib/upload_delete.c index b019ff2c..5101729a 100644 --- a/src/cli/lib/upload_delete.c +++ b/src/cli/lib/upload_delete.c @@ -72,8 +72,8 @@ int cli_upload_delete(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // Delete uploads diff --git a/src/cli/lib/upload_list.c b/src/cli/lib/upload_list.c index 4ca7a7ce..ccebc9dd 100644 --- a/src/cli/lib/upload_list.c +++ b/src/cli/lib/upload_list.c @@ -41,8 +41,8 @@ int cli_upload_list(void* data, int argc, char* argv[]) { goto ERROR; // Connect to the build service - r = pakfire_buildservice_create(&service, global_args->ctx); - if (r) + r = cli_setup_buildservice(&service, global_args); + if (r < 0) goto ERROR; // List uploads diff --git a/src/pakfire/buildservice.c b/src/pakfire/buildservice.c index 3729699c..be53e78e 100644 --- a/src/pakfire/buildservice.c +++ b/src/pakfire/buildservice.c @@ -103,52 +103,6 @@ ERROR: return r; } -static int pakfire_buildservice_setup(struct pakfire_buildservice* service) { - struct pakfire_config* config = NULL; - const char* url = NULL; - const char* keytab = NULL; - int r; - - // Fetch the configuration - config = pakfire_ctx_get_config(service->ctx); - if (!config) { - r = 1; - goto ERROR; - } - - // Fetch the URL - url = pakfire_config_get(config, "client", "url", NULL); - if (!url) { - ERROR(service->ctx, "Build Service URL is not configured\n"); - r = 1; - goto ERROR; - } - - // Store the URL - r = pakfire_string_set(service->url, url); - if (r < 0) - goto ERROR; - - // Fetch the keytab - keytab = pakfire_config_get(config, "client", "keytab", DEFAULT_KEYTAB); - - // Store the keytab - r = pakfire_string_set(service->keytab, keytab); - if (r) - goto ERROR; - - // Setup authentication - r = pakfire_buildservice_setup_auth(service); - if (r) - goto ERROR; - -ERROR: - if (config) - pakfire_config_unref(config); - - return r; -} - static void pakfire_buildservice_free(struct pakfire_buildservice* service) { if (service->krb5_ctx) krb5_free_context(service->krb5_ctx); @@ -159,7 +113,7 @@ static void pakfire_buildservice_free(struct pakfire_buildservice* service) { } int pakfire_buildservice_create( - struct pakfire_buildservice** service, struct pakfire_ctx* ctx) { + struct pakfire_buildservice** service, struct pakfire_ctx* ctx, const char* url) { struct pakfire_buildservice* s = NULL; int r; @@ -174,13 +128,13 @@ int pakfire_buildservice_create( // Initialize the reference counter s->nrefs = 1; - // Setup everything - r = pakfire_buildservice_setup(s); - if (r) + // Store the URL + r = pakfire_string_set(s->url, url); + if (r < 0) goto ERROR; - DEBUG(s->ctx, - "Pakfire Build Service initialized for %s\n", pakfire_buildservice_get_url(s)); + DEBUG(s->ctx, "Pakfire Build Service initialized for %s\n", + pakfire_buildservice_get_url(s)); // Return the pointer *service = s; diff --git a/src/pakfire/buildservice.h b/src/pakfire/buildservice.h index 9b71863d..06fe4c77 100644 --- a/src/pakfire/buildservice.h +++ b/src/pakfire/buildservice.h @@ -28,7 +28,7 @@ struct pakfire_buildservice; #include int pakfire_buildservice_create(struct pakfire_buildservice** service, - struct pakfire_ctx* ctx); + struct pakfire_ctx* ctx, const char* url); struct pakfire_buildservice* pakfire_buildservice_ref(struct pakfire_buildservice* service); struct pakfire_buildservice* pakfire_buildservice_unref(struct pakfire_buildservice* service);