From aec06b39452539fb894c4b222c980763642066e8 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Wed, 26 Feb 2020 14:07:48 -0700 Subject: [PATCH] Support passing --token-type to build-export Provide a --token-type command line option and a token-type manifest property that allows passing the token type to build-export. The manifest property takes precendence over the CLI option. In either case, the value will be passed to build-export if it's >= 0. This requires flatpak >= 1.6 to use the --token-type option in build-export. --- doc/flatpak-builder.xml | 13 +++++++++++++ doc/flatpak-manifest.xml | 7 +++++++ src/builder-main.c | 28 +++++++++++++++++++++++++++- src/builder-manifest.c | 35 +++++++++++++++++++++++++++++++++++ src/builder-manifest.h | 3 +++ tests/test.json | 1 + tests/test.yaml | 1 + 7 files changed, 87 insertions(+), 1 deletion(-) diff --git a/doc/flatpak-builder.xml b/doc/flatpak-builder.xml index 1e09e82d..2c8cdf4b 100644 --- a/doc/flatpak-builder.xml +++ b/doc/flatpak-builder.xml @@ -428,6 +428,19 @@ + + + + + Set type of token needed to install this commit. + Setting this to a value greater than 0 implies that + authentication will be needed to install the + flatpak. A property set + in the manifest takes precedence over this option. + Used when exporting the build results. + + + diff --git a/doc/flatpak-manifest.xml b/doc/flatpak-manifest.xml index 1457ae6f..7d53fa5c 100644 --- a/doc/flatpak-manifest.xml +++ b/doc/flatpak-manifest.xml @@ -101,6 +101,13 @@ locations for the same extension point defined with different tags then an error will occur. + + (integer) + The type of token needed to install + this commit. Setting this to a value greater than 0 + implies that authentication will be needed to + install the flatpak. + (string) The name of the runtime that the application uses. diff --git a/src/builder-main.c b/src/builder-main.c index a5f66015..f8c53b89 100644 --- a/src/builder-main.c +++ b/src/builder-main.c @@ -71,6 +71,7 @@ static char *opt_repo; static char *opt_subject; static char *opt_body; static char *opt_collection_id = NULL; +static int opt_token_type = -1; static char *opt_gpg_homedir; static char **opt_key_ids; static char **opt_sources_dirs; @@ -118,6 +119,7 @@ static GOptionEntry entries[] = { { "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject (passed to build-export)", "SUBJECT" }, { "body", 'b', 0, G_OPTION_ARG_STRING, &opt_body, "Full description (passed to build-export)", "BODY" }, { "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, "Collection ID (passed to build-export)", "COLLECTION-ID" }, + { "token-type", 0, 0, G_OPTION_ARG_INT, &opt_token_type, "Set type of token needed to install this commit (passed to build-export)", "VAL" }, { "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"}, { "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"}, { "force-clean", 0, 0, G_OPTION_ARG_NONE, &opt_force_clean, "Erase previous contents of DIRECTORY", NULL }, @@ -199,6 +201,7 @@ do_export (BuilderContext *build_context, char **exclude_dirs, const gchar *branch, const gchar *collection_id, + gint32 token_type, ...) { va_list ap; @@ -231,8 +234,11 @@ do_export (BuilderContext *build_context, if (collection_id) g_ptr_array_add (args, g_strdup_printf ("--collection-id=%s", collection_id)); + if (token_type >= 0) + g_ptr_array_add (args, g_strdup_printf ("--token-type=%d", token_type)); + /* Additional flags. */ - va_start (ap, collection_id); + va_start (ap, token_type); while ((arg = va_arg (ap, const gchar *))) if (arg != skip_arg) g_ptr_array_add (args, g_strdup ((gchar *) arg)); @@ -501,6 +507,16 @@ main (int argc, return 1; } + if (opt_token_type < -1 +#if G_MAXINT > 0x7fffffff + || opt_token_type > G_MAXINT32 +#endif + ) + { + g_printerr ("--token-type value must be a 32 bit integer >= 0\n"); + return 1; + } + if (app_dir_path) app_dir = g_file_new_for_path (app_dir_path); cwd = g_get_current_dir (); @@ -669,6 +685,9 @@ main (int argc, if (opt_collection_id) builder_manifest_set_default_collection_id (manifest, opt_collection_id); + if (opt_token_type >= 0) + builder_manifest_set_default_token_type (manifest, (gint32)opt_token_type); + if (is_run && argc == 3) return usage (context, "Program to run must be specified"); @@ -993,6 +1012,7 @@ main (int argc, flatpak_file_get_path_cached (export_repo), app_dir_path, exclude_dirs, builder_manifest_get_branch (manifest, build_context), builder_manifest_get_collection_id (manifest), + builder_manifest_get_token_type (manifest), "--exclude=/lib/debug/*", "--include=/lib/debug/app", builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg, @@ -1027,6 +1047,7 @@ main (int argc, flatpak_file_get_path_cached (export_repo), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context), builder_manifest_get_collection_id (manifest), + builder_manifest_get_token_type (manifest), metadata_arg, files_arg, NULL)) @@ -1047,6 +1068,7 @@ main (int argc, flatpak_file_get_path_cached (export_repo), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context), builder_manifest_get_collection_id (manifest), + builder_manifest_get_token_type (manifest), "--metadata=metadata.debuginfo", builder_context_get_build_runtime (build_context) ? "--files=usr/lib/debug" : "--files=files/lib/debug", NULL)) @@ -1078,6 +1100,7 @@ main (int argc, flatpak_file_get_path_cached (export_repo), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context), builder_manifest_get_collection_id (manifest), + builder_manifest_get_token_type (manifest), metadata_arg, files_arg, NULL)) { @@ -1097,6 +1120,7 @@ main (int argc, flatpak_file_get_path_cached (export_repo), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context), builder_manifest_get_collection_id (manifest), + builder_manifest_get_token_type (manifest), "--metadata=metadata.sources", "--files=sources", NULL)) @@ -1117,6 +1141,7 @@ main (int argc, flatpak_file_get_path_cached (export_repo), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context), builder_manifest_get_collection_id (manifest), + builder_manifest_get_token_type (manifest), "--metadata=metadata.platform", "--files=platform", builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg, @@ -1151,6 +1176,7 @@ main (int argc, flatpak_file_get_path_cached (export_repo), app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context), builder_manifest_get_collection_id (manifest), + builder_manifest_get_token_type (manifest), metadata_arg, files_arg, NULL)) diff --git a/src/builder-manifest.c b/src/builder-manifest.c index 19769104..b15a3f56 100644 --- a/src/builder-manifest.c +++ b/src/builder-manifest.c @@ -63,6 +63,7 @@ struct BuilderManifest char *branch; char *default_branch; char *collection_id; + gint32 token_type; char *extension_tag; char *type; char *runtime; @@ -167,6 +168,7 @@ enum { PROP_ADD_EXTENSIONS, PROP_ADD_BUILD_EXTENSIONS, PROP_EXTENSION_TAG, + PROP_TOKEN_TYPE, LAST_PROP }; @@ -470,6 +472,10 @@ builder_manifest_get_property (GObject *object, g_value_set_string (value, self->extension_tag); break; + case PROP_TOKEN_TYPE: + g_value_set_int (value, (int)self->token_type); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -729,6 +735,10 @@ builder_manifest_set_property (GObject *object, self->extension_tag = g_value_dup_string (value); break; + case PROP_TOKEN_TYPE: + self->token_type = (gint32)g_value_get_int (value); + break; + default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); } @@ -1070,11 +1080,22 @@ builder_manifest_class_init (BuilderManifestClass *klass) "", NULL, G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_TOKEN_TYPE, + g_param_spec_int ("token-type", + "", + "", + -1, + G_MAXINT32, + -1, + G_PARAM_READWRITE)); } static void builder_manifest_init (BuilderManifest *self) { + self->token_type = -1; self->appstream_compose = TRUE; self->separate_locales = TRUE; } @@ -1426,6 +1447,20 @@ builder_manifest_set_default_collection_id (BuilderManifest *self, self->collection_id = g_strdup (default_collection_id); } +gint32 +builder_manifest_get_token_type (BuilderManifest *self) +{ + return self->token_type; +} + +void +builder_manifest_set_default_token_type (BuilderManifest *self, + gint32 default_token_type) +{ + if (self->token_type == -1) + self->token_type = default_token_type; +} + void builder_manifest_add_tags (BuilderManifest *self, const char **add_tags) diff --git a/src/builder-manifest.h b/src/builder-manifest.h index 1d656c96..cec00063 100644 --- a/src/builder-manifest.h +++ b/src/builder-manifest.h @@ -62,9 +62,12 @@ GList * builder_manifest_get_add_build_extensions (BuilderManifest *self const char * builder_manifest_get_branch (BuilderManifest *self, BuilderContext *context); const char * builder_manifest_get_collection_id (BuilderManifest *self); +gint32 builder_manifest_get_token_type (BuilderManifest *self); const char * builder_manifest_get_extension_tag (BuilderManifest *self); void builder_manifest_set_default_collection_id (BuilderManifest *self, const char *default_collection_id); +void builder_manifest_set_default_token_type (BuilderManifest *self, + gint32 default_token_type); void builder_manifest_add_tags (BuilderManifest *self, const char **add_tags); diff --git a/tests/test.json b/tests/test.json index c837e725..cbadd015 100644 --- a/tests/test.json +++ b/tests/test.json @@ -4,6 +4,7 @@ "sdk": "org.test.Sdk", "command": "hello2.sh", "tags": ["test"], + "token-type": 0, "finish-args": [ "--share=network" ], diff --git a/tests/test.yaml b/tests/test.yaml index a210510e..021ebaa7 100644 --- a/tests/test.yaml +++ b/tests/test.yaml @@ -3,6 +3,7 @@ runtime: org.test.Platform sdk: org.test.Sdk command: hello2.sh tags: [test] +token-type: 0 finish-args: - --share=network build-options: