diff --git a/api/api.go b/api/api.go index 2f8e21f3..c69f20ac 100644 --- a/api/api.go +++ b/api/api.go @@ -7,7 +7,7 @@ import ( "net/http" "github.com/ONSdigital/dp-authorisation/auth" - dpelastic "github.com/ONSdigital/dp-elasticsearch/v2/elasticsearch" + dpelastic "github.com/ONSdigital/dp-elasticsearch/v3/elasticsearch" "github.com/gorilla/mux" "github.com/pkg/errors" ) @@ -72,9 +72,7 @@ func NewSearchAPI(router *mux.Router, dpESClient *dpelastic.Client, deprecatedES router.HandleFunc("/search", SearchHandlerFunc(queryBuilder, api.deprecatedESClient, api.Transformer)).Methods("GET") router.HandleFunc("/timeseries/{cdid}", TimeseriesLookupHandlerFunc(api.deprecatedESClient)).Methods("GET") router.HandleFunc("/data", DataLookupHandlerFunc(api.deprecatedESClient)).Methods("GET") - - createSearchIndexHandler := permissions.Require(update, CreateSearchIndexHandlerFunc(api.dpESClient)) + createSearchIndexHandler := permissions.Require(update, api.CreateSearchIndexHandlerFunc) router.HandleFunc("/search", createSearchIndexHandler).Methods("POST") - return api, nil } diff --git a/api/search.go b/api/search.go index 37bb5985..d2c63626 100644 --- a/api/search.go +++ b/api/search.go @@ -8,7 +8,6 @@ import ( "strconv" "time" - dpelastic "github.com/ONSdigital/dp-elasticsearch/v2/elasticsearch" "github.com/ONSdigital/dp-search-api/elasticsearch" "github.com/ONSdigital/log.go/v2/log" "github.com/pkg/errors" @@ -148,43 +147,41 @@ func SearchHandlerFunc(queryBuilder QueryBuilder, elasticSearchClient ElasticSea } } -func CreateSearchIndexHandlerFunc(dpESClient *dpelastic.Client) http.HandlerFunc { - return func(w http.ResponseWriter, req *http.Request) { - ctx := req.Context() - indexName := createIndexName("ons") - fmt.Printf("Index created: %s\n", indexName) - indexCreated := true +func (a SearchAPI) CreateSearchIndexHandlerFunc(w http.ResponseWriter, req *http.Request) { + ctx := req.Context() + indexName := createIndexName("ons") + fmt.Printf("Index created: %s\n", indexName) + indexCreated := true - status, err := dpESClient.CreateIndex(ctx, indexName, elasticsearch.GetSearchIndexSettings()) - if err != nil { - log.Error(ctx, "error creating index", err, log.Data{"response_status": status, "index_name": indexName}) - indexCreated = false - } + status, err := a.dpESClient.CreateIndex(ctx, indexName, elasticsearch.GetSearchIndexSettings()) + if err != nil { + log.Error(ctx, "error creating index", err, log.Data{"response_status": status, "index_name": indexName}) + indexCreated = false + } - if status != http.StatusOK { - log.Error(ctx, "unexpected http status when creating index", err, log.Data{"response_status": status, "index_name": indexName}) - indexCreated = false - } + if status != http.StatusOK { + log.Error(ctx, "unexpected http status when creating index", err, log.Data{"response_status": status, "index_name": indexName}) + indexCreated = false + } - if !indexCreated { - if err != nil { - log.Error(ctx, "creating index failed with this error", err) - } - http.Error(w, serverErrorMessage, http.StatusInternalServerError) - return + if !indexCreated { + if err != nil { + log.Error(ctx, "creating index failed with this error", err) } + http.Error(w, serverErrorMessage, http.StatusInternalServerError) + return + } - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusCreated) - createIndexResponse := CreateIndexResponse{IndexName: indexName} - jsonResponse, _ := json.Marshal(createIndexResponse) + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(http.StatusCreated) + createIndexResponse := CreateIndexResponse{IndexName: indexName} + jsonResponse, _ := json.Marshal(createIndexResponse) - _, err = w.Write(jsonResponse) - if err != nil { - log.Error(ctx, "writing response failed", err) - http.Error(w, serverErrorMessage, http.StatusInternalServerError) - return - } + _, err = w.Write(jsonResponse) + if err != nil { + log.Error(ctx, "writing response failed", err) + http.Error(w, serverErrorMessage, http.StatusInternalServerError) + return } } diff --git a/elasticsearch/client.go b/elasticsearch/client.go index b530b532..f6265ede 100644 --- a/elasticsearch/client.go +++ b/elasticsearch/client.go @@ -5,32 +5,26 @@ import ( "context" "io" "net/http" - "time" - esauth "github.com/ONSdigital/dp-elasticsearch/v2/awsauth" dphttp "github.com/ONSdigital/dp-net/http" "github.com/pkg/errors" ) // Client represents an instance of the elasticsearch client - now deprecated type Client struct { - awsRegion string - awsSDKSigner *esauth.Signer - awsService string - url string - client dphttp.Clienter - signRequests bool + awsRegion string + awsService string + url string + client dphttp.Clienter } // New creates a new elasticsearch client. Any trailing slashes from the URL are removed. -func New(url string, client dphttp.Clienter, signRequests bool, awsSDKSigner *esauth.Signer, awsService, awsRegion string) *Client { +func New(url string, client dphttp.Clienter, awsService, awsRegion string) *Client { return &Client{ - awsSDKSigner: awsSDKSigner, - awsRegion: awsRegion, - awsService: awsService, - client: client, - signRequests: signRequests, - url: url, + awsRegion: awsRegion, + awsService: awsService, + client: client, + url: url, } } @@ -51,12 +45,6 @@ func (cli *Client) post(ctx context.Context, index, docType, action string, requ return nil, err } - if cli.signRequests { - if awsSignErr := cli.awsSDKSigner.Sign(req, reader, time.Now()); awsSignErr != nil { - return nil, awsSignErr - } - } - resp, err := cli.client.Do(ctx, req) if err != nil { return nil, err diff --git a/elasticsearch/client_test.go b/elasticsearch/client_test.go index b7867f1e..9132661d 100644 --- a/elasticsearch/client_test.go +++ b/elasticsearch/client_test.go @@ -8,7 +8,6 @@ import ( "net/http/httptest" "testing" - esauth "github.com/ONSdigital/dp-elasticsearch/v2/awsauth" dphttp "github.com/ONSdigital/dp-net/http" . "github.com/smartystreets/goconvey/convey" ) @@ -23,9 +22,7 @@ func TestSearch(t *testing.T) { }, } - var testSigner *esauth.Signer - - client := New("http://localhost:999", dphttpMock, false, testSigner, "es", "eu-west-1") + client := New("http://localhost:999", dphttpMock, "es", "eu-west-1") res, err := client.Search(context.Background(), "index", "doctype", []byte("search request")) So(err, ShouldBeNil) @@ -46,9 +43,7 @@ func TestSearch(t *testing.T) { }, } - var testSigner *esauth.Signer - - client := New("http://localhost:999", dphttpMock, false, testSigner, "es", "eu-west-1") + client := New("http://localhost:999", dphttpMock, "es", "eu-west-1") _, err := client.Search(context.Background(), "index", "doctype", []byte("search request")) So(err, ShouldNotBeNil) @@ -73,9 +68,7 @@ func TestMultiSearch(t *testing.T) { }, } - var testSigner *esauth.Signer - - client := New("http://localhost:999", dphttpMock, false, testSigner, "es", "eu-west-1") + client := New("http://localhost:999", dphttpMock, "es", "eu-west-1") res, err := client.MultiSearch(context.Background(), "index", "doctype", []byte("multiSearch request")) So(err, ShouldBeNil) @@ -95,9 +88,8 @@ func TestMultiSearch(t *testing.T) { return nil, errors.New("http error") }, } - var testSigner *esauth.Signer - client := New("http://localhost:999", dphttpMock, false, testSigner, "es", "eu-west-1") + client := New("http://localhost:999", dphttpMock, "es", "eu-west-1") _, err := client.MultiSearch(context.Background(), "index", "doctype", []byte("search request")) So(err, ShouldNotBeNil) diff --git a/go.mod b/go.mod index ec99aec4..28032846 100644 --- a/go.mod +++ b/go.mod @@ -8,9 +8,9 @@ require ( github.com/ONSdigital/dp-api-clients-go/v2 v2.4.4 github.com/ONSdigital/dp-authorisation v0.2.0 github.com/ONSdigital/dp-component-test v0.6.3 - github.com/ONSdigital/dp-elasticsearch/v2 v2.3.0 - github.com/ONSdigital/dp-healthcheck v1.2.1 - github.com/ONSdigital/dp-net v1.2.0 + github.com/ONSdigital/dp-elasticsearch/v3 v3.0.0-alpha + github.com/ONSdigital/dp-healthcheck v1.2.3 + github.com/ONSdigital/dp-net v1.4.1 github.com/ONSdigital/log.go/v2 v2.0.9 github.com/cucumber/godog v0.12.2 github.com/google/go-cmp v0.5.6 @@ -23,11 +23,12 @@ require ( ) require ( - github.com/ONSdigital/dp-api-clients-go v1.41.1 // indirect + github.com/ONSdigital/dp-api-clients-go v1.43.0 // indirect github.com/ONSdigital/dp-mongodb-in-memory v1.1.0 // indirect + github.com/ONSdigital/dp-net/v2 v2.4.0-beta // indirect github.com/ONSdigital/dp-rchttp v1.0.0 // indirect - github.com/ONSdigital/go-ns v0.0.0-20200205115900-a11716f93bad // indirect - github.com/aws/aws-sdk-go v1.38.15 // indirect + github.com/ONSdigital/go-ns v0.0.0-20210916104633-ac1c1c52327e // indirect + github.com/aws/aws-sdk-go v1.42.30 // indirect github.com/cucumber/gherkin-go/v19 v19.0.3 // indirect github.com/cucumber/messages-go/v16 v16.0.1 // indirect github.com/davecgh/go-spew v1.1.1 // indirect @@ -59,9 +60,9 @@ require ( github.com/youmark/pkcs8 v0.0.0-20181117223130-1be2e3e5546d // indirect go.mongodb.org/mongo-driver v1.8.0 // indirect golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 // indirect - golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 // indirect + golang.org/x/net v0.0.0-20211216030914-fe4d6282115f // indirect golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect - golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 // indirect + golang.org/x/sys v0.0.0-20211205182925-97ca703d548d // indirect golang.org/x/text v0.3.7 // indirect gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect ) diff --git a/go.sum b/go.sum index 44effc12..0cfd1f45 100644 --- a/go.sum +++ b/go.sum @@ -16,22 +16,26 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym github.com/ONSdigital/dp-api-clients-go v1.1.0/go.mod h1:9lqor0I7caCnRWr04gU/r7x5dqxgoODob8L48q+cE4E= github.com/ONSdigital/dp-api-clients-go v1.28.0/go.mod h1:iyJy6uRL4B6OYOJA0XMr5UHt6+Q8XmN9uwmURO+9Oj4= github.com/ONSdigital/dp-api-clients-go v1.34.3/go.mod h1:kX+YKuoLYLfkeLHMvQKRRydZVxO7ZEYyYiwG2xhV51E= -github.com/ONSdigital/dp-api-clients-go v1.41.1 h1:xkeT6dCTFSAoBpZxgiJUiuqgcfjCX+c52CIiZo1Y2iU= github.com/ONSdigital/dp-api-clients-go v1.41.1/go.mod h1:Ga1+ANjviu21NFJI9wp5NctJIdB4TJLDGbpQFl2V8Wc= +github.com/ONSdigital/dp-api-clients-go v1.43.0 h1:0982P/YxnYXvba1RhEcFmwF3xywC4eXokWQ8YH3Mm24= +github.com/ONSdigital/dp-api-clients-go v1.43.0/go.mod h1:V5MfINik+o3OAF985UXUoMjXIfrZe3JKYa5AhZn5jts= +github.com/ONSdigital/dp-api-clients-go/v2 v2.1.7-beta/go.mod h1:p9Ig0jUJmOXYpsZFZkb+mBeUgNBKoTiTVqHt1kJlVrM= github.com/ONSdigital/dp-api-clients-go/v2 v2.4.4 h1:v04tB2xmVgrSIsskm+jGkmjsE/1F+80io6I2Sw/0C0I= github.com/ONSdigital/dp-api-clients-go/v2 v2.4.4/go.mod h1:oB+Pw1BJlLHUh+a6BJY52VFTRGBEM5RSPlg2Xkq7D9k= github.com/ONSdigital/dp-authorisation v0.2.0 h1:QVjTUSR3c1swZwP7lMbvnBsh4Je9oc54eGzgwPOvHOc= github.com/ONSdigital/dp-authorisation v0.2.0/go.mod h1:Tg3BiohT3+bRv4vr4aid/1Rf+S3eXLUI8oHbOLFqFpQ= +github.com/ONSdigital/dp-authorisation v0.2.1-0.20220216122812-b7a4926697fb h1:u/xbrsrPlxoTq/2oqY4eYzcb5iTLsw7mmNHC/lX34DQ= +github.com/ONSdigital/dp-authorisation v0.2.1-0.20220216122812-b7a4926697fb/go.mod h1:Y43b8WMEUV/bL5K+eNhl8UxpI2PNzmh8LdTCgzTA0pQ= github.com/ONSdigital/dp-component-test v0.6.3 h1:WxaKaMZGdTUAb9DNp1K+PH+Xfc8ATIXpJ3lhcUW3myk= github.com/ONSdigital/dp-component-test v0.6.3/go.mod h1:CfpOujIEqZS5qON7sWn0LRyiP0V+5l12+2XWHB7S/oo= -github.com/ONSdigital/dp-elasticsearch/v2 v2.3.0 h1:RPGEjjpnJQrbEEFY/uPf2yb4ewhRlDk9AJOc7LZfWW4= -github.com/ONSdigital/dp-elasticsearch/v2 v2.3.0/go.mod h1:B+WXR1PRVgrU1/tS3UygATLVTnX+5Sp+M0w5i3LROac= +github.com/ONSdigital/dp-elasticsearch/v3 v3.0.0-alpha h1:I4+FtE9OwofikJFnzToWob63HIljVnvCq4TLkjlTOJ4= +github.com/ONSdigital/dp-elasticsearch/v3 v3.0.0-alpha/go.mod h1:lc9XONnHQuL9SjHpFDnVEqUcGYN9uzVKD87jd9dwJ+0= github.com/ONSdigital/dp-frontend-models v1.1.0/go.mod h1:TT96P7Mi69N3Tc/jFNdbjiwG4GAaMjP26HLotFQ6BPw= github.com/ONSdigital/dp-healthcheck v0.0.0-20200131122546-9db6d3f0494e/go.mod h1:zighxZ/0m5u7zo0eAr8XFlA+Dz2ic7A1vna6YXvhCjQ= github.com/ONSdigital/dp-healthcheck v1.0.5/go.mod h1:2wbVAUHMl9+4tWhUlxYUuA1dnf2+NrwzC+So5f5BMLk= github.com/ONSdigital/dp-healthcheck v1.1.0/go.mod h1:vZwyjMJiCHjp/sJ2R1ZEqzZT0rJ0+uHVGwxqdP4J5vg= -github.com/ONSdigital/dp-healthcheck v1.2.1 h1:HL0zHV5FI2Ym31gdMVNW9VLWiEJ0nrwXkVKX1MMPNr4= -github.com/ONSdigital/dp-healthcheck v1.2.1/go.mod h1:XUhXoDIWPCdletDtpDOoXhmDFcc9b/kbedx96jN75aI= +github.com/ONSdigital/dp-healthcheck v1.2.3 h1:8/qTe0TjXouQWW0jgrtDGMFl+fUWigfyntL+q96GUSY= +github.com/ONSdigital/dp-healthcheck v1.2.3/go.mod h1:XUhXoDIWPCdletDtpDOoXhmDFcc9b/kbedx96jN75aI= github.com/ONSdigital/dp-mocking v0.0.0-20190905163309-fee2702ad1b9/go.mod h1:BcIRgitUju//qgNePRBmNjATarTtynAgc0yV29VpLEk= github.com/ONSdigital/dp-mongodb-in-memory v1.1.0 h1:EjUU1zpIU1LElhiTMAG7qxy7Rq9+VTUtt3/lyA+K7jI= github.com/ONSdigital/dp-mongodb-in-memory v1.1.0/go.mod h1:AQaNcbSS18WtldA4iWUlHQDn9FCLB2K6ff68QnvZBqM= @@ -40,15 +44,19 @@ github.com/ONSdigital/dp-net v1.0.5-0.20200805145012-9227a11caddb/go.mod h1:MrSZ github.com/ONSdigital/dp-net v1.0.5-0.20200805150805-cac050646ab5/go.mod h1:de3LB9tedE0tObBwa12dUOt5rvTW4qQkF5rXtt4b6CE= github.com/ONSdigital/dp-net v1.0.7/go.mod h1:1QFzx32FwPKD2lgZI6MtcsUXritsBdJihlzIWDrQ/gc= github.com/ONSdigital/dp-net v1.0.12/go.mod h1:2lvIKOlD4T3BjWQwjHhBUO2UNWDk82u/+mHRn0R3C9A= -github.com/ONSdigital/dp-net v1.2.0 h1:gP9pBt/J8gktYeKsb7hq6uOC2xx1tfvTorUBNXp6pX0= github.com/ONSdigital/dp-net v1.2.0/go.mod h1:NinlaqcsPbIR+X7j5PXCl3UI5G2zCL041SDF6WIiiO4= +github.com/ONSdigital/dp-net v1.4.1 h1:hfhtQ2l7pGtC2nBze7YtFzvkVEMCYprHgojNYVPL134= +github.com/ONSdigital/dp-net v1.4.1/go.mod h1:VK8dah+G0TeVO/Os/w17Rk4WM6hIGmdUXrm8fBWyC+g= +github.com/ONSdigital/dp-net/v2 v2.4.0-beta h1:DMDKKYI4BQgjis8W3A2DS2G0qg1DOx9OQCMSU4A35Ac= +github.com/ONSdigital/dp-net/v2 v2.4.0-beta/go.mod h1:lEGqzHaVQPpM69SD4mN65iJDmMaOvMKrYlLtbJ/16Mw= github.com/ONSdigital/dp-rchttp v0.0.0-20190919143000-bb5699e6fd59/go.mod h1:KkW68U3FPuivW4ogi9L8CPKNj9ZxGko4qcUY7KoAAkQ= github.com/ONSdigital/dp-rchttp v0.0.0-20200114090501-463a529590e8/go.mod h1:821jZtK0oBsV8hjIkNr8vhAWuv0FxJBPJuAHa2B70Gk= github.com/ONSdigital/dp-rchttp v1.0.0 h1:K/1/gDtfMZCX1Mbmq80nZxzDirzneqA1c89ea26FqP4= github.com/ONSdigital/dp-rchttp v1.0.0/go.mod h1:821jZtK0oBsV8hjIkNr8vhAWuv0FxJBPJuAHa2B70Gk= github.com/ONSdigital/go-ns v0.0.0-20191104121206-f144c4ec2e58/go.mod h1:iWos35il+NjbvDEqwtB736pyHru0MPFE/LqcwkV1wDc= -github.com/ONSdigital/go-ns v0.0.0-20200205115900-a11716f93bad h1:Axoxm5rF6j7LSZfm4AGBT5IwGhWIcfcOkkhy/su/UpA= github.com/ONSdigital/go-ns v0.0.0-20200205115900-a11716f93bad/go.mod h1:uHT6LaUlRbJsJRrIlN31t+QLUB80tAbk6ZR9sfoHL8Y= +github.com/ONSdigital/go-ns v0.0.0-20210916104633-ac1c1c52327e h1:o+AK5m0lxRIFn4t9ng9x19kez72ErAB0cW9ArT6sAZM= +github.com/ONSdigital/go-ns v0.0.0-20210916104633-ac1c1c52327e/go.mod h1:BCx4ULp5nT3dT7Mft5iMrp9439JG9lqIlc0JOPmsHTg= github.com/ONSdigital/log.go v0.0.0-20191127134126-2a610b254f20/go.mod h1:BD7D8FWP1fzwUWsrCopEG72jl9cchCaVNIGSz6YvL+Y= github.com/ONSdigital/log.go v1.0.0/go.mod h1:UnGu9Q14gNC+kz0DOkdnLYGoqugCvnokHBRBxFRpVoQ= github.com/ONSdigital/log.go v1.0.1-0.20200805084515-ee61165ea36a/go.mod h1:dDnQATFXCBOknvj6ZQuKfmDhbOWf3e8mtV+dPEfWJqs= @@ -65,8 +73,9 @@ github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRF github.com/armon/circbuf v0.0.0-20150827004946-bbbad097214e/go.mod h1:3U/XgcO3hCbHZ8TKRvWD2dDTCfh9M9ya+I9JpbB7O8o= github.com/armon/go-metrics v0.0.0-20180917152333-f0300d1749da/go.mod h1:Q73ZrmVTwzkszR9V5SSuryQ31EELlFMUz1kKyl939pY= github.com/armon/go-radix v0.0.0-20180808171621-7fddfc383310/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8= -github.com/aws/aws-sdk-go v1.38.15 h1:usaPeqoxFUzy0FfBLZLZHya5Kv2cpURjb1jqCa7+odA= github.com/aws/aws-sdk-go v1.38.15/go.mod h1:hcU610XS61/+aQV88ixoOzUoG7v3b31pl2zKMmprdro= +github.com/aws/aws-sdk-go v1.42.30 h1:GvzWHwAdE5ZQ9UOcq0lX+PTzVJ4+sm1DjYrk6nUSTgA= +github.com/aws/aws-sdk-go v1.42.30/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc= github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q= github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= @@ -330,6 +339,7 @@ golang.org/x/crypto v0.0.0-20190820162420-60c769a6c586/go.mod h1:yigFU9vqHzYiE8U golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20201216223049-8b5274cf687f/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/crypto v0.0.0-20210314154223-e6e6c4f2bb5b/go.mod h1:T9bdIzuCu7OtxOm1hfPfRQxPLYneinmdGuTeoZ9dtd4= +golang.org/x/crypto v0.0.0-20210817164053-32db794688a5/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871 h1:/pEO3GD/ABYAjuakUS6xSEmmlyVS4kxBNkeA9tLJiTI= golang.org/x/crypto v0.0.0-20211117183948-ae814b36b871/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= @@ -370,8 +380,8 @@ golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81R golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2 h1:CIJ76btIcR3eFI5EgSo6k1qKw9KJexJuRLI9G7Hp5wE= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= +golang.org/x/net v0.0.0-20211216030914-fe4d6282115f h1:hEYJvxw1lSnWIl8X9ofsYMklzaDs90JI2az5YMd4fPM= +golang.org/x/net v0.0.0-20211216030914-fe4d6282115f/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -405,11 +415,12 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210414055047-fe65e336abe0/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20211124211545-fe61309f8881 h1:TyHqChC80pFkXWraUUf6RuB5IqFdQieMLwwCJokV2pc= -golang.org/x/sys v0.0.0-20211124211545-fe61309f8881/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d h1:FjkYO/PPp4Wi0EAUOVLxePm7qVW4r4ctbWpURyuOD0E= +golang.org/x/sys v0.0.0-20211205182925-97ca703d548d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -466,6 +477,7 @@ google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZi google.golang.org/grpc v1.20.1/go.mod h1:10oTOabMzJvdu6/UiuZezV6QK5dSlG84ov/aaiqXj38= google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ijfRaM= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= +gopkg.in/avro.v0 v0.0.0-20171217001914-a730b5802183/go.mod h1:FvqrFXt+jCsyQibeRv4xxEJBL5iG2DDW5aeJwzDiq4A= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= diff --git a/service/service.go b/service/service.go index a9273fa4..ecbfaf21 100644 --- a/service/service.go +++ b/service/service.go @@ -12,8 +12,7 @@ import ( "github.com/gorilla/mux" "github.com/pkg/errors" - esauth "github.com/ONSdigital/dp-elasticsearch/v2/awsauth" - dpelastic "github.com/ONSdigital/dp-elasticsearch/v2/elasticsearch" + dpelastic "github.com/ONSdigital/dp-elasticsearch/v3/elasticsearch" dphttp "github.com/ONSdigital/dp-net/http" ) @@ -23,7 +22,6 @@ type Service struct { api *api.SearchAPI config *config.Config elasticSearchClient elasticsearch.Client - esSigner *esauth.Signer healthCheck HealthChecker queryBuilder api.QueryBuilder router *mux.Router @@ -47,11 +45,6 @@ func (svc *Service) SetQueryBuilder(queryBuilder api.QueryBuilder) { svc.queryBuilder = queryBuilder } -// SetEsSigner sets the AWS signer for a service -func (svc *Service) SetEsSigner(esSigner *esauth.Signer) { - svc.esSigner = esSigner -} - // SetElasticSearchClient sets the new instance of elasticsearch for a service func (svc *Service) SetElasticSearchClient(elasticSearchClient elasticsearch.Client) { svc.elasticSearchClient = elasticSearchClient @@ -64,7 +57,6 @@ func (svc *Service) SetTransformer(transformerClient *transformer.Transformer) { // Run the service func Run(ctx context.Context, cfg *config.Config, serviceList *ExternalServiceList, buildTime, gitCommit, version string, svcErrors chan error) (svc *Service, err error) { - var esSigner *esauth.Signer elasticHTTPClient := dphttp.NewClient() // Initialise transformerClient @@ -72,17 +64,17 @@ func Run(ctx context.Context, cfg *config.Config, serviceList *ExternalServiceLi // Initialse AWS signer if cfg.SignElasticsearchRequests { - esSigner, err = esauth.NewAwsSigner("", "", cfg.AwsRegion, cfg.AwsService) + elasticHTTPClient, err = dphttp.NewClientWithAwsSigner("", "", cfg.AwsRegion, cfg.AwsService) if err != nil { log.Error(ctx, "failed to create aws v4 signer", err) return nil, err } } - dpESClient := dpelastic.NewClientWithHTTPClientAndAwsSigner(cfg.ElasticSearchAPIURL, esSigner, cfg.SignElasticsearchRequests, elasticHTTPClient) + dpESClient := dpelastic.NewClientWithHTTPClient(cfg.ElasticSearchAPIURL, elasticHTTPClient) // Initialise deprecatedESClient - deprecatedESClient := elasticsearch.New(cfg.ElasticSearchAPIURL, elasticHTTPClient, cfg.SignElasticsearchRequests, esSigner, cfg.AwsRegion, cfg.AwsService) + deprecatedESClient := elasticsearch.New(cfg.ElasticSearchAPIURL, elasticHTTPClient, cfg.AwsRegion, cfg.AwsService) // Initialise query builder queryBuilder, err := query.NewQueryBuilder(pathToTemplates) @@ -130,7 +122,6 @@ func Run(ctx context.Context, cfg *config.Config, serviceList *ExternalServiceLi api: searchAPI, config: cfg, elasticSearchClient: *deprecatedESClient, - esSigner: esSigner, healthCheck: healthCheck, queryBuilder: queryBuilder, router: router,