Documentation
¶
Overview ¶
Package auth is a reverse proxy.
It translates gRPC into RESTful JSON APIs.
Index ¶
- Constants
- Variables
- func New(config config.Config) (server.Plugin, error)
- func RegisterAccountServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error
- func RegisterAccountServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client AccountServiceClient) error
- func RegisterAccountServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, ...) (err error)
- func RegisterAccountServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server AccountServiceServer) error
- func RegisterAccountServiceServer(s grpc.ServiceRegistrar, srv AccountServiceServer)
- type Account
- type AccountServiceClient
- type AccountServiceServer
- type Auth
- func (a *Auth) Delete(ctx context.Context, req *DeleteAccountRequest) (resp *empty.Empty, err error)
- func (a *Auth) Get(ctx context.Context, req *GetAccountRequest) (resp *GetAccountResponse, err error)
- func (a *Auth) HookWrapper() server.HookWrapper
- func (a *Auth) List(ctx context.Context, req *ListAccountsRequest) (resp *ListAccountsResponse, err error)
- func (a *Auth) Load(service server.Server) error
- func (a *Auth) Name() string
- func (a *Auth) OnBasicAuthWrapper(pre server.OnBasicAuth) server.OnBasicAuth
- func (a *Auth) RegisterGRPC(s grpc.ServiceRegistrar)
- func (a *Auth) RegisterHTTP(ctx context.Context, mux *runtime.ServeMux, endpoint string, ...) (err error)
- func (a *Auth) Unload() error
- func (a *Auth) Update(ctx context.Context, req *UpdateAccountRequest) (resp *empty.Empty, err error)
- type Config
- type DeleteAccountRequest
- func (*DeleteAccountRequest) Descriptor() ([]byte, []int)deprecated
- func (x *DeleteAccountRequest) GetUsername() string
- func (*DeleteAccountRequest) ProtoMessage()
- func (x *DeleteAccountRequest) ProtoReflect() protoreflect.Message
- func (x *DeleteAccountRequest) Reset()
- func (x *DeleteAccountRequest) String() string
- type GetAccountRequest
- type GetAccountResponse
- func (*GetAccountResponse) Descriptor() ([]byte, []int)deprecated
- func (x *GetAccountResponse) GetAccount() *Account
- func (*GetAccountResponse) ProtoMessage()
- func (x *GetAccountResponse) ProtoReflect() protoreflect.Message
- func (x *GetAccountResponse) Reset()
- func (x *GetAccountResponse) String() string
- type ListAccountsRequest
- func (*ListAccountsRequest) Descriptor() ([]byte, []int)deprecated
- func (x *ListAccountsRequest) GetPage() uint32
- func (x *ListAccountsRequest) GetPageSize() uint32
- func (*ListAccountsRequest) ProtoMessage()
- func (x *ListAccountsRequest) ProtoReflect() protoreflect.Message
- func (x *ListAccountsRequest) Reset()
- func (x *ListAccountsRequest) String() string
- type ListAccountsResponse
- func (*ListAccountsResponse) Descriptor() ([]byte, []int)deprecated
- func (x *ListAccountsResponse) GetAccounts() []*Account
- func (x *ListAccountsResponse) GetTotalCount() uint32
- func (*ListAccountsResponse) ProtoMessage()
- func (x *ListAccountsResponse) ProtoReflect() protoreflect.Message
- func (x *ListAccountsResponse) Reset()
- func (x *ListAccountsResponse) String() string
- type UnimplementedAccountServiceServer
- func (UnimplementedAccountServiceServer) Delete(context.Context, *DeleteAccountRequest) (*empty.Empty, error)
- func (UnimplementedAccountServiceServer) Get(context.Context, *GetAccountRequest) (*GetAccountResponse, error)
- func (UnimplementedAccountServiceServer) List(context.Context, *ListAccountsRequest) (*ListAccountsResponse, error)
- func (UnimplementedAccountServiceServer) Update(context.Context, *UpdateAccountRequest) (*empty.Empty, error)
- type UnsafeAccountServiceServer
- type UpdateAccountRequest
- func (*UpdateAccountRequest) Descriptor() ([]byte, []int)deprecated
- func (x *UpdateAccountRequest) GetPassword() string
- func (x *UpdateAccountRequest) GetUsername() string
- func (*UpdateAccountRequest) ProtoMessage()
- func (x *UpdateAccountRequest) ProtoReflect() protoreflect.Message
- func (x *UpdateAccountRequest) Reset()
- func (x *UpdateAccountRequest) String() string
Constants ¶
const ( Plain hashType = "plain" MD5 = "md5" SHA256 = "sha256" Bcrypt = "bcrypt" )
const Name = "auth"
Variables ¶
var DefaultConfig = Config{ Hash: MD5, }
DefaultConfig is the default configuration.
var File_account_proto protoreflect.FileDescriptor
Functions ¶
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) GetPassword ¶
func (*Account) GetUsername ¶
func (*Account) ProtoMessage ¶
func (*Account) ProtoMessage()
func (*Account) ProtoReflect ¶
func (x *Account) ProtoReflect() protoreflect.Message
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.
func NewAccountServiceClient ¶
func NewAccountServiceClient(cc grpc.ClientConnInterface) AccountServiceClient
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) OnBasicAuthWrapper ¶
func (a *Auth) OnBasicAuthWrapper(pre server.OnBasicAuth) server.OnBasicAuth
func (*Auth) RegisterGRPC ¶
func (a *Auth) RegisterGRPC(s grpc.ServiceRegistrar)
func (*Auth) RegisterHTTP ¶
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 ¶
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 UnimplementedAccountServiceServer ¶
type UnimplementedAccountServiceServer struct {
}
UnimplementedAccountServiceServer must be embedded to have forward compatible implementations.
func (UnimplementedAccountServiceServer) Delete ¶
func (UnimplementedAccountServiceServer) Delete(context.Context, *DeleteAccountRequest) (*empty.Empty, error)
func (UnimplementedAccountServiceServer) Get ¶
func (UnimplementedAccountServiceServer) Get(context.Context, *GetAccountRequest) (*GetAccountResponse, error)
func (UnimplementedAccountServiceServer) List ¶
func (UnimplementedAccountServiceServer) List(context.Context, *ListAccountsRequest) (*ListAccountsResponse, error)
func (UnimplementedAccountServiceServer) Update ¶
func (UnimplementedAccountServiceServer) Update(context.Context, *UpdateAccountRequest) (*empty.Empty, error)
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