operator

package module
v0.0.0-...-707806d Latest Latest
Warning

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

Go to latest
Published: Jun 6, 2017 License: MIT Imports: 21 Imported by: 0

README

Operator

Operator is a tool that for creating and maintaining ChatOps commands. It's built around a few opinions on how to do that:

  • Chat is just an interface to an automation server.
  • Authentication and authorization rules are enforced server-side.
  • The clients communicate with the server via a language-agnostic RPC protocol.
  • Clients do not have access (account identifiers, tokens, ...) to the resources being automated. Only the server does.
  • All operations are logged to an audit log and can always be attributed to an human or machine entity.
  • There is at least one alternative client with the exact same feature set. This ensures that the chat bot is not a SPOF.

Checkout the chatoops project for a complete example. It demonstrates how to describe and implement an automation server and generate Hubot scripts and commond-line client.

DISCLAIMER: I have not used this in production yet. Consider this is a early preview release. Ping @sr on Twitter or open an issue if you have any question or feedback.

Documentation

Overview

Package operator is a generated protocol buffer package.

It is generated from these files:

operator.proto

It has these top-level messages:

Request
Response
Call
Source
Room
User

Index

Constants

View Source
const DefaultAddress = "localhost:9000"
View Source
const ReCommandMessage = `\A%s(?P<service>[\w|-]+)\s+(?P<method>[\w|\-]+)(?:\s+(?P<options>.*))?\z`

Variables

View Source
var E_Enabled = &proto.ExtensionDesc{
	ExtendedType:  (*google_protobuf.ServiceOptions)(nil),
	ExtensionType: (*bool)(nil),
	Field:         51235,
	Name:          "operator.enabled",
	Tag:           "varint,51235,opt,name=enabled",
	Filename:      "operator.proto",
}
View Source
var E_Name = &proto.ExtensionDesc{
	ExtendedType:  (*google_protobuf.ServiceOptions)(nil),
	ExtensionType: (*string)(nil),
	Field:         51234,
	Name:          "operator.name",
	Tag:           "bytes,51234,opt,name=name",
	Filename:      "operator.proto",
}
View Source
var ErrInvalidRequest = errors.New("invalid rpc request")
View Source
var SourceType_name = map[int32]string{
	0: "HUBOT",
	1: "COMMAND",
}
View Source
var SourceType_value = map[string]int32{
	"HUBOT":   0,
	"COMMAND": 1,
}

Functions

func Camelize

func Camelize(s string, sep string) string

func GetUserEmail

func GetUserEmail(r Requester) string

func NewHandler

func NewHandler(
	ctx context.Context,
	inst Instrumenter,
	decoder Decoder,
	invoker Invoker,
	pkg string,
	prefix string,
) (http.Handler, error)

func NewUnaryServerInterceptor

func NewUnaryServerInterceptor(auth Authorizer, inst Instrumenter) grpc.UnaryServerInterceptor

func Send

func Send(ctx context.Context, s Sender, r Requester, msg *Message) error

Types

type Authorizer

type Authorizer interface {
	Authorize(context.Context, *Request) error
}

type Call

type Call struct {
	Service  string                     `protobuf:"bytes,1,opt,name=service" json:"service,omitempty"`
	Method   string                     `protobuf:"bytes,2,opt,name=method" json:"method,omitempty"`
	Args     map[string]string          `` /* 128-byte string literal not displayed */
	Error    string                     `protobuf:"bytes,4,opt,name=error" json:"error,omitempty"`
	Duration *google_protobuf1.Duration `protobuf:"bytes,5,opt,name=duration" json:"duration,omitempty"`
}

Call represents a completed gRPC call. The Error field will be non-nil if it resulted in an error.

func (*Call) Descriptor

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

func (*Call) GetArgs

func (m *Call) GetArgs() map[string]string

func (*Call) GetDuration

func (m *Call) GetDuration() *google_protobuf1.Duration

func (*Call) GetError

func (m *Call) GetError() string

func (*Call) GetMethod

func (m *Call) GetMethod() string

func (*Call) GetService

func (m *Call) GetService() string

func (*Call) ProtoMessage

func (*Call) ProtoMessage()

func (*Call) Reset

func (m *Call) Reset()

func (*Call) String

func (m *Call) String() string

type Command

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

func NewCommand

func NewCommand(name string, services []ServiceCommand) Command

func (Command) Run

func (c Command) Run(args []string) (int, string)

type CommandContext

type CommandContext struct {
	Address string
	Request *Request
	Flags   *flag.FlagSet
	Args    []string
}

func (*CommandContext) GetConn

func (c *CommandContext) GetConn() (*grpc.ClientConn, error)

type Decoder

type Decoder interface {
	Decode(context.Context, *http.Request) (*Message, string, error)
}

type Event

type Event struct {
	Key     string
	Message *Message
	Request *Request
	Error   error
}

type Instrumenter

type Instrumenter interface {
	Instrument(*Event)
}

type Invoker

type Invoker interface {
	Invoke(context.Context, *Message, *Request)
}

func NewInvoker

func NewInvoker(
	conn *grpc.ClientConn,
	inst Instrumenter,
	sender Sender,
	f InvokerFunc,
	timeout time.Duration,
	pkg string,
	errMsgOpts interface{},
) Invoker

type InvokerFunc

type InvokerFunc func(context.Context, *grpc.ClientConn, *Request, string) error

type Message

type Message struct {
	Source  *Source
	Text    string
	HTML    string
	Options interface{} `json:"-"`
}

type MethodCommand

type MethodCommand struct {
	Name     string
	Synopsis string
	Flags    []*flag.Flag
	Run      func(*CommandContext) (string, error)
}

type Request

type Request struct {
	Source   *Source `protobuf:"bytes,1,opt,name=source" json:"source,omitempty"`
	Call     *Call   `protobuf:"bytes,2,opt,name=call" json:"call,omitempty"`
	SenderId string  `protobuf:"bytes,3,opt,name=sender_id,json=senderId" json:"sender_id,omitempty"`
	Otp      string  `protobuf:"bytes,4,opt,name=otp" json:"otp,omitempty"`
}

func (*Request) Descriptor

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

func (*Request) GetCall

func (m *Request) GetCall() *Call

func (*Request) GetOtp

func (m *Request) GetOtp() string

func (*Request) GetSenderId

func (m *Request) GetSenderId() string

func (*Request) GetSource

func (m *Request) GetSource() *Source

func (*Request) GetUserEmail

func (req *Request) GetUserEmail() string

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) Reset

func (m *Request) Reset()

func (*Request) String

func (m *Request) String() string

type RequestSender

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

func GetSender

func GetSender(s Sender, r Requester) *RequestSender

func (*RequestSender) Send

func (s *RequestSender) Send(ctx context.Context, msg *Message) error

type Requester

type Requester interface {
	GetRequest() *Request
}

type Response

type Response struct {
	Message string `protobuf:"bytes,1,opt,name=message" json:"message,omitempty"`
}

func Reply

func Reply(ctx context.Context, s Sender, req Requester, msg *Message) (*Response, error)

func (*Response) Descriptor

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

func (*Response) GetMessage

func (m *Response) GetMessage() string

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) Reset

func (m *Response) Reset()

func (*Response) String

func (m *Response) String() string

type Room

type Room struct {
	Id   int64  `protobuf:"varint,1,opt,name=id" json:"id,omitempty"`
	Name string `protobuf:"bytes,2,opt,name=name" json:"name,omitempty"`
}

func (*Room) Descriptor

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

func (*Room) GetId

func (m *Room) GetId() int64

func (*Room) GetName

func (m *Room) GetName() string

func (*Room) ProtoMessage

func (*Room) ProtoMessage()

func (*Room) Reset

func (m *Room) Reset()

func (*Room) String

func (m *Room) String() string

type Sender

type Sender interface {
	Send(context.Context, *Source, string, *Message) error
}

type ServiceCommand

type ServiceCommand struct {
	Name     string
	Synopsis string
	Methods  []MethodCommand
}

type Source

type Source struct {
	Type     SourceType `protobuf:"varint,1,opt,name=type,enum=operator.SourceType" json:"type,omitempty"`
	User     *User      `protobuf:"bytes,2,opt,name=user" json:"user,omitempty"`
	Room     *Room      `protobuf:"bytes,3,opt,name=room" json:"room,omitempty"`
	Hostname string     `protobuf:"bytes,4,opt,name=hostname" json:"hostname,omitempty"`
}

func (*Source) Descriptor

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

func (*Source) GetHostname

func (m *Source) GetHostname() string

func (*Source) GetRoom

func (m *Source) GetRoom() *Room

func (*Source) GetType

func (m *Source) GetType() SourceType

func (*Source) GetUser

func (m *Source) GetUser() *User

func (*Source) ProtoMessage

func (*Source) ProtoMessage()

func (*Source) Reset

func (m *Source) Reset()

func (*Source) String

func (m *Source) String() string

type SourceType

type SourceType int32
const (
	SourceType_HUBOT   SourceType = 0
	SourceType_COMMAND SourceType = 1
)

func (SourceType) EnumDescriptor

func (SourceType) EnumDescriptor() ([]byte, []int)

func (SourceType) String

func (x SourceType) String() string

type User

type User struct {
	Id       string `protobuf:"bytes,1,opt,name=id" json:"id,omitempty"`
	Login    string `protobuf:"bytes,2,opt,name=login" json:"login,omitempty"`
	RealName string `protobuf:"bytes,3,opt,name=real_name,json=realName" json:"real_name,omitempty"`
	Email    string `protobuf:"bytes,4,opt,name=email" json:"email,omitempty"`
}

func (*User) Descriptor

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

func (*User) GetEmail

func (m *User) GetEmail() string

func (*User) GetId

func (m *User) GetId() string

func (*User) GetLogin

func (m *User) GetLogin() string

func (*User) GetRealName

func (m *User) GetRealName() string

func (*User) ProtoMessage

func (*User) ProtoMessage()

func (*User) Reset

func (m *User) Reset()

func (*User) String

func (m *User) String() string

Directories

Path Synopsis
cmd
Package generator generates Golang code from the input proto files then compiles the code into protobuf structures for use by the protoc executable.
Package generator generates Golang code from the input proto files then compiles the code into protobuf structures for use by the protoc executable.
Package operatortesting is a generated protocol buffer package.
Package operatortesting is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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