[ostree] core: Support a per-remote "proxy" configuration option



commit b97a5f59df26267b893a05b3cecbe04fe6e8db7e
Author: Colin Walters <walters verbum org>
Date:   Fri Jul 25 07:55:55 2014 -0400

    core: Support a per-remote "proxy" configuration option
    
    We don't want to have to force people to set it in the environment.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=733734

 doc/ostree.repo-config.xml       |    6 ++++++
 src/libostree/ostree-fetcher.c   |   27 +++++++++++++++++----------
 src/libostree/ostree-fetcher.h   |    3 +++
 src/libostree/ostree-repo-pull.c |   11 +++++++++++
 4 files changed, 37 insertions(+), 10 deletions(-)
---
diff --git a/doc/ostree.repo-config.xml b/doc/ostree.repo-config.xml
index bbacdd0..26fef07 100644
--- a/doc/ostree.repo-config.xml
+++ b/doc/ostree.repo-config.xml
@@ -127,6 +127,12 @@ Boston, MA 02111-1307, USA.
       </varlistentry>
 
       <varlistentry>
+        <term><varname>proxy</varname></term>
+        <listitem><para>A string value, if given should be a URL for a
+        HTTP proxy to use for access to this repository.</para></listitem>
+      </varlistentry>
+
+      <varlistentry>
         <term><varname>gpg-verify</varname></term>
         <listitem><para>A boolean value, defaults to true.
         Controls whether or not OSTree will require commits to be
diff --git a/src/libostree/ostree-fetcher.c b/src/libostree/ostree-fetcher.c
index 0ea4d29..298ba63 100644
--- a/src/libostree/ostree-fetcher.c
+++ b/src/libostree/ostree-fetcher.c
@@ -172,16 +172,7 @@ _ostree_fetcher_init (OstreeFetcher *self)
   http_proxy = g_getenv ("http_proxy");
   if (http_proxy)
     {
-      SoupURI *proxy_uri = soup_uri_new (http_proxy);
-      if (!proxy_uri)
-        {
-          g_warning ("Invalid proxy URI '%s'", http_proxy);
-        }
-      else
-        {
-          g_object_set (self->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
-          soup_uri_free (proxy_uri);
-        }
+      _ostree_fetcher_set_proxy (self, http_proxy);
     }
 
   if (g_getenv ("OSTREE_DEBUG_HTTP"))
@@ -225,6 +216,22 @@ _ostree_fetcher_new (GFile                    *tmpdir,
 }
 
 void
+_ostree_fetcher_set_proxy (OstreeFetcher *self,
+                           const char    *http_proxy)
+{
+  SoupURI *proxy_uri = soup_uri_new (http_proxy);
+  if (!proxy_uri)
+    {
+      g_warning ("Invalid proxy URI '%s'", http_proxy);
+    }
+  else
+    {
+      g_object_set (self->session, SOUP_SESSION_PROXY_URI, proxy_uri, NULL);
+      soup_uri_free (proxy_uri);
+    }
+}
+
+void
 _ostree_fetcher_set_client_cert (OstreeFetcher *fetcher,
                                 GTlsCertificate *cert)
 {
diff --git a/src/libostree/ostree-fetcher.h b/src/libostree/ostree-fetcher.h
index 850d317..0ab1def 100644
--- a/src/libostree/ostree-fetcher.h
+++ b/src/libostree/ostree-fetcher.h
@@ -54,6 +54,9 @@ GType   _ostree_fetcher_get_type (void) G_GNUC_CONST;
 OstreeFetcher *_ostree_fetcher_new (GFile                     *tmpdir,
                                    OstreeFetcherConfigFlags   flags);
 
+void _ostree_fetcher_set_proxy (OstreeFetcher *fetcher,
+                                const char    *proxy);
+
 void _ostree_fetcher_set_client_cert (OstreeFetcher *fetcher,
                                      GTlsCertificate *cert);
 
diff --git a/src/libostree/ostree-repo-pull.c b/src/libostree/ostree-repo-pull.c
index 51eb4d0..76798d6 100644
--- a/src/libostree/ostree-repo-pull.c
+++ b/src/libostree/ostree-repo-pull.c
@@ -1151,6 +1151,17 @@ ostree_repo_pull (OstreeRepo               *self,
       }
   }
 
+  {
+    gs_free char *http_proxy = NULL;
+
+    if (!ot_keyfile_get_value_with_default (config, remote_key, "proxy",
+                                            NULL, &http_proxy, error))
+      goto out;
+
+    if (http_proxy)
+      _ostree_fetcher_set_proxy (pull_data->fetcher, http_proxy);
+  }
+
   if (!pull_data->base_uri)
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED,


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