nopaste

package module
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2024 License: MIT Imports: 24 Imported by: 0

README

nopaste

nopaste http server & IRC agent.

Install

$ go get github.com/kayac/nopaste/cmd/nopaste

Usage

$ nopaste -config config.yaml

nopaste will rewrite the config.yaml(irc.channels section) when join to a new IRC channel.

Configuration

base_url: http://example.com  # for IRC messages
listen: "localhost:3000"
data_dir: data
irc:
  host: localhost
  port: 6666
  secure: false
  password: secret
  nick: npbot
slack:
  webhook_url: https://hooks.slack.com/services/XXX/YYY/zzzz
channels:
- '#general'
- '#infra'

nopaste runs http server on http://#{listen}/np.

Amazon SNS http endpoint

nopaste can accept Amazon SNS notification messages.

Set environment variables.

  • AWS_ACCESS_KEY_ID=XXXXXXXXXX
  • AWS_SECRET_ACCESS_KEY=yyyyyyyyyyy

Add a SNS topic http(s) endpoint to http://example.com/np/amazon-sns/{channel_name}?key={message key}.

LICENCE

The MIT License (MIT)

Documentation

Index

Constants

View Source
const (
	MsgBufferLen = 100
)
View Source
const MsgrRoot = "/irc-msgr"
View Source
const Root = "/np"
View Source
const SlackMaxBackOff = 3600

Variables

View Source
var (
	SlackThrottleWindow = 1 * time.Second
	SlackInitialBackOff = 30
	Epoch               = time.Unix(0, 0)
)
View Source
var (
	IRCThrottleWindow = 1 * time.Second
)

Functions

func NewSNS added in v0.0.3

func NewSNS(region string) *sns.SNS

func Run

func Run(configFile string) error

func RunIRCAgent

func RunIRCAgent(c *Config, ch chan IRCMessage)

func RunMsgr

func RunMsgr(configFile string) error

func RunSlackAgent added in v0.0.5

func RunSlackAgent(c *Config, ch chan SlackMessage)

Types

type Config

type Config struct {
	BaseURL string       `yaml:"base_url"`
	Listen  string       `yaml:"listen"`
	DataDir string       `yaml:"data_dir"`
	S3      *S3Config    `yaml:"s3"`
	IRC     *IRCConfig   `yaml:"irc"`
	Slack   *SlackConfig `yaml:"slack"`

	Channels []string `yaml:"channels"`
	// contains filtered or unexported fields
}

func LoadConfig

func LoadConfig(file string) (*Config, error)

func (*Config) AddChannel

func (c *Config) AddChannel(channel string)

func (*Config) Save

func (c *Config) Save() error

func (*Config) SetFilePath

func (c *Config) SetFilePath(path string)

func (*Config) Storages added in v0.2.0

func (c *Config) Storages() []Storage

type HttpNotification added in v0.2.0

type HttpNotification struct {
	Type             string    `json:"Type"`
	MessageId        string    `json:"MessageId"`
	Token            string    `json:"Token" optional` // Only for subscribe and unsubscribe
	TopicArn         string    `json:"TopicArn"`
	Subject          string    `json:"Subject" optional` // Only for Notification
	Message          string    `json:"Message"`
	SubscribeURL     string    `json:"SubscribeURL" optional` // Only for subscribe and unsubscribe
	Timestamp        time.Time `json:"Timestamp"`
	SignatureVersion string    `json:"SignatureVersion"`
	Signature        string    `json:"Signature"`
	SigningCertURL   string    `json:"SigningCertURL"`
	UnsubscribeURL   string    `json:"UnsubscribeURL" optional` // Only for notifications
}

https://docs.aws.amazon.com/sns/latest/dg/json-formats.html

type IRCConfig

type IRCConfig struct {
	Host     string `yaml:"host"`
	Port     int    `yaml:"port"`
	Secure   bool   `yaml:"secure"`
	Debug    bool   `yaml:"debug"`
	Password string `yaml:"password"`
	Nick     string `yaml:"nick"`
}

type IRCMessage

type IRCMessage struct {
	Channel string
	Notice  bool
	Text    string
}

type IRCMessageChan added in v0.0.5

type IRCMessageChan chan IRCMessage

func (IRCMessageChan) PostMsgr added in v0.0.5

func (ch IRCMessageChan) PostMsgr(req *http.Request)

func (IRCMessageChan) PostNopaste added in v0.0.5

func (ch IRCMessageChan) PostNopaste(np nopasteContent, url string)

type LocalStorage added in v0.2.0

type LocalStorage struct {
	DataDir string
}

func NewLocalStorage added in v0.2.0

func NewLocalStorage(datadir string) *LocalStorage

func (*LocalStorage) Load added in v0.2.0

func (s *LocalStorage) Load(name string) (io.ReadCloser, error)

func (*LocalStorage) Save added in v0.2.0

func (s *LocalStorage) Save(name string, data []byte) error

type MessageChan added in v0.0.5

type MessageChan interface {
	PostNopaste(np nopasteContent, url string)
	PostMsgr(np *http.Request)
}

type S3Config added in v0.2.0

type S3Config struct {
	Bucket    string `yaml:"bucket"`
	KeyPrefix string `yaml:"key_prefix"`
}

type S3Storage added in v0.2.0

type S3Storage struct {
	Bucket    string
	KeyPrefix string
	// contains filtered or unexported fields
}

func NewS3Storage added in v0.2.0

func NewS3Storage(c *S3Config) *S3Storage

func (*S3Storage) Load added in v0.2.0

func (s *S3Storage) Load(name string) (io.ReadCloser, error)

func (*S3Storage) Save added in v0.2.0

func (s *S3Storage) Save(name string, b []byte) error

type SlackAgent added in v0.0.5

type SlackAgent struct {
	WebhookURL string
	// contains filtered or unexported fields
}

func (*SlackAgent) Post added in v0.0.5

func (a *SlackAgent) Post(m SlackMessage) error

type SlackConfig added in v0.0.5

type SlackConfig struct {
	WebhookURL string `yaml:"webhook_url"`
}

type SlackMessage added in v0.0.5

type SlackMessage struct {
	Channel   string `json:"channel"`
	Text      string `json:"text"`
	IconEmoji string `json:"icon_emoji,omitempty"`
	IconURL   string `json:"icon_url,omitempty"`
	Username  string `json:"username"`
	LinkNames int    `json:"link_names,omitempty"`
}

type SlackMessageChan added in v0.0.5

type SlackMessageChan chan SlackMessage

func (SlackMessageChan) PostMsgr added in v0.0.5

func (ch SlackMessageChan) PostMsgr(req *http.Request)

func (SlackMessageChan) PostNopaste added in v0.0.5

func (ch SlackMessageChan) PostNopaste(np nopasteContent, url string)

type Storage added in v0.2.0

type Storage interface {
	Save(string, []byte) error
	Load(string) (io.ReadCloser, error)
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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