From 0cdf9d80f8c617b73d43ac0425a7207571262e3b Mon Sep 17 00:00:00 2001 From: Jaume Marhuenda Date: Sat, 23 Dec 2023 08:48:28 -0500 Subject: [PATCH] remove the http code in meta.go (#230) * remove the http code in meta.go * remove unused imports --- meta.go | 43 ------------------------------------------- meta_test.go | 12 +++++++++++- 2 files changed, 11 insertions(+), 44 deletions(-) diff --git a/meta.go b/meta.go index 0559614..61afd10 100644 --- a/meta.go +++ b/meta.go @@ -1,12 +1,9 @@ package gohive import ( - "encoding/base64" "fmt" "github.com/apache/thrift/lib/go/thrift" "github.com/beltran/gohive/hive_metastore" - "github.com/beltran/gosasl" - "net/http" "os/user" "strings" ) @@ -78,40 +75,6 @@ func ConnectToMetastore(host string, port int, auth string, configuration *Metas } else { panic("Unrecognized auth") } - } else if configuration.TransportMode == "http" { - if auth == "KERBEROS" { - mechanism, err := gosasl.NewGSSAPIMechanism("hive") - if err != nil { - return nil, err - } - saslClient := gosasl.NewSaslClient(host, mechanism) - token, err := saslClient.Start() - if err != nil { - return nil, err - } - if len(token) == 0 { - return nil, fmt.Errorf("Gssapi init context returned an empty token. Probably the service is empty in the configuration") - } - - httpClient, protocol, err := getHTTPClientForMeta() - if err != nil { - return nil, err - } - - httpOptions := thrift.THttpClientOptions{ - Client: httpClient, - } - transport, err = thrift.NewTHttpClientTransportFactoryWithOptions(fmt.Sprintf(protocol+"://%s:%d/"+"cliservice", host, port), httpOptions).GetTransport(socket) - httpTransport, ok := transport.(*thrift.THttpClient) - if ok { - httpTransport.SetHeader("Authorization", "Negotiate "+base64.StdEncoding.EncodeToString(token)) - } - if err != nil { - return nil, err - } - } else { - panic("Unrecognized auth") - } } else { panic("Unrecognized transport mode " + configuration.TransportMode) } @@ -136,9 +99,3 @@ func ConnectToMetastore(host string, port int, auth string, configuration *Metas func (c *HiveMetastoreClient) Close() { c.transport.Close() } - -func getHTTPClientForMeta() (httpClient *http.Client, protocol string, err error) { - httpClient = http.DefaultClient - protocol = "http" - return -} diff --git a/meta_test.go b/meta_test.go index 9db6842..088a7e7 100644 --- a/meta_test.go +++ b/meta_test.go @@ -21,7 +21,7 @@ func randSeqDb(n int) string { } var tableIdDb = 0 -var randNameDb = randSeq(10) +var randNameDb = randSeqDb(10) func GetDatabaseName() string { tableName := fmt.Sprintf("db_pokes_%s%d", randNameDb, tableIdDb) @@ -34,6 +34,7 @@ func TestConnectDefaultMeta(t *testing.T) { t.Skip("metastore not set.") } configuration := NewMetastoreConnectConfiguration() + configuration.TransportMode = getTransportForMeta() client, err := ConnectToMetastore("hm.example.com", 9083, getAuthForMeta(), configuration) if err != nil { log.Fatal(err) @@ -55,6 +56,7 @@ func TestDatabaseOperations(t *testing.T) { t.Skip("metastore not set.") } configuration := NewMetastoreConnectConfiguration() + configuration.TransportMode = getTransportForMeta() connection, err := ConnectToMetastore("hm.example.com", 9083, getAuthForMeta(), configuration) if err != nil { log.Fatal(err) @@ -98,3 +100,11 @@ func getAuthForMeta() string { } return auth } + +func getTransportForMeta() string { + transport := os.Getenv("TRANSPORT") + if transport == "" { + transport = "binary" + } + return transport +}