mirror of
https://github.com/rancher/os.git
synced 2025-09-09 02:31:36 +00:00
Refactor a little so 'ros os list' also uses the configured proxy info
Signed-off-by: Sven Dowideit <SvenDowideit@home.org.au>
This commit is contained in:
@@ -3,7 +3,6 @@ package control
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
@@ -22,6 +21,7 @@ import (
|
||||
"github.com/rancher/os/compose"
|
||||
"github.com/rancher/os/config"
|
||||
"github.com/rancher/os/docker"
|
||||
"github.com/rancher/os/util/network"
|
||||
)
|
||||
|
||||
type Images struct {
|
||||
@@ -83,7 +83,6 @@ func osSubcommands() []cli.Command {
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: this and the getLatestImage should probably move to utils/network and be suitably cached.
|
||||
func getImages() (*Images, error) {
|
||||
upgradeURL, err := getUpgradeURL()
|
||||
if err != nil {
|
||||
@@ -108,12 +107,7 @@ func getImages() (*Images, error) {
|
||||
u.RawQuery = q.Encode()
|
||||
upgradeURL = u.String()
|
||||
|
||||
resp, err := http.Get(upgradeURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err = ioutil.ReadAll(resp.Body)
|
||||
body, err = network.LoadFromNetwork(upgradeURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -19,6 +19,7 @@ import (
|
||||
|
||||
"github.com/rancher/os/config/cloudinit/datasource"
|
||||
"github.com/rancher/os/config/cloudinit/pkg"
|
||||
"github.com/rancher/os/util/network"
|
||||
)
|
||||
|
||||
type RemoteFile struct {
|
||||
@@ -31,6 +32,7 @@ func NewDatasource(url string) *RemoteFile {
|
||||
}
|
||||
|
||||
func (f *RemoteFile) IsAvailable() bool {
|
||||
network.SetProxyEnvironmentVariables()
|
||||
client := pkg.NewHTTPClient()
|
||||
_, f.lastError = client.Get(f.url)
|
||||
return (f.lastError == nil)
|
||||
|
@@ -451,7 +451,7 @@ func RunInit() error {
|
||||
}},
|
||||
config.CfgFuncData{"load modules2", loadModules},
|
||||
config.CfgFuncData{"set proxy env", func(cfg *config.CloudConfig) (*config.CloudConfig, error) {
|
||||
network.SetProxyEnvironmentVariables(cfg)
|
||||
network.SetProxyEnvironmentVariables()
|
||||
return cfg, nil
|
||||
}},
|
||||
config.CfgFuncData{"init SELinux", initializeSelinux},
|
||||
|
@@ -57,7 +57,8 @@ func getServices(urls []string, key string) ([]string, error) {
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func SetProxyEnvironmentVariables(cfg *config.CloudConfig) {
|
||||
func SetProxyEnvironmentVariables() {
|
||||
cfg := config.LoadConfig()
|
||||
if cfg.Rancher.Network.HTTPProxy != "" {
|
||||
err := os.Setenv("HTTP_PROXY", cfg.Rancher.Network.HTTPProxy)
|
||||
if err != nil {
|
||||
@@ -78,14 +79,16 @@ func SetProxyEnvironmentVariables(cfg *config.CloudConfig) {
|
||||
}
|
||||
}
|
||||
|
||||
func loadFromNetwork(location string) ([]byte, error) {
|
||||
func LoadFromNetworkWithCache(location string) ([]byte, error) {
|
||||
bytes := cacheLookup(location)
|
||||
if bytes != nil {
|
||||
return bytes, nil
|
||||
}
|
||||
return LoadFromNetwork(location)
|
||||
}
|
||||
|
||||
cfg := config.LoadConfig()
|
||||
SetProxyEnvironmentVariables(cfg)
|
||||
func LoadFromNetwork(location string) ([]byte, error) {
|
||||
SetProxyEnvironmentVariables()
|
||||
|
||||
var err error
|
||||
|
||||
@@ -116,7 +119,7 @@ func LoadResource(location string, network bool) ([]byte, error) {
|
||||
if !network {
|
||||
return nil, ErrNoNetwork
|
||||
}
|
||||
return loadFromNetwork(location)
|
||||
return LoadFromNetworkWithCache(location)
|
||||
} else if strings.HasPrefix(location, "/") {
|
||||
return ioutil.ReadFile(location)
|
||||
}
|
||||
|
Reference in New Issue
Block a user