func (config *Config) HTTPSProxy() string {
	if config.ENV.HTTPSProxy != "" {
		return config.ENV.HTTPSProxy
	}
	return ""
}
HTTPSProxy returns the proxy url that the CLI should use. The url is based
off of:
1. The $https_proxy environment variable if set
2. Defaults to the empty string
package configv3
import (
	"encoding/json"
	"io/ioutil"
	"math"
	"os"
	"os/signal"
	"path/filepath"
	"strconv"
	"strings"
	"syscall"
	"time"
	"golang.org/x/crypto/ssh/terminal"
	"code.cloudfoundry.org/cli/command/translatableerror"
	"code.cloudfoundry.org/cli/version"
)
const (
	DefaultDialTimeout = 5 * time.Second
	DefaultNOAARetryCount = 5
	DefaultOverallPollingTimeout = time.Duration(1 << 62)
	DefaultPollingInterval = 3 * time.Second
	DefaultStagingTimeout = 15 * time.Minute
	DefaultStartupTimeout = 5 * time.Minute
	DefaultTarget = ""
	DefaultSSHOAuthClient = "ssh-proxy"
	DefaultUAAOAuthClient = "cf"
	DefaultUAAOAuthClientSecret = ""
	DefaultRetryCount = 2
)
func LoadConfig(flags ...FlagOverride) (*Config, error) {
	err := removeOldTempConfigFiles()
	if err != nil {
		return nil, err
	}
	configFilePath := ConfigFilePath()
	config := Config{
		ConfigFile: CFConfig{
			ConfigVersion: 3,
			Target:        DefaultTarget,
			ColorEnabled:  DefaultColorEnabled,
			PluginRepositories: []PluginRepository{{
				Name: DefaultPluginRepoName,
				URL:  DefaultPluginRepoURL,
			}},
		},
	}
	var jsonError error
	if _, err = os.Stat(configFilePath); err == nil || !os.IsNotExist(err) {
		var file []byte
		file, err = ioutil.ReadFile(configFilePath)
		if err != nil {
			return nil, err
		}
		if len(file) == 0 {
			jsonError = translatableerror.EmptyConfigError{FilePath: configFilePath}
		} else {
			var configFile CFConfig
			err = json.Unmarshal(file, &configFile)
			if err != nil {
				return nil, err
			}
			config.ConfigFile = configFile
		}
	}
	if config.ConfigFile.SSHOAuthClient == "" {
		config.ConfigFile.SSHOAuthClient = DefaultSSHOAuthClient
	}
	if config.ConfigFile.UAAOAuthClient == "" {
		config.ConfigFile.UAAOAuthClient = DefaultUAAOAuthClient
		config.ConfigFile.UAAOAuthClientSecret = DefaultUAAOAuthClientSecret
	}
	config.ENV = EnvOverride{
		BinaryName:       filepath.Base(os.Args[0]),
		CFColor:          os.Getenv("CF_COLOR"),
		CFDialTimeout:    os.Getenv("CF_DIAL_TIMEOUT"),
		CFLogLevel:       os.Getenv("CF_LOG_LEVEL"),
		CFPluginHome:     os.Getenv("CF_PLUGIN_HOME"),
		CFStagingTimeout: os.Getenv("CF_STAGING_TIMEOUT"),
		CFStartupTimeout: os.Getenv("CF_STARTUP_TIMEOUT"),
		CFTrace:          os.Getenv("CF_TRACE"),
		DockerPassword:   os.Getenv("CF_DOCKER_PASSWORD"),
		Experimental:     os.Getenv("CF_CLI_EXPERIMENTAL"),
		ForceTTY:         os.Getenv("FORCE_TTY"),
		HTTPSProxy:       os.Getenv("https_proxy"),
		Lang:             os.Getenv("LANG"),
		LCAll:            os.Getenv("LC_ALL"),
	}
	pluginFilePath := filepath.Join(config.PluginHome(), "config.json")
	if _, err = os.Stat(pluginFilePath); os.IsNotExist(err) {
		config.pluginsConfig = PluginsConfig{
			Plugins: make(map[string]Plugin),
		}
	} else {
		var file []byte
		file, err = ioutil.ReadFile(pluginFilePath)
		if err != nil {
			return nil, err
		}
		err = json.Unmarshal(file, &config.pluginsConfig)
		if err != nil {
			return nil, err
		}
		for name, plugin := range config.pluginsConfig.Plugins {
			plugin.Name = name
			config.pluginsConfig.Plugins[name] = plugin
		}
	}
	if len(flags) > 0 {
		config.Flags = flags[0]
	}
	pwd, err := os.Getwd()
	if err != nil {
		return nil, err
	}
	isTTY := terminal.IsTerminal(int(os.Stdout.Fd()))
	terminalWidth := math.MaxInt32
	if isTTY {
		var err error
		terminalWidth, _, err = terminal.GetSize(int(os.Stdout.Fd()))
		if err != nil {
			return nil, err
		}
	}
	config.detectedSettings = detectedSettings{
		currentDirectory: pwd,
		terminalWidth:    terminalWidth,
		tty:              isTTY,
	}
	return &config, jsonError
}
func removeOldTempConfigFiles() error {
	oldTempFileNames, err := filepath.Glob(filepath.Join(configDirectory(), "temp-config?*"))
	if err != nil {
		return err
	}
	for _, oldTempFileName := range oldTempFileNames {
		err = os.Remove(oldTempFileName)
		if err != nil {
			return err
		}
	}
	return nil
}
func WriteConfig(c *Config) error {
	rawConfig, err := json.MarshalIndent(c.ConfigFile, "", "  ")
	if err != nil {
		return err
	}
	dir := configDirectory()
	err = os.MkdirAll(dir, 0700)
	if err != nil {
		return err
	}
	sig := make(chan os.Signal, 10)
	signal.Notify(sig, syscall.SIGHUP, syscall.SIGINT, syscall.SIGKILL, syscall.SIGQUIT, syscall.SIGTERM, os.Interrupt)
	defer signal.Stop(sig)
	tempConfigFile, err := ioutil.TempFile(dir, "temp-config")
	if err != nil {
		return err
	}
	tempConfigFile.Close()
	tempConfigFileName := tempConfigFile.Name()
	go catchSignal(sig, tempConfigFileName)
	err = ioutil.WriteFile(tempConfigFileName, rawConfig, 0600)
	if err != nil {
		return err
	}
	return os.Rename(tempConfigFileName, ConfigFilePath())
}
func catchSignal(sig chan os.Signal, tempConfigFileName string) {
	select {
	case <-sig:
		_ = os.Remove(tempConfigFileName)
		os.Exit(2)
	}
}
type Config struct {
	ConfigFile CFConfig
	ENV EnvOverride
	Flags FlagOverride
	detectedSettings detectedSettings
	pluginsConfig PluginsConfig
}
type CFConfig struct {
	ConfigVersion            int                `json:"ConfigVersion"`
	Target                   string             `json:"Target"`
	APIVersion               string             `json:"APIVersion"`
	AuthorizationEndpoint    string             `json:"AuthorizationEndpoint"`
	DopplerEndpoint          string             `json:"DopplerEndPoint"`
	UAAEndpoint              string             `json:"UaaEndpoint"`
	RoutingEndpoint          string             `json:"RoutingAPIEndpoint"`
	AccessToken              string             `json:"AccessToken"`
	SSHOAuthClient           string             `json:"SSHOAuthClient"`
	UAAOAuthClient           string             `json:"UAAOAuthClient"`
	UAAOAuthClientSecret     string             `json:"UAAOAuthClientSecret"`
	RefreshToken             string             `json:"RefreshToken"`
	TargetedOrganization     Organization       `json:"OrganizationFields"`
	TargetedSpace            Space              `json:"SpaceFields"`
	SkipSSLValidation        bool               `json:"SSLDisabled"`
	AsyncTimeout             int                `json:"AsyncTimeout"`
	Trace                    string             `json:"Trace"`
	ColorEnabled             string             `json:"ColorEnabled"`
	Locale                   string             `json:"Locale"`
	PluginRepositories       []PluginRepository `json:"PluginRepos"`
	MinCLIVersion            string             `json:"MinCLIVersion"`
	MinRecommendedCLIVersion string             `json:"MinRecommendedCLIVersion"`
}
type Organization struct {
	GUID            string          `json:"GUID"`
	Name            string          `json:"Name"`
	QuotaDefinition QuotaDefinition `json:"QuotaDefinition"`
}
type QuotaDefinition struct {
	GUID                    string `json:"guid"`
	Name                    string `json:"name"`
	MemoryLimit             int    `json:"memory_limit"`
	InstanceMemoryLimit     int    `json:"instance_memory_limit"`
	TotalRoutes             int    `json:"total_routes"`
	TotalServices           int    `json:"total_services"`
	NonBasicServicesAllowed bool   `json:"non_basic_services_allowed"`
	AppInstanceLimit        int    `json:"app_instance_limit"`
	TotalReservedRoutePorts int    `json:"total_reserved_route_ports"`
}
type Space struct {
	GUID     string `json:"GUID"`
	Name     string `json:"Name"`
	AllowSSH bool   `json:"AllowSSH"`
}
type EnvOverride struct {
	BinaryName       string
	CFColor          string
	CFDialTimeout    string
	CFHome           string
	CFLogLevel       string
	CFPluginHome     string
	CFStagingTimeout string
	CFStartupTimeout string
	CFTrace          string
	DockerPassword   string
	Experimental     string
	ForceTTY         string
	HTTPSProxy       string
	Lang             string
	LCAll            string
}
type FlagOverride struct {
	Verbose bool
}
type detectedSettings struct {
	currentDirectory string
	terminalWidth    int
	tty              bool
}
func (config *Config) Target() string {
	return config.ConfigFile.Target
}
func (config *Config) PollingInterval() time.Duration {
	return DefaultPollingInterval
}
func (config *Config) OverallPollingTimeout() time.Duration {
	if config.ConfigFile.AsyncTimeout == 0 {
		return DefaultOverallPollingTimeout
	}
	return time.Duration(config.ConfigFile.AsyncTimeout) * time.Minute
}
func (config *Config) SkipSSLValidation() bool {
	return config.ConfigFile.SkipSSLValidation
}
func (config *Config) AccessToken() string {
	return config.ConfigFile.AccessToken
}
func (config *Config) RefreshToken() string {
	return config.ConfigFile.RefreshToken
}
func (config *Config) SSHOAuthClient() string {
	return config.ConfigFile.SSHOAuthClient
}
func (config *Config) UAAOAuthClient() string {
	return config.ConfigFile.UAAOAuthClient
}
func (config *Config) UAAOAuthClientSecret() string {
	return config.ConfigFile.UAAOAuthClientSecret
}
func (config *Config) APIVersion() string {
	return config.ConfigFile.APIVersion
}
func (config *Config) MinCLIVersion() string {
	return config.ConfigFile.MinCLIVersion
}
func (config *Config) TargetedOrganization() Organization {
	return config.ConfigFile.TargetedOrganization
}
func (config *Config) TargetedSpace() Space {
	return config.ConfigFile.TargetedSpace
}
func (config *Config) StagingTimeout() time.Duration {
	if config.ENV.CFStagingTimeout != "" {
		val, err := strconv.ParseInt(config.ENV.CFStagingTimeout, 10, 64)
		if err == nil {
			return time.Duration(val) * time.Minute
		}
	}
	return DefaultStagingTimeout
}
func (config *Config) StartupTimeout() time.Duration {
	if config.ENV.CFStartupTimeout != "" {
		val, err := strconv.ParseInt(config.ENV.CFStartupTimeout, 10, 64)
		if err == nil {
			return time.Duration(val) * time.Minute
		}
	}
	return DefaultStartupTimeout
}