Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- func (c *Client) GetConfiguration(applicationName string, profiles ...string) (Source, error)
- func (c *Client) GetConfigurationWithLabel(label string, applicationName string, profiles ...string) (Source, error)
- func (c *Client) GetFile(directory string, file string, interfaceType interface{}) error
- func (c *Client) GetFileFromBranch(branch string, directory string, file string, interfaceType interface{}) error
- func (c *Client) GetFileFromBranchRaw(branch string, directory string, file string) ([]byte, error)
- func (c *Client) GetFileRaw(directory string, file string) ([]byte, error)
- type Configuration
- type HTTPClient
- type Option
- func Basic(client *http.Client, username, password string, urls ...string) Option
- func CFService(service string) Option
- func DefaultCFService() Option
- func Local(client *http.Client, urls ...string) Option
- func LocalEnv(client *http.Client) Option
- func OAuth2(baseURL string, clientID string, secret string, tokenURI string) Option
- type PropertySource
- type PropertySourceHandler
- type Resource
- type Source
Constants ¶
const ( // ConfigServerName the service name of the Config Server in PCF. ConfigServerName = "p-config-server" // EnvironmentLocalConfigServerUrls is an environment variable for setting base URLs for local Config Servers. EnvironmentLocalConfigServerUrls = "CONFIG_SERVER_URLS" // SpringCloudConfigServerName the service name of the Spring Cloud Config Server in PCF. SpringCloudConfigServerName = "p.config-server" )
Variables ¶
var ErrPropertySourceDoesNotExist = errors.New("property source does not exist")
ErrPropertySourceDoesNotExist is the error that is returned when there are no PropertySource that match the specified file name.
var ErrResourceNotFound = errors.New("failed to find resource")
ErrResourceNotFound is a special error that is used to propagate 404s.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client contains the clients of the Config Servers.
func New ¶
New creates a new Client based on the provided options. A Client can be configured to communicate with a local Config Server, an OAuth2 Server, and Config Servers in Cloud Foundry.
At least one option must be provided.
func (*Client) GetConfiguration ¶
GetConfiguration retrieves the configurations/property sources of an application based on the name of the application and the profiles of the application.
func (*Client) GetConfigurationWithLabel ¶ added in v2.1.0
func (c *Client) GetConfigurationWithLabel(label string, applicationName string, profiles ...string) (Source, error)
GetConfigurationWithLabel retrieves the configurations/property sources of an application based on the name of the application and the profiles of the application and the label.
func (*Client) GetFile ¶
GetFile retrieves the specified file from the provided directory from the Config Server's default branch.
The file will be deserialized into the specified interface type.
func (*Client) GetFileFromBranch ¶
func (c *Client) GetFileFromBranch(branch string, directory string, file string, interfaceType interface{}) error
GetFileFromBranch retrieves the specified file from the provided branch in the provided directory.
The file will be deserialized into the specified interface type.
func (*Client) GetFileFromBranchRaw ¶
GetFileFromBranchRaw retrieves the file from the specified branch as a byte slice.
type Configuration ¶
type Configuration interface { // GetConfiguration retrieves the configurations/property sources of an application based on the name of the application // and the profiles of the application. GetConfiguration(applicationName string, profiles ...string) (Source, error) // GetConfigurationWithLabel retrieves the configurations/property sources of an application based on the name of the application // and the profiles of the application and the label. GetConfigurationWithLabel(label string, applicationName string, profiles ...string) (Source, error) }
Configuration interface for retrieving an application's configuration files from the Config Server.
type HTTPClient ¶
type HTTPClient struct { *http.Client // BaseURL is the base URL for the Config Server. BaseURL string // Authorization is the authorization header value for the Config Server. If not provided, no authorization header is not explicitly set. // If the client is using OAuth2, the authorization header is set automatically. Authorization string }
HTTPClient is a wrapper for http.Client.
func (*HTTPClient) Get ¶
Get performs a http.MethodGet operation. Builds the URL based on the provided paths and params.
func (*HTTPClient) GetResource ¶
func (h *HTTPClient) GetResource(paths []string, params map[string]string, dest interface{}) error
GetResource performs a http.MethodGet operation. Builds the URL based on the provided paths and params. Deserializes the response to the specified destination.
Capable of unmarshalling YAML, JSON, and XML. If file type is of another type, use GetResourceRaw instead.
func (*HTTPClient) GetResourceRaw ¶
GetResourceRaw performs a http.MethodGet operation. Builds the URL based on the provided paths and params. Returns the byte slice response.
type Option ¶
type Option func(*[]*HTTPClient) error
Option creates a slice of httpClients per Config Server instance.
func Basic ¶ added in v2.2.0
Basic creates a clients for a Config Server based on the provided basic authentication information.
func CFService ¶
CFService creates a clients for each Config Servers the application is bounded to in Cloud Foundry. The environment variable 'VCAP_SERVICES' provides a JSON. The JSON should contain the entry matching the specified name. This entry and used to build an OAuth Client.
func DefaultCFService ¶
func DefaultCFService() Option
DefaultCFService creates a clients for each Config Servers the application is bounded to in Cloud Foundry. The environment variable 'VCAP_SERVICES' provides a JSON that contains an entry with the key 'p-config-server' (v2.x) or 'p.config-server' (v3.x).
The service 'p.config-server' is search for first. If not found, 'p-config-server' is searched for.
type PropertySource ¶
type PropertySource struct { Source map[string]interface{} `json:"source"` Name string `json:"name"` }
PropertySource is the property source for the application.
A property source is either a YAML or a PROPERTIES file located in the repository that a Config Server is pointed at.
type PropertySourceHandler ¶
type PropertySourceHandler func(propertySource PropertySource)
PropertySourceHandler handles the specific PropertySource.
type Resource ¶
type Resource interface { // GetFile retrieves the specified file from the provided directory from the Config Server's default branch. // // The file will be deserialized into the specified interface type. GetFile(directory string, file string, interfaceType interface{}) error // GetFileFromBranch retrieves the specified file from the provided branch in the provided directory. // // The file will be deserialized into the specified interface type. GetFileFromBranch(branch string, directory string, file string, interfaceType interface{}) error // GetFileRaw retrieves the file from the default branch as a byte slice. GetFileRaw(directory string, file string) ([]byte, error) // GetFileFromBranchRaw retrieves the file from the specified branch as a byte slice. GetFileFromBranchRaw(branch string, directory string, file string) ([]byte, error) }
Resource interface describes how to retrieve files from the Config Server.
type Source ¶
type Source struct { Name string `json:"name"` Profiles []string `json:"profiles"` Label string `json:"label"` Version string `json:"version"` State string `json:"state"` PropertySources []PropertySource `json:"propertySources"` }
Source is the application's source configurations. It con contain zero to n number of property sources.
func (*Source) GetPropertySource ¶
func (s *Source) GetPropertySource(fileName string) (PropertySource, error)
GetPropertySource retrieves the PropertySource that has the specifies fileName. The fileName is the name of the file with extension - e.g. application-foo.yml.
Usually the Config Server will return the PropertySource.Name as an URL of sorts (e.g. ssh://base-url.com/path/to/repository/path/to/file.yml/properties). So in order to find the specific file with the desired configurations, the ending of the name needs to be matched against.
func (*Source) HandlePropertySources ¶
func (s *Source) HandlePropertySources(handler PropertySourceHandler)
HandlePropertySources handles all PropertySource configurations that are files. This is a convenience method to handle boilerplate for-loop code and filtering of non-configuration files.
Config Server may return other configurations (e.g. credhub property sources) that contain no configurations (PropertySource.Source is empty).
func (*Source) Unmarshal ¶ added in v2.0.2
Unmarshal converts the Source.PropertySources to the specified type. The type must be a pointer to a struct.
The provided pointer struct must use JSON tags to map to the PropertySource.Source.
This function is not optimized (ugly) and is intended to only be used at startup.