summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Nicholson <dbn@endlessos.org>2023-01-29 22:45:29 -0700
committerDan Nicholson <dbn@endlessos.org>2023-02-07 22:59:30 -0700
commit70ec92e1cdc3ad882ac569a3655857fb1241a449 (patch)
treeb52627eae56d23df06b1d0765432f359f4b5faa0
parentb49f93aa951c5a168ccd32908425c670f319a65f (diff)
downloadostree-70ec92e1cdc3ad882ac569a3655857fb1241a449.tar.gz
bin/remote-summary: Add options to show metadata
-rw-r--r--bash/ostree2
-rw-r--r--src/ostree/ot-remote-builtin-summary.c78
-rwxr-xr-xtests/test-pull-summary-sigs.sh10
-rwxr-xr-xtests/test-signed-pull-summary.sh10
4 files changed, 69 insertions, 31 deletions
diff --git a/bash/ostree b/bash/ostree
index 0415e225..875b34ff 100644
--- a/bash/ostree
+++ b/bash/ostree
@@ -1345,11 +1345,13 @@ _ostree_remote_show_url() {
_ostree_remote_summary() {
local boolean_options="
$main_boolean_options
+ --list-metadata-keys
--raw
"
local options_with_args="
--cache-dir
+ --print-metadata-key
--repo
"
diff --git a/src/ostree/ot-remote-builtin-summary.c b/src/ostree/ot-remote-builtin-summary.c
index fb2c45a3..55ccc396 100644
--- a/src/ostree/ot-remote-builtin-summary.c
+++ b/src/ostree/ot-remote-builtin-summary.c
@@ -25,8 +25,10 @@
#include "ot-dump.h"
#include "ot-remote-builtins.h"
+static gboolean opt_list_metadata_keys;
static gboolean opt_raw;
+static char *opt_print_metadata_key;
static char* opt_cache_dir;
/* ATTENTION:
@@ -35,6 +37,8 @@ static char* opt_cache_dir;
*/
static GOptionEntry option_entries[] = {
+ { "list-metadata-keys", 0, 0, G_OPTION_ARG_NONE, &opt_list_metadata_keys, "List the available metadata keys", NULL },
+ { "print-metadata-key", 0, 0, G_OPTION_ARG_STRING, &opt_print_metadata_key, "Print string value of metadata key", "KEY" },
{ "cache-dir", 0, 0, G_OPTION_ARG_FILENAME, &opt_cache_dir, "Use custom cache dir", NULL },
{ "raw", 0, 0, G_OPTION_ARG_NONE, &opt_raw, "Show raw variant data", NULL },
{ NULL }
@@ -90,42 +94,54 @@ ot_remote_builtin_summary (int argc, char **argv, OstreeCommandInvocation *invoc
goto out;
}
- ot_dump_summary_bytes (summary_bytes, flags);
+ if (opt_list_metadata_keys)
+ {
+ ot_dump_summary_metadata_keys (summary_bytes);
+ }
+ else if (opt_print_metadata_key)
+ {
+ if (!ot_dump_summary_metadata_key (summary_bytes, opt_print_metadata_key, error))
+ goto out;
+ }
+ else
+ {
+ ot_dump_summary_bytes (summary_bytes, flags);
#ifndef OSTREE_DISABLE_GPGME
- if (!ostree_repo_remote_get_gpg_verify_summary (repo, remote_name,
- &gpg_verify_summary,
- error))
- goto out;
-
- if (!gpg_verify_summary)
- g_clear_pointer (&signature_bytes, g_bytes_unref);
-
- /* XXX Note we don't show signatures for "--raw". My intuition is
- * if someone needs to see or parse raw summary data, including
- * signatures in the output would probably just interfere.
- * If there's demand for it I suppose we could introduce a new
- * option for raw signature data like "--raw-signatures". */
- if (signature_bytes != NULL && !opt_raw)
- {
- g_autoptr(OstreeGpgVerifyResult) result = NULL;
-
- /* The actual signed summary verification happens above in
- * ostree_repo_remote_fetch_summary(). Here we just parse
- * the signatures again for the purpose of printing. */
- result = ostree_repo_verify_summary (repo,
- remote_name,
- summary_bytes,
- signature_bytes,
- cancellable,
- error);
- if (result == NULL)
+ if (!ostree_repo_remote_get_gpg_verify_summary (repo, remote_name,
+ &gpg_verify_summary,
+ error))
goto out;
- g_print ("\n");
- ostree_print_gpg_verify_result (result);
- }
+ if (!gpg_verify_summary)
+ g_clear_pointer (&signature_bytes, g_bytes_unref);
+
+ /* XXX Note we don't show signatures for "--raw". My intuition is
+ * if someone needs to see or parse raw summary data, including
+ * signatures in the output would probably just interfere.
+ * If there's demand for it I suppose we could introduce a new
+ * option for raw signature data like "--raw-signatures". */
+ if (signature_bytes != NULL && !opt_raw)
+ {
+ g_autoptr(OstreeGpgVerifyResult) result = NULL;
+
+ /* The actual signed summary verification happens above in
+ * ostree_repo_remote_fetch_summary(). Here we just parse
+ * the signatures again for the purpose of printing. */
+ result = ostree_repo_verify_summary (repo,
+ remote_name,
+ summary_bytes,
+ signature_bytes,
+ cancellable,
+ error);
+ if (result == NULL)
+ goto out;
+
+ g_print ("\n");
+ ostree_print_gpg_verify_result (result);
+ }
#endif /* OSTREE_DISABLE_GPGME */
+ }
ret = TRUE;
out:
diff --git a/tests/test-pull-summary-sigs.sh b/tests/test-pull-summary-sigs.sh
index 03a40e46..e1b0412e 100755
--- a/tests/test-pull-summary-sigs.sh
+++ b/tests/test-pull-summary-sigs.sh
@@ -157,6 +157,16 @@ assert_file_has_content summary.txt "Good signature from \"Ostree Tester <test@t
grep static-deltas summary.txt > static-deltas.txt
assert_file_has_content static-deltas.txt \
$(${OSTREE} --repo=repo rev-parse origin:main)
+${OSTREE} --repo=repo remote summary origin --list-metadata-keys > metadata
+assert_file_has_content metadata "^ostree.static-deltas$"
+assert_file_has_content metadata "^ostree.summary.indexed-deltas$"
+assert_file_has_content metadata "^ostree.summary.last-modified$"
+assert_file_has_content metadata "^ostree.summary.mode$"
+assert_file_has_content metadata "^ostree.summary.tombstone-commits$"
+${OSTREE} --repo=repo remote summary origin --print-metadata-key=ostree.summary.indexed-deltas > metadata
+assert_file_has_content metadata "^true$"
+${OSTREE} --repo=repo remote summary origin --print-metadata-key=ostree.summary.mode > metadata
+assert_file_has_content metadata "^'archive-z2'$"
## Tests for handling of cached summaries while racing with remote summary updates
diff --git a/tests/test-signed-pull-summary.sh b/tests/test-signed-pull-summary.sh
index 2d6b2552..d2873894 100755
--- a/tests/test-signed-pull-summary.sh
+++ b/tests/test-signed-pull-summary.sh
@@ -194,6 +194,16 @@ assert_file_has_content summary.txt "* yet-another"
grep static-deltas summary.txt > static-deltas.txt
assert_file_has_content static-deltas.txt \
$(${OSTREE} --repo=repo rev-parse origin:main)
+${OSTREE} --repo=repo remote summary origin --list-metadata-keys > metadata
+assert_file_has_content metadata "^ostree.static-deltas$"
+assert_file_has_content metadata "^ostree.summary.indexed-deltas$"
+assert_file_has_content metadata "^ostree.summary.last-modified$"
+assert_file_has_content metadata "^ostree.summary.mode$"
+assert_file_has_content metadata "^ostree.summary.tombstone-commits$"
+${OSTREE} --repo=repo remote summary origin --print-metadata-key=ostree.summary.indexed-deltas > metadata
+assert_file_has_content metadata "^true$"
+${OSTREE} --repo=repo remote summary origin --print-metadata-key=ostree.summary.mode > metadata
+assert_file_has_content metadata "^'archive-z2'$"
## Tests for handling of cached summaries while racing with remote summary updates