mirror of
https://github.com/replicatedhq/troubleshoot.git
synced 2026-02-14 18:29:53 +00:00
* add a TLS parameter for cacert * pass a ca cert into http request * test preflight * make schemas * log extra information from http request * pass a proxy into the collector spec * hitting a segfault; breakpoint * accept a dir, file, or a string-literal as CA * move tls params into get, put, post methods * test for cert untrusted response * make generate * make schemas * more test cases * make schemas * dont include system certs * make generate && make schemas * resolve gosec G402 warning * remove old check for system certs * ignore errcheck "return value not checked" linter errors
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package collect
|
|
|
|
import (
|
|
"bytes"
|
|
"net/http"
|
|
"path/filepath"
|
|
|
|
"github.com/pkg/errors"
|
|
troubleshootv1beta2 "github.com/replicatedhq/troubleshoot/pkg/apis/troubleshoot/v1beta2"
|
|
)
|
|
|
|
type CollectHostHTTP struct {
|
|
hostCollector *troubleshootv1beta2.HostHTTP
|
|
BundlePath string
|
|
}
|
|
|
|
func (c *CollectHostHTTP) Title() string {
|
|
return hostCollectorTitleOrDefault(c.hostCollector.HostCollectorMeta, "HTTP Request")
|
|
}
|
|
|
|
func (c *CollectHostHTTP) IsExcluded() (bool, error) {
|
|
return isExcluded(c.hostCollector.Exclude)
|
|
}
|
|
|
|
func (c *CollectHostHTTP) Collect(progressChan chan<- interface{}) (map[string][]byte, error) {
|
|
httpCollector := c.hostCollector
|
|
|
|
var response *http.Response
|
|
var err error
|
|
|
|
switch {
|
|
case httpCollector.Get != nil:
|
|
response, err = doRequest(
|
|
"GET", httpCollector.Get.URL, httpCollector.Get.Headers,
|
|
"", httpCollector.Get.InsecureSkipVerify, httpCollector.Get.Timeout, httpCollector.Get.TLS, httpCollector.Get.Proxy)
|
|
case httpCollector.Post != nil:
|
|
response, err = doRequest(
|
|
"POST", httpCollector.Post.URL, httpCollector.Post.Headers,
|
|
httpCollector.Post.Body, httpCollector.Post.InsecureSkipVerify, httpCollector.Post.Timeout, httpCollector.Post.TLS, httpCollector.Post.Proxy)
|
|
case httpCollector.Put != nil:
|
|
response, err = doRequest(
|
|
"PUT", httpCollector.Put.URL, httpCollector.Put.Headers,
|
|
httpCollector.Put.Body, httpCollector.Put.InsecureSkipVerify, httpCollector.Put.Timeout, httpCollector.Put.TLS, httpCollector.Put.Proxy)
|
|
default:
|
|
return nil, errors.New("no supported http request type")
|
|
}
|
|
|
|
responseOutput, err := responseToOutput(response, err)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
collectorName := c.hostCollector.CollectorName
|
|
if collectorName == "" {
|
|
collectorName = "result"
|
|
}
|
|
name := filepath.Join("host-collectors/http", collectorName+".json")
|
|
|
|
output := NewResult()
|
|
output.SaveResult(c.BundlePath, name, bytes.NewBuffer(responseOutput))
|
|
|
|
httpOutput := map[string][]byte{
|
|
name: responseOutput,
|
|
}
|
|
|
|
return httpOutput, nil
|
|
}
|
|
|
|
func (c *CollectHostHTTP) RemoteCollect(progressChan chan<- interface{}) (map[string][]byte, error) {
|
|
return nil, ErrRemoteCollectorNotImplemented
|
|
}
|