sasl

package module
v0.0.0-...-cbf8345 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 24, 2023 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

go Kerberos sasl authtication steps

1. go

go 1.19

2. basic software

2.1 hbase 1.2.6.1
https://archive.apache.org/dist/hbase/1.2.6.1/
2.2 thrift 0.9.3
http://archive.apache.org/dist/thrift/0.9.3/
2.3 libkrb5
Ubuntu: sudo apt-get install libkrb5-dev
MacOS: brew install homebrew/dupes/heimdal --without-x11
Debian: yum install -y krb5-devel 

3. go dependence

3.1 go thrift
go get git.apache.org/thrift.git/lib/go/thrift@0.9.3
3.2 go gosasl
go get -tags kerberos github.com/beltran/gosasl
3.3 thrift hbase client(already integration,pass to 4)
tar -zxvf hbase-1.2.6.1-src-tar.gz && cd hbase-1.2.6.1
thrift --out ./ --gen go ./hbase-thrift/src/main/resources/org/apache/hadoop/hbase/thrift/Hbase.thrift
cp -r ./hbase/* {you application dir}

4.export env

export KRB5CCNAME={your file path}
export KRB5_CONFIG={your file path}

5. install & run & build

go get github.com/spierman/gosasl
go run -tags kerberos {XX}.go
go build -tags kerberos {XX}.go

6. example code

```
import (
    "fmt"
    "log"
    "os"
    sasl "github.com/spierman/gosasl"
"github.com/spierman/gosasl/hbase"
)

func main() {
    host := "XX.com"
    port := 9090
    table := "aa"
    connection, err := sasl.Connect(host, port, sasl.WithGSSAPISaslTransport("hbase"))
    if err != nil {
        log.Fatal("Error connecting", err)
        return
    }
    l := log.New(os.Stderr, "GOKRB5 Client: ", log.LstdFlags)
    client := hbase.NewHbaseClientFactory(connection.Transport, connection.ProtocolFactory)
    isExists, err := client.IsTableEnabled([]byte(table))
    if err != nil {
        l.Fatalf("could not load: %v", err)
    }
    fmt.Printf("rst {%s}\n", isExists)
}
```

7. issuse

if the hbase.go report error,please replace like this
```
replace temp  to  string(temp[:])

```

Documentation

Index

Constants

View Source
const (
	START    = 1
	OK       = 2
	BAD      = 3
	ERROR    = 4
	COMPLETE = 5
)
View Source
const DEFAULT_MAX_LENGTH = 16384000

Variables

View Source
var (
	DefaultOptions = Options{PollIntervalSeconds: 0.1, BatchSize: 10000, ConnectionTimeout: 10000 * time.Millisecond}
)

Functions

This section is empty.

Types

type Connection

type Connection struct {
	Transport       *TSaslTransport
	ProtocolFactory *thrift.TBinaryProtocolFactory
}

func Connect

func Connect(host string, port int, opts ...Option) (*Connection, error)

func (*Connection) Close

func (c *Connection) Close() error

type Option

type Option func(*Options)

func WithBatchSize

func WithBatchSize(bs int64) Option

func WithConnectionTimeout

func WithConnectionTimeout(timeout time.Duration) Option

func WithGSSAPISaslTransport

func WithGSSAPISaslTransport(service string) Option

func WithPollInterval

func WithPollInterval(pollIntervalSeconds float64) Option

type Options

type Options struct {
	PollIntervalSeconds float64
	BatchSize           int64
	ConnectionTimeout   time.Duration
	SaslTransportConfig map[string]string
}

type TSaslTransport

type TSaslTransport struct {
	OpeningContext context.Context
	// contains filtered or unexported fields
}

TSaslTransport is a tranport thrift struct that uses SASL

func NewTSaslTransport

func NewTSaslTransport(trans thrift.TTransport, host string, configuration map[string]string) (*TSaslTransport, error)

NewTSaslTransport return a TSaslTransport

func (*TSaslTransport) Close

func (p *TSaslTransport) Close() (err error)

Close close a SASL transport connection

func (*TSaslTransport) Flush

func (p *TSaslTransport) Flush() (err error)

Flush the bytes in the buffer

func (*TSaslTransport) IsOpen

func (p *TSaslTransport) IsOpen() bool

IsOpen opens a SASL connection

func (*TSaslTransport) Open

func (p *TSaslTransport) Open() (err error)

Open check if a SASL transport connection is opened

func (*TSaslTransport) Read

func (p *TSaslTransport) Read(buf []byte) (l int, err error)

func (*TSaslTransport) RemainingBytes

func (p *TSaslTransport) RemainingBytes() uint64

RemainingBytes return the size of the unwrapped bytes

func (*TSaslTransport) Write

func (p *TSaslTransport) Write(buf []byte) (int, error)

Directories

Path Synopsis
hbase-remote command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址