mochicloudhooks

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Sep 11, 2023 License: GPL-3.0 Imports: 17 Imported by: 1

README

Go Reference

Mochi Cloud Hooks

Mochi Cloud Hooks is a collection of hooks that can be imported and used for Mochi MQTT Broker. Implementations of certain hooks are inspired by other open source projects

Table of contents
Hooks
Auth
HTTP

The HTTP hook is a simple HTTP hook that uses two hooks to authorize the client to connect to the broker and authorizes topic level ACLs. It works by checking the response code of each endpoint. If an endpoint returns back a non 200 response a false is returned from the hook

GCP Secret Manager

⚠ this is currently experimental and should not be used in production. The functionality is purly for testing and will be changed in the future

The GCP Secret Manager hook should be utilized as a super admin hook. Secrets stored in Secret Manager will be loaded into memory and compared at runtime. If the connecting client's username matches what is stored in Secret Manager, this user will be a super user and will have access to all ACLs.

Messaging
Pub/Sub

The Pub/Sub hook uses GCP Pub/Sub to publish messages to topics for subscribing, publishing, and connecting. An optional disallow list can be passed in that will check if the username responsible for the event should be allowed to publish to the topic. This is done to prevent overloading from admin clients that may be responsible for a large amount of messages, connections, or subscriptions.

Documentation

Overview

Package assetattributor is a generated GoMock package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTransport

func NewTransport(rt http.RoundTripper) *http.Client

NewTransport creates a new Transport object with any passed in information

Types

type ACLCheckPOST

type ACLCheckPOST struct {
	Username string `json:"username"`
	ClientID string `json:"clientid"`
	Topic    string `json:"topic"`
	ACC      string `json:"acc"`
}

type ClientCheckPOST

type ClientCheckPOST struct {
	ClientID string `json:"clientid"`
	Password string `json:"password"`
	Username string `json:"username"`
}

type HTTPAuthHook

type HTTPAuthHook struct {
	mqtt.HookBase
	// contains filtered or unexported fields
}

func (*HTTPAuthHook) ID

func (h *HTTPAuthHook) ID() string

func (*HTTPAuthHook) Init

func (h *HTTPAuthHook) Init(config any) error

func (*HTTPAuthHook) OnACLCheck

func (h *HTTPAuthHook) OnACLCheck(cl *mqtt.Client, topic string, write bool) bool

func (*HTTPAuthHook) OnConnectAuthenticate

func (h *HTTPAuthHook) OnConnectAuthenticate(cl *mqtt.Client, pk packets.Packet) bool

func (*HTTPAuthHook) Provides

func (h *HTTPAuthHook) Provides(b byte) bool

type HTTPAuthHookConfig

type HTTPAuthHookConfig struct {
	Timeout                  TimeoutConfig
	ACLHost                  string
	SuperUserHost            string
	ClientAuthenticationHost string // currently unused
	RoundTripper             http.RoundTripper
}

type MockRoundTripper

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

MockRoundTripper is a mock of RoundTripper interface

func NewMockRoundTripper

func NewMockRoundTripper(ctrl *gomock.Controller) *MockRoundTripper

NewMockRoundTripper creates a new mock instance

func (*MockRoundTripper) EXPECT

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

func (*MockRoundTripper) RoundTrip

func (m *MockRoundTripper) RoundTrip(arg0 *http.Request) (*http.Response, error)

RoundTrip mocks base method

type MockRoundTripperMockRecorder

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

MockRoundTripperMockRecorder is the mock recorder for MockRoundTripper

func (*MockRoundTripperMockRecorder) RoundTrip

func (mr *MockRoundTripperMockRecorder) RoundTrip(arg0 interface{}) *gomock.Call

RoundTrip indicates an expected call of RoundTrip

type OnConnectMessage added in v0.1.1

type OnConnectMessage struct {
	ClientID  string    `json:"client_id"`
	Username  string    `json:"username"`
	Timestamp time.Time `json:"timestamp"`
}

type OnDisconnectMessage added in v0.1.1

type OnDisconnectMessage struct {
	ClientID  string    `json:"client_id"`
	Username  string    `json:"username"`
	Timestamp time.Time `json:"timestamp"`
}

type OnPublishedMessage added in v0.1.1

type OnPublishedMessage struct {
	ClientID  string    `json:"client_id"`
	Topic     string    `json:"topic"`
	Payload   []byte    `json:"payload"`
	Timestamp time.Time `json:"timestamp"`
}

type OnSessionEstablishedMessage added in v0.0.8

type OnSessionEstablishedMessage struct {
	ClientID  string    `json:"client_id"`
	Username  string    `json:"username"`
	Timestamp time.Time `json:"timestamp"`
	Connected bool      `json:"connected"`
}

type OnStartedMessage added in v0.1.0

type OnStartedMessage struct {
	Timestamp time.Time
}

type OnStoppedMessage added in v0.1.0

type OnStoppedMessage struct {
	Timestamp time.Time
}

type OnSubscribedMessage added in v0.1.1

type OnSubscribedMessage struct {
	ClientID   string    `json:"client_id"`
	Username   string    `json:"username"`
	Topic      string    `json:"topic"`
	Subscribed bool      `json:"subscribed"`
	Timestamp  time.Time `json:"timestamp"`
}

type OnUnsubscribedMessage added in v0.1.1

type OnUnsubscribedMessage struct {
	ClientID   string    `json:"client_id"`
	Username   string    `json:"username"`
	Topic      string    `json:"topic"`
	Subscribed bool      `json:"subscribed"`
	Timestamp  time.Time `json:"timestamp"`
}

type OnWillSentMessage added in v0.0.4

type OnWillSentMessage struct {
	ClientID  string    `json:"client_id"`
	Topic     string    `json:"topic"`
	Payload   []byte    `json:"payload"`
	Timestamp time.Time `json:"timestamp"`
}

type PubsubMessagingHook added in v0.0.4

type PubsubMessagingHook struct {
	mqtt.HookBase
	// contains filtered or unexported fields
}

func (*PubsubMessagingHook) ID added in v0.0.4

func (pmh *PubsubMessagingHook) ID() string

func (*PubsubMessagingHook) Init added in v0.0.4

func (pmh *PubsubMessagingHook) Init(config any) error

func (*PubsubMessagingHook) OnConnect added in v0.0.4

func (pmh *PubsubMessagingHook) OnConnect(cl *mqtt.Client, pk packets.Packet) error

func (*PubsubMessagingHook) OnDisconnect added in v0.0.4

func (pmh *PubsubMessagingHook) OnDisconnect(cl *mqtt.Client, connect_err error, expire bool)

func (*PubsubMessagingHook) OnPublished added in v0.0.4

func (pmh *PubsubMessagingHook) OnPublished(cl *mqtt.Client, pk packets.Packet)

func (*PubsubMessagingHook) OnSessionEstablished added in v0.0.8

func (pmh *PubsubMessagingHook) OnSessionEstablished(cl *mqtt.Client, pk packets.Packet)

func (*PubsubMessagingHook) OnStarted added in v0.1.0

func (pmh *PubsubMessagingHook) OnStarted()

func (*PubsubMessagingHook) OnStopped added in v0.1.0

func (pmh *PubsubMessagingHook) OnStopped()

func (*PubsubMessagingHook) OnSubscribed added in v0.0.4

func (pmh *PubsubMessagingHook) OnSubscribed(cl *mqtt.Client, pk packets.Packet, reasonCodes []byte)

func (*PubsubMessagingHook) OnUnsubscribed added in v0.0.4

func (pmh *PubsubMessagingHook) OnUnsubscribed(cl *mqtt.Client, pk packets.Packet)

func (*PubsubMessagingHook) OnWillSent added in v0.0.4

func (pmh *PubsubMessagingHook) OnWillSent(cl *mqtt.Client, pk packets.Packet)

func (*PubsubMessagingHook) Provides added in v0.0.4

func (pmh *PubsubMessagingHook) Provides(b byte) bool

type PubsubMessagingHookConfig added in v0.0.4

type PubsubMessagingHookConfig struct {
	OnStartedTopic            *pubsub.Topic
	OnStoppedTopic            *pubsub.Topic
	OnConnectTopic            *pubsub.Topic
	OnDisconnectTopic         *pubsub.Topic
	OnSessionEstablishedTopic *pubsub.Topic
	OnPublishedTopic          *pubsub.Topic
	OnSubscribedTopic         *pubsub.Topic
	OnUnubscribedTopic        *pubsub.Topic
	OnWillSentTopic           *pubsub.Topic
	DisallowList              []string
}

type SecretManagerAuthHook added in v0.0.3

type SecretManagerAuthHook struct {
	mqtt.HookBase
	// contains filtered or unexported fields
}

func (*SecretManagerAuthHook) ID added in v0.0.3

func (h *SecretManagerAuthHook) ID() string

func (*SecretManagerAuthHook) Init added in v0.0.3

func (h *SecretManagerAuthHook) Init(config any) error

func (*SecretManagerAuthHook) OnACLCheck added in v0.0.3

func (h *SecretManagerAuthHook) OnACLCheck(cl *mqtt.Client, topic string, write bool) bool

func (*SecretManagerAuthHook) OnConnectAuthenticate added in v0.0.3

func (h *SecretManagerAuthHook) OnConnectAuthenticate(cl *mqtt.Client, pk packets.Packet) bool

func (*SecretManagerAuthHook) Provides added in v0.0.3

func (h *SecretManagerAuthHook) Provides(b byte) bool

type SecretManagerHookConfig added in v0.0.3

type SecretManagerHookConfig struct {
	Names []string
}

type SuperuserCheckPOST

type SuperuserCheckPOST struct {
	Username string `json:"username"`
}

type TimeoutConfig added in v0.0.8

type TimeoutConfig struct {
	TimeoutDuration time.Duration
}

type Transport

type Transport struct {
	OriginalTransport http.RoundTripper
}

Transport represents everything required for adding to the roundtripper interface

func (*Transport) RoundTrip

func (st *Transport) RoundTrip(r *http.Request) (*http.Response, error)

RoundTrip goes through the HTTP RoundTrip implementation and attempts to add ASAP if not passed it

Jump to

Keyboard shortcuts

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