broker

package
v0.0.0-...-35f4a6f Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2017 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Overview

Package broker implements the HTTP handlers for the Stardog Service Broker

Index

Constants

View Source
const (
	// ERROR level will only log error messages.
	ERROR = 1
	// WARN level will log warnings and error messages.
	WARN = 2
	// INFO level will log information, warnings, and errors.
	INFO = 3
	// DEBUG level will log all messages and produces a large amount of detail.
	DEBUG = 4
)

Variables

This section is empty.

Functions

func GetRandomName

func GetRandomName(base string, n int) string

GetRandomName is a convience function for creating random strings.

func GetRouteVariable

func GetRouteVariable(r *http.Request, varName string) (string, error)

GetRouteVariable pulls a variable out of the HTTP path that the client sent.

func GetVCAPServices

func GetVCAPServices() (map[string][]VCAPService, error)

GetVCAPServices is used in Cloud Foundry environments to pull out bound service information

func HTTPBasicCheck

func HTTPBasicCheck(r *http.Request, w http.ResponseWriter, username string, password string) error

HTTPBasicCheck checks the authentication information in a HTTP basic auth header.

func LoadJSON

func LoadJSON(obj interface{}, path string) error

LoadJSON creates an object from a JSON file.

func ReSerializeInterface

func ReSerializeInterface(in interface{}, out interface{}) error

ReSerializeInterface takes an already inflated JSON object (typically a map[string]interface{}) and re-serializes it to a specific object type. This is basically a work around to how Go deals with JSON objects and allows us to have plugs that define their own JSON types.

func ReadRequestBody

func ReadRequestBody(r *http.Request, object interface{}) error

ReadRequestBody is a convenience function for writing an HTTP response.

func SendError

func SendError(logger SdLogger, w http.ResponseWriter, code int, desc string)

SendError sends an error message to the client with a description.

func SendInternalError

func SendInternalError(w http.ResponseWriter)

SendInternalError sends a bodiless HTTP error message to the client.

func WriteResponse

func WriteResponse(w http.ResponseWriter, code int, object interface{})

WriteResponse Send data to the client with an HTTP header.

Types

type BindInstance

type BindInstance struct {
	BindGUID   string      `json:"binding_guid"`
	PlanParams interface{} `json:"plan_params"`
}

BindInstance is used to represent bounded applications. The PlanParams field is defined by the plan in use. It can be serialized by a Store.

type BindRequest

type BindRequest struct {
	ServiceID  string       `json:"service_id"`
	PlanID     string       `json:"plan_id"`
	Resource   BindResource `json:"bind_resource, omitempty"`
	Parameters interface{}  `json:"parameters, omitempty"`
}

BindRequest is the object representation of the clients request to bind and application to a service instance.

type BindResource

type BindResource struct {
	AppGUID string `json:"app_GUID, omitempty"`
}

BindResource describes that application being bound.

type BindResponse

type BindResponse struct {
	Credentials interface{} `json:"credentials"`
}

BindResponse is the data sent back to the client after a bind. The structure of Credentials is defined by the plan in use.

type CatalogMetadata

type CatalogMetadata struct {
	DisplayName         string `json:"displayName"`
	ImageURL            string `json:"imageUrl"`
	LongDescription     string `json:"longDescription"`
	ProviderDisplayName string `json:"providerDisplayName"`
	DocumentationURL    string `json:"documentationUrl"`
	SupportURL          string `json:"supportUrl"`
}

CatalogMetadata is the community driven stadard catalog response for providing friendly information.

type CatalogResponse

type CatalogResponse struct {
	Services []CatalogService `json:"services"`
}

CatalogResponse is the top level object for the document returned to the client when it requests a catalog of services offered by this this service broker.

type CatalogService

type CatalogService struct {
	Name           string          `json:"name"`
	ID             string          `json:"id"`
	Description    string          `json:"description"`
	Bindable       bool            `json:"bindable"`
	PlanUpdateable bool            `json:"plan_updateable, omitempty"`
	Plans          []ServicePlan   `json:"plans"`
	Metadata       CatalogMetadata `json:"metadata, omitempty"`
}

CatalogService is a catalog entry that describes one of the brokers service offerings. This broker only offers a single service.

type Controller

type Controller interface {
	Catalog(http.ResponseWriter, *http.Request)
	CreateServiceInstance(http.ResponseWriter, *http.Request)
	GetServiceInstance(http.ResponseWriter, *http.Request)
	RemoveServiceInstance(http.ResponseWriter, *http.Request)
	Bind(http.ResponseWriter, *http.Request)
	UnBind(http.ResponseWriter, *http.Request)
}

Controller object handles the HTTP network API calls.

func CreateController

func CreateController(databasePlanMap map[string]PlanFactory, conf *ServerConfig, clientFactory StardogClientFactory, logger SdLogger, store Store) (Controller, error)

CreateController makes a ControllerImpl object and returns it as a Controller interface to the main thread.

type ControllerImpl

type ControllerImpl struct {
	BrokerID string
	// contains filtered or unexported fields
}

The ControllerImpl is the object that contains the handler functions for the service broker

func (*ControllerImpl) Bind

Bind associates an application with a service instance. The Plan object used by the service does the work of the Bind and then the Store object persists information about the bind.

func (*ControllerImpl) Catalog

func (c *ControllerImpl) Catalog(w http.ResponseWriter, r *http.Request)

Catalog returns the information describing what this service broker offers.

func (*ControllerImpl) CreateServiceInstance

func (c *ControllerImpl) CreateServiceInstance(w http.ResponseWriter, r *http.Request)

CreateServiceInstance is called when a client attempts to create a new instance.

func (*ControllerImpl) GetServiceInstance

func (c *ControllerImpl) GetServiceInstance(w http.ResponseWriter, r *http.Request)

GetServiceInstance looks up a service instance and returns information about the instance if it is found.

func (*ControllerImpl) RemoveServiceInstance

func (c *ControllerImpl) RemoveServiceInstance(w http.ResponseWriter, r *http.Request)

RemoveServiceInstance deletes a service instance and all of its bound applications.

func (*ControllerImpl) UnBind

func (c *ControllerImpl) UnBind(w http.ResponseWriter, r *http.Request)

UnBind removes an application's association with a service instance by calling into the Plan module and then instructing the Store module to delete its association.

type CreateGetServiceInstanceResponse

type CreateGetServiceInstanceResponse struct {
	DashboardURL  string         `json:"dashboard_url, omitempty"`
	LastOperation *LastOperation `json:"last_operation, omitempty"`
}

CreateGetServiceInstanceResponse is the response to the client when a service is created or looked up.

type CreateServiceInstanceRequest

type CreateServiceInstanceRequest struct {
	ServiceID        string      `json:"service_id"`
	PlanID           string      `json:"plan_id"`
	OrganizationGUID string      `json:"organization_guid"`
	SpaceGUID        string      `json:"space_guid"`
	Parameters       interface{} `json:"parameters, omitempty"`
}

CreateServiceInstanceRequest is the object representation of the clients request to create a new service instance.

type DatabaseCredentials

type DatabaseCredentials struct {
	Password string `json:"password"`
	Username string `json:"username"`
}

DatabaseCredentials is a convenience object for passing around the credentials needed to access a Stardog service.

type ErrorMessageResponse

type ErrorMessageResponse struct {
	Description string `json:"description, omitempty"`
}

ErrorMessageResponse wraps up error messages that are sent to the client.

type LastOperation

type LastOperation struct {
	State                    string `json:"state"`
	Description              string `json:"description"`
	AsyncPollIntervalSeconds int    `json:"async_poll_interval_seconds, omitempty"`
}

LastOperation is used for async messaging.

type Plan

type Plan interface {
	CreateServiceInstance() (int, interface{}, error)
	RemoveInstance() (int, interface{}, error)
	Bind(interface{}) (int, interface{}, error)
	UnBind(interface{}) (int, error)
	PlanID() string
	EqualInstance(interface{}) bool
	EqualBinding(*BindInstance, *BindRequest) bool
}

Plan represents a Plan that is associated with the service instance and application bindings.

type PlanConfig

type PlanConfig struct {
	PlanName   string      `json:"name"`
	PlanID     string      `json:"id"`
	Parameters interface{} `json:"parameters"`
}

PlanConfig contains the configuration information for a given plan. The plan is looked up via PlanID and if found Parameters are passed to that plan module for processing.

type PlanFactory

type PlanFactory interface {
	PlanName() string
	PlanDescription() string
	PlanID() string
	Metadata() interface{}
	Free() bool
	Bindable() bool
	InflatePlan(interface{}, StardogClientFactory, SdLogger) (Plan, error)
}

PlanFactory holds the information needed to create a plan instance. When the instance is new MakePlan is used. To inflate an existing instance InflatePlan is used.

type SdLogger

type SdLogger interface {
	Logf(level int, format string, v ...interface{})
}

SdLogger is the stardog logger for Go. It wraps up logging in a convenient way.

func NewSdLogger

func NewSdLogger(realLogger *log.Logger, logLevel string) (SdLogger, error)

NewSdLogger creates a new SdLogger based on the passed in Go standard logger.

type Server

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

Server is the object that controlls running the HTTP server and the controller. It is essentially an embedded service broker.

func CreateServer

func CreateServer(databasePlanMap map[string]PlanFactory, conf *ServerConfig, clientFactory StardogClientFactory, logger SdLogger, store Store) (*Server, error)

CreateServer makes an instance of the BrokerServer.

func (*Server) GetAddr

func (s *Server) GetAddr() (net.Addr, error)

GetAddr returns the addr object on which the server is listening.

func (*Server) Start

func (s *Server) Start() error

Start begins listening for HTTP connections on a port. The listening is doneChannel in a go routine and control is handed back to the calling thread.

func (*Server) Stop

func (s *Server) Stop(wait bool) error

Stop is called to stop Server object from listening.

func (*Server) Wait

func (s *Server) Wait() error

Wait will block on a running server until the Stop method is called.

type ServerConfig

type ServerConfig struct {
	Port           string        `json:"port"`
	Plans          []PlanConfig  `json:"plans"`
	Storage        StorageConfig `json:"storage"`
	BrokerUsername string        `json:"broker_username"`
	BrokerPassword string        `json:"broker_password"`
	BrokerID       string        `json:"broker_id"`
	LogLevel       string        `json:"log_level"`
	LogFile        string        `json:"log_file"`
}

ServerConfig the configuration document that is passed to the broker when it is started. It contains plan and storage information.

type ServiceInstance

type ServiceInstance struct {
	Plan             Plan        `json:"-"`
	InstanceGUID     string      `json:"instance_guid"`
	PlanID           string      `json:"plan_id"`
	OrganizationGUID string      `json:"organization_guid"`
	SpaceGUID        string      `json:"space_guid"`
	ServiceID        string      `json:"service_id"`
	InstanceParams   interface{} `json:"plan_params"`
}

ServiceInstance is the brokers representation of a service instance and contains and interface to the plan in use. It can be serialized by Stores.

type ServicePlan

type ServicePlan struct {
	Name        string      `json:"name"`
	ID          string      `json:"id"`
	Description string      `json:"description"`
	Metadata    interface{} `json:"metadata,omitempty"`
	Free        bool        `json:"free,omitempty"`
	Bindable    bool        `json:"bindable,omitempty"`
}

ServicePlan is a catalog entry that describes a plan. Currently the only plan offered by this service is the shared plan.

type StardogClient

type StardogClient interface {
	CreateDatabase(string) error
	DeleteDatabase(string) error
	UserExists(string) (bool, error)
	NewUser(string, string) error
	DeleteUser(string) error
	GrantUserAccessToDb(string, string) error
	RevokeUserAccess(string, string) error
	GetDatabaseSize(dbName string) (int, error)
	AddData(dbName string, format string, data string) error
	Query(dbName string, data string) ([]byte, error)
}

StardogClient is the object used to interact with the Stardog service. At some point it may make sense to break this out into its own package.

func NewStardogClient

func NewStardogClient(sdURL string, dbCreds DatabaseCredentials, logger SdLogger) StardogClient

NewStardogClient creates a StardogClient network API object

type StardogClientFactory

type StardogClientFactory interface {
	GetStardogAdminClient(string, DatabaseCredentials) StardogClient
}

StardogClientFactory creates netwrok API connection objects to a Stardog service. This mainly serves and a place to insert mock objects for testing.

func NewClientFactory

func NewClientFactory(logger SdLogger) StardogClientFactory

NewClientFactory returns an object that will create StardogClient objects that interact with a Stardog service

type StorageConfig

type StorageConfig struct {
	Type       string      `json:"type"`
	Parameters interface{} `json:"parameters"`
}

StorageConfig describes the storage module to be used with this instance of the storage broker. Currently there is an in memory store and a Stardog store.

type Store

type Store interface {
	AddInstance(string, *ServiceInstance) error
	GetInstance(string) (*ServiceInstance, error)
	DeleteInstance(string) error
	AddBinding(string, string, *BindInstance) error
	GetBinding(string, string) (*BindInstance, error)
	GetAllBindings(string) (map[string]*BindInstance, error)
	DeleteBinding(string, string) error
}

Store is the interface to persisting information related to service instances and bounded applications. There is an in memory store for testing and Stardog store for the shared plan. More storage drivers maybe needed as more plans are created.

type UnbindResponse

type UnbindResponse struct {
}

UnbindResponse is the empty reply to a successful unbind call.

type VCAPService

type VCAPService struct {
	Credentials map[string]interface{} `json:"credentials"`
	Label       string                 `json:"label"`
	Plan        string                 `json:"plan"`
	Name        string                 `json:"name"`
	Tags        []string               `json:"tags"`
}

VCAPService is used to decode a cloud foundry environment.

Jump to

Keyboard shortcuts

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