From c727eaf898e3d971f7314bfb574ed091378b2069 Mon Sep 17 00:00:00 2001 From: Heston Snodgrass Date: Mon, 12 Oct 2020 09:51:02 -0700 Subject: [PATCH] Fixed forgeapi http transport to support proxy settings from envvars. Made forgeapi error logging more useful. Updated README with proxy settings. --- README.md | 8 ++++++++ pkg/forgeapi/errors.go | 8 ++++---- pkg/forgeapi/forgeapi.go | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 48c18b8..5978101 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Pufctl allows you to quickly add modules to a Puppetfile from a git source or th * [Working With Puppetfiles](#working-with-puppetfiles) * [Git and Authentication](#git-and-authentication) * [Using a Config File](#using-a-config-file) + * [Proxy Settings](#proxy-settings) * [Features](#features) * [Usage](#usage) * [Basic Examples](#basic-examples) @@ -88,6 +89,13 @@ Nearly every option provided by a command line flag can be configured using a co The default location for the config file is `$HOME/.pufctl.yaml`. You can use a config file at a different path by passing the path to the `--config` global flag. +### Proxy Settings + +If you are behind a proxy, so can configure Pufctl to use the proxy by settings the following environment variables: + +* `HTTP_PROXY` +* `HTTPS_PROXY` +* `USE_PROXIES` (optional) ## Features diff --git a/pkg/forgeapi/errors.go b/pkg/forgeapi/errors.go index 2123e43..d1a22d3 100644 --- a/pkg/forgeapi/errors.go +++ b/pkg/forgeapi/errors.go @@ -20,7 +20,7 @@ type GetError struct { } func (r *GetError) Error() string { - return fmt.Sprintf("%s HTTP GET request failed. URL: %s, Headers: %#v, Error: %#v", prefix(), r.URL, r.Headers, r.Err) + return fmt.Sprintf("%s HTTP GET request failed. URL: %s, Headers: %#v, Error: %s", prefix(), r.URL, r.Headers, r.Err.Error()) } // GetNon200Error provides an error wrapper for when @@ -41,7 +41,7 @@ type JSONDecodeError struct { } func (r *JSONDecodeError) Error() string { - return fmt.Sprintf("%s Failed to decode HTTP response body: %#v", prefix(), r.Err) + return fmt.Sprintf("%s Failed to decode HTTP response body: %#v", prefix(), r.Err.Error()) } // FetchError provides a wrapper for errors encountered @@ -51,7 +51,7 @@ type FetchError struct { } func (r *FetchError) Error() string { - return fmt.Sprintf("%s Fetch failed: %#v", prefix(), r.Err) + return fmt.Sprintf("%s Fetch failed: %#v", prefix(), r.Err.Error()) } // ListError provides a wrapper for errors encountered @@ -61,5 +61,5 @@ type ListError struct { } func (r *ListError) Error() string { - return fmt.Sprintf("%s List failed: %#v", prefix(), r.Err) + return fmt.Sprintf("%s List failed: %#v", prefix(), r.Err.Error()) } diff --git a/pkg/forgeapi/forgeapi.go b/pkg/forgeapi/forgeapi.go index 6bef928..66f40b4 100644 --- a/pkg/forgeapi/forgeapi.go +++ b/pkg/forgeapi/forgeapi.go @@ -20,6 +20,7 @@ var ( MaxIdleConns: 3, IdleConnTimeout: 5 * time.Second, DisableCompression: true, + Proxy: http.ProxyFromEnvironment, } )