<commit_before>// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor: <NAME> <EMAIL> [:ulfr]
package client

import (
	"code.google.com/p/gcfg"
	"encoding/json"
	"fmt"
	"github.com/jvehent/cljs"
	"io/ioutil"
	"mig"
	"mig/pgp"
	"net/http"
	"net/url"
	"os"
	"os/user"
	"runtime"
	"time"
)

// A Client provides all the needed functionalities to interact with the MIG API.
// It should be initialized with a proper configuration file.
type Client struct {
	API   *http.Client
	Token string
	Conf  Configuration
}

// Configuration stores the live configuration and global parameters of a client
type Configuration struct {
	API struct {
		URL string
	}
	Homedir string
	GPG     struct {
		Home      string
		KeyID     string
		Keyserver string
	}
}

// NewClient initiates a new instance of a Client
func NewClient(conf Configuration) Client {
	var cli Client
	cli.Conf = conf
	tr := &http.Transport{
		// TODO: add TLS support
		//TLSClientConfig:    &tls.Config{RootCAs: pool},
		DisableCompression: false,
		DisableKeepAlives:  false,
	}
	cli.API = &http.Client{Transport: tr}
	return cli
}

// ReadConfiguration loads a client configuration from a local configuration file
// and verifies that GnuPG's secring is available
func ReadConfiguration(file string) (conf Configuration, err error) {
	defer func() {
		if e := recover(); e != nil {
			err = fmt.Errorf("ReadConfiguration() -> %v", e)
		}<commit_msg>[minor] TLS conf for api client<commit_after>// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
// Contributor: <NAME> <EMAIL> [:ulfr]
package client

import (
	"code.google.com/p/gcfg"
	"crypto/tls"
	"encoding/json"
	"fmt"
	"github.com/jvehent/cljs"
	"io/ioutil"
	"mig"
	"mig/pgp"
	"net/http"
	"net/url"
	"os"
	"os/user"
	"runtime"
	"time"
)

// A Client provides all the needed functionalities to interact with the MIG API.
// It should be initialized with a proper configuration file.
type Client struct {
	API   *http.Client
	Token string
	Conf  Configuration
}

// Configuration stores the live configuration and global parameters of a client
type Configuration struct {
	API     ApiConf
	Homedir string
	GPG     GpgConf
}

type ApiConf struct {
	URL            string
	SkipVerifyCert bool
}
type GpgConf struct {
	Home      string
	KeyID     string
	Keyserver string
}

// NewClient initiates a new instance of a Client
func NewClient(conf Configuration) Client {
	var cli Client
	cli.Conf = conf
	tr := &http.Transport{
		// TODO: add TLS support
		//TLSClientConfig:    &tls.Config{RootCAs: pool},
		DisableCompression: false,
		DisableKeepAlives:  false,
		TLSClientConfig: &tls.Config{
			MinVersion: tls.VersionTLS10,
			CipherSuites: []uint16{
				tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
				tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
				tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
				tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
				tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
				tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
				tls.TLS_RSA_WITH_AES_128_CBC_SHA,
				tls.TLS_RSA_WITH_AES_256_CBC_SHA,
			},
			InsecureSkipVerify: conf.API.SkipVerifyCert,
		},
	}
	cli.API = &http.Client{Transport: tr}
	return cli
}

// ReadConfiguration loads a client configuration from a local configuration file
// and verifies that GnuPG's secring is available
func ReadConfiguration(file string) (conf Configuration, err error) {
	defer func() {
		if e := recover(); e != nil {
			err = fmt.Errorf("ReadConfiguration() -> %v", e)
		}
{'fraction_non_alphanumeric': 0.0989888238424694, 'fraction_numerical': 0.011176157530601383, 'mean_word_length': 3.617936117936118, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2817130', 'n_tokens_mistral': 1396, 'n_tokens_neox': 1282, 'n_words': 398}