pull: Add per-remote cookie jar

Optionally read cookie jars for a remote to be used when downloading
data. This can be used for private repositories which require specific
cookies to be present, e.g. repositories hosted on Amazon cloudfront
using signed cookies.

Closes: #531
Approved by: cgwalters
This commit is contained in:
Sjoerd Simons 2016-10-17 21:39:38 +02:00 committed by Atomic Bot
parent 2139f0e437
commit 96356aa192
3 changed files with 43 additions and 0 deletions

View File

@ -326,6 +326,16 @@ session_thread_set_proxy_cb (ThreadClosure *thread_closure,
}
}
static void
session_thread_set_cookie_jar_cb (ThreadClosure *thread_closure,
gpointer data)
{
SoupCookieJar *jar = data;
soup_session_add_feature (thread_closure->session,
SOUP_SESSION_FEATURE (jar));
}
#ifdef HAVE_LIBSOUP_CLIENT_CERTS
static void
session_thread_set_tls_interaction_cb (ThreadClosure *thread_closure,
@ -746,6 +756,23 @@ _ostree_fetcher_set_proxy (OstreeFetcher *self,
}
}
void
_ostree_fetcher_set_cookie_jar (OstreeFetcher *self,
const char *jar_path)
{
SoupCookieJar *jar;
g_return_if_fail (OSTREE_IS_FETCHER (self));
g_return_if_fail (jar_path != NULL);
jar = soup_cookie_jar_text_new (jar_path, TRUE);
session_thread_idle_add (self->thread_closure,
session_thread_set_cookie_jar_cb,
jar, /* takes ownership */
(GDestroyNotify) g_object_unref);
}
void
_ostree_fetcher_set_client_cert (OstreeFetcher *self,
GTlsCertificate *cert)

View File

@ -59,6 +59,9 @@ OstreeFetcher *_ostree_fetcher_new (int tmpdir_dfd,
int _ostree_fetcher_get_dfd (OstreeFetcher *fetcher);
void _ostree_fetcher_set_cookie_jar (OstreeFetcher *self,
const char *jar_path);
void _ostree_fetcher_set_proxy (OstreeFetcher *fetcher,
const char *proxy);

View File

@ -1964,6 +1964,19 @@ _ostree_repo_remote_new_fetcher (OstreeRepo *self,
_ostree_fetcher_set_proxy (fetcher, http_proxy);
}
{
g_autofree char *jar_path = NULL;
g_autofree char *cookie_file = g_strdup_printf ("%s.cookies.txt",
remote_name);
jar_path = g_build_filename (g_file_get_path (self->repodir), cookie_file,
NULL);
if (g_file_test(jar_path, G_FILE_TEST_IS_REGULAR))
_ostree_fetcher_set_cookie_jar (fetcher, jar_path);
}
success = TRUE;
out: