auth

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 11, 2022 License: MIT Imports: 37 Imported by: 1

README

Auth

Auth plugin provides a simple username/password authentication mechanism.

API Doc

See swagger

Documentation

Overview

Package auth is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Package auth is a generated GoMock package.

Index

Constants

View Source
const (
	Plain  hashType = "plain"
	MD5             = "md5"
	SHA256          = "sha256"
	Bcrypt          = "bcrypt"
)
View Source
const Name = "auth"

Variables

View Source
var DefaultConfig = Config{
	Hash:         MD5,
	PasswordFile: "./gmqtt_password.yml",
}

DefaultConfig is the default configuration.

View Source
var File_account_proto protoreflect.FileDescriptor
View Source
var ValidateHashType = []string{
	Plain, MD5, SHA256, Bcrypt,
}

Functions

func New

func New(config config.Config) (server.Plugin, error)

func RegisterAccountServiceHandler

func RegisterAccountServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterAccountServiceHandler registers the http handlers for service AccountService to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterAccountServiceHandlerClient

func RegisterAccountServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AccountServiceClient) error

RegisterAccountServiceHandlerClient registers the http handlers for service AccountService to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "AccountServiceClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "AccountServiceClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "AccountServiceClient" to call the correct interceptors.

func RegisterAccountServiceHandlerFromEndpoint

func RegisterAccountServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterAccountServiceHandlerFromEndpoint is same as RegisterAccountServiceHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterAccountServiceHandlerServer

func RegisterAccountServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AccountServiceServer) error

RegisterAccountServiceHandlerServer registers the http handlers for service AccountService to "mux". UnaryRPC :call AccountServiceServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906.

func RegisterAccountServiceServer

func RegisterAccountServiceServer(s grpc.ServiceRegistrar, srv AccountServiceServer)

Types

type Account

type Account struct {
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
	// contains filtered or unexported fields
}

func (*Account) Descriptor deprecated

func (*Account) Descriptor() ([]byte, []int)

Deprecated: Use Account.ProtoReflect.Descriptor instead.

func (*Account) GetPassword

func (x *Account) GetPassword() string

func (*Account) GetUsername

func (x *Account) GetUsername() string

func (*Account) ProtoMessage

func (*Account) ProtoMessage()

func (*Account) ProtoReflect

func (x *Account) ProtoReflect() protoreflect.Message

func (*Account) Reset

func (x *Account) Reset()

func (*Account) String

func (x *Account) String() string

type AccountServiceClient

type AccountServiceClient interface {
	// List all accounts
	List(ctx context.Context, in *ListAccountsRequest, opts ...grpc.CallOption) (*ListAccountsResponse, error)
	// Get the account for given username.
	// Return NotFound error when account not found.
	Get(ctx context.Context, in *GetAccountRequest, opts ...grpc.CallOption) (*GetAccountResponse, error)
	// Update the password for the account.
	// This API will create the account if not exists.
	Update(ctx context.Context, in *UpdateAccountRequest, opts ...grpc.CallOption) (*empty.Empty, error)
	// Delete the account for given username
	Delete(ctx context.Context, in *DeleteAccountRequest, opts ...grpc.CallOption) (*empty.Empty, error)
}

AccountServiceClient is the client API for AccountService service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type AccountServiceServer

type AccountServiceServer interface {
	// List all accounts
	List(context.Context, *ListAccountsRequest) (*ListAccountsResponse, error)
	// Get the account for given username.
	// Return NotFound error when account not found.
	Get(context.Context, *GetAccountRequest) (*GetAccountResponse, error)
	// Update the password for the account.
	// This API will create the account if not exists.
	Update(context.Context, *UpdateAccountRequest) (*empty.Empty, error)
	// Delete the account for given username
	Delete(context.Context, *DeleteAccountRequest) (*empty.Empty, error)
	// contains filtered or unexported methods
}

AccountServiceServer is the server API for AccountService service. All implementations must embed UnimplementedAccountServiceServer for forward compatibility

type Auth

type Auth struct {
	// contains filtered or unexported fields
}

Auth provides the username/password authentication for gmqtt. The authentication data is persist in config.PasswordFile.

func (*Auth) Delete

func (a *Auth) Delete(ctx context.Context, req *DeleteAccountRequest) (resp *empty.Empty, err error)

Delete deletes the account for the username.

func (*Auth) Get

func (a *Auth) Get(ctx context.Context, req *GetAccountRequest) (resp *GetAccountResponse, err error)

Get gets the account for given username. Return NotFound error when account not found.

func (*Auth) HookWrapper

func (a *Auth) HookWrapper() server.HookWrapper

func (*Auth) List

func (a *Auth) List(ctx context.Context, req *ListAccountsRequest) (resp *ListAccountsResponse, err error)

List lists all accounts

func (*Auth) Load

func (a *Auth) Load(service server.Server) error

func (*Auth) Name

func (a *Auth) Name() string

func (*Auth) OnBasicAuthWrapper

func (a *Auth) OnBasicAuthWrapper(pre server.OnBasicAuth) server.OnBasicAuth

func (*Auth) Unload

func (a *Auth) Unload() error

func (*Auth) Update

func (a *Auth) Update(ctx context.Context, req *UpdateAccountRequest) (resp *empty.Empty, err error)

Update updates the password for the account. Create a new account if the account for the username is not exists. Update will persist the account data to the password file.

type Config

type Config struct {
	// PasswordFile is the file to store username and password.
	PasswordFile string `yaml:"password_file"`
	// Hash is the password hash algorithm.
	// Possible values: plain | md5 | sha256 | bcrypt
	Hash string `yaml:"hash"`
}

Config is the configuration for the auth plugin.

func (*Config) UnmarshalYAML

func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error

func (*Config) Validate

func (c *Config) Validate() error

validate validates the configuration, and return an error if it is invalid.

type DeleteAccountRequest

type DeleteAccountRequest struct {
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	// contains filtered or unexported fields
}

func (*DeleteAccountRequest) Descriptor deprecated

func (*DeleteAccountRequest) Descriptor() ([]byte, []int)

Deprecated: Use DeleteAccountRequest.ProtoReflect.Descriptor instead.

func (*DeleteAccountRequest) GetUsername

func (x *DeleteAccountRequest) GetUsername() string

func (*DeleteAccountRequest) ProtoMessage

func (*DeleteAccountRequest) ProtoMessage()

func (*DeleteAccountRequest) ProtoReflect

func (x *DeleteAccountRequest) ProtoReflect() protoreflect.Message

func (*DeleteAccountRequest) Reset

func (x *DeleteAccountRequest) Reset()

func (*DeleteAccountRequest) String

func (x *DeleteAccountRequest) String() string

type GetAccountRequest

type GetAccountRequest struct {
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	// contains filtered or unexported fields
}

func (*GetAccountRequest) Descriptor deprecated

func (*GetAccountRequest) Descriptor() ([]byte, []int)

Deprecated: Use GetAccountRequest.ProtoReflect.Descriptor instead.

func (*GetAccountRequest) GetUsername

func (x *GetAccountRequest) GetUsername() string

func (*GetAccountRequest) ProtoMessage

func (*GetAccountRequest) ProtoMessage()

func (*GetAccountRequest) ProtoReflect

func (x *GetAccountRequest) ProtoReflect() protoreflect.Message

func (*GetAccountRequest) Reset

func (x *GetAccountRequest) Reset()

func (*GetAccountRequest) String

func (x *GetAccountRequest) String() string

type GetAccountResponse

type GetAccountResponse struct {
	Account *Account `protobuf:"bytes,1,opt,name=account,proto3" json:"account,omitempty"`
	// contains filtered or unexported fields
}

func (*GetAccountResponse) Descriptor deprecated

func (*GetAccountResponse) Descriptor() ([]byte, []int)

Deprecated: Use GetAccountResponse.ProtoReflect.Descriptor instead.

func (*GetAccountResponse) GetAccount

func (x *GetAccountResponse) GetAccount() *Account

func (*GetAccountResponse) ProtoMessage

func (*GetAccountResponse) ProtoMessage()

func (*GetAccountResponse) ProtoReflect

func (x *GetAccountResponse) ProtoReflect() protoreflect.Message

func (*GetAccountResponse) Reset

func (x *GetAccountResponse) Reset()

func (*GetAccountResponse) String

func (x *GetAccountResponse) String() string

type ListAccountsRequest

type ListAccountsRequest struct {
	PageSize uint32 `protobuf:"varint,1,opt,name=page_size,json=pageSize,proto3" json:"page_size,omitempty"`
	Page     uint32 `protobuf:"varint,2,opt,name=page,proto3" json:"page,omitempty"`
	// contains filtered or unexported fields
}

func (*ListAccountsRequest) Descriptor deprecated

func (*ListAccountsRequest) Descriptor() ([]byte, []int)

Deprecated: Use ListAccountsRequest.ProtoReflect.Descriptor instead.

func (*ListAccountsRequest) GetPage

func (x *ListAccountsRequest) GetPage() uint32

func (*ListAccountsRequest) GetPageSize

func (x *ListAccountsRequest) GetPageSize() uint32

func (*ListAccountsRequest) ProtoMessage

func (*ListAccountsRequest) ProtoMessage()

func (*ListAccountsRequest) ProtoReflect

func (x *ListAccountsRequest) ProtoReflect() protoreflect.Message

func (*ListAccountsRequest) Reset

func (x *ListAccountsRequest) Reset()

func (*ListAccountsRequest) String

func (x *ListAccountsRequest) String() string

type ListAccountsResponse

type ListAccountsResponse struct {
	Accounts   []*Account `protobuf:"bytes,1,rep,name=accounts,proto3" json:"accounts,omitempty"`
	TotalCount uint32     `protobuf:"varint,2,opt,name=total_count,json=totalCount,proto3" json:"total_count,omitempty"`
	// contains filtered or unexported fields
}

func (*ListAccountsResponse) Descriptor deprecated

func (*ListAccountsResponse) Descriptor() ([]byte, []int)

Deprecated: Use ListAccountsResponse.ProtoReflect.Descriptor instead.

func (*ListAccountsResponse) GetAccounts

func (x *ListAccountsResponse) GetAccounts() []*Account

func (*ListAccountsResponse) GetTotalCount

func (x *ListAccountsResponse) GetTotalCount() uint32

func (*ListAccountsResponse) ProtoMessage

func (*ListAccountsResponse) ProtoMessage()

func (*ListAccountsResponse) ProtoReflect

func (x *ListAccountsResponse) ProtoReflect() protoreflect.Message

func (*ListAccountsResponse) Reset

func (x *ListAccountsResponse) Reset()

func (*ListAccountsResponse) String

func (x *ListAccountsResponse) String() string

type MockAccountServiceClient added in v0.3.0

type MockAccountServiceClient struct {
	// contains filtered or unexported fields
}

MockAccountServiceClient is a mock of AccountServiceClient interface

func NewMockAccountServiceClient added in v0.3.0

func NewMockAccountServiceClient(ctrl *gomock.Controller) *MockAccountServiceClient

NewMockAccountServiceClient creates a new mock instance

func (*MockAccountServiceClient) Delete added in v0.3.0

Delete mocks base method

func (*MockAccountServiceClient) EXPECT added in v0.3.0

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAccountServiceClient) Get added in v0.3.0

Get mocks base method

func (*MockAccountServiceClient) List added in v0.3.0

List mocks base method

func (*MockAccountServiceClient) Update added in v0.3.0

Update mocks base method

type MockAccountServiceClientMockRecorder added in v0.3.0

type MockAccountServiceClientMockRecorder struct {
	// contains filtered or unexported fields
}

MockAccountServiceClientMockRecorder is the mock recorder for MockAccountServiceClient

func (*MockAccountServiceClientMockRecorder) Delete added in v0.3.0

func (mr *MockAccountServiceClientMockRecorder) Delete(ctx, in interface{}, opts ...interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockAccountServiceClientMockRecorder) Get added in v0.3.0

func (mr *MockAccountServiceClientMockRecorder) Get(ctx, in interface{}, opts ...interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockAccountServiceClientMockRecorder) List added in v0.3.0

func (mr *MockAccountServiceClientMockRecorder) List(ctx, in interface{}, opts ...interface{}) *gomock.Call

List indicates an expected call of List

func (*MockAccountServiceClientMockRecorder) Update added in v0.3.0

func (mr *MockAccountServiceClientMockRecorder) Update(ctx, in interface{}, opts ...interface{}) *gomock.Call

Update indicates an expected call of Update

type MockAccountServiceServer added in v0.3.0

type MockAccountServiceServer struct {
	// contains filtered or unexported fields
}

MockAccountServiceServer is a mock of AccountServiceServer interface

func NewMockAccountServiceServer added in v0.3.0

func NewMockAccountServiceServer(ctrl *gomock.Controller) *MockAccountServiceServer

NewMockAccountServiceServer creates a new mock instance

func (*MockAccountServiceServer) Delete added in v0.3.0

Delete mocks base method

func (*MockAccountServiceServer) EXPECT added in v0.3.0

EXPECT returns an object that allows the caller to indicate expected use

func (*MockAccountServiceServer) Get added in v0.3.0

Get mocks base method

func (*MockAccountServiceServer) List added in v0.3.0

List mocks base method

func (*MockAccountServiceServer) Update added in v0.3.0

Update mocks base method

type MockAccountServiceServerMockRecorder added in v0.3.0

type MockAccountServiceServerMockRecorder struct {
	// contains filtered or unexported fields
}

MockAccountServiceServerMockRecorder is the mock recorder for MockAccountServiceServer

func (*MockAccountServiceServerMockRecorder) Delete added in v0.3.0

func (mr *MockAccountServiceServerMockRecorder) Delete(arg0, arg1 interface{}) *gomock.Call

Delete indicates an expected call of Delete

func (*MockAccountServiceServerMockRecorder) Get added in v0.3.0

func (mr *MockAccountServiceServerMockRecorder) Get(arg0, arg1 interface{}) *gomock.Call

Get indicates an expected call of Get

func (*MockAccountServiceServerMockRecorder) List added in v0.3.0

func (mr *MockAccountServiceServerMockRecorder) List(arg0, arg1 interface{}) *gomock.Call

List indicates an expected call of List

func (*MockAccountServiceServerMockRecorder) Update added in v0.3.0

func (mr *MockAccountServiceServerMockRecorder) Update(arg0, arg1 interface{}) *gomock.Call

Update indicates an expected call of Update

type MockUnsafeAccountServiceServer added in v0.3.0

type MockUnsafeAccountServiceServer struct {
	// contains filtered or unexported fields
}

MockUnsafeAccountServiceServer is a mock of UnsafeAccountServiceServer interface

func NewMockUnsafeAccountServiceServer added in v0.3.0

func NewMockUnsafeAccountServiceServer(ctrl *gomock.Controller) *MockUnsafeAccountServiceServer

NewMockUnsafeAccountServiceServer creates a new mock instance

func (*MockUnsafeAccountServiceServer) EXPECT added in v0.3.0

EXPECT returns an object that allows the caller to indicate expected use

type MockUnsafeAccountServiceServerMockRecorder added in v0.3.0

type MockUnsafeAccountServiceServerMockRecorder struct {
	// contains filtered or unexported fields
}

MockUnsafeAccountServiceServerMockRecorder is the mock recorder for MockUnsafeAccountServiceServer

type UnimplementedAccountServiceServer

type UnimplementedAccountServiceServer struct {
}

UnimplementedAccountServiceServer must be embedded to have forward compatible implementations.

func (UnimplementedAccountServiceServer) Delete

func (UnimplementedAccountServiceServer) Get

func (UnimplementedAccountServiceServer) List

func (UnimplementedAccountServiceServer) Update

type UnsafeAccountServiceServer

type UnsafeAccountServiceServer interface {
	// contains filtered or unexported methods
}

UnsafeAccountServiceServer may be embedded to opt out of forward compatibility for this service. Use of this interface is not recommended, as added methods to AccountServiceServer will result in compilation errors.

type UpdateAccountRequest

type UpdateAccountRequest struct {
	Username string `protobuf:"bytes,1,opt,name=username,proto3" json:"username,omitempty"`
	Password string `protobuf:"bytes,2,opt,name=password,proto3" json:"password,omitempty"`
	// contains filtered or unexported fields
}

func (*UpdateAccountRequest) Descriptor deprecated

func (*UpdateAccountRequest) Descriptor() ([]byte, []int)

Deprecated: Use UpdateAccountRequest.ProtoReflect.Descriptor instead.

func (*UpdateAccountRequest) GetPassword

func (x *UpdateAccountRequest) GetPassword() string

func (*UpdateAccountRequest) GetUsername

func (x *UpdateAccountRequest) GetUsername() string

func (*UpdateAccountRequest) ProtoMessage

func (*UpdateAccountRequest) ProtoMessage()

func (*UpdateAccountRequest) ProtoReflect

func (x *UpdateAccountRequest) ProtoReflect() protoreflect.Message

func (*UpdateAccountRequest) Reset

func (x *UpdateAccountRequest) Reset()

func (*UpdateAccountRequest) String

func (x *UpdateAccountRequest) String() string

Jump to

Keyboard shortcuts

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