Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions internal/fields/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
5 changes: 4 additions & 1 deletion internal/files/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions internal/kibana/agents.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package kibana
import (
"encoding/json"
"fmt"
"net/http"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/kibana/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/kibana/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package kibana
import (
"encoding/json"
"fmt"
"net/http"

"github.com/pkg/errors"

Expand Down Expand Up @@ -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)
}

Expand Down
9 changes: 5 additions & 4 deletions internal/kibana/policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package kibana
import (
"encoding/json"
"fmt"
"net/http"

"github.com/pkg/errors"

Expand Down Expand Up @@ -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)
}

Expand All @@ -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)
}

Expand All @@ -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)
}

Expand Down Expand Up @@ -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)
}

Expand Down
4 changes: 2 additions & 2 deletions internal/kibana/saved_objects.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions internal/packages/packages.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion internal/registry/revisions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package registry
import (
"encoding/json"
"fmt"
"net/http"
"sort"

"github.com/Masterminds/semver"
Expand Down Expand Up @@ -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)
}

Expand Down
7 changes: 4 additions & 3 deletions internal/testrunner/runners/pipeline/ingest_pipeline.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"io"
"log"
"net/http"
"os"
"path/filepath"
"regexp"
Expand Down Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down Expand Up @@ -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())
}

Expand Down