Ejemplo n.º 1
0
func (fileSource *FileSource) Get() (map[string]interface{}, error) {

	content, err := ioutil.ReadFile(fileSource.Path)

	if err != nil {
		return nil, err
	}

	result := make(map[string]interface{})
	parsers.MustGetParser(fileSource.Format).Parse(content, result)

	return result, nil
}
Ejemplo n.º 2
0
func (shellSource *ShellSource) Get() (map[string]interface{}, error) {

	cmd := exec.ShellInvocationCommand(shellSource.Command)

	cmdOut, err := cmd.Output()
	if err != nil {
		return nil, err
	}

	result := make(map[string]interface{})
	parsers.MustGetParser(shellSource.Format).Parse(cmdOut, result)

	return result, nil
}
Ejemplo n.º 3
0
func (httpSource *HTTPSource) Get() (map[string]interface{}, error) {
	response, err := http.Get(httpSource.URL)

	if err != nil {
		return nil, err
	}

	defer response.Body.Close()

	content, err := ioutil.ReadAll(response.Body)

	if err != nil {
		return nil, err
	}

	result := make(map[string]interface{})
	parsers.MustGetParser(httpSource.Format).Parse(content, result)

	return result, nil
}
Ejemplo n.º 4
0
func (httpSource *HTTPSource) Get() (map[string]interface{}, error) {
	transport := &http.Transport{
		TLSClientConfig: &tls.Config{
			InsecureSkipVerify: httpSource.Insecure,
		},
	}

	if httpSource.TLS.Cert != "" {
		cert, err := tls.X509KeyPair([]byte(httpSource.TLS.Cert), []byte(httpSource.TLS.Key))
		if err != nil {
			return nil, err
		}

		transport.TLSClientConfig.Certificates = []tls.Certificate{cert}
	}

	client := &http.Client{Transport: transport}

	response, err := client.Get(httpSource.URL)

	if err != nil {
		return nil, err
	}

	if response.StatusCode < http.StatusOK || response.StatusCode >= http.StatusBadRequest {
		return nil, errors.New(response.Status)
	}

	defer response.Body.Close()

	content, err := ioutil.ReadAll(response.Body)

	if err != nil {
		return nil, err
	}

	result := make(map[string]interface{})
	parsers.MustGetParser(httpSource.Format).Parse(content, result)

	return result, nil
}