Merge ~brad-marshall/charm-grafana/+git/grafana-charm:http-proxy-install into ~prometheus-charmers/charm-grafana:master

Proposed by Brad Marshall
Status: Merged
Merged at revision: 3938ce8428471e02cea32e81675fa37af3fbeb56
Proposed branch: ~brad-marshall/charm-grafana/+git/grafana-charm:http-proxy-install
Merge into: ~prometheus-charmers/charm-grafana:master
Diff against target: 40 lines (+15/-1)
2 files modified
config.yaml (+5/-0)
reactive/grafana.py (+10/-1)
Reviewer Review Type Date Requested Status
Paul Gear (community) Approve
Review via email: mp+330050@code.launchpad.net

Description of the change

Added the ability to use a http_proxy for the install file option. I've tested this locally and ensured it went via the proxy.

To post a comment you must log in.
Revision history for this message
Paul Gear (paulgear) wrote :

LGTM

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 60f282e..f5c4e6c 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -127,3 +127,8 @@ options:
6 Comma separated list of http(s) URLs where grafana plugin tarballs can be found.
7 Example:
8 install_plugins: http://my.company.com/packages/grafana/plugins/plugin-panel.tar.gz
9+ http_proxy:
10+ default: ""
11+ type: string
12+ description: |
13+ Proxy URL to use for install_file
14diff --git a/reactive/grafana.py b/reactive/grafana.py
15index 91f813f..d3b90bc 100644
16--- a/reactive/grafana.py
17+++ b/reactive/grafana.py
18@@ -44,12 +44,21 @@ def install_packages():
19 config = hookenv.config()
20 install_opts = ('install_sources', 'install_keys')
21 hookenv.status_set('maintenance', 'Installing grafana')
22+
23+ if config.get('http_proxy'):
24+ proxy = {"http": config.get('http_proxy'),
25+ "https": config.get('http_proxy'),
26+ }
27+ else:
28+ proxy = {}
29+
30 if config.changed('install_file') and config.get('install_file', False):
31 hookenv.status_set('maintenance', 'Installing deb pkgs')
32 fetch.apt_install(GRAFANA_DEPS)
33 pkg_file = '/tmp/grafana.deb'
34 with open(pkg_file, 'wb') as f:
35- r = requests.get(config.get('install_file'), stream=True)
36+ r = requests.get(config.get('install_file'), stream=True,
37+ proxies=proxy)
38 for block in r.iter_content(1024):
39 f.write(block)
40 subprocess.check_call(['dpkg', '-i', pkg_file])

Subscribers

People subscribed via source and target branches