Skip to content

feat: pass dynamic credential provider to transport #965

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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 _benchmarks/benchmarks/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.0
replace github.com/elastic/go-elasticsearch/v8 => ../../

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0
github.com/elastic/elastic-transport-go/v8 v8.6.1
github.com/elastic/go-elasticsearch/v8 v8.0.0-20200408073057-6f36a473b19f
github.com/fatih/color v1.7.0
github.com/montanaflynn/stats v0.6.3
Expand Down
3 changes: 2 additions & 1 deletion _examples/bulk/kafka/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/elastic/go-elasticsearch/v8/_examples/bulk/kafka

go 1.22

toolchain go1.22.0

replace github.com/elastic/go-elasticsearch/v8 => ../../..
Expand All @@ -13,7 +14,7 @@ require (

require (
github.com/armon/go-radix v1.0.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.1 // indirect
github.com/elastic/go-licenser v0.3.1 // indirect
github.com/elastic/go-sysinfo v1.1.1 // indirect
github.com/elastic/go-windows v1.0.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions _examples/bulk/kafka/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21 h1:YEetp8
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
github.com/elastic/elastic-transport-go/v8 v8.6.0 h1:Y2S/FBjx1LlCv5m6pWAF2kDJAHoSjSRSJCApolgfthA=
github.com/elastic/elastic-transport-go/v8 v8.6.0/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
github.com/elastic/elastic-transport-go/v8 v8.6.1/go.mod h1:YLHer5cj0csTzNFXoNQ8qhtGY1GTvSqPnKWKaqQE3Hk=
github.com/elastic/go-licenser v0.3.1 h1:RmRukU/JUmts+rpexAw0Fvt2ly7VVu6mw8z4HrEzObU=
github.com/elastic/go-licenser v0.3.1/go.mod h1:D8eNQk70FOCVBl3smCGQt/lv7meBeQno2eI1S5apiHQ=
github.com/elastic/go-sysinfo v1.1.1 h1:ZVlaLDyhVkDfjwPGU55CQRCRolNpc7P0BbyhhQZQmMI=
Expand Down
2 changes: 1 addition & 1 deletion _examples/cloudfunction/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace github.com/elastic/go-elasticsearch/v8 => ../..
require github.com/elastic/go-elasticsearch/v8 v8.0.0-20210817150010-57d659deaca7

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion _examples/encoding/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
)

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/josharian/intern v1.0.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion _examples/extension/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.0
replace github.com/elastic/go-elasticsearch/v8 => ../..

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0
github.com/elastic/elastic-transport-go/v8 v8.6.1
github.com/elastic/go-elasticsearch/v8 v8.13.1
)

Expand Down
2 changes: 1 addition & 1 deletion _examples/fasthttp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (

require (
github.com/andybalholm/brotli v1.0.4 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/klauspost/compress v1.15.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion _examples/instrumentation/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.0
replace github.com/elastic/go-elasticsearch/v8 => ../..

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0
github.com/elastic/elastic-transport-go/v8 v8.6.1
github.com/elastic/go-elasticsearch/v8 v8.0.0-20191002063538-b491ce54d752
github.com/fatih/color v1.7.0
go.elastic.co/apm v1.11.0
Expand Down
2 changes: 1 addition & 1 deletion _examples/logging/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.0
replace github.com/elastic/go-elasticsearch/v8 => ../..

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0
github.com/elastic/elastic-transport-go/v8 v8.6.1
github.com/elastic/go-elasticsearch/v8 v8.0.0-00010101000000-000000000000
github.com/rs/zerolog v1.32.0
)
Expand Down
2 changes: 1 addition & 1 deletion _examples/security/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ replace github.com/elastic/go-elasticsearch/v8 => ../..
require github.com/elastic/go-elasticsearch/v8 v8.0.0-00010101000000-000000000000

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
go.opentelemetry.io/otel v1.28.0 // indirect
Expand Down
2 changes: 1 addition & 1 deletion _examples/xkcdsearch/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
)

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0 // indirect
github.com/elastic/elastic-transport-go/v8 v8.6.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
Expand Down
32 changes: 19 additions & 13 deletions elasticsearch.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
package elasticsearch

import (
"context"
"encoding/base64"
"errors"
"fmt"
"go.opentelemetry.io/otel/trace"
"net/http"
"net/url"
"os"
Expand All @@ -32,13 +32,13 @@ import (
"sync"
"time"

"github.com/elastic/go-elasticsearch/v8/typedapi"
"github.com/elastic/elastic-transport-go/v8/elastictransport"
tpversion "github.com/elastic/elastic-transport-go/v8/elastictransport/version"
"go.opentelemetry.io/otel/trace"

"github.com/elastic/go-elasticsearch/v8/esapi"
"github.com/elastic/go-elasticsearch/v8/internal/version"

"github.com/elastic/elastic-transport-go/v8/elastictransport"
tpversion "github.com/elastic/elastic-transport-go/v8/elastictransport/version"
"github.com/elastic/go-elasticsearch/v8/typedapi"
)

const (
Expand Down Expand Up @@ -69,13 +69,16 @@ func init() {
// Config represents the client configuration.
type Config struct {
Addresses []string // A list of Elasticsearch nodes to use.
Username string // Username for HTTP Basic Authentication.
Password string // Password for HTTP Basic Authentication.

CloudID string // Endpoint for the Elastic Service (https://elastic.co/cloud).
APIKey string // Base64-encoded token for authorization; if set, overrides username/password and service token.
ServiceToken string // Service token for authorization; if set, overrides username/password.
CertificateFingerprint string // SHA256 hex fingerprint given by Elasticsearch on first launch.
CloudID string // Endpoint for the Elastic Service (https://elastic.co/cloud).
APIKeyProvider func(context.Context) (string, error) // If set, the Client shall call this func to obtain an API Key, overriding APIKey.
APIKey string // Base64-encoded token for authorization; if set, overrides username/password and service token.
ServiceTokenProvider func(context.Context) (string, error) // If set, the Client shall call this func to obtain a service token, overriding ServiceToken.
ServiceToken string // Service token for authorization; if set, overrides username/password.
BasicAuthProvider func(context.Context) (string, string, error) // If set, the Client shall call this func to obtain a username and password, overriding Username and Password.
Username string // Username for HTTP Basic Authentication.
Password string // Password for HTTP Basic Authentication.
CertificateFingerprint string // SHA256 hex fingerprint given by Elasticsearch on first launch.

Header http.Header // Global HTTP request header.

Expand Down Expand Up @@ -278,10 +281,13 @@ func newTransport(cfg Config) (*elastictransport.Client, error) {
UserAgent: userAgent,

URLs: urls,
Username: cfg.Username,
Password: cfg.Password,
APIKeyProvider: cfg.APIKeyProvider,
APIKey: cfg.APIKey,
ServiceTokenProvider: cfg.ServiceTokenProvider,
ServiceToken: cfg.ServiceToken,
BasicAuthProvider: cfg.BasicAuthProvider,
Username: cfg.Username,
Password: cfg.Password,
CertificateFingerprint: cfg.CertificateFingerprint,

Header: cfg.Header,
Expand Down
2 changes: 1 addition & 1 deletion esapi/test/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ toolchain go1.22.0
replace github.com/elastic/go-elasticsearch/v8 => ../../

require (
github.com/elastic/elastic-transport-go/v8 v8.6.0
github.com/elastic/elastic-transport-go/v8 v8.6.1
github.com/elastic/go-elasticsearch/v8 v8.0.0-20210817150010-57d659deaca7
gopkg.in/yaml.v2 v2.4.0
)