diff --git a/internal/fields/dependency_manager.go b/internal/fields/dependency_manager.go index 5a0de82bde..d9b979af93 100644 --- a/internal/fields/dependency_manager.go +++ b/internal/fields/dependency_manager.go @@ -86,9 +86,9 @@ func loadECSFieldsSchema(dep buildmanifest.ECSDependency) ([]FieldDefinition, er return nil, errors.Wrapf(err, "can't download the online schema (URL: %s)", url) } defer resp.Body.Close() - if resp.StatusCode == 404 { - return nil, fmt.Errorf("unsatisfied ECS dependency, reference defined in build manifest doesn't exist (HTTP 404, URL: %s)", url) - } else if resp.StatusCode != 200 { + if resp.StatusCode == http.StatusNotFound { + return nil, fmt.Errorf("unsatisfied ECS dependency, reference defined in build manifest doesn't exist (HTTP StatusNotFound, URL: %s)", url) + } else if resp.StatusCode != http.StatusOK { return nil, fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode) } diff --git a/internal/files/compress.go b/internal/files/compress.go index 3325016cff..0ce7019755 100644 --- a/internal/files/compress.go +++ b/internal/files/compress.go @@ -36,7 +36,10 @@ func Zip(sourcePath, destinationFile string) error { } defer os.RemoveAll(tempDir) workDir := filepath.Join(tempDir, folderNameFromFileName(destinationFile)) - os.MkdirAll(workDir, 0755) + err = os.MkdirAll(workDir, 0755) + if err != nil { + return errors.Wrapf(err, "can't prepare work directory: %s", workDir) + } logger.Debugf("Create work directory for archiving: %s", workDir) err = CopyAll(sourcePath, workDir) diff --git a/internal/kibana/agents.go b/internal/kibana/agents.go index 3ce0c52ffd..b605881866 100644 --- a/internal/kibana/agents.go +++ b/internal/kibana/agents.go @@ -7,6 +7,7 @@ package kibana import ( "encoding/json" "fmt" + "net/http" "time" "github.com/pkg/errors" @@ -45,8 +46,8 @@ func (c *Client) ListAgents() ([]Agent, error) { return nil, errors.Wrap(err, "could not list agents") } - if statusCode != 200 { - return nil, fmt.Errorf("could not list agents; API status code = %d", statusCode) + if statusCode != http.StatusOK { + return nil, fmt.Errorf("could not list agents; API status code = %d; response body = %s", statusCode, respBody) } var resp struct { @@ -70,8 +71,8 @@ func (c *Client) AssignPolicyToAgent(a Agent, p Policy) error { return errors.Wrap(err, "could not assign policy to agent") } - if statusCode != 200 { - return fmt.Errorf("could not assign policy to agent; API status code = %d; response body = %s", statusCode, string(respBody)) + if statusCode != http.StatusOK { + return fmt.Errorf("could not assign policy to agent; API status code = %d; response body = %s", statusCode, respBody) } err = c.waitUntilPolicyAssigned(a, p) @@ -115,8 +116,8 @@ func (c *Client) getAgent(agentID string) (*Agent, error) { return nil, errors.Wrap(err, "could not list agents") } - if statusCode != 200 { - return nil, fmt.Errorf("could not list agents; API status code = %d", statusCode) + if statusCode != http.StatusOK { + return nil, fmt.Errorf("could not list agents; API status code = %d; response body = %s", statusCode, respBody) } var resp struct { diff --git a/internal/kibana/dashboards.go b/internal/kibana/dashboards.go index d43397134a..d1e9313ad0 100644 --- a/internal/kibana/dashboards.go +++ b/internal/kibana/dashboards.go @@ -35,13 +35,13 @@ func (c *Client) Export(dashboardIDs []string) ([]common.MapStr, error) { path := fmt.Sprintf("%s/dashboards/export%s", CoreAPI, query.String()) statusCode, respBody, err := c.get(path) if err != nil { - return nil, errors.Wrapf(err, "could not export dashboards; API status code = %d; response body = %s", statusCode, string(respBody)) + return nil, errors.Wrapf(err, "could not export dashboards; API status code = %d; response body = %s", statusCode, respBody) } var exported exportedType err = json.Unmarshal(respBody, &exported) if err != nil { - return nil, errors.Wrapf(err, "unmarshalling response failed (body: \n%s)", string(respBody)) + return nil, errors.Wrapf(err, "unmarshalling response failed (body: \n%s)", respBody) } var multiErr multierror.Error diff --git a/internal/kibana/packages.go b/internal/kibana/packages.go index ab0710b878..c0669a5e98 100644 --- a/internal/kibana/packages.go +++ b/internal/kibana/packages.go @@ -7,6 +7,7 @@ package kibana import ( "encoding/json" "fmt" + "net/http" "github.com/pkg/errors" @@ -38,7 +39,7 @@ func (c *Client) RemovePackage(pkg packages.PackageManifest) ([]packages.Asset, } func processResults(action string, statusCode int, respBody []byte) ([]packages.Asset, error) { - if statusCode != 200 { + if statusCode != http.StatusOK { return nil, fmt.Errorf("could not %s package; API status code = %d; response body = %s", action, statusCode, respBody) } diff --git a/internal/kibana/policies.go b/internal/kibana/policies.go index 4db40a6714..86bc2bf020 100644 --- a/internal/kibana/policies.go +++ b/internal/kibana/policies.go @@ -7,6 +7,7 @@ package kibana import ( "encoding/json" "fmt" + "net/http" "github.com/pkg/errors" @@ -34,7 +35,7 @@ func (c *Client) CreatePolicy(p Policy) (*Policy, error) { return nil, errors.Wrap(err, "could not create policy") } - if statusCode != 200 { + if statusCode != http.StatusOK { return nil, fmt.Errorf("could not create policy; API status code = %d; response body = %s", statusCode, respBody) } @@ -56,7 +57,7 @@ func (c *Client) GetPolicy(policyID string) (*Policy, error) { return nil, errors.Wrap(err, "could not get policy") } - if statusCode != 200 { + if statusCode != http.StatusOK { return nil, fmt.Errorf("could not get policy; API status code = %d; response body = %s", statusCode, respBody) } @@ -80,7 +81,7 @@ func (c *Client) DeletePolicy(p Policy) error { return errors.Wrap(err, "could not delete policy") } - if statusCode != 200 { + if statusCode != http.StatusOK { return fmt.Errorf("could not delete policy; API status code = %d; response body = %s", statusCode, respBody) } @@ -150,7 +151,7 @@ func (c *Client) AddPackageDataStreamToPolicy(r PackageDataStream) error { return errors.Wrap(err, "could not add package to policy") } - if statusCode != 200 { + if statusCode != http.StatusOK { return fmt.Errorf("could not add package to policy; API status code = %d; response body = %s", statusCode, respBody) } diff --git a/internal/kibana/saved_objects.go b/internal/kibana/saved_objects.go index 8afcd36b72..c1a35ba9b4 100644 --- a/internal/kibana/saved_objects.go +++ b/internal/kibana/saved_objects.go @@ -60,7 +60,7 @@ func (c *Client) FindDashboards() (DashboardSavedObjects, error) { logger.Debug("Find dashboards using the Saved Objects API") var foundObjects DashboardSavedObjects - var page = 1 + page := 1 for { r, err := c.findDashboardsNextPage(page) @@ -94,7 +94,7 @@ func (c *Client) findDashboardsNextPage(page int) (*savedObjectsResponse, error) path := fmt.Sprintf("%s/_find?type=dashboard&fields=title&per_page=%d&page=%d", SavedObjectsAPI, findDashboardsPerPage, page) statusCode, respBody, err := c.get(path) if err != nil { - return nil, errors.Wrapf(err, "could not find dashboards; API status code = %d; response body = %s", statusCode, string(respBody)) + return nil, errors.Wrapf(err, "could not find dashboards; API status code = %d; response body = %s", statusCode, respBody) } var r savedObjectsResponse diff --git a/internal/packages/packages.go b/internal/packages/packages.go index ef4ca55b3a..89cfd24a8b 100644 --- a/internal/packages/packages.go +++ b/internal/packages/packages.go @@ -43,12 +43,10 @@ func (vv *VarValue) Unpack(value interface{}) error { switch u := value.(type) { case []interface{}: vv.list = u - return nil default: vv.scalar = u - return nil } - return errors.New("unknown variable value") + return nil } // MarshalJSON knows how to serialize a VarValue into the appropriate diff --git a/internal/registry/revisions.go b/internal/registry/revisions.go index 6e3f13e4ff..bbc6715b56 100644 --- a/internal/registry/revisions.go +++ b/internal/registry/revisions.go @@ -7,6 +7,7 @@ package registry import ( "encoding/json" "fmt" + "net/http" "sort" "github.com/Masterminds/semver" @@ -44,7 +45,7 @@ func (c *Client) Revisions(packageName string, options SearchOptions) ([]package if err != nil { return nil, errors.Wrap(err, "could not retrieve package") } - if statusCode != 200 { + if statusCode != http.StatusOK { return nil, fmt.Errorf("could not retrieve package; API status code = %d; response body = %s", statusCode, respBody) } diff --git a/internal/testrunner/runners/pipeline/ingest_pipeline.go b/internal/testrunner/runners/pipeline/ingest_pipeline.go index 2b4becf891..ce27a786ec 100644 --- a/internal/testrunner/runners/pipeline/ingest_pipeline.go +++ b/internal/testrunner/runners/pipeline/ingest_pipeline.go @@ -10,6 +10,7 @@ import ( "fmt" "io" "log" + "net/http" "os" "path/filepath" "regexp" @@ -169,7 +170,7 @@ func putIngestPipeline(esClient *elasticsearch.Client, pipeline pipelineResource return errors.Wrapf(err, "failed to read PutPipeline API response body (pipelineName: %s)", pipeline.name) } - if r.StatusCode != 200 { + if r.StatusCode != http.StatusOK { return errors.Wrapf(es.NewError(body), "unexpected response status for PutPipeline (%d): %s (pipelineName: %s)", r.StatusCode, r.Status(), pipeline.name) } @@ -190,7 +191,7 @@ func getIngestPipeline(esClient *elasticsearch.Client, pipelineName string) erro return errors.Wrapf(err, "failed to read GetPipeline API response body (pipelineName: %s)", pipelineName) } - if r.StatusCode != 200 { + if r.StatusCode != http.StatusOK { return errors.Wrapf(es.NewError(body), "unexpected response status for GetPipeline (%d): %s (pipelineName: %s)", r.StatusCode, r.Status(), pipelineName) } @@ -237,7 +238,7 @@ func simulatePipelineProcessing(esClient *elasticsearch.Client, pipelineName str return nil, errors.Wrap(err, "failed to read Simulate API response body") } - if r.StatusCode != 200 { + if r.StatusCode != http.StatusOK { return nil, errors.Wrapf(es.NewError(body), "unexpected response status for Simulate (%d): %s", r.StatusCode, r.Status()) }