config

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 24, 2019 License: Apache-2.0 Imports: 8 Imported by: 14

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadConfigAs

func LoadConfigAs(confFile string, conf interface{}) error

LoadConfigAs loads a generic configuration from a JSON file into predefined structure.

func LoadConfigAsTypeAndMerge

func LoadConfigAsTypeAndMerge(confFile string, conf interface{}, variables interface{}) error

LoadConfigAsTypeAndMerge loads configuration template from a file and merges with the provided variables. The configuration is unmarshalled into the provided configuration interface.

func LoadRemoteConfig

func LoadRemoteConfig(configURL string, configObj interface{}, templateData interface{}) (interface{}, error)

LoadRemoteConfig loads a configuration from a remote location (configURL) into an object reference. For convenience, it also returns the loaded object.

func LoadRemoteConfigWithLoader

func LoadRemoteConfigWithLoader(configURL string, loader DataLoader, configObj interface{}, templateData interface{}) (interface{}, error)

LoadRemoteConfigWithLoader loads a configuration from a remote location (configURL) into an object reference using a DataLoader to fetch the data from the remote source. If config is template file it evaluates the template variable with templateData fields For convenience, it also returns the loaded object.

Types

type ACLConfig

type ACLConfig struct {

	// Disable signals whether to disable the ACL check.
	Disable bool `json:"disable"`

	// Policies is the list of default policies.
	Policies []ACLPolicy `json:"policies,omitempty"`
}

ACLConfig holds the ACL middleware configuration.

type ACLPolicy

type ACLPolicy struct {
	// The ID of the policy document
	ID string `json:"id" bson:"id"`

	// Description is the human readable description of the document.
	Description string `json:"description" bson:"description"`

	// List of subjects (may be patterns) to which this policy applies.
	Subjects []string `json:"subjects" bson:"subjects"`

	// Effect is the effect of this policy if applied to the requested resource. May be "allow" or "deny".
	Effect string `json:"effect" bson:"effect"`

	// Resources is a list of resources (may be patterns) to which this policy applies.
	Resources []string `json:"resources" bson:"resources"`

	// Actions is a list of actions (may be patterns) to which this policy applies.
	Actions []string `json:"actions" bson:"actions"`

	// Conditions additional ACL policy conditions.
	Conditions map[string]interface{} `json:"conditions,omitempty"`
}

ACLPolicy represents an ACL policy

type DBConfig

type DBConfig struct {
	// DBname is the database name (mongodb/dynamodb)
	DBName string `json:"dbName"`

	// DB Info holds the database connection configuration
	DBInfo `json:"dbInfo"`
}

DBConfig holds the database configuration parameters.

type DBInfo

type DBInfo struct {
	// Host is the database host+port URL
	Host string `json:"host,omitempty"`

	// Username is the username used to access the database
	Username string `json:"user,omitempty"`

	// Password is the database user password
	Password string `json:"pass,omitempty"`

	// DatabaseName is the name of the database where the server will store the collections
	DatabaseName string `json:"database,omitempty"`

	// AWSCredentials is the full path to aws credentials file
	AWSCredentials string `json:"credentials,omitempty"`

	// AWSEndpoint is the full path to aws credentials file
	AWSEndpoint string `json:"endpoint,omitempty"`

	// AWSRegion is the AWS region
	AWSRegion string `json:"awsRegion,omitempty"`

	// AWS Secret Key ID
	AWSSecretKeyID string `json:"awsSecretKeyId,omitempty"`

	// AWS Secret Access Key
	AWSSecretAccessKey string `json:"awsSecretAccessKey,omitempty"`

	// AWS Session Token
	AWSSessionToken string `json:"awsSessionToken,omitempty"`
}

DBInfo holds the database connection configuration

type DataLoader

type DataLoader func(dataURL string) ([]byte, error)

DataLoader loads data from a remote source. It just specifies a contractual intrface for fetching data - the means of fetching data are left completely to the implementors.

func NewConsulKVDataLoader

func NewConsulKVDataLoader(consulURL string, client *http.Client) DataLoader

NewConsulKVDataLoader creates a DataLoader that loads data from Consul Key-Value store. You must provide a URL to the Consul server and an http.Client. The dataURI for the data is the key under which the remote data is stored on the consul server.

func NewHTTPDataLoader

func NewHTTPDataLoader(client *http.Client) DataLoader

NewHTTPDataLoader creates a DataLoader that fetches data from an HTTP server using the provided http.Client. The dataURL must be a full URL to the remote data.

type JWTConfig

type JWTConfig struct {

	// Name is the name of the JWT middleware. Used in error messages.
	Name string

	// Description holds the description for the middleware. Used for documentation purposes.
	Description string

	// TokenURL is the URL of the JWT token provider. Use a full URL here.
	TokenURL string `json:"tokenUrl"`
}

JWTConfig holds the JWT configuration.

type MQConfig

type MQConfig struct {
	// Host is the remote mq host
	Host string `json:"host"`
	// Port is the port on which the remote mq server listens
	Port string `json:"port"`
	// Username to access the mq server
	Username string `json:"username"`
	// Port to access the mq server
	Password string `json:"password"`
}

MQConfig holds the messaging queue configuration.

type OAuth2Config

type OAuth2Config struct {

	// TokenURL is the path of the token endpoint. Usually "/oauth2/token".
	TokenURL string `json:"tokenUrl"`

	// AuthorizationURL is the path of the authorize endpoint. Usually "/oauth2/authorize".
	AuthorizationURL string `json:"authorizeUrl"`

	// Description is the description of the middleware. Used for documentation purposes.
	Description string `json:"description"`
}

OAuth2Config holds the OAuth2 configuration.

type SAMLConfig

type SAMLConfig struct {

	// CertFile is the location of the certificate file.
	CertFile string `json:"certFile"`

	// KeyFile is the location of the key file.
	KeyFile string `json:"keyFile"`

	// IdentityProviderURL is the URL of the SAML Identity Provider server. User a full URL here.
	IdentityProviderURL string `json:"identityProviderUrl"`

	// UserServiceURL is the URL of the user microservice. This should be the public url (usually over the Gateway).
	UserServiceURL string `json:"userServiceUrl"`

	// RegistrationServiceURL is the URL of the registration service. This should be the public registration URL (usually over the Gateway).
	RegistrationServiceURL string `json:"registrationServiceUrl"`

	// RootURL is the base URL of the microservice
	RootURL string `json:"rootURL"`
}

SAMLConfig holds the SAML configuration.

type SecurityConfig

type SecurityConfig struct {
	// Disable flags signals whether to disable the security completely.
	Disable bool

	// Path patterns to be ignored by the security chain (regexp).
	IgnorePatterns []string `json:"ignorePatterns,omitempty"`

	// Ignore HTTP methods
	IgnoreHTTPMethods []string `json:"ignoreHttpMethods,omitempty"`

	// KeysDir is the loacation of the directory holding the private-public key pairs.
	KeysDir string `json:"keysDir"`

	// JWTConfig holds the JWT configuration. If ommited the JWT security will not be used.
	*JWTConfig `json:"jwt,omitempty"`

	// SAMLConfig holds the SAML configuration. If ommited the SAML security will not be used.
	*SAMLConfig `json:"saml,omitempty"`

	//OAuth2Config holds the OAuth2 configuration. If ommited the OAuth2 security will not be used.
	*OAuth2Config `json:"oauth2,omitempty"`

	// ACL Middleware configuration
	*ACLConfig `json:"acl,omitempty"`
}

SecurityConfig holds the security configuration. The subsections for JWT, SAML and OAuth2 are optional. If a subsection is ommited, then the appropriate security will not be configured and used by the security chain.

type ServiceConfig

type ServiceConfig struct {
	// Service holds the confgiuration for connecting and registering the service with the API Gateway
	Service *gateway.MicroserviceConfig `json:"service"`
	// SecurityConfig holds the security configuration
	SecurityConfig `json:"security,omitempty"`
	// DBConfig holds the database connection configuration
	DBConfig `json:"database"`
	// GatewayURL is the URL of the API Gateway
	GatewayURL string `json:"gatewayUrl"`
	// GatewayAdminURL is the administration URL of the API Gateway. Used for purposes of registration of a
	// microservice with the API gateway.
	GatewayAdminURL string `json:"gatewayAdminUrl"`
	// ContainerManager is the platform for managing containerized services
	// Can be swarm or kubernetes
	ContainerManager string `json:"containerManager,omitempty"`
	//Version is version of the service
	Version string `json:"version"`
}

ServiceConfig holds the full microservice configuration: - Configuration for registering on the API Gateway - Security configuration - Database configuration

func LoadConfig

func LoadConfig(confFile string) (*ServiceConfig, error)

LoadConfig loads the service configuration from a file.

func LoadConfigAndMerge

func LoadConfigAndMerge(confFile string, variables interface{}) (*ServiceConfig, error)

LoadConfigAndMerge loads configuration template from a file and merges the template with the provided variables. The merged configuration is then unmarshalled into a standard ServiceConfig structure.

func LoadRemoteStdConfig

func LoadRemoteStdConfig(configURL string, templateData interface{}) (*ServiceConfig, error)

LoadRemoteStdConfig loads a standard configuration (ServiceConfig struct) from a remote source.

func LoadRemoteStdConfigWithLoader

func LoadRemoteStdConfigWithLoader(configURL string, loader DataLoader, templateData interface{}) (*ServiceConfig, error)

LoadRemoteStdConfigWithLoader loads a standard configuration (ServiceConfig struct) from a remote source using a DataLoader to fetch the data.

Jump to

Keyboard shortcuts

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