client

package
v0.4.0-dev.0 Latest Latest
Warning

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

Go to latest
Published: Mar 17, 2019 License: Apache-2.0 Imports: 15 Imported by: 0

README

This package contains a web client for the Cog service.

It's used here for testing, and by cogctl.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrBadProfile indicates an invalid or missing client profile.
	ErrBadProfile = errors.New("invalid or missing client profile")

	// ErrBadRequest indicates that a request could not be constructed.
	ErrBadRequest = errors.New("request could not be constructed")

	// ErrConnectionFailed is a failure for a client to connect to the Cog service.
	ErrConnectionFailed = errors.New("failure to connect to the Cog service")

	// ErrResourceExists is returned if a client tries to put a resource that
	// already exists.
	ErrResourceExists = errors.New("resource already exists")

	// ErrResourceNotFound is returned if a client tries to get or update a
	// resource that doesn't exist.
	ErrResourceNotFound = errors.New("resource doesn't exist")

	// ErrResponseReadFailure indicates an error in reading a server response.
	ErrResponseReadFailure = errors.New("error reading a server response")

	// ErrURLFormat indicates badly formatted URL.
	ErrURLFormat = errors.New("invalid URL format")
)

Functions

This section is empty.

Types

type CogClient

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

CogClient comments to be written...

func Connect

func Connect(profileName string) (*CogClient, error)

Connect creates and returns a configured instance of the client for the specified host. An empty string will use the default profile. If the requested profile doesn't exist, an empty ProfileEntry is returned.

func ConnectWithNewProfile

func ConnectWithNewProfile(entry ProfileEntry) (*CogClient, error)

ConnectWithNewProfile generates a connection using the supplied profile entry data.

func (*CogClient) Authenticate

func (c *CogClient) Authenticate() (rest.Token, error)

Authenticate requests a new authentication token from the Cog service. If a valid token already exists it will be automatically invalidated if this call is successful.

func (*CogClient) Authenticated

func (c *CogClient) Authenticated() (bool, error)

Authenticated looks for any cached tokens associated with the current server. Returns false if no tokens exist or tokens are expired.

func (*CogClient) Bootstrap

func (c *CogClient) Bootstrap(user rest.User) (rest.User, error)

Bootstrap calls the POST /v2/bootstrap endpoint.

func (*CogClient) BundleDisable

func (c *CogClient) BundleDisable(bundlename string, version string) error

BundleDisable comments to be written...

func (*CogClient) BundleEnable

func (c *CogClient) BundleEnable(bundlename string, version string) error

BundleEnable comments to be written...

func (*CogClient) BundleExists

func (c *CogClient) BundleExists(bundlename string, version string) (bool, error)

BundleExists simply returns true if a bundle exists with the specified bundlename; false otherwise.

func (*CogClient) BundleGet

func (c *CogClient) BundleGet(bundlename string, version string) (data.Bundle, error)

BundleGet comments to be written...

func (*CogClient) BundleInstall

func (c *CogClient) BundleInstall(bundle data.Bundle) error

BundleInstall comments to be written...

func (*CogClient) BundleList

func (c *CogClient) BundleList() ([]data.Bundle, error)

BundleList comments to be written...

func (*CogClient) BundleListVersions

func (c *CogClient) BundleListVersions(bundlename string) ([]data.Bundle, error)

BundleListVersions comments to be written...

func (*CogClient) BundleUninstall

func (c *CogClient) BundleUninstall(bundlename string, version string) error

BundleUninstall comments to be written...

func (*CogClient) GroupDelete

func (c *CogClient) GroupDelete(groupname string) error

GroupDelete comments to be written...

func (*CogClient) GroupExists

func (c *CogClient) GroupExists(groupname string) (bool, error)

GroupExists simply returns true if a group exists with the specified groupname; false otherwise.

func (*CogClient) GroupGet

func (c *CogClient) GroupGet(groupname string) (rest.Group, error)

GroupGet comments to be written...

func (*CogClient) GroupList

func (c *CogClient) GroupList() ([]rest.Group, error)

GroupList comments to be written...

func (*CogClient) GroupMemberAdd

func (c *CogClient) GroupMemberAdd(groupname string, username string) error

GroupMemberAdd comments to be written...

func (*CogClient) GroupMemberDelete

func (c *CogClient) GroupMemberDelete(groupname string, username string) error

GroupMemberDelete comments to be written...

func (*CogClient) GroupMemberList

func (c *CogClient) GroupMemberList(groupname string) ([]rest.User, error)

GroupMemberList comments to be written...

func (*CogClient) GroupSave

func (c *CogClient) GroupSave(group rest.Group) error

GroupSave comments to be written...

func (*CogClient) Token

func (c *CogClient) Token() (rest.Token, error)

Token is just a wrapper around a call to Authenticated() followed by a call to Authenticate() if false.

func (*CogClient) UserDelete

func (c *CogClient) UserDelete(username string) error

UserDelete comments to be written...

func (*CogClient) UserExists

func (c *CogClient) UserExists(username string) (bool, error)

UserExists simply returns true if a user exists with the specified username; false otherwise.

func (*CogClient) UserGet

func (c *CogClient) UserGet(username string) (rest.User, error)

UserGet comments to be written...

func (*CogClient) UserGroupList

func (c *CogClient) UserGroupList(username string) ([]rest.Group, error)

UserGroupList comments to be written...

func (*CogClient) UserList

func (c *CogClient) UserList() ([]rest.User, error)

UserList comments to be written...

func (*CogClient) UserSave

func (c *CogClient) UserSave(user rest.User) error

UserSave will create or update a user. Note the the key is the username: if this is called with a user whose username exists that user is updated (empty fields will not be overwritten); otherwise a new user is created.

type Error

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

Error is an error implementation that represents either a a non-2XX response from the server, or a failure to connect to the server (in which case Status() will return 0).

func (Error) Error

func (c Error) Error() string

Error returns the error message for this error.

func (Error) Profile

func (c Error) Profile() ProfileEntry

Profile returns the active profile entry for the client that returned this error.

func (Error) Status

func (c Error) Status() uint

Status returns the HTTP status code provided by the server. A status of 0 indicates that the client failed to connect entirely.

type Profile

type Profile struct {
	Defaults ProfileDefaults
	Profiles map[string]ProfileEntry `yaml:",inline"`
}

Profile represents a set of user profiles from a $HOME/.cog/profiles file

func (Profile) Default

func (p Profile) Default() ProfileEntry

Default returns this Profile's default entry. If there's no default, or if the default doesn't exist, an empty ProfileEntry is returned.

type ProfileDefaults

type ProfileDefaults struct {
	Profile string
}

ProfileDefaults is used to store default values for a cog client profile.

type ProfileEntry

type ProfileEntry struct {
	Name      string   `yaml:"-"`
	URLString string   `yaml:"url"`
	Password  string   `yaml:"password"`
	URL       *url.URL `yaml:"-"`
	Username  string   `yaml:"user"`
}

ProfileEntry represents a single profile entry.

func (ProfileEntry) User

func (pe ProfileEntry) User() rest.User

User is a convenience method that returns a rest.User pre-set with the entry's username and password.

Jump to

Keyboard shortcuts

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