<commit_before>//
// SPDX-License-Identifier: BSD-3-Clause
//

package gofish

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net/http"

	"strings"

	"github.com/stmcginnis/gofish/school/common"
)

// ApiClient represents a connection to a Redfish/Swordfish enabled service
// or device.
type ApiClient struct {
	// Endpoint is the URL of the *fish service
	Endpoint string

	// Token is the session token to be used for all requests issued
	Token string

	// httpClient is for direct http actions
	httpClient *http.Client
}

// APIClient creates a new client connection to a Redfish service.
func APIClient(endpoint string, httpClient *http.Client) (c *ApiClient, err error) {
	if !strings.HasPrefix(endpoint, "http") {
		return c, fmt.Errorf("endpoint must starts with http or https")
	}
	client := &ApiClient{Endpoint: endpoint}
	if httpClient != nil {
		client.httpClient = httpClient
	} else {
		client.httpClient = &http.Client{}
	}
	return client, err
}

// Get performs a GET request against the Redfish service.
func (c *ApiClient) Get(url string) (*http.Response, error) {
	relativePath := url<commit_msg>Ignore cert validation for now<commit_after>//
// SPDX-License-Identifier: BSD-3-Clause
//

package gofish

import (
	"bytes"
	"crypto/tls"
	"fmt"
	"io/ioutil"
	"net/http"

	"strings"

	"github.com/stmcginnis/gofish/school/common"
)

// ApiClient represents a connection to a Redfish/Swordfish enabled service
// or device.
type ApiClient struct {
	// Endpoint is the URL of the *fish service
	Endpoint string

	// Token is the session token to be used for all requests issued
	Token string

	// httpClient is for direct http actions
	httpClient *http.Client
}

// APIClient creates a new client connection to a Redfish service.
func APIClient(endpoint string, httpClient *http.Client) (c *ApiClient, err error) {
	if !strings.HasPrefix(endpoint, "http") {
		return c, fmt.Errorf("endpoint must starts with http or https")
	}

	client := &ApiClient{Endpoint: endpoint}
	if httpClient != nil {
		client.httpClient = httpClient
	} else {
		// TODO: Provide config or arg to be able to control whether to skip
		// certificate validation.
		defaultTransport := http.DefaultTransport.(*http.Transport)
		transport := &http.Transport{ // copy default parameters
			Proxy:                 defaultTransport.Proxy,
			DialContext:           defaultTransport.DialContext,
			MaxIdleConns:          defaultTransport.MaxIdleConns,
			IdleConnTimeout:       defaultTransport.IdleConnTimeout,
			ExpectContinueTimeout: defaultTransport.ExpectContinueTimeout,
			TLSHandshakeTimeout:   defaultTransport.TLSHandshakeTimeout,
			TLSClientConfig: &tls.Config{
				InsecureSkipVerify: true,
			},
		}
		client.httpClient = &http.Client{Transport: transport}
	}
	return client, err
}

// Get performs a GET request against the Redfish service.
func (c *ApiClient) Get(url string) (*http.Response, error) {
	relativePath := url
{'fraction_non_alphanumeric': 0.09879931389365351, 'fraction_numerical': 0.0006861063464837049, 'mean_word_length': 3.827814569536424, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '868058', 'n_tokens_mistral': 916, 'n_tokens_neox': 891, 'n_words': 285}