summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOwen W. Taylor <otaylor@fishsoup.net>2018-08-08 09:54:39 +0200
committerAlexander Larsson <alexander.larsson@gmail.com>2018-08-13 11:23:28 +0200
commitd7d05a861948bce8ffcdb05dd6c9e11f69ade755 (patch)
tree45eeb8a0472efe1a83a31908632fc31ca69f82cd
parentb28308482670f8c36a2c308a591815ef0cb39dbd (diff)
downloadflatpak-d7d05a861948bce8ffcdb05dd6c9e11f69ade755.tar.gz
Use oci+http[s]:// as an URL to identify OCI registries
The old pattern of using a separate 'OCI' flag was very ugly internally in the code once it was extended to flatpak bundles and flatpakrefs - using a different URI scheme means that the nature of the remote can't be accidentally lost in some part of the code. Probing would be possible as well, but would make it difficult to add a remote when offline, and also doesn't deal well with the fact that our data layout is different for the two types of remotes - the type of remote could change at any point! As a side effect this change enables flatpakrefs and flatpak bundles for OCI registries.
-rw-r--r--app/flatpak-builtins-add-remote.c14
-rw-r--r--common/flatpak-dir.c12
-rw-r--r--common/flatpak-oci-registry.c9
-rw-r--r--doc/flatpak-remote-add.xml9
-rw-r--r--doc/flatpak-remote.xml11
-rwxr-xr-xtests/test-oci-registry.sh2
6 files changed, 26 insertions, 31 deletions
diff --git a/app/flatpak-builtins-add-remote.c b/app/flatpak-builtins-add-remote.c
index 28b84196..f17ef647 100644
--- a/app/flatpak-builtins-add-remote.c
+++ b/app/flatpak-builtins-add-remote.c
@@ -41,7 +41,6 @@ static gboolean opt_do_deps;
static gboolean opt_no_deps;
static gboolean opt_if_not_exists;
static gboolean opt_enable;
-static gboolean opt_oci;
static gboolean opt_update_metadata;
static gboolean opt_disable;
static int opt_prio = -1;
@@ -79,7 +78,6 @@ static GOptionEntry common_options[] = {
{ "collection-id", 0, 0, G_OPTION_ARG_STRING, &opt_collection_id, N_("Collection ID"), N_("COLLECTION-ID") },
{ "gpg-import", 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &opt_gpg_import, N_("Import GPG key from FILE (- for stdin)"), N_("FILE") },
{ "disable", 0, 0, G_OPTION_ARG_NONE, &opt_disable, N_("Disable the remote"), NULL },
- { "oci", 0, 0, G_OPTION_ARG_NONE, &opt_oci, N_("Add OCI registry"), NULL },
{ NULL }
};
@@ -176,12 +174,6 @@ get_config_from_opts (FlatpakDir *dir, const char *remote_name, gboolean *change
*changed = TRUE;
}
- if (opt_oci)
- {
- g_key_file_set_boolean (config, group, "xa.oci", TRUE);
- *changed = TRUE;
- }
-
if (opt_prio != -1)
{
g_autofree char *prio_as_string = g_strdup_printf ("%d", opt_prio);
@@ -312,6 +304,7 @@ flatpak_builtin_add_remote (int argc, char **argv,
g_autoptr(GBytes) gpg_data = NULL;
gboolean changed = FALSE;
g_autoptr(GError) local_error = NULL;
+ gboolean is_oci;
context = g_option_context_new (_("NAME LOCATION - Add a remote repository"));
g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
@@ -374,8 +367,9 @@ flatpak_builtin_add_remote (int argc, char **argv,
opt_url = remote_url;
}
- /* Default to gpg verify, except for --oci */
- if (!opt_no_gpg_verify && !opt_oci)
+ /* Default to gpg verify, except for OCI registries */
+ is_oci = opt_url && g_str_has_prefix (opt_url, "oci+");
+ if (!opt_no_gpg_verify && !is_oci)
opt_do_gpg_verify = TRUE;
config = get_config_from_opts (dir, remote_name, &changed);
diff --git a/common/flatpak-dir.c b/common/flatpak-dir.c
index c903ff22..e673156b 100644
--- a/common/flatpak-dir.c
+++ b/common/flatpak-dir.c
@@ -10269,13 +10269,15 @@ gboolean
flatpak_dir_get_remote_oci (FlatpakDir *self,
const char *remote_name)
{
- GKeyFile *config = ostree_repo_get_config (self->repo);
- g_autofree char *group = get_group (remote_name);
+ g_autofree char *url = NULL;
- if (config)
- return g_key_file_get_boolean (config, group, "xa.oci", NULL);
+ if (!ostree_repo_remote_get_url (self->repo,
+ remote_name,
+ &url,
+ NULL))
+ return FALSE;
- return FALSE;
+ return url && g_str_has_prefix (url, "oci+");
}
char *
diff --git a/common/flatpak-oci-registry.c b/common/flatpak-oci-registry.c
index 56154162..76f9070f 100644
--- a/common/flatpak-oci-registry.c
+++ b/common/flatpak-oci-registry.c
@@ -1940,7 +1940,14 @@ flatpak_oci_index_ensure_cached (SoupSession *soup_session,
gboolean success = FALSE;
g_autoptr(GError) local_error = NULL;
- base_uri = soup_uri_new (uri);
+ if (!g_str_has_prefix (uri, "oci+http:") && !g_str_has_prefix (uri, "oci+https:"))
+ {
+ g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
+ "OCI Index URI %s does not start with oci+http(s)://", uri);
+ return FALSE;
+ }
+
+ base_uri = soup_uri_new (uri + 4);
if (base_uri == NULL)
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_ARGUMENT,
diff --git a/doc/flatpak-remote-add.xml b/doc/flatpak-remote-add.xml
index 3a09915f..d2ef456b 100644
--- a/doc/flatpak-remote-add.xml
+++ b/doc/flatpak-remote-add.xml
@@ -195,15 +195,6 @@
</varlistentry>
<varlistentry>
- <term><option>--oci</option></term>
-
- <listitem><para>
- This is a OCI format registry rather than a regular
- flatpak repository.
- </para></listitem>
- </varlistentry>
-
- <varlistentry>
<term><option>-v</option></term>
<term><option>--verbose</option></term>
diff --git a/doc/flatpak-remote.xml b/doc/flatpak-remote.xml
index 116e8e2d..1883ab0e 100644
--- a/doc/flatpak-remote.xml
+++ b/doc/flatpak-remote.xml
@@ -70,7 +70,12 @@
<variablelist>
<varlistentry>
<term><option>url</option> (string)</term>
- <listitem><para>The url for the remote.</para></listitem>
+ <listitem><para>
+ The url for the remote. An URL of the form oci+https:// or oci+http://
+ is a Flatpak extension that indicates that the remote is not an ostree
+ repository, but is rather an URL to an index of OCI images that are stored
+ within a container image registry.
+ </para></listitem>
</varlistentry>
<varlistentry>
<term><option>gpg-verify</option> (boolean)</term>
@@ -128,10 +133,6 @@
<term><option>xa.main-ref</option> (string)</term>
<listitem><para>The main reference served by this remote. This is used for origin remotes of applications installed via a flatpakref file.</para></listitem>
</varlistentry>
- <varlistentry>
- <term><option>xa.oci</option> (boolean)</term>
- <listitem><para>Whether this is an OCI remote. Defaults to false.</para></listitem>
- </varlistentry>
</variablelist>
</refsect2>
</refsect1>
diff --git a/tests/test-oci-registry.sh b/tests/test-oci-registry.sh
index 3814ce8c..61dd4f78 100755
--- a/tests/test-oci-registry.sh
+++ b/tests/test-oci-registry.sh
@@ -45,7 +45,7 @@ $client add hello latest $(pwd)/oci/app-image
# Add an OCI remote
-flatpak remote-add ${U} --oci oci-registry "http://127.0.0.1:${port}"
+flatpak remote-add ${U} oci-registry "oci+http://127.0.0.1:${port}"
# Check that the images we expect are listed