Skip to content

Commit

Permalink
remove the http code in meta.go (#230)
Browse files Browse the repository at this point in the history
* remove the http code in meta.go

* remove unused imports
  • Loading branch information
beltran authored Dec 23, 2023
1 parent 9323989 commit 0cdf9d8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 44 deletions.
43 changes: 0 additions & 43 deletions meta.go
Original file line number Diff line number Diff line change
@@ -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"
)
Expand Down Expand Up @@ -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)
}
Expand All @@ -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
}
12 changes: 11 additions & 1 deletion meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -98,3 +100,11 @@ func getAuthForMeta() string {
}
return auth
}

func getTransportForMeta() string {
transport := os.Getenv("TRANSPORT")
if transport == "" {
transport = "binary"
}
return transport
}

0 comments on commit 0cdf9d8

Please sign in to comment.