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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
6 changes: 5 additions & 1 deletion components/reporters/elasticsearch/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# json-logger
# Elasticsearch

This component implements a [reporter](https://github.com/smithy-security/smithy/blob/main/sdk/component/component.go)
that sends vulnerabilities to elasticsearch.
Expand All @@ -8,6 +8,10 @@ The API key requires reading cluster's information in order for the component t
validate connectivity and write to any indexes you plan on using this component
with.

## Supported Versions

Be aware that at the moment of writing this we have proper support for two major versions of Elasticsearch 8.x.x and 9.x.x. For any major versions of elasticsearch above 9, there is no guarantee that it will work properly.

## Environment variables

The component uses environment variables for configuration.
Expand Down
10 changes: 3 additions & 7 deletions components/reporters/elasticsearch/cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,12 @@ func Main(ctx context.Context, opts ...component.RunnerOption) error {
}
opts = append(opts, component.RunnerWithComponentName("elasticsearch"))

client, err := reporter.GetESClient(conf)
esReporter, err := reporter.New(ctx, conf)
if err != nil {
return errors.Errorf("could not create elasticsearch client: %w", err)
return errors.Errorf("could not create elasticsearch reporter: %w", err)
}

reporter, err := reporter.NewElasticsearchLogger(conf, client)
if err != nil {
return errors.Errorf("could not instantiate logger err: %w", err)
}
if err := component.RunReporter(ctx, reporter, opts...); err != nil {
if err := component.RunReporter(ctx, esReporter, opts...); err != nil {
Comment thread
senglezou marked this conversation as resolved.
return errors.Errorf("could not run reporter: %w", err)
}

Expand Down
3 changes: 3 additions & 0 deletions components/reporters/elasticsearch/component.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ parameters:
- name: elasticsearch_api_key
type: string
value: ""
- name: elasticsearch_server_version
Comment thread
ptzianos marked this conversation as resolved.
type: string
value: ""
steps:
- name: elasticsearch
image: components/reporters/elasticsearch
Expand Down
13 changes: 7 additions & 6 deletions components/reporters/elasticsearch/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module github.com/smithy-security/smithy/components/reporters/elasticsearch
go 1.23.4

require (
github.com/elastic/go-elasticsearch/v8 v8.17.1
github.com/elastic/go-elasticsearch/v8 v8.19.0
github.com/elastic/go-elasticsearch/v9 v9.1.0
github.com/go-errors/errors v1.5.1
github.com/smithy-security/pkg/env v0.0.3
github.com/smithy-security/smithy/sdk v0.0.19-alpha
Expand All @@ -23,12 +24,12 @@ require (
github.com/bmatcuk/doublestar v1.3.4 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.6 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.1 // indirect
github.com/elastic/elastic-transport-go/v8 v8.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/inflect v0.21.0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/go-cmp v0.7.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/hashicorp/hcl/v2 v2.23.0 // indirect
github.com/huandu/xstrings v1.5.0 // indirect
Expand All @@ -55,9 +56,9 @@ require (
github.com/zclconf/go-cty v1.16.2 // indirect
github.com/zclconf/go-cty-yaml v1.1.0 // indirect
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
go.opentelemetry.io/otel v1.34.0 // indirect
go.opentelemetry.io/otel/metric v1.34.0 // indirect
go.opentelemetry.io/otel/trace v1.34.0 // indirect
go.opentelemetry.io/otel v1.35.0 // indirect
go.opentelemetry.io/otel/metric v1.35.0 // indirect
go.opentelemetry.io/otel/trace v1.35.0 // indirect
go.uber.org/mock v0.5.0 // indirect
golang.org/x/crypto v0.33.0 // indirect
golang.org/x/mod v0.23.0 // indirect
Expand Down
26 changes: 14 additions & 12 deletions components/reporters/elasticsearch/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
github.com/elastic/elastic-transport-go/v8 v8.6.1 h1:h2jQRqH6eLGiBSN4eZbQnJLtL4bC5b4lfVFRjw2R4e4=
github.com/elastic/elastic-transport-go/v8 v8.6.1/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
github.com/elastic/go-elasticsearch/v8 v8.17.1 h1:bOXChDoCMB4TIwwGqKd031U8OXssmWLT3UrAr9EGs3Q=
github.com/elastic/go-elasticsearch/v8 v8.17.1/go.mod h1:MVJCtL+gJJ7x5jFeUmA20O7rvipX8GcQmo5iBcmaJn4=
github.com/elastic/elastic-transport-go/v8 v8.7.0 h1:OgTneVuXP2uip4BA658Xi6Hfw+PeIOod2rY3GVMGoVE=
github.com/elastic/elastic-transport-go/v8 v8.7.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
github.com/elastic/go-elasticsearch/v8 v8.19.0 h1:VmfBLNRORY7RZL+9hTxBD97ehl9H8Nxf2QigDh6HuMU=
github.com/elastic/go-elasticsearch/v8 v8.19.0/go.mod h1:F3j9e+BubmKvzvLjNui/1++nJuJxbkhHefbaT0kFKGY=
github.com/elastic/go-elasticsearch/v9 v9.1.0 h1:+qmeMi+Zuyc/BzTWxHUouGJX5aF567IA2De7OoDgagE=
github.com/elastic/go-elasticsearch/v9 v9.1.0/go.mod h1:2PB5YQPpY5tWbF65MRqzEXA31PZOdXCkloQSOZtU14I=
github.com/frankban/quicktest v1.14.6 h1:7Xjx+VpznH+oBnejlPUj8oUpdxnVs4f8XU8WnHkI4W8=
github.com/frankban/quicktest v1.14.6/go.mod h1:4ptaffx2x8+WTWXmUCuVU6aPUX1/Mz7zb5vbUoiM6w0=
github.com/go-errors/errors v1.5.1 h1:ZwEMSLRCapFLflTpT7NKaAc7ukJ8ZPEjzlxt8rPN8bk=
Expand All @@ -66,8 +68,8 @@ github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
github.com/golang/mock v1.6.0/go.mod h1:p6yTPP+5HYm5mzsMV8JkE6ZKdX+/wYM6Hr+LicevLPs=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
Expand Down Expand Up @@ -167,16 +169,16 @@ github.com/zclconf/go-cty-yaml v1.1.0 h1:nP+jp0qPHv2IhUVqmQSzjvqAWcObN0KBkUl2rWB
github.com/zclconf/go-cty-yaml v1.1.0/go.mod h1:9YLUH4g7lOhVWqUbctnVlZ5KLpg7JAprQNgxSZ1Gyxs=
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
go.opentelemetry.io/otel v1.34.0 h1:zRLXxLCgL1WyKsPVrgbSdMN4c0FMkDAskSTQP+0hdUY=
go.opentelemetry.io/otel v1.34.0/go.mod h1:OWFPOQ+h4G8xpyjgqo4SxJYdDQ/qmRH+wivy7zzx9oI=
go.opentelemetry.io/otel/metric v1.34.0 h1:+eTR3U0MyfWjRDhmFMxe2SsW64QrZ84AOhvqS7Y+PoQ=
go.opentelemetry.io/otel/metric v1.34.0/go.mod h1:CEDrp0fy2D0MvkXE+dPV7cMi8tWZwX3dmaIhwPOaqHE=
go.opentelemetry.io/otel v1.35.0 h1:xKWKPxrxB6OtMCbmMY021CqC45J+3Onta9MqjhnusiQ=
go.opentelemetry.io/otel v1.35.0/go.mod h1:UEqy8Zp11hpkUrL73gSlELM0DupHoiq72dR+Zqel/+Y=
go.opentelemetry.io/otel/metric v1.35.0 h1:0znxYu2SNyuMSQT4Y9WDWej0VpcsxkuklLa4/siN90M=
go.opentelemetry.io/otel/metric v1.35.0/go.mod h1:nKVFgxBZ2fReX6IlyW28MgZojkoAkJGaE8CpgeAU3oE=
go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4=
go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU=
go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU=
go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ=
go.opentelemetry.io/otel/trace v1.34.0 h1:+ouXS2V8Rd4hp4580a8q23bg0azF2nI8cqLYnC8mh/k=
go.opentelemetry.io/otel/trace v1.34.0/go.mod h1:Svm7lSjQD7kG7KJ/MUHPVXSDGz2OX4h0M2jHBhmSfRE=
go.opentelemetry.io/otel/trace v1.35.0 h1:dPpEfJu1sDIqruz7BHFG3c7528f6ddfSWfFDVt/xgMs=
go.opentelemetry.io/otel/trace v1.35.0/go.mod h1:WUk7DtFp1Aw2MkvqGdwiXYDZZNvA/1J8o6xRXLrIkyc=
go.uber.org/mock v0.5.0 h1:KAMbZvZPyBPWgD14IrIQ38QCyjwpvVVV6K/bHl1IwQU=
go.uber.org/mock v0.5.0/go.mod h1:ge71pBPLYDk7QIi1LupWxdAykm7KIEFchiOqd6z7qMM=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
Expand Down
77 changes: 77 additions & 0 deletions components/reporters/elasticsearch/internal/reporter/es_clients.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package reporter

import (
"io"

esv8 "github.com/elastic/go-elasticsearch/v8"
esapiv8 "github.com/elastic/go-elasticsearch/v8/esapi"

esv9 "github.com/elastic/go-elasticsearch/v9"
esapiv9 "github.com/elastic/go-elasticsearch/v9/esapi"
)

// v8Client is a wrapper for the es v8 client
type v8Client struct {
client *esv8.Client
}

// Index calls the underlying v8 client's Index method and wraps the response
func (a *v8Client) Index(index string, body io.Reader) (esResponse, error) {
res, err := a.client.Index(index, body)
if err != nil {
return nil, err
}
return &v8EsAPIRes{res}, nil
}

// Info calls the underlying v8 client's Info method and wraps the response
func (a *v8Client) Info() (esResponse, error) {
res, err := a.client.Info()
if err != nil {
return nil, err
}
return &v8EsAPIRes{res}, nil
}

// v8EsAPIRes wraps the v8 ES API
type v8EsAPIRes struct {
res *esapiv8.Response
}

func (r *v8EsAPIRes) IsError() bool { return r.res.IsError() }
func (r *v8EsAPIRes) String() string { return r.res.String() }
func (r *v8EsAPIRes) StatusCode() int { return r.res.StatusCode }
func (r *v8EsAPIRes) Body() io.ReadCloser { return r.res.Body }

// v9Client is a wrapper for the es v9 client
type v9Client struct {
client *esv9.Client
}

// Index calls the underlying v9 client's Index method and wraps the response.
func (a *v9Client) Index(index string, body io.Reader) (esResponse, error) {
res, err := a.client.Index(index, body)
if err != nil {
return nil, err
}
return &v9EsAPIRes{res}, nil
}

// Info calls the underlying v9 client's Info method and wraps the response
func (a *v9Client) Info() (esResponse, error) {
res, err := a.client.Info()
if err != nil {
return nil, err
}
return &v9EsAPIRes{res}, nil
}

// v9EsAPIRes wraps the v9 ES API
type v9EsAPIRes struct {
res *esapiv9.Response
}

func (r *v9EsAPIRes) IsError() bool { return r.res.IsError() }
func (r *v9EsAPIRes) String() string { return r.res.String() }
func (r *v9EsAPIRes) StatusCode() int { return r.res.StatusCode }
func (r *v9EsAPIRes) Body() io.ReadCloser { return r.res.Body }
Loading
Loading