model

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2019 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

View Source
const ErrNotLoggedIn = Error("Not authorized. Make sure you log in and your account has the proper privileges")

ErrNotLoggedIn returned when the user is not logged into CPPM yet

View Source
const ErrPageTooSmall = Error("Page size is too small")

ErrPageTooSmall when paginated commands are givel a page size too small (<=0)

Variables

This section is empty.

Functions

func ToCSV

func ToCSV(data RawReply, selectors []string) string

ToCSV returns a line with the selected attribs of the object

Types

type Clearpass

type Clearpass interface {
	// Login into CPPM. Returns access and refresh tokens, or error.
	// - 'address' is the CPPM server address (:port, if different from 443).
	// - 'clientID' is the OAuth2 Client ID
	// - 'secret' is the OAuth2 Client secret. Empty if client is public (trusted).
	// - 'user', 'pass' are the username and password for "password"
	//   authentication. If any of them is empty,  'client_credentials'
	//   authentication is used instead.
	Login(ctx context.Context, address, clientID, secret, user, pass string) (string, string, error)
	// Validate / Refresh credentials.
	// - 'address' is the CPPM server address (:port, if different from 443).
	// - 'clientID' is the OAuth2 Client ID
	// - 'secret' is the OAuth2 Client secret.
	// - 'token', 'refresh': the authentication and refresh tokens.
	//   If a refresh token is provided, attempt to refresh the
	//   authentication token. Otherwise, just check it is valid.
	Validate(ctx context.Context, address, clientID, secret, token, refresh string) (string, string, error)
	// Token obtained after authentication / validation
	Token() string
	// WebLogin into clearpass with the provided credentials, return token.
	WebLogin(ctx context.Context, address, username, pass string) ([]*http.Cookie, error)
	// WebLogout from clearpass.
	WebLogout(ctx context.Context, address string) error
	// WebValidate checks the cookie is still useful
	WebValidate(ctx context.Context, address string) ([]*http.Cookie, error)
	// Cookies obtained after web authentication
	Cookies() []*http.Cookie
	// Request made to the CPPM.
	Request(method Method, path string, params Params, request interface{}) *Reply
	// Export some resource from ClearPass, return the exported stream.
	Export(ctx context.Context, resource, pass string) (string, io.ReadCloser, error)
	// Import some resource to ClearPass.
	Import(ctx context.Context, fileName, resource, pass string) error
}

Clearpass server interface

func New

func New(address, token, refresh string, cookies []*http.Cookie, skipVerify bool) Clearpass

New creates a Clearpass object with cached IP and token

type Error

type Error string

Error type

func (Error) Error

func (e Error) Error() string

Error implements Error interface

type MAC

type MAC string

MAC address

func NewMAC

func NewMAC(mac string) MAC

NewMAC builds a MAC address, uppercased.

func (MAC) Colon

func (mac MAC) Colon() string

Colon returns the uppercased, colon-separated representation of the MAC

func (MAC) Dot

func (mac MAC) Dot() string

Dot returns the uppercased, dot-separated representation of the MAC

func (MAC) Hyphen

func (mac MAC) Hyphen() string

Hyphen returns the uppercased, hyphen-separated representation of the MAC

type Method

type Method string

Method is the HTTP method for the request

const (
	GET    Method = "GET"
	POST   Method = "POST"
	PUT    Method = "PUT"
	UPDATE Method = "UPDATE"
	DELETE Method = "DELETE"
	PATCH  Method = "PATCH"
)

HTTP methods supported

type Params

type Params map[string]string

Params for ClearPass request

type RawReply

type RawReply = json.RawMessage

RawReply is the json body of each reply

type Reply

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

Reply is kind of an iterator on rest replies. you can iterate over this with a loop like: r := Request(...)

for r.Next(ctx) {
  current := r.Get()
}
if r.Error() != nil {
  iteration ended with error
}

func NewReply

func NewReply(r RawReply, err error) *Reply

NewReply wraps a RawReply inside a Reply iterator

func Request

func Request(client *http.Client, method Method, url, token string, query map[string]string, request interface{}) *Reply

Request runs a REST request and returns an 'iterable' Reply

func (*Reply) Error

func (r *Reply) Error() error

Error returns the last error in the stream

func (*Reply) Get

func (r *Reply) Get() RawReply

Get returns the current reply

func (*Reply) Next

func (r *Reply) Next(ctx context.Context) bool

Next asks for the next reply in the stream

type RestError

type RestError struct {
	Err         error
	Method      Method
	URL         string
	Query       string
	Header      http.Header
	Body        []byte
	StatusCode  int
	ReplyHeader http.Header
	Reply       []byte
}

RestError encodes info about REST errors

func (RestError) Error

func (e RestError) Error() string

Error implements Error interface

Jump to

Keyboard shortcuts

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