<commit_before>package config

import (
	"encoding/json"
	"os"
	"time"

	"code.cloudfoundry.org/debugserver"
	"code.cloudfoundry.org/durationjson"
	"code.cloudfoundry.org/lager/lagerflags"
)

type SSHProxyConfig struct {
	lagerflags.LagerConfig
	debugserver.DebugServerConfig
	Address                   string                `json:"address,omitempty"`
	HealthCheckAddress        string                `json:"health_check_address,omitempty"`
	HostKey                   string                `json:"host_key"`
	BBSAddress                string                `json:"bbs_address"`
	CCAPIURL                  string                `json:"cc_api_url"`
	UAATokenURL               string                `json:"uaa_token_url"`
	UAAPassword               string                `json:"<PASSWORD>"`
	UAAUsername               string                `json:"uaa_username"`
	UAACACert                 string                `json:"uaa_ca_cert"`
	SkipCertVerify            bool                  `json:"skip_cert_verify"`
	DropsondePort             int                   `json:"dropsonde_port,omitempty"`
	EnableCFAuth              bool                  `json:"enable_cf_auth"`
	EnableDiegoAuth           bool                  `json:"enable_diego_auth"`
	DiegoCredentials          string                `json:"diego_credentials"`
	BBSCACert                 string                `json:"bbs_ca_cert"`
	BBSClientCert             string                `json:"bbs_client_cert"`
	BBSClientKey              string                `json:"bbs_client_key"`
	BBSClientSessionCacheSize int                   `json:"bbs_client_session_cache_size"`
	BBSMaxIdleConnsPerHost    int                   `json:"bbs_max_idle_conns_per_host"`
	ConsulCluster             string                `json:"consul_cluster"`
	AllowedCiphers            string                `json:"allowed_ciphers"`
	AllowedMACs               string                `json:"allowed_macs"`
	AllowedKeyExchanges       string                `json:"allowed_key_exchanges"`
	CommunicationTimeout      durationjson.Duration `json:"communication_timeout,omitempty"`
}

func defaultConfig() SSHProxyConfig {
	return SSHProxyConfig{
		Address:              ":2222",
		HealthCheckAddress:   ":2223",
		CommunicationTimeout: durationjson.Duration(10 * time.Second),
		DropsondePort:        3457,
		LagerConfig:          lagerflags.DefaultLagerConfig(),
	}
}

func NewSSHProxyConfig(configPath string) (SSHProxyConfig, error) {
	proxyConfig := defaultConfig()

	configFile, err := os.Open(configPath)
	if err != nil {
		return SSHProxyConfig{}, err
	}
	decoder := json.NewDecoder(configFile)

	err = decoder.Decode(&proxyConfig)
	if err != nil {
		return SSHProxyConfig{}, err
	}

	return proxyConfig, nil
}<commit_msg>Close config file after reading.<commit_after>package config

import (
	"encoding/json"
	"os"
	"time"

	"code.cloudfoundry.org/debugserver"
	"code.cloudfoundry.org/durationjson"
	"code.cloudfoundry.org/lager/lagerflags"
)

type SSHProxyConfig struct {
	lagerflags.LagerConfig
	debugserver.DebugServerConfig
	Address                   string                `json:"address,omitempty"`
	HealthCheckAddress        string                `json:"health_check_address,omitempty"`
	HostKey                   string                `json:"host_key"`
	BBSAddress                string                `json:"bbs_address"`
	CCAPIURL                  string                `json:"cc_api_url"`
	UAATokenURL               string                `json:"uaa_token_url"`
	UAAPassword               string                `json:"uaa_password"`
	UAAUsername               string                `json:"uaa_username"`
	UAACACert                 string                `json:"uaa_ca_cert"`
	SkipCertVerify            bool                  `json:"skip_cert_verify"`
	DropsondePort             int                   `json:"dropsonde_port,omitempty"`
	EnableCFAuth              bool                  `json:"enable_cf_auth"`
	EnableDiegoAuth           bool                  `json:"enable_diego_auth"`
	DiegoCredentials          string                `json:"diego_credentials"`
	BBSCACert                 string                `json:"bbs_ca_cert"`
	BBSClientCert             string                `json:"bbs_client_cert"`
	BBSClientKey              string                `json:"bbs_client_key"`
	BBSClientSessionCacheSize int                   `json:"bbs_client_session_cache_size"`
	BBSMaxIdleConnsPerHost    int                   `json:"bbs_max_idle_conns_per_host"`
	ConsulCluster             string                `json:"consul_cluster"`
	AllowedCiphers            string                `json:"allowed_ciphers"`
	AllowedMACs               string                `json:"allowed_macs"`
	AllowedKeyExchanges       string                `json:"allowed_key_exchanges"`
	CommunicationTimeout      durationjson.Duration `json:"communication_timeout,omitempty"`
}

func defaultConfig() SSHProxyConfig {
	return SSHProxyConfig{
		Address:              ":2222",
		HealthCheckAddress:   ":2223",
		CommunicationTimeout: durationjson.Duration(10 * time.Second),
		DropsondePort:        3457,
		LagerConfig:          lagerflags.DefaultLagerConfig(),
	}
}

func NewSSHProxyConfig(configPath string) (SSHProxyConfig, error) {
	proxyConfig := defaultConfig()

	configFile, err := os.Open(configPath)
	if err != nil {
		return SSHProxyConfig{}, err
	}

	defer configFile.Close()

	decoder := json.NewDecoder(configFile)

	err = decoder.Decode(&proxyConfig)
	if err != nil {
		return SSHProxyConfig{}, err
	}

	return proxyConfig, nil
}
{'fraction_non_alphanumeric': 0.08395151076533382, 'fraction_numerical': 0.005066039442735661, 'mean_word_length': 2.030701754385965, 'pattern_counts': {'":': 4, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7532618', 'n_tokens_mistral': 1619, 'n_tokens_neox': 1513, 'n_words': 268}