1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
9
"github.com/juju/errors"
10
"github.com/juju/juju/api/base"
11
apiwatcher "github.com/juju/juju/api/watcher"
12
"github.com/juju/juju/apiserver/params"
13
"github.com/juju/juju/watcher"
14
"github.com/juju/utils/proxy"
15
"gopkg.in/juju/names.v2"
18
const proxyUpdaterFacade = "ProxyUpdater"
20
// API provides access to the ProxyUpdater API facade.
23
facade base.FacadeCaller
26
// NewAPI returns a new api client facade instance.
27
func NewAPI(caller base.APICaller, tag names.Tag) (*API, error) {
29
return nil, fmt.Errorf("caller is nil")
33
return nil, fmt.Errorf("tag is nil")
37
facade: base.NewFacadeCaller(caller, proxyUpdaterFacade),
42
// WatchForProxyConfigAndAPIHostPortChanges returns a NotifyWatcher waiting for
43
// changes in the proxy configuration or API host ports
44
func (api *API) WatchForProxyConfigAndAPIHostPortChanges() (watcher.NotifyWatcher, error) {
45
var results params.NotifyWatchResults
46
args := params.Entities{
47
Entities: []params.Entity{{Tag: api.tag.String()}},
49
err := api.facade.FacadeCall("WatchForProxyConfigAndAPIHostPortChanges", args, &results)
53
if len(results.Results) != 1 {
54
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
56
result := results.Results[0]
57
if result.Error != nil {
58
return nil, result.Error
61
return newNotifyWatcher(api.facade.RawAPICaller(), result), nil
64
var newNotifyWatcher = apiwatcher.NewNotifyWatcher
66
func proxySettingsParamToProxySettings(cfg params.ProxyConfig) proxy.Settings {
67
return proxy.Settings{
75
// ProxyConfig returns the proxy settings for the current environment
76
func (api *API) ProxyConfig() (proxySettings, APTProxySettings proxy.Settings, err error) {
77
var results params.ProxyConfigResults
78
args := params.Entities{
79
Entities: []params.Entity{{Tag: api.tag.String()}},
81
err = api.facade.FacadeCall("ProxyConfig", args, &results)
83
return proxySettings, APTProxySettings, err
85
if len(results.Results) != 1 {
86
return proxySettings, APTProxySettings, errors.NotFoundf("ProxyConfig for %q", api.tag)
88
result := results.Results[0]
89
proxySettings = proxySettingsParamToProxySettings(result.ProxySettings)
90
APTProxySettings = proxySettingsParamToProxySettings(result.APTProxySettings)
91
return proxySettings, APTProxySettings, nil