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.
This commit is contained in:
parent
38a5f6e5ed
commit
0f486105db
|
|
@ -26,7 +26,10 @@
|
||||||
#include "ostree.h"
|
#include "ostree.h"
|
||||||
#include "otutil.h"
|
#include "otutil.h"
|
||||||
|
|
||||||
|
char **opt_set;
|
||||||
|
|
||||||
static GOptionEntry options[] = {
|
static GOptionEntry options[] = {
|
||||||
|
{ "set", 0, 0, G_OPTION_ARG_STRING_ARRAY, &opt_set, "Set config option KEY=VALUE for remote", "KEY=VALUE" },
|
||||||
{ NULL }
|
{ NULL }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -40,6 +43,24 @@ usage_error (GOptionContext *context, const char *message, GError **error)
|
||||||
message);
|
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
|
gboolean
|
||||||
ostree_builtin_remote (int argc, char **argv, OstreeRepo *repo, GCancellable *cancellable, GError **error)
|
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"))
|
if (!strcmp (op, "add"))
|
||||||
{
|
{
|
||||||
char *key;
|
char *key;
|
||||||
|
char **iter;
|
||||||
if (argc < 4)
|
if (argc < 4)
|
||||||
{
|
{
|
||||||
usage_error (context, "NAME and URL must be specified", error);
|
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]);
|
key = g_strdup_printf ("remote \"%s\"", argv[2]);
|
||||||
g_key_file_set_string (config, key, "url", argv[3]);
|
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)
|
if (branches->len > 0)
|
||||||
g_key_file_set_string_list (config, key, "branches",
|
g_key_file_set_string_list (config, key, "branches",
|
||||||
(const char *const *)branches->pdata,
|
(const char *const *)branches->pdata,
|
||||||
|
|
|
||||||
|
|
@ -299,3 +299,9 @@ ${CMD_PREFIX} ostree --repo=repo2 init
|
||||||
${CMD_PREFIX} ostree --repo=repo2 pull-local repo
|
${CMD_PREFIX} ostree --repo=repo2 pull-local repo
|
||||||
echo "ok pull-local after commit metadata"
|
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"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue