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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/elastic/elastic-package

go 1.15
go 1.16

require (
github.com/AlecAivazis/survey/v2 v2.2.15
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,11 @@ github.com/fatih/camelcase v1.0.0/go.mod h1:yN2Sb0lFhZJUdVvtELVWefmrXpuZESvPmqwo
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc=
github.com/fatih/color v1.12.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568 h1:BHsljHzVlRcyQhjrss6TZTdY2VfCqZPbv5k3iBFa2ZQ=
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k=
github.com/franela/goblin v0.0.0-20200105215937-c9ffbefa60db/go.mod h1:7dvUGVsVBjqR7JHJk0brhHOZYGmfBYOrK0ZhYMEtBr4=
github.com/franela/goreq v0.0.0-20171204163338-bcd34c9993f8/go.mod h1:ZhphrRTfi2rbfLwlschooIH4+wKKDR4Pdxhh+TRoA20=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fvbommel/sortorder v1.0.1/go.mod h1:uk88iVf1ovNn1iLfgUVU2F9o5eO30ui720w+kxuqRs0=
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
Expand Down
6 changes: 3 additions & 3 deletions internal/builder/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package builder

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
Expand All @@ -31,7 +31,7 @@ func encodeDashboards(destinationDir string) error {
}
for _, file := range savedObjects {

data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
return err
}
Expand All @@ -41,7 +41,7 @@ func encodeDashboards(destinationDir string) error {
}

if changed {
err = ioutil.WriteFile(file, output, 0644)
err = os.WriteFile(file, output, 0644)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions internal/builder/external_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package builder

import (
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
Expand Down Expand Up @@ -42,7 +42,7 @@ func resolveExternalFields(packageRoot, destinationDir string) error {
return err
}
for _, file := range fieldsFile {
data, err := ioutil.ReadFile(file)
data, err := os.ReadFile(file)
if err != nil {
return err
}
Expand All @@ -54,7 +54,7 @@ func resolveExternalFields(packageRoot, destinationDir string) error {
} else if injected {
logger.Debugf("%s: source file has been changed", rel)

err = ioutil.WriteFile(file, output, 0644)
err = os.WriteFile(file, output, 0644)
if err != nil {
return err
}
Expand Down
9 changes: 4 additions & 5 deletions internal/docs/readme.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ package docs
import (
"bytes"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"text/template"
Expand All @@ -33,7 +32,7 @@ func AreReadmesUpToDate() ([]ReadmeFile, error) {
return nil, errors.Wrap(err, "package root not found")
}

files, err := ioutil.ReadDir(filepath.Join(packageRoot, "_dev", "build", "docs"))
files, err := os.ReadDir(filepath.Join(packageRoot, "_dev", "build", "docs"))
if err != nil && !os.IsNotExist(err) {
return nil, errors.Wrap(err, "reading directory entries failed")
}
Expand Down Expand Up @@ -87,7 +86,7 @@ func isReadmeUpToDate(fileName, packageRoot string) (bool, error) {
// UpdateReadmes function updates all .md readme files using a defined template
// files. The function doesn't perform any action if the template file is not present.
func UpdateReadmes(packageRoot string) ([]string, error) {
readmeFiles, err := ioutil.ReadDir(filepath.Join(packageRoot, "_dev", "build", "docs"))
readmeFiles, err := os.ReadDir(filepath.Join(packageRoot, "_dev", "build", "docs"))
if err != nil && !os.IsNotExist(err) {
return nil, errors.Wrap(err, "reading directory entries failed")
}
Expand Down Expand Up @@ -199,7 +198,7 @@ func readReadme(fileName, packageRoot string) ([]byte, bool, error) {
logger.Debugf("Read existing %s file (package: %s)", fileName, packageRoot)

readmePath := filepath.Join(packageRoot, "docs", fileName)
b, err := ioutil.ReadFile(readmePath)
b, err := os.ReadFile(readmePath)
if err != nil && os.IsNotExist(err) {
return nil, false, nil
}
Expand All @@ -222,7 +221,7 @@ func writeReadme(fileName, packageRoot string, content []byte) (string, error) {
aReadmePath := readmePath(fileName, packageRoot)
logger.Debugf("Write %s file to: %s", fileName, aReadmePath)

err = ioutil.WriteFile(aReadmePath, content, 0644)
err = os.WriteFile(aReadmePath, content, 0644)
if err != nil {
return "", errors.Wrapf(err, "writing file failed (path: %s)", aReadmePath)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/docs/sample_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package docs

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

Expand All @@ -20,7 +20,7 @@ const sampleEventFile = "sample_event.json"
func renderSampleEvent(packageRoot, dataStreamName string) (string, error) {
eventPath := filepath.Join(packageRoot, "data_stream", dataStreamName, sampleEventFile)

body, err := ioutil.ReadFile(eventPath)
body, err := os.ReadFile(eventPath)
if err != nil {
return "", errors.Wrapf(err, "reading sample event file failed (path: %s)", eventPath)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/export/dashboards.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package export

import (
"encoding/json"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -86,7 +85,7 @@ func saveObjectsToFiles(packageRoot string, objects []common.MapStr) error {

// Save object to file
objectPath := filepath.Join(targetDir, id.(string)+".json")
err = ioutil.WriteFile(objectPath, b, 0644)
err = os.WriteFile(objectPath, b, 0644)
if err != nil {
return errors.Wrap(err, "writing to file failed")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/export/dashboards_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package export

import (
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -15,7 +15,7 @@ import (
)

func TestTransform(t *testing.T) {
b, err := ioutil.ReadFile("./test/system-navigation.json")
b, err := os.ReadFile("./test/system-navigation.json")
require.NoError(t, err)

var given common.MapStr
Expand All @@ -33,7 +33,7 @@ func TestTransform(t *testing.T) {
result, err := json.MarshalIndent(&results[0], "", " ")
require.NoError(t, err)

expected, err := ioutil.ReadFile("./test/system-navigation.json-expected.json")
expected, err := os.ReadFile("./test/system-navigation.json-expected.json")
require.NoError(t, err)

require.Equal(t, string(expected), string(result))
Expand Down
8 changes: 4 additions & 4 deletions internal/fields/dependency_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package fields

import (
"fmt"
"io/ioutil"
"io"
"net/http"
"os"
"path/filepath"
Expand Down Expand Up @@ -72,7 +72,7 @@ func loadECSFieldsSchema(dep buildmanifest.ECSDependency) ([]FieldDefinition, er
}

cachedSchemaPath := filepath.Join(loc.FieldsCacheDir(), ecsSchemaName, gitReference, ecsSchemaFile)
content, err := ioutil.ReadFile(cachedSchemaPath)
content, err := os.ReadFile(cachedSchemaPath)
if err != nil && !errors.Is(err, os.ErrNotExist) {
return nil, errors.Wrapf(err, "can't read cached schema (path: %s)", cachedSchemaPath)
}
Expand All @@ -92,7 +92,7 @@ func loadECSFieldsSchema(dep buildmanifest.ECSDependency) ([]FieldDefinition, er
return nil, fmt.Errorf("unexpected HTTP status code: %d", resp.StatusCode)
}

content, err = ioutil.ReadAll(resp.Body)
content, err = io.ReadAll(resp.Body)
if err != nil {
return nil, errors.Wrapf(err, "can't read schema content (URL: %s)", url)
}
Expand All @@ -105,7 +105,7 @@ func loadECSFieldsSchema(dep buildmanifest.ECSDependency) ([]FieldDefinition, er
}

logger.Debugf("Cache downloaded schema: %s", cachedSchemaPath)
err = ioutil.WriteFile(cachedSchemaPath, content, 0644)
err = os.WriteFile(cachedSchemaPath, content, 0644)
if err != nil {
return nil, errors.Wrapf(err, "can't write cached schema (path: %s)", cachedSchemaPath)
}
Expand Down
6 changes: 3 additions & 3 deletions internal/fields/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ package fields
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"regexp"
"strings"
Expand Down Expand Up @@ -101,15 +101,15 @@ func CreateValidatorForDataStream(dataStreamRootPath string, opts ...ValidatorOp

func loadFieldsForDataStream(dataStreamRootPath string) ([]FieldDefinition, error) {
fieldsDir := filepath.Join(dataStreamRootPath, "fields")
fileInfos, err := ioutil.ReadDir(fieldsDir)
fileInfos, err := os.ReadDir(fieldsDir)
if err != nil {
return nil, errors.Wrapf(err, "reading directory with fields failed (path: %s)", fieldsDir)
}

var fields []FieldDefinition
for _, fileInfo := range fileInfos {
f := filepath.Join(fieldsDir, fileInfo.Name())
body, err := ioutil.ReadFile(f)
body, err := os.ReadFile(f)
if err != nil {
return nil, errors.Wrap(err, "reading fields file failed")
}
Expand Down
6 changes: 3 additions & 3 deletions internal/fields/validate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package fields

import (
"encoding/json"
"io/ioutil"
"os"
"testing"

"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -210,7 +210,7 @@ func Test_parseElementValue(t *testing.T) {
}

func readTestResults(t *testing.T, path string) (f results) {
c, err := ioutil.ReadFile(path)
c, err := os.ReadFile(path)
require.NoError(t, err)

err = json.Unmarshal(c, &f)
Expand All @@ -219,7 +219,7 @@ func readTestResults(t *testing.T, path string) (f results) {
}

func readSampleEvent(t *testing.T, path string) json.RawMessage {
c, err := ioutil.ReadFile(path)
c, err := os.ReadFile(path)
require.NoError(t, err)
return c
}
3 changes: 1 addition & 2 deletions internal/files/remove.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
package files

import (
"io/ioutil"
"os"
"path/filepath"

Expand All @@ -14,7 +13,7 @@ import (

// RemoveContent method wipes out the directory content.
func RemoveContent(dir string) error {
fis, err := ioutil.ReadDir(dir)
fis, err := os.ReadDir(dir)
if err != nil {
return errors.Wrapf(err, "readdir failed (path: %s)", dir)
}
Expand Down
5 changes: 2 additions & 3 deletions internal/formatter/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package formatter

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -51,7 +50,7 @@ func formatFile(path string, failFast bool) error {
file := filepath.Base(path)
ext := filepath.Ext(file)

content, err := ioutil.ReadFile(path)
content, err := os.ReadFile(path)
if err != nil {
return errors.Wrap(err, "reading file content failed")
}
Expand All @@ -74,7 +73,7 @@ func formatFile(path string, failFast bool) error {
return fmt.Errorf("file is not formatted (path: %s)", path)
}

err = ioutil.WriteFile(path, newContent, 0755)
err = os.WriteFile(path, newContent, 0755)
if err != nil {
return errors.Wrapf(err, "rewriting file failed (path: %s)", path)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/github/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package github

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -43,7 +42,7 @@ func AuthToken() (string, error) {
}

githubTokenPath := filepath.Join(homeDir, ".elastic/github.token")
token, err := ioutil.ReadFile(githubTokenPath)
token, err := os.ReadFile(githubTokenPath)
if err != nil {
return "", errors.Wrapf(err, "reading Github token file failed (path: %s)", githubTokenPath)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/install/application_configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ package install

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"

"github.com/pkg/errors"
Expand Down Expand Up @@ -73,7 +73,7 @@ func Configuration() (*ApplicationConfiguration, error) {
return nil, errors.Wrap(err, "can't read configuration directory")
}

cfg, err := ioutil.ReadFile(filepath.Join(configPath.RootDir(), applicationConfigurationYmlFile))
cfg, err := os.ReadFile(filepath.Join(configPath.RootDir(), applicationConfigurationYmlFile))
if err != nil {
return nil, errors.Wrap(err, "can't read configuration file")
}
Expand Down
3 changes: 1 addition & 2 deletions internal/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package install

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -197,7 +196,7 @@ func writeStaticResource(err error, path, content string) error {
return err
}

err = ioutil.WriteFile(path, []byte(content), 0644)
err = os.WriteFile(path, []byte(content), 0644)
if err != nil {
return errors.Wrapf(err, "writing file failed (path: %s)", path)
}
Expand Down
3 changes: 1 addition & 2 deletions internal/install/version_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package install

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand All @@ -20,7 +19,7 @@ import (

func checkIfLatestVersionInstalled(elasticPackagePath *locations.LocationManager) (bool, error) {
versionPath := filepath.Join(elasticPackagePath.RootDir(), versionFilename)
versionFile, err := ioutil.ReadFile(versionPath)
versionFile, err := os.ReadFile(versionPath)
if os.IsExist(err) {
return false, nil // old version, no version file
}
Expand Down
Loading