npmgo

package module
v0.0.0-...-1c9a8b7 Latest Latest
Warning

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

Go to latest
Published: Jan 24, 2019 License: BSD-2-Clause Imports: 8 Imported by: 1

README

NPM-Go, a NPM HTTP API Client for Go

This library is a [NPM HTTP API] client for the Go language.

Supported Go Versions

NPM-Go requires Go 1.6+.

Project Maturity

NPM-Go is a fairly new library (started in January 2018) as a dependancy for the NPM Vault Secret Engine. It only impliments token and whoami.

Installation

go get github.com/chrismatteson/npm-go

Documentation

Overview

To import the package:

import (
       "github.com/chrismatteson/npm-go"
)

All HTTP API operations are accessible via npmgo.Client, which should be instantiated with npm.go.NewClient:

// URI, username, password
rmqc, _ = NewClient("http://127.0.0.1:15672", "guest", "guest")

TLS (HTTPS) can be enabled by adding an HTTP transport to the parameters of npmgo.NewTLSClient:

transport := &http.Transport{TLSClientConfig: tlsConfig}
rmqc, _ := NewTLSClient("https://127.0.0.1:15672", "guest", "guest", transport)

NPM HTTP API has to be [configured to use TLS].

Operations on Connections
xs, err := rmqc.ListConnections()
// => []ConnectionInfo, err

conn, err := rmqc.GetConnection("127.0.0.1:50545 -> 127.0.0.1:5672")
// => ConnectionInfo, err

// Forcefully close connection
_, err := rmqc.CloseConnection("127.0.0.1:50545 -> 127.0.0.1:5672")
// => *http.Response, err
HTTPS Connections
var tlsConfig *tls.Config

...

transport := &http.Transport{TLSClientConfig: tlsConfig}

rmqc, err := NewTLSClient("https://127.0.0.1:15672", "guest", "guest", transport)

2-clause BSD license.

(c) Chris Matteson, 2013-2018.

Documentation

Overview

NPM-GO is a Go client for the NPM HTTP API based on rabbithole (https://github.com/michaelklishin/rabbit-hole)

All HTTP API operations are accessible via `npmgo.Client`, which should be instantiated with `npmgo.NewClient`.

// URI, username, password
rmqc, _ = NewClient("http://127.0.0.1:15672", "guest", "guest")

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func JSONMarshal

func JSONMarshal(v interface{}, safeEncoding bool) ([]byte, error)

func PathEscape

func PathEscape(s string) string

PathEscape escapes the string so it can be safely placed inside a URL path segment.

Types

type BrokerContext

type BrokerContext struct {
	Node        string `json:"node"`
	Description string `json:"description"`
	Path        string `json:"path"`
	Port        Port   `json:"port"`
	Ignore      bool   `json:"ignore_in_use"`
}

RabbitMQ context (Erlang app) running on a node

type Client

type Client struct {
	// URI of a NPM server node to use, not including the path, e.g. http://127.0.0.1:15672.
	Endpoint string
	// Username to use. This RabbitMQ user must have the "management" tag.
	Username string
	// Password to use.
	Password string
	// Token to use
	Token string
	// contains filtered or unexported fields
}

func NewClient

func NewClient(uri string, username string, password string) (me *Client, err error)

func NewTLSClient

func NewTLSClient(uri string, username string, password string, transport *http.Transport) (me *Client, err error)

Creates a client with a transport; it is up to the developer to make that layer secure.

func NewTokenClient

func NewTokenClient(uri string, token string) (me *Client, err error)

func (*Client) CloseConnection

func (c *Client) CloseConnection(name string) (res *http.Response, err error)

func (*Client) CreateToken

func (c *Client) CreateToken(info TokenSettings) (res Objects, err error)

Creates a new token.

func (*Client) DeleteToken

func (c *Client) DeleteToken(id string) (res *http.Response, err error)

Deletes token.

func (*Client) GetConnection

func (c *Client) GetConnection(name string) (rec *ConnectionInfo, err error)

func (*Client) GetToken

func (c *Client) GetToken(id string) (rec Objects, err error)

Returns information about individual user.

func (*Client) ListConnections

func (c *Client) ListConnections() (rec []ConnectionInfo, err error)

func (*Client) ListTokens

func (c *Client) ListTokens() (rec []Objects, err error)

Returns a list of all users in a cluster.

func (*Client) SetTimeout

func (c *Client) SetTimeout(timeout time.Duration)

SetTimeout changes the HTTP timeout that the Client will use. By default there is no timeout.

func (*Client) SetTransport

func (c *Client) SetTransport(transport *http.Transport)

SetTransport changes the Transport Layer that the Client will use.

func (*Client) Whoami

func (c *Client) Whoami() (rec *WhoamiInfo, err error)

type ConnectionInfo

type ConnectionInfo struct {
	// Connection name
	Name string `json:"name"`
	// Node the client is connected to
	Node string `json:"node"`
	// Number of open channels
	Channels int `json:"channels"`
	// Connection state
	State string `json:"state"`
	// Connection type, network (via AMQP client) or direct (via direct Erlang client)
	Type string `json:"type"`

	// Server port
	Port Port `json:"port"`
	// Client port
	PeerPort Port `json:"peer_port"`

	// Server host
	Host string `json:"host"`
	// Client host
	PeerHost string `json:"peer_host"`

	// Last connection blocking reason, if any
	LastBlockedBy string `json:"last_blocked_by"`
	// When connection was last blocked
	LastBlockedAge string `json:"last_blocked_age"`

	// True if connection uses TLS/SSL
	UsesTLS bool `json:"ssl"`
	// Client certificate subject
	PeerCertSubject string `json:"peer_cert_subject"`
	// Client certificate validity
	PeerCertValidity string `json:"peer_cert_validity"`
	// Client certificate issuer
	PeerCertIssuer string `json:"peer_cert_issuer"`

	// TLS/SSL protocol and version
	SSLProtocol string `json:"ssl_protocol"`
	// Key exchange mechanism
	SSLKeyExchange string `json:"ssl_key_exchange"`
	// SSL cipher suite used
	SSLCipher string `json:"ssl_cipher"`
	// SSL hash
	SSLHash string `json:"ssl_hash"`

	// Protocol, e.g. AMQP 0-9-1 or MQTT 3-1
	Protocol string `json:"protocol"`
	User     string `json:"user"`
	// Virtual host
	Vhost string `json:"vhost"`

	// Heartbeat timeout
	Timeout int `json:"timeout"`
	// Maximum frame size (AMQP 0-9-1)
	FrameMax int `json:"frame_max"`

	// A map of client properties (name, version, capabilities, etc)
	ClientProperties Properties `json:"client_properties"`

	// Octets received
	RecvOct uint64 `json:"recv_oct"`
	// Octets sent
	SendOct     uint64 `json:"send_oct"`
	RecvCount   uint64 `json:"recv_cnt"`
	SendCount   uint64 `json:"send_cnt"`
	SendPending uint64 `json:"send_pend"`
	// Ingress data rate
	RecvOctDetails RateDetails `json:"recv_oct_details"`
	// Egress data rate
	SendOctDetails RateDetails `json:"send_oct_details"`
}

Provides information about connection to a RabbitMQ node.

type ErrorResponse

type ErrorResponse struct {
	StatusCode int
	Message    string `json:"error"`
	Reason     string `json:"reason"`
}

func (ErrorResponse) Error

func (rme ErrorResponse) Error() string

type MessageStats

type MessageStats struct {
	Publish             int64       `json:"publish"`
	PublishDetails      RateDetails `json:"publish_details"`
	Deliver             int64       `json:"deliver"`
	DeliverDetails      RateDetails `json:"deliver_details"`
	DeliverNoAck        int64       `json:"deliver_noack"`
	DeliverNoAckDetails RateDetails `json:"deliver_noack_details"`
	DeliverGet          int64       `json:"deliver_get"`
	DeliverGetDetails   RateDetails `json:"deliver_get_details"`
	Redeliver           int64       `json:"redeliver"`
	RedeliverDetails    RateDetails `json:"redeliver_details"`
	Get                 int64       `json:"get"`
	GetDetails          RateDetails `json:"get_details"`
	GetNoAck            int64       `json:"get_no_ack"`
	GetNoAckDetails     RateDetails `json:"get_no_ack_details"`
	Ack                 int64       `json:"ack"`
	AckDetails          RateDetails `json:"ack_details"`
}

Basic published messages statistics

type Objects

type Objects struct {
	Id            string   `json:"key"`
	Token         string   `json:"token"`
	Created       string   `json:"created"`
	Readonly      bool     `json:"readonly"`
	CidrWhitelist []string `json:"cidr_whitelist"`
}

type Port

type Port int

Port used by NPM or clients

func (*Port) UnmarshalJSON

func (p *Port) UnmarshalJSON(b []byte) error

type Properties

type Properties map[string]interface{}

Extra arguments as a map (on queues, bindings, etc)

type RateDetailSample

type RateDetailSample struct {
	Sample    int64 `json:"sample"`
	Timestamp int64 `json:"timestamp"`
}

RateDetailSample single touple

type RateDetails

type RateDetails struct {
	Rate    float32            `json:"rate"`
	Samples []RateDetailSample `json:"samples"`
}

Rate of change of a numerical value

type TokenInfo

type TokenInfo struct {
	Objects []Objects `json:"objects"`
}

type TokenSettings

type TokenSettings struct {
	//Password is required again to create token
	Password      string   `json:"password"`
	Readonly      bool     `json:"readonly"`
	CidrWhitelist []string `json:"cidr_whitelist"`
}

Settings used to create users. Tags must be comma-separated.

type WhoamiInfo

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

Jump to

Keyboard shortcuts

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