[ostree] remote-add: Add --set=KEY=VALUE option



commit 0f486105db56e16302a9298ae68449ef07461459
Author: Colin Walters <walters verbum org>
Date:   Sat Sep 28 12:00:16 2013 -0400

    remote-add: Add --set=KEY=VALUE option
    
    This can be used to add a remote and set e.g. tls-permissive=true, or
    gpgverify=false.

 src/ostree/ot-builtin-remote.c |   35 +++++++++++++++++++++++++++++++++++
 tests/test-basic.sh            |    6 ++++++
 2 files changed, 41 insertions(+), 0 deletions(-)
---
diff --git a/src/ostree/ot-builtin-remote.c b/src/ostree/ot-builtin-remote.c
index 98a8b4b..1f72883 100644
--- a/src/ostree/ot-builtin-remote.c
+++ b/src/ostree/ot-builtin-remote.c
@@ -26,7 +26,10 @@
 #include "ostree.h"
 #include "otutil.h"
 
+char **opt_set;
+
 static GOptionEntry options[] = {
+  { "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, "Set config option KEY=VALUE for remote", "KEY=VALUE" 
},
   { NULL }
 };
 
@@ -40,6 +43,24 @@ usage_error (GOptionContext *context, const char *message, GError **error)
                        message);
 }
 
+static gboolean
+parse_keyvalue (const char  *keyvalue,
+                char       **out_key,
+                char       **out_value,
+                GError     **error)
+{
+  const char *eq = strchr (keyvalue, '=');
+  if (!eq)
+    {
+      g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,
+                   "Missing '=' in KEY=VALUE for --set");
+      return FALSE;
+    }
+  *out_key = g_strndup (keyvalue, eq - keyvalue);
+  *out_value = g_strdup (eq + 1);
+  return TRUE;
+}
+
 gboolean
 ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
 {
@@ -69,6 +90,7 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
   if (!strcmp (op, "add"))
     {
       char *key;
+      char **iter;
       if (argc < 4)
         {
           usage_error (context, "NAME and URL must be specified", error);
@@ -81,6 +103,19 @@ ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *ca
 
       key = g_strdup_printf ("remote \"%s\"", argv[2]);
       g_key_file_set_string (config, key, "url", argv[3]);
+
+      for (iter = opt_set; iter && *iter; iter++)
+        {
+          const char *keyvalue = *iter;
+          gs_free char *subkey = NULL;
+          gs_free char *subvalue = NULL;
+
+          if (!parse_keyvalue (keyvalue, &subkey, &subvalue, error))
+            goto out;
+
+          g_key_file_set_string (config, key, subkey, subvalue);
+        }
+
       if (branches->len > 0)
         g_key_file_set_string_list (config, key, "branches",
                                     (const char *const *)branches->pdata,
diff --git a/tests/test-basic.sh b/tests/test-basic.sh
index 4c7e056..8c32b09 100755
--- a/tests/test-basic.sh
+++ b/tests/test-basic.sh
@@ -299,3 +299,9 @@ ${CMD_PREFIX} ostree --repo=repo2 init
 ${CMD_PREFIX} ostree --repo=repo2 pull-local repo
 echo "ok pull-local after commit metadata"
 
+cd ${test_tmpdir}
+${CMD_PREFIX} ostree --repo=repo remote --set=tls-permissive=true add aremote http://remote.example.com/repo 
testos/buildmaster/x86_64-runtime
+assert_file_has_content repo/config 'tls-permissive=true'
+assert_file_has_content repo/config 'remote\.example\.com'
+echo "ok remote add with set"
+


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]