Skip to content

Commit aec06b3

Browse files
dbnicholsonalexlarsson
authored andcommitted
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.
1 parent 3fda50c commit aec06b3

File tree

7 files changed

+87
-1
lines changed

7 files changed

+87
-1
lines changed

doc/flatpak-builder.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,19 @@
428428
</para></listitem>
429429
</varlistentry>
430430

431+
<varlistentry>
432+
<term><option>--token-type=VAL</option></term>
433+
434+
<listitem><para>
435+
Set type of token needed to install this commit.
436+
Setting this to a value greater than 0 implies that
437+
authentication will be needed to install the
438+
flatpak. A <option>token-type</option> property set
439+
in the manifest takes precedence over this option.
440+
Used when exporting the build results.
441+
</para></listitem>
442+
</varlistentry>
443+
431444
<varlistentry>
432445
<term><option>--gpg-sign=KEYID</option></term>
433446

doc/flatpak-manifest.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@
101101
locations for the same extension point defined with different tags
102102
then an error will occur.</para></listitem>
103103
</varlistentry>
104+
<varlistentry>
105+
<term><option>token-type</option> (integer)</term>
106+
<listitem><para>The type of token needed to install
107+
this commit. Setting this to a value greater than 0
108+
implies that authentication will be needed to
109+
install the flatpak.</para></listitem>
110+
</varlistentry>
104111
<varlistentry>
105112
<term><option>runtime</option> (string)</term>
106113
<listitem><para>The name of the runtime that the application uses.</para></listitem>

src/builder-main.c

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ static char *opt_repo;
7171
static char *opt_subject;
7272
static char *opt_body;
7373
static char *opt_collection_id = NULL;
74+
static int opt_token_type = -1;
7475
static char *opt_gpg_homedir;
7576
static char **opt_key_ids;
7677
static char **opt_sources_dirs;
@@ -118,6 +119,7 @@ static GOptionEntry entries[] = {
118119
{ "subject", 's', 0, G_OPTION_ARG_STRING, &opt_subject, "One line subject (passed to build-export)", "SUBJECT" },
119120
{ "body", 'b', 0, G_OPTION_ARG_STRING, &opt_body, "Full description (passed to build-export)", "BODY" },
120121
{ "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, "Collection ID (passed to build-export)", "COLLECTION-ID" },
122+
{ "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" },
121123
{ "gpg-sign", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_key_ids, "GPG Key ID to sign the commit with", "KEY-ID"},
122124
{ "gpg-homedir", 0, 0, G_OPTION_ARG_STRING, &opt_gpg_homedir, "GPG Homedir to use when looking for keyrings", "HOMEDIR"},
123125
{ "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,
199201
char **exclude_dirs,
200202
const gchar *branch,
201203
const gchar *collection_id,
204+
gint32 token_type,
202205
...)
203206
{
204207
va_list ap;
@@ -231,8 +234,11 @@ do_export (BuilderContext *build_context,
231234
if (collection_id)
232235
g_ptr_array_add (args, g_strdup_printf ("--collection-id=%s", collection_id));
233236

237+
if (token_type >= 0)
238+
g_ptr_array_add (args, g_strdup_printf ("--token-type=%d", token_type));
239+
234240
/* Additional flags. */
235-
va_start (ap, collection_id);
241+
va_start (ap, token_type);
236242
while ((arg = va_arg (ap, const gchar *)))
237243
if (arg != skip_arg)
238244
g_ptr_array_add (args, g_strdup ((gchar *) arg));
@@ -501,6 +507,16 @@ main (int argc,
501507
return 1;
502508
}
503509

510+
if (opt_token_type < -1
511+
#if G_MAXINT > 0x7fffffff
512+
|| opt_token_type > G_MAXINT32
513+
#endif
514+
)
515+
{
516+
g_printerr ("--token-type value must be a 32 bit integer >= 0\n");
517+
return 1;
518+
}
519+
504520
if (app_dir_path)
505521
app_dir = g_file_new_for_path (app_dir_path);
506522
cwd = g_get_current_dir ();
@@ -669,6 +685,9 @@ main (int argc,
669685
if (opt_collection_id)
670686
builder_manifest_set_default_collection_id (manifest, opt_collection_id);
671687

688+
if (opt_token_type >= 0)
689+
builder_manifest_set_default_token_type (manifest, (gint32)opt_token_type);
690+
672691
if (is_run && argc == 3)
673692
return usage (context, "Program to run must be specified");
674693

@@ -993,6 +1012,7 @@ main (int argc,
9931012
flatpak_file_get_path_cached (export_repo),
9941013
app_dir_path, exclude_dirs, builder_manifest_get_branch (manifest, build_context),
9951014
builder_manifest_get_collection_id (manifest),
1015+
builder_manifest_get_token_type (manifest),
9961016
"--exclude=/lib/debug/*",
9971017
"--include=/lib/debug/app",
9981018
builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg,
@@ -1027,6 +1047,7 @@ main (int argc,
10271047
flatpak_file_get_path_cached (export_repo),
10281048
app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
10291049
builder_manifest_get_collection_id (manifest),
1050+
builder_manifest_get_token_type (manifest),
10301051
metadata_arg,
10311052
files_arg,
10321053
NULL))
@@ -1047,6 +1068,7 @@ main (int argc,
10471068
flatpak_file_get_path_cached (export_repo),
10481069
app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
10491070
builder_manifest_get_collection_id (manifest),
1071+
builder_manifest_get_token_type (manifest),
10501072
"--metadata=metadata.debuginfo",
10511073
builder_context_get_build_runtime (build_context) ? "--files=usr/lib/debug" : "--files=files/lib/debug",
10521074
NULL))
@@ -1078,6 +1100,7 @@ main (int argc,
10781100
flatpak_file_get_path_cached (export_repo),
10791101
app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
10801102
builder_manifest_get_collection_id (manifest),
1103+
builder_manifest_get_token_type (manifest),
10811104
metadata_arg, files_arg,
10821105
NULL))
10831106
{
@@ -1097,6 +1120,7 @@ main (int argc,
10971120
flatpak_file_get_path_cached (export_repo),
10981121
app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
10991122
builder_manifest_get_collection_id (manifest),
1123+
builder_manifest_get_token_type (manifest),
11001124
"--metadata=metadata.sources",
11011125
"--files=sources",
11021126
NULL))
@@ -1117,6 +1141,7 @@ main (int argc,
11171141
flatpak_file_get_path_cached (export_repo),
11181142
app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
11191143
builder_manifest_get_collection_id (manifest),
1144+
builder_manifest_get_token_type (manifest),
11201145
"--metadata=metadata.platform",
11211146
"--files=platform",
11221147
builder_context_get_separate_locales (build_context) ? "--exclude=/share/runtime/locale/*/*" : skip_arg,
@@ -1151,6 +1176,7 @@ main (int argc,
11511176
flatpak_file_get_path_cached (export_repo),
11521177
app_dir_path, NULL, builder_manifest_get_branch (manifest, build_context),
11531178
builder_manifest_get_collection_id (manifest),
1179+
builder_manifest_get_token_type (manifest),
11541180
metadata_arg,
11551181
files_arg,
11561182
NULL))

src/builder-manifest.c

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ struct BuilderManifest
6363
char *branch;
6464
char *default_branch;
6565
char *collection_id;
66+
gint32 token_type;
6667
char *extension_tag;
6768
char *type;
6869
char *runtime;
@@ -167,6 +168,7 @@ enum {
167168
PROP_ADD_EXTENSIONS,
168169
PROP_ADD_BUILD_EXTENSIONS,
169170
PROP_EXTENSION_TAG,
171+
PROP_TOKEN_TYPE,
170172
LAST_PROP
171173
};
172174

@@ -470,6 +472,10 @@ builder_manifest_get_property (GObject *object,
470472
g_value_set_string (value, self->extension_tag);
471473
break;
472474

475+
case PROP_TOKEN_TYPE:
476+
g_value_set_int (value, (int)self->token_type);
477+
break;
478+
473479
default:
474480
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
475481
}
@@ -729,6 +735,10 @@ builder_manifest_set_property (GObject *object,
729735
self->extension_tag = g_value_dup_string (value);
730736
break;
731737

738+
case PROP_TOKEN_TYPE:
739+
self->token_type = (gint32)g_value_get_int (value);
740+
break;
741+
732742
default:
733743
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
734744
}
@@ -1070,11 +1080,22 @@ builder_manifest_class_init (BuilderManifestClass *klass)
10701080
"",
10711081
NULL,
10721082
G_PARAM_READWRITE));
1083+
1084+
g_object_class_install_property (object_class,
1085+
PROP_TOKEN_TYPE,
1086+
g_param_spec_int ("token-type",
1087+
"",
1088+
"",
1089+
-1,
1090+
G_MAXINT32,
1091+
-1,
1092+
G_PARAM_READWRITE));
10731093
}
10741094

10751095
static void
10761096
builder_manifest_init (BuilderManifest *self)
10771097
{
1098+
self->token_type = -1;
10781099
self->appstream_compose = TRUE;
10791100
self->separate_locales = TRUE;
10801101
}
@@ -1426,6 +1447,20 @@ builder_manifest_set_default_collection_id (BuilderManifest *self,
14261447
self->collection_id = g_strdup (default_collection_id);
14271448
}
14281449

1450+
gint32
1451+
builder_manifest_get_token_type (BuilderManifest *self)
1452+
{
1453+
return self->token_type;
1454+
}
1455+
1456+
void
1457+
builder_manifest_set_default_token_type (BuilderManifest *self,
1458+
gint32 default_token_type)
1459+
{
1460+
if (self->token_type == -1)
1461+
self->token_type = default_token_type;
1462+
}
1463+
14291464
void
14301465
builder_manifest_add_tags (BuilderManifest *self,
14311466
const char **add_tags)

src/builder-manifest.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,12 @@ GList * builder_manifest_get_add_build_extensions (BuilderManifest *self
6262
const char * builder_manifest_get_branch (BuilderManifest *self,
6363
BuilderContext *context);
6464
const char * builder_manifest_get_collection_id (BuilderManifest *self);
65+
gint32 builder_manifest_get_token_type (BuilderManifest *self);
6566
const char * builder_manifest_get_extension_tag (BuilderManifest *self);
6667
void builder_manifest_set_default_collection_id (BuilderManifest *self,
6768
const char *default_collection_id);
69+
void builder_manifest_set_default_token_type (BuilderManifest *self,
70+
gint32 default_token_type);
6871

6972
void builder_manifest_add_tags (BuilderManifest *self,
7073
const char **add_tags);

tests/test.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"sdk": "org.test.Sdk",
55
"command": "hello2.sh",
66
"tags": ["test"],
7+
"token-type": 0,
78
"finish-args": [
89
"--share=network"
910
],

tests/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ runtime: org.test.Platform
33
sdk: org.test.Sdk
44
command: hello2.sh
55
tags: [test]
6+
token-type: 0
67
finish-args:
78
- --share=network
89
build-options:

0 commit comments

Comments
 (0)