config

package
v0.0.0-...-68b20d9 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

******************************************************************************

  • Copyright 2023 Winc link Inc.
  • Copyright 2020 Intel Inc. *
  • Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at *
  • http://www.apache.org/licenses/LICENSE-2.0 *
  • Unless required by applicable law or agreed to in writing, software distributed under the License
  • is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
  • or implied. See the License for the specific language governing permissions and limitations under
  • the License. ******************************************************************************

Index

Constants

View Source
const DefaultProtocol = "http"

Variables

View Source
var (
	ConfDir string
)

Functions

func ReadConfig

func ReadConfig() (err error)

Types

type AuthenticationInfo

type AuthenticationInfo struct {
	AuthType  string
	AuthToken string
}

test!!! AuthenticationInfo contains authentication information to be used when communicating with an HTTP based provider

type BootstrapConfiguration

type BootstrapConfiguration struct {
	Clients     map[string]ClientInfo
	Service     ServiceInfo
	RpcServer   RPCServiceInfo
	Config      ConfigProviderInfo
	Registry    RegistryInfo
	SecretStore SecretStoreInfo
}

BootstrapConfiguration defines the configuration elements required by the bootstrap.

type CertKeyPair

type CertKeyPair struct {
	Cert string
	Key  string
}

CertKeyPair encapsulates public certificate/private key pair for an SSL certificate

type ClientInfo

type ClientInfo struct {
	// Host is the hostname or IP address of a service.
	Host string
	// Port defines the port on which to access a given service
	Port int
	// Protocol indicates the protocol to use when accessing a given service
	Protocol string
	// 是否启用tls
	UseTLS bool
	// ca cert
	CertFilePath string
}

ClientInfo provides the host and port of another service in the eco-system.

func (ClientInfo) Address

func (c ClientInfo) Address() string

func (ClientInfo) RpcUrl

func (c ClientInfo) RpcUrl() string

func (ClientInfo) Url

func (c ClientInfo) Url() string

type ConfigProviderInfo

type ConfigProviderInfo struct {
	Host string
	Port int
	Type string
}

ConfigProviderInfo defines the type and location (via host/port) of the desired configuration provider (e.g. Consul, Eureka)

type Configuration

type Configuration interface {
	// UpdateFromRaw converts configuration received from the registry to a service-specific configuration struct which is
	// then used to overwrite the service's existing configuration struct.
	UpdateFromRaw(rawConfig interface{}) bool

	// EmptyWritablePtr returns a pointer to a service-specific empty WritableInfo struct.  It is used by the bootstrap to
	// provide the appropriate structure to registry.Client's WatchForChanges().
	EmptyWritablePtr() interface{}

	// UpdateWritableFromRaw converts configuration received from the registry to a service-specific WritableInfo struct
	// which is then used to overwrite the service's existing configuration's WritableInfo struct.
	UpdateWritableFromRaw(rawWritable interface{}) bool

	// GetBootstrap returns the configuration elements required by the bootstrap.
	GetBootstrap() BootstrapConfiguration

	// GetLogLevel returns the current ConfigurationStruct's log level.
	GetLogLevel() string

	// GetLogPath returns the current ConfigurationStruct's log path.
	GetLogPath() string

	// GetRegistryInfo gets the config.RegistryInfo field from the ConfigurationStruct.
	GetRegistryInfo() RegistryInfo

	// GetInsecureSecrets gets the config.InsecureSecrets field from the ConfigurationStruct.
	GetInsecureSecrets() InsecureSecrets
}

Configuration interface provides an abstraction around a configuration struct.

type ConfigurationStruct

type ConfigurationStruct struct {
	Writable     WritableInfo
	Clients      map[string]ClientInfo
	Proxy        map[string]ClientInfo
	Databases    map[string]Database
	Service      ServiceInfo
	RpcServer    RPCServiceInfo
	MessageQueue MessageQueueInfo
	Topics       struct {
		CommandTopic  TopicInfo
		CloudnetTopic TopicInfo
	}
	ApplicationSettings struct {
		CloseAuthToken bool
	}
}

func GetConfig

func GetConfig() ConfigurationStruct

type Credentials

type Credentials struct {
	Username string
	Password string
}

Credentials encapsulates username-password attributes.

type Database

type Database struct {
	Type       string
	Timeout    int
	Host       string
	Port       int
	Name       string
	DataSource string
	Dsn        string
	Cluster    []string
	Username   string
	Password   string
}

type DatabaseConfig

type DatabaseConfig interface {
	Configuration
	DatabaseInfo
}

type DatabaseInfo

type DatabaseInfo interface {
	// GetDatabaseInfo returns a database information map.
	GetDatabaseInfo() map[string]Database
}

DatabaseInfo interfaces provides an abstraction for obtaining the database configuration information.

type InsecureSecrets

type InsecureSecrets map[string]InsecureSecretsInfo

InsecureSecrets is used to hold the secrets stored in the configuration

type InsecureSecretsInfo

type InsecureSecretsInfo struct {
	Path    string
	Secrets map[string]string
}

InsecureSecretsInfo encapsulates info used to retrieve insecure secrets

type LimitSetting

type LimitSetting struct {
	LimitTime int64 // 发放的间隔时间
	Burst     int   // 发放的个数
}

type MessageQueueInfo

type MessageQueueInfo struct {
	// Host is the hostname or IP address of the broker, if applicable.
	Host string
	// Port defines the port on which to access the message queue.
	Port int
	// Protocol indicates the protocol to use when accessing the message queue.
	Protocol string
	// Indicates the message queue platform being used.
	Type string
	// Indicates the topic the data is published/subscribed
	// TODO this configuration shall be removed once v1 API is deprecated.
	EventTopic string
	// Indicates the topic the data is published/subscribed
	SubscribeTopics []string
	// sync device status to cloud by message queue
	DeviceStatusTopic string
	// Indicates the topic prefix the data is published to. Note that /<device-profile-name>/<device-name> will be
	// added to this Publish Topic prefix as the complete publish topic
	PublishTopicPrefix string
	// Provides additional configuration properties which do not fit within the existing field.
	// Typically the key is the name of the configuration property and the value is a string representation of the
	// desired value for the configuration property.
	Optional map[string]string
}

MessageQueueInfo provides parameters related to connecting to a message bus

func (MessageQueueInfo) Enable

func (m MessageQueueInfo) Enable() bool

type RPCServiceInfo

type RPCServiceInfo struct {
	Address  string
	UseTLS   bool
	CertFile string
	KeyFile  string
	// 服务器响应超时时间,单位为毫秒
	Timeout      int
	LimitSetting LimitSetting
}

rpc server info

type RedisConfig

type RedisConfig struct {
	Enable bool
	// The network type, either tcp or unix.
	// Default is tcp.
	Network string
	// host:port address.
	Addr string

	// Dialer creates new network connection and has priority over
	// Network and Addr options.
	Dialer func(ctx context.Context, network, addr string) (net.Conn, error)

	// Use the specified Username to authenticate the current connection
	// with one of the connections defined in the ACL list when connecting
	// to a Redis 6.0 instance, or greater, that is using the Redis ACL system.
	Username string
	// Optional password. Must match the password specified in the
	// requirepass server configuration option (if connecting to a Redis 5.0 instance, or lower),
	// or the User Password when connecting to a Redis 6.0 instance, or greater,
	// that is using the Redis ACL system.
	Password string

	// Database to be selected after connecting to the server.
	DB int

	// Maximum number of retries before giving up.
	// Default is 3 retries; -1 (not 0) disables retries.
	MaxRetries int
	// Minimum backoff between each retry.
	// Default is 8 milliseconds; -1 disables backoff.
	MinRetryBackoff time.Duration
	// Maximum backoff between each retry.
	// Default is 512 milliseconds; -1 disables backoff.
	MaxRetryBackoff time.Duration

	// Dial timeout for establishing new connections.
	// Default is 5 seconds.
	DialTimeout time.Duration
	// Timeout for socket reads. If reached, commands will fail
	// with a timeout instead of blocking. Use value -1 for no timeout and 0 for default.
	// Default is 3 seconds.
	ReadTimeout time.Duration
	// Timeout for socket writes. If reached, commands will fail
	// with a timeout instead of blocking.
	// Default is ReadTimeout.
	WriteTimeout time.Duration

	// Maximum number of socket connections.
	// Default is 10 connections per every CPU as reported by runtime.NumCPU.
	PoolSize int
	// Minimum number of idle connections which is useful when establishing
	// new connection is slow.
	MinIdleConns int
	// Connection age at which client retires (closes) the connection.
	// Default is to not close aged connections.
	MaxConnAge time.Duration
	// Amount of time client waits for connection if all connections
	// are busy before returning an error.
	// Default is ReadTimeout + 1 second.
	PoolTimeout time.Duration
	// Amount of time after which client closes idle connections.
	// Should be less than server's timeout.
	// Default is 5 minutes. -1 disables idle timeout check.
	IdleTimeout time.Duration
	// Frequency of idle checks made by idle connections reaper.
	// Default is 1 minute. -1 disables idle connections reaper,
	// but idle connections are still discarded by the client
	// if IdleTimeout is set.
	IdleCheckFrequency time.Duration

	// TLS Config to use. When set TLS will be negotiated.
	TLSConfig *tls.Config
	// contains filtered or unexported fields
}

type RegistryInfo

type RegistryInfo struct {
	Host string
	Port int
	Type string
}

RegistryInfo defines the type and location (via host/port) of the desired service registry (e.g. Consul, Eureka)

type SecretStoreInfo

type SecretStoreInfo struct {
	Host           string
	Port           int
	Path           string
	Protocol       string
	Namespace      string
	RootCaCertPath string
	ServerName     string
	//Authentication          types.AuthenticationInfo
	Authentication          AuthenticationInfo
	AdditionalRetryAttempts int
	RetryWaitPeriod         string

	// TokenFile provides a location to a token file.
	TokenFile string
	// contains filtered or unexported fields
}

SecretStoreInfo encapsulates configuration properties used to create a SecretClient.

type ServiceConfig

type ServiceConfig struct {
	// The Protocol that should be used to connect to the Configuration service. HTTP is used if not set.
	Protocol string
	// Host is the hostname or IP address of the Configuration service
	Host string
	// Port is the HTTP port of the Configuration service
	Port int
	// Type is the implementation type of the Configuration service, i.e. consul
	Type string
	// BasePath is the base path with in the Configuration service where the your service's configuration is stored
	BasePath string
}

ServiceConfig defines the information need to connect to the Configuration service and optionally register the service for discovery and health checks

func (*ServiceConfig) GetProtocol

func (config *ServiceConfig) GetProtocol() string

func (ServiceConfig) GetUrl

func (config ServiceConfig) GetUrl() string

func (*ServiceConfig) PopulateFromUrl

func (config *ServiceConfig) PopulateFromUrl(providerUrl string) error

type ServiceInfo

type ServiceInfo struct {
	// BootTimeout indicates, in milliseconds, how long the service will retry connecting to upstream dependencies
	// before giving up. Default is 30,000.
	BootTimeout int
	// Health check interval
	CheckInterval string
	// Host is the hostname or IP address of the service.
	Host string
	// Port is the HTTP port of the service.
	Port int
	// ServerBindAddr specifies an IP address or hostname
	// for ListenAndServe to bind to, such as 0.0.0.0
	ServerBindAddr string
	// The protocol that should be used to call this service
	Protocol string
	// StartupMsg specifies a string to log once service
	// initialization and startup is completed.
	StartupMsg string
	// MaxResultCount specifies the maximum size list supported
	// in response to REST calls to other services.
	MaxResultCount int
	// Timeout specifies a timeout (in milliseconds) for
	// processing REST calls from other services.
	Timeout int
}

ServiceInfo contains configuration settings necessary for the basic operation of any EdgeX service.

func (ServiceInfo) Url

func (s ServiceInfo) Url() string

Url provides a way to obtain the full url of the host service for use in initialization or, in some cases, responses to a caller.

type TopicInfo

type TopicInfo struct {
	Topic string
	Group string
}

type WritableInfo

type WritableInfo struct {
	LogLevel                        string
	LogPath                         string
	EnableValueDescriptorManagement bool
	DebugProfile                    bool
	IsNewModel                      bool
}

Jump to

Keyboard shortcuts

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