Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new subcommand to dump Agent Policies #862

Merged
merged 28 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4b3a1c6
Rename dump installed objects action
mrodm Jun 21, 2022
e8be6c8
Add new subcommand to dump agent policies
mrodm Jun 22, 2022
ab1f310
Add parameter to get agent policies using some package
mrodm Jun 22, 2022
469fe8c
Rephrase long descriptions
mrodm Jun 22, 2022
9bb50ff
Remove debug prints
mrodm Jun 22, 2022
c33295d
Comment reviews
mrodm Jun 23, 2022
d813be9
Set required package flag just for installed-objects subcommand
mrodm Jun 23, 2022
c175000
Add pagination support to list all agent policies
mrodm Jun 23, 2022
62e51fc
Remove debug statements
mrodm Jun 23, 2022
80a61b0
Changes from review
mrodm Jun 23, 2022
898f15f
Rename dumpInstalledObject to be more generic
mrodm Jun 23, 2022
fb226d9
Reuse agent filtering method to get all policies
mrodm Jun 23, 2022
7e17639
Remove caching for agent policies
mrodm Jun 23, 2022
862883f
Rename Ingest Manager to Fleet
mrodm Jun 27, 2022
d126235
Update dump command descriptions
mrodm Jun 27, 2022
47fcf74
Update README
mrodm Jun 27, 2022
0bbcc90
Merge 'origin/main' branch into dump_agent_policies
mrodm Jun 27, 2022
c9af623
Added tests for agent-policies dump subcommand
mrodm Jun 27, 2022
5aa71f3
Use get public method in client_test
mrodm Jun 27, 2022
3fa942b
Set post,put,delete methods public as Get
mrodm Jun 27, 2022
2184cec
Rename method to list all agent policies
mrodm Jun 27, 2022
58487b5
Move functions to dump a generic json resource to its own file
mrodm Jun 28, 2022
3334135
Replace question mark char in files too
mrodm Jun 28, 2022
d872ec2
Fix default path url name
mrodm Jun 28, 2022
ac2b8ca
Use formatter package to dump JSONs - rewritten all dumped files
mrodm Jun 28, 2022
7251ad6
Set again get,post,put,delete methods as private
mrodm Jun 28, 2022
cc1a245
Fix
mrodm Jun 28, 2022
eb1fe46
Revert "Use formatter package to dump JSONs - rewritten all dumped fi…
mrodm Jun 28, 2022
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
7 changes: 3 additions & 4 deletions internal/dump/agentpolicies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"github.com/stretchr/testify/suite"

"github.com/elastic/elastic-package/internal/kibana"
kibtest "github.com/elastic/elastic-package/internal/kibana/test"
)

func TestDumpAgentPolicies(t *testing.T) {
Expand Down Expand Up @@ -111,7 +110,7 @@ func (s *agentPoliciesDumpSuite) SetupTest() {
}

func (s *agentPoliciesDumpSuite) TestDumpAll() {
client := kibtest.KibanaClient(s.T(), s.RecordDir)
client := kibana.NewTestClient(s.T(), s.RecordDir)

outputDir := s.T().TempDir()
dumper := NewAgentPoliciesDumper(client)
Expand All @@ -128,7 +127,7 @@ func (s *agentPoliciesDumpSuite) TestDumpAll() {
}

func (s *agentPoliciesDumpSuite) TestDumpByPackage() {
client := kibtest.KibanaClient(s.T(), s.RecordDir)
client := kibana.NewTestClient(s.T(), s.RecordDir)

outputDir := s.T().TempDir()
dumper := NewAgentPoliciesDumper(client)
Expand All @@ -145,7 +144,7 @@ func (s *agentPoliciesDumpSuite) TestDumpByPackage() {
}

func (s *agentPoliciesDumpSuite) TestDumpByName() {
client := kibtest.KibanaClient(s.T(), s.RecordDir)
client := kibana.NewTestClient(s.T(), s.RecordDir)

outputDir := s.T().TempDir()
dumper := NewAgentPoliciesDumper(client)
Expand Down
15 changes: 3 additions & 12 deletions internal/dump/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
package dump

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

"github.com/elastic/elastic-package/internal/formatter"
)

type DumpableJSONResource interface {
Expand All @@ -22,7 +22,7 @@ func dumpJSONResource(dir string, object DumpableJSONResource) error {
if err := os.MkdirAll(dir, 0755); err != nil {
return fmt.Errorf("failed to create dump directory: %w", err)
}
formatted, err := formatJSON(object.JSON())
formatted, _, err := formatter.JSONFormatter(object.JSON())
if err != nil {
return fmt.Errorf("failed to format JSON object: %w", err)
}
Expand All @@ -33,12 +33,3 @@ func dumpJSONResource(dir string, object DumpableJSONResource) error {
}
return nil
}

func formatJSON(in []byte) ([]byte, error) {
var buf bytes.Buffer
err := json.Indent(&buf, in, "", " ")
if err != nil {
return nil, err
}
return buf.Bytes(), nil
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
{
"name": ".fleet_component_template-1",
"component_template": {
"template": {
"settings": {
"index": {
"final_pipeline": ".fleet_final_pipeline-1"
}
},
"mappings": {
"properties": {
"event": {
"properties": {
"agent_id_status": {
"ignore_above": 1024,
"type": "keyword"
},
"ingested": {
"format": "strict_date_time_no_millis||strict_date_optional_time||epoch_millis",
"type": "date"
}
"name": ".fleet_component_template-1",
"component_template": {
"template": {
"settings": {
"index": {
"final_pipeline": ".fleet_final_pipeline-1"
}
},
"mappings": {
"properties": {
"event": {
"properties": {
"agent_id_status": {
"ignore_above": 1024,
"type": "keyword"
},
"ingested": {
"format": "strict_date_time_no_millis||strict_date_optional_time||epoch_millis",
"type": "date"
}
}
}
}
}
}
}
}
},
"_meta": {}
}
},
"_meta": {}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "logs-apache.access@custom",
"component_template": {
"template": {
"settings": {}
},
"_meta": {
"package": {
"name": "apache"
}
"name": "logs-apache.access@custom",
"component_template": {
"template": {
"settings": {}
},
"_meta": {
"package": {
"name": "apache"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,97 +1,97 @@
{
"name": "logs-apache.access@settings",
"component_template": {
"template": {
"settings": {
"index": {
"lifecycle": {
"name": "logs"
},
"codec": "best_compression",
"mapping": {
"total_fields": {
"limit": "10000"
"name": "logs-apache.access@settings",
"component_template": {
"template": {
"settings": {
"index": {
"lifecycle": {
"name": "logs"
},
"codec": "best_compression",
"mapping": {
"total_fields": {
"limit": "10000"
}
},
"query": {
"default_field": [
"cloud.account.id",
"cloud.availability_zone",
"cloud.instance.id",
"cloud.instance.name",
"cloud.machine.type",
"cloud.provider",
"cloud.region",
"cloud.project.id",
"cloud.image.id",
"container.id",
"container.image.name",
"container.name",
"host.architecture",
"host.domain",
"host.hostname",
"host.id",
"host.mac",
"host.name",
"host.os.family",
"host.os.kernel",
"host.os.name",
"host.os.platform",
"host.os.version",
"host.type",
"host.os.build",
"host.os.codename",
"input.type",
"destination.domain",
"ecs.version",
"event.category",
"event.kind",
"event.outcome",
"file.path",
"http.request.method",
"http.request.referrer",
"http.version",
"log.file.path",
"log.level",
"source.address",
"source.as.organization.name",
"source.domain",
"source.geo.city_name",
"source.geo.continent_name",
"source.geo.country_iso_code",
"source.geo.country_name",
"source.geo.region_iso_code",
"source.geo.region_name",
"tags",
"tls.cipher",
"tls.version",
"tls.version_protocol",
"url.domain",
"url.extension",
"url.query",
"user.name",
"user_agent.device.name",
"user_agent.device.name",
"user_agent.name",
"user_agent.name",
"user_agent.original",
"user_agent.original",
"user_agent.os.full",
"user_agent.os.name",
"user_agent.os.name",
"user_agent.os.version",
"user_agent.version",
"apache.access.ssl.protocol",
"apache.access.ssl.cipher"
]
}
}
}
},
"_meta": {
"package": {
"name": "apache"
}
},
"query": {
"default_field": [
"cloud.account.id",
"cloud.availability_zone",
"cloud.instance.id",
"cloud.instance.name",
"cloud.machine.type",
"cloud.provider",
"cloud.region",
"cloud.project.id",
"cloud.image.id",
"container.id",
"container.image.name",
"container.name",
"host.architecture",
"host.domain",
"host.hostname",
"host.id",
"host.mac",
"host.name",
"host.os.family",
"host.os.kernel",
"host.os.name",
"host.os.platform",
"host.os.version",
"host.type",
"host.os.build",
"host.os.codename",
"input.type",
"destination.domain",
"ecs.version",
"event.category",
"event.kind",
"event.outcome",
"file.path",
"http.request.method",
"http.request.referrer",
"http.version",
"log.file.path",
"log.level",
"source.address",
"source.as.organization.name",
"source.domain",
"source.geo.city_name",
"source.geo.continent_name",
"source.geo.country_iso_code",
"source.geo.country_name",
"source.geo.region_iso_code",
"source.geo.region_name",
"tags",
"tls.cipher",
"tls.version",
"tls.version_protocol",
"url.domain",
"url.extension",
"url.query",
"user.name",
"user_agent.device.name",
"user_agent.device.name",
"user_agent.name",
"user_agent.name",
"user_agent.original",
"user_agent.original",
"user_agent.os.full",
"user_agent.os.name",
"user_agent.os.name",
"user_agent.os.version",
"user_agent.version",
"apache.access.ssl.protocol",
"apache.access.ssl.cipher"
]
}
}
}
},
"_meta": {
"package": {
"name": "apache"
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{
"name": "logs-apache.error@custom",
"component_template": {
"template": {
"settings": {}
},
"_meta": {
"package": {
"name": "apache"
}
"name": "logs-apache.error@custom",
"component_template": {
"template": {
"settings": {}
},
"_meta": {
"package": {
"name": "apache"
}
}
}
}
}
Loading