config

package
v0.0.0-...-4086bda Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: Apache-2.0 Imports: 35 Imported by: 0

README

Configuration

Configuration is defined in TOML.

Table of Contents

General settings

Section Key Type Description
api addr string Address that API server will listen on, e.g. localhost:9410
api external_addr string The Externally visible URL that the server is available on
api org_name string The organization name to use when issuing client certificates
ocpp heartbeat_interval string Frequency to request charge station heartbeat messages at, e.g. "5m"
ocpp ocpp16_enabled bool Is OCPP 1.6 support enabled, e.g. "true"?
ocpp ocpp201_enabled bool Is OCPP 2.0.1 support enabled, e.g. "true"?
observability log_format string Either "json" or "text"
observability otel_collector_addr string Address of the OpenTelemetry collector, e.g. "localhost:4317"
observability tls_keylog_file string File where TLS session keys will be written for use with Wireshark

Transport settings

This section consists of a type parameter and a set of parameters specific to that type prefixed by the type name.

e.g.

[transport]
type = "mqtt"
mqtt.urls = ["mqtt://mqtt-server.example.com:1883"]
MQTT

Configures the MQTT transport.

Section Key Type Description
mqtt urls array of strings List of MQTT broker URLs, e.g. [mqtt://localhost:1883]
mqtt prefix string MQTT topic prefix, e.g. "cs"
mqtt group string MQTT subscriber group name, e.g. "manager"
mqtt connect_timeout string MQTT connection timeout, e.g. "10s"
mqtt connect_retry_delay string MQTT connection retry delay, e.g. "1s"
mqtt keep_alive_interval string MQTT keep alive interval, e.g. "10s"

Service settings

The following types of service can be configured, each service has its own section:

Each section consists of a type parameter and a set of parameters specific to that type prefixed by the type name.

e.g.

[storage]
type = "firestore"
firestore.project_id = "my-google-project"
Storage

There are two storage implementations:

Firestore
Key Type Description
project_id string Google Cloud project ID
In-memory

There is no additional configuration for in-memory storage.

Contract certificate validator

There is just one contract certificate validator implementation:

  • ocsp - checks the certificate chain and validates the OCSP status of each provided certificate
OCSP contract certificate validator
Key Type Description
root_certs RootCertProvider Configures how to retrieve the trusted root certificates
max_attempts int Maximum number of attempts to check the OCSP status of a certificate
Contract certificate provider

There are two contract certificate provider implementations:

  • opcp - contract certificates are retrieved from a contract certificate pool using the Open Plug&Charge Protocol (OPCP)
  • default - returns an error for all requests
OPCP contract certificate provider
Key Type Description
url string Base URL for OPCP service that provides the contract certificate pool
auth HttpAuthService Configures how to authenticate with the OPCP service
Default contract certificate provider

There is no additional configuration for the default contract certificate provider.

Charge station certificate provider

There are four charge station certificate provider implementations:

  • opcp - charge station certificates are issued using the EST service from the Open Plug&Charge Protocol (OPCP)
  • local - charge station certificates are issued using a CA implemented by the CSMS
  • delegating - supports different charge station certificate providers for issuing V2G and CSO certificates
  • default - returns an error for all requests
OPCP charge station certificate provider
Key Type Description
url string Base URL for OPCP service that provides the EST service
auth HttpAuthService Configures how to authenticate with the OPCP service
Local charge station certificate provider
Key Type Description
cert LocalSource The source that provides the signing certificate, must be a PEM encoded certificate
key LocalSource The source that provides the signing key, must be a PEM encoded private key
Delegating charge station certificate provider
Key Type Description
v2g ChargeStationCertificateProvider The charge station certificate provider for V2G certificates
cso ChargeStationCertificateProvider The charge station certificate provider for CSO certificates
Default charge station certificate provider

There is no additional configuration for the default charge station certificate provider.

Tariff service

There is a single tariff service implementation:

  • kwh - calculates the tariff based on the energy consumed
kWh tariff service

There is no additional configuration for the kWh tariff service.

Root certificate provider

There are several implementations of RootCertProvider:

  • opcp - root certificates are retrieved from a root certificate pool using the Open Plug&Charge Protocol (OPCP)
  • file - root certificates are retrieved from a file
OPCP root certificate provider
Key Type Description
url string Base URL for OPCP service that provides the root certificate pool
ttl string Time before cached values are discarded, e.g. "1h"
auth HttpAuthService Configures how to authenticate with the OPCP service
File root certificate provider
Key Type Description
files array of strings List of files containing root certificates
Http auth service

There are several implementation of HttpAuthService:

  • env_token - token is read from an environment variable
  • fixed_token - token is read from the configuration
  • oauth2_token - token is retrieved using OAuth2 client credentials grant
  • hubject_test_token - token is scraped from the Hubject test environment authorization page
Environment token auth service
Key Type Description
variable string Name of the environment variable
Fixed token auth service
Key Type Description
token string The token value
OAuth2 token auth service
Key Type Description
url string The URL of the OAuth2 Authorization Server token endpoint
client_id string The client id to use in the client credentials grant
client_secret string The client secret to use in the client credentials grant
client_secret_env_var string The environment variable to read the client secret from to use in the client credentials grant
Hubject test token auth service
Key Type Description
url string URL of the Hubject test environment authorization page
ttl string The duration for which the token is valid, e.g. "1h"
Local source

There are two different local source implementations:

File local source

The value is a file to be read from the operating system.

Google cloud secret local source

The value is the name of a secret to be read from google cloud secrets. The name must be of the form:

projects/<project-number>/secrets/<secret-name>/[latest|<version>]

Example configuration

[api]
addr = ":9410"

[mqtt]
urls = ["mqtt://mqtt:1883"]

[observability]
otel_collector_addr = "otel-collector:4317"

[storage]
type = "firestore"
firestore.project_id = "*detect-project-id*"

[contract_cert_validator]
type = "ocsp"

[contract_cert_validator.ocsp.root_certs]
type = "opcp"
opcp.url = "https://open.plugncharge-test.hubject.com/mo/cacerts/ISO15118-2"
opcp.auth.type = "env_token"
opcp.auth.env_token.variable = "HUBJECT_TOKEN"

[contract_cert_provider]
type = "opcp"
opcp.url = "https://open.plugncharge-test.hubject.com"
opcp.auth.type = "env_token"
opcp.auth.env_token.variable = "HUBJECT_TOKEN"

[charge_station_cert_provider]
type = "opcp"
opcp.url = "https://open.plugncharge-test.hubject.com"
opcp.auth.type = "env_token"
opcp.auth.env_token.variable = "HUBJECT_TOKEN"

Documentation

Overview

Package config provides support for configuring the system.

BaseConfig provides the data structures that represent the configuration and can be used to load configuration from a TOML file.

Config consumes the BaseConfig and returns implementations of the various interfaces used by the application (in a dependency-injection style).

Index

Constants

This section is empty.

Variables

View Source
var DefaultConfig = BaseConfig{
	Api: ApiSettingsConfig{
		Addr:    "localhost:9410",
		Host:    "localhost",
		WsPort:  80,
		WssPort: 443,
		OrgName: "Thoughtworks",
	},
	Transport: TransportConfig{
		Type: "mqtt",
		Mqtt: &MqttSettingsConfig{
			Urls:              []string{"mqtt://localhost:1883"},
			Prefix:            "cs",
			Group:             "manager",
			ConnectTimeout:    "10s",
			ConnectRetryDelay: "1s",
			KeepAliveInterval: "10s",
		},
	},
	Ocpp: OcppSettingsConfig{
		HeartbeatInterval: "5m",
		Ocpp16Enabled:     true,
		Ocpp201Enabled:    true,
	},
	Observability: ObservabilitySettingsConfig{
		LogFormat: "text",
	},
	Storage: StorageConfig{
		Type: "in_memory",
	},
	ContractCertValidator: ContractCertValidatorConfig{
		Type: "ocsp",
		Ocsp: &OcspContractCertValidatorConfig{
			RootCertProvider: RootCertProviderConfig{
				Type: "file",
				File: &FileRootCertProviderConfig{
					FileNames: []string{"root_ca.pem"},
				},
			},
			MaxAttempts: 1,
		},
	},
	ContractCertProvider: ContractCertProviderConfig{
		Type: "default",
	},
	ChargeStationCertProvider: ChargeStationCertProviderConfig{
		Type: "default",
	},
	TariffService: TariffServiceConfig{
		Type: "kwh",
	},
}

DefaultConfig provides the default configuration. The configuration read from the TOML file will overlay this configuration.

Functions

This section is empty.

Types

type ApiSettings

type ApiSettings struct {
	Addr    string
	Host    string
	WsPort  int
	WssPort int
	OrgName string
}

type ApiSettingsConfig

type ApiSettingsConfig struct {
	Addr    string `mapstructure:"addr" toml:"addr" validate:"required"`
	Host    string `mapstructure:"host,omitempty" toml:"host,omitempty"`
	WsPort  int    `mapstructure:"ws_port,omitempty" toml:"ws_port,omitempty"`
	WssPort int    `mapstructure:"wss_port,omitempty" toml:"wss_port,omitempty"`
	OrgName string `mapstructure:"org_name,omitempty" toml:"org_name,omitempty"`
}

type BaseConfig

type BaseConfig struct {
	Api                       ApiSettingsConfig               `mapstructure:"api" toml:"api" validate:"required"`
	Transport                 TransportConfig                 `mapstructure:"transport" toml:"transport" validate:"required"`
	Ocpp                      OcppSettingsConfig              `mapstructure:"ocpp" toml:"ocpp" validate:"required"`
	Observability             ObservabilitySettingsConfig     `mapstructure:"observability" toml:"observability" validate:"required"`
	Storage                   StorageConfig                   `mapstructure:"storage" toml:"storage" validate:"required"`
	ContractCertValidator     ContractCertValidatorConfig     `mapstructure:"contract_cert_validator" toml:"contract_cert_validator" validate:"required"`
	ContractCertProvider      ContractCertProviderConfig      `mapstructure:"contract_cert_provider" toml:"contract_cert_provider" validate:"required"`
	ChargeStationCertProvider ChargeStationCertProviderConfig `mapstructure:"charge_station_cert_provider" toml:"charge_station_cert_provider" validate:"required"`
	TariffService             TariffServiceConfig             `mapstructure:"tariff_service" toml:"tariff_service" validate:"required"`
	Ocpi                      *OcpiConfig                     `mapstructure:"ocpi,omitempty" toml:"ocpi,omitempty"`
}

BaseConfig provides the data structures that represent the configuration and provides the ability to load the configuration from a TOML file.

func (*BaseConfig) Load

func (c *BaseConfig) Load(reader io.Reader) error

Load reads TOML configuration from a reader.

func (*BaseConfig) LoadFromFile

func (c *BaseConfig) LoadFromFile(configFile string) error

LoadFromFile reads TOML configuration from a file.

func (*BaseConfig) Validate

func (c *BaseConfig) Validate() error

Validate ensures that the configuration is structurally valid.

type ChargeStationCertProviderConfig

type ChargeStationCertProviderConfig struct {
	Type       string                                     `mapstructure:"type" toml:"type" validate:"required,oneof=default opcp local delegating"`
	Opcp       *OpcpChargeStationCertProviderConfig       `mapstructure:"opcp,omitempty" toml:"opcp,omitempty" validate:"required_if=Type opcp"`
	Local      *LocalChargeStationCertProviderConfig      `mapstructure:"local,omitempty" toml:"local,omitempty" validate:"required_if=Type local"`
	Delegating *DelegatingChargeStationCertProviderConfig `mapstructure:"delegating,omitempty" toml:"delegating,omitempty" validate:"required_if=Type delegating"`
}

type CompositeRootCertProviderConfig

type CompositeRootCertProviderConfig struct {
	Providers []RootCertProviderConfig `mapstructure:"providers" toml:"providers" validate:"required,dive,required"`
}

type Config

type Config struct {
	Api                              ApiSettings
	Tracer                           oteltrace.Tracer
	TracerProvider                   *trace.TracerProvider
	Storage                          store.Engine
	MsgEmitter                       transport.Emitter
	MsgListener                      transport.Listener
	Ocpp16Handler                    transport.MessageHandler
	Ocpp201Handler                   transport.MessageHandler
	ContractCertValidationService    services.CertificateValidationService
	ContractCertProviderService      services.ContractCertificateProvider
	ChargeStationCertProviderService services.ChargeStationCertificateProvider
	TariffService                    services.TariffService
	OcpiApi                          ocpi.Api
}

func Configure

func Configure(ctx context.Context, cfg *BaseConfig) (c *Config, err error)

type ContractCertProviderConfig

type ContractCertProviderConfig struct {
	Type string                          `mapstructure:"type" toml:"type" validate:"required,oneof=default opcp"`
	Opcp *OpcpContractCertProviderConfig `mapstructure:"opcp,omitempty" toml:"opcp,omitempty" validate:"required_if=Type opcp"`
}

type ContractCertValidatorConfig

type ContractCertValidatorConfig struct {
	Type string                           `mapstructure:"type" toml:"type" validate:"required,oneof=ocsp"`
	Ocsp *OcspContractCertValidatorConfig `mapstructure:"ocsp,omitempty" toml:"ocsp,omitempty" validate:"required_if=Type ocsp"`
}

type DelegatingChargeStationCertProviderConfig

type DelegatingChargeStationCertProviderConfig struct {
	V2G *ChargeStationCertProviderConfig `mapstructure:"v2g" toml:"v2g" validate:"required"`
	CSO *ChargeStationCertProviderConfig `mapstructure:"cso" toml:"cso" validate:"required"`
}

type EnvHttpTokenConfig

type EnvHttpTokenConfig struct {
	EnvVar string `mapstructure:"variable" toml:"variable" validate:"required"`
}

type FileRootCertProviderConfig

type FileRootCertProviderConfig struct {
	FileNames []string `mapstructure:"files" toml:"files" validate:"required,dive,required"`
}

type FirestoreStorageConfig

type FirestoreStorageConfig struct {
	ProjectId string `mapstructure:"project_id" toml:"project_id" validate:"required"`
}

type FixedHttpTokenConfig

type FixedHttpTokenConfig struct {
	Token string `mapstructure:"token" toml:"token" validate:"required"`
}

type HttpAuthConfig

type HttpAuthConfig struct {
	Type             string                      `mapstructure:"type" toml:"type" validate:"required,oneof=env_token fixed_token oauth2_token hubject_test_token"`
	EnvToken         *EnvHttpTokenConfig         `mapstructure:"env_token,omitempty" toml:"env_token,omitempty" validate:"required_if=Type env_token"`
	FixedToken       *FixedHttpTokenConfig       `mapstructure:"fixed_token,omitempty" toml:"fixed_token,omitempty" validate:"required_if=Type fixed_token"`
	OAuth2Token      *OAuth2HttpTokenConfig      `mapstructure:"oauth2_token,omitempty" toml:"oauth2_token,omitempty" validate:"required_if=Type oauth2_token"`
	HubjectTestToken *HubjectTestHttpTokenConfig `` /* 126-byte string literal not displayed */
}

type HubjectTestHttpTokenConfig

type HubjectTestHttpTokenConfig struct {
	Url string `mapstructure:"url" toml:"url"`
	Ttl string `mapstructure:"ttl" toml:"ttl"`
}

type InMemoryStorageConfig

type InMemoryStorageConfig struct{}

type LocalChargeStationCertProviderConfig

type LocalChargeStationCertProviderConfig struct {
	CertificateSource *LocalSourceConfig `mapstructure:"cert" toml:"cert" validate:"required"`
	PrivateKeySource  *LocalSourceConfig `mapstructure:"key" toml:"key" validate:"required"`
}

type LocalSourceConfig

type LocalSourceConfig struct {
	Type              string `mapstructure:"type" toml:"type" validate:"required,oneof=file google_cloud_secret"`
	File              string `mapstructure:"file,omitempty" toml:"file,omitempty" validate:"required_if=Type file"`
	GoogleCloudSecret string `` /* 129-byte string literal not displayed */
}

type MqttSettingsConfig

type MqttSettingsConfig struct {
	Urls              []string `mapstructure:"urls" toml:"urls" validate:"required,dive,required"`
	Prefix            string   `mapstructure:"prefix" toml:"prefix" validate:"required"`
	Group             string   `mapstructure:"group" toml:"group" validate:"required"`
	ConnectTimeout    string   `mapstructure:"connect_timeout" toml:"connect_timeout" validate:"required"`
	ConnectRetryDelay string   `mapstructure:"connect_retry_delay" toml:"connect_retry_delay" validate:"required"`
	KeepAliveInterval string   `mapstructure:"keep_alive_interval" toml:"keep_alive_interval" validate:"required"`
}

type OAuth2HttpTokenConfig

type OAuth2HttpTokenConfig struct {
	Url                string  `mapstructure:"url" toml:"url" validate:"required"`
	ClientId           string  `mapstructure:"client_id" toml:"client_id" validate:"required"`
	ClientSecret       *string `mapstructure:"client_secret,omitempty" toml:"client_secret,omitempty" validate:"required_without=ClientSecretEnvVar"`
	ClientSecretEnvVar *string `` /* 126-byte string literal not displayed */
}

type ObservabilitySettingsConfig

type ObservabilitySettingsConfig struct {
	LogFormat         string `mapstructure:"log_format" toml:"log_format" validate:"required"`
	OtelCollectorAddr string `mapstructure:"otel_collector_addr" toml:"otel_collector_addr"`
	TlsKeylogFile     string `mapstructure:"tls_keylog_file" toml:"tls_keylog_file"`
}

type OcpiConfig

type OcpiConfig struct {
	Addr        string `mapstructure:"addr" toml:"addr" validate:"required"`
	ExternalURL string `mapstructure:"external_url" toml:"external_url" validate:"required"`
	CountryCode string `mapstructure:"country_code" toml:"country_code" validate:"required"`
	PartyId     string `mapstructure:"party_id" toml:"party_id" validate:"required"`
}

type OcppSettingsConfig

type OcppSettingsConfig struct {
	HeartbeatInterval string `mapstructure:"heartbeat_interval" toml:"heartbeat_interval" validate:"required"`
	Ocpp16Enabled     bool   `mapstructure:"ocpp16_enabled" toml:"ocpp16_enabled" validate:"required_without=Ocpp201Enabled"`
	Ocpp201Enabled    bool   `mapstructure:"ocpp201_enabled" toml:"ocpp201_enabled" validate:"required_without=Ocpp16Enabled"`
}

type OcspContractCertValidatorConfig

type OcspContractCertValidatorConfig struct {
	RootCertProvider RootCertProviderConfig `mapstructure:"root_certs" toml:"root_certs" validate:"required"`
	MaxAttempts      int                    `mapstructure:"max_attempts" toml:"max_attempts" validate:"required"`
}

type OpcpChargeStationCertProviderConfig

type OpcpChargeStationCertProviderConfig struct {
	Url      string         `mapstructure:"url" toml:"url" validate:"required"`
	HttpAuth HttpAuthConfig `mapstructure:"auth" toml:"auth" validate:"required"`
}

type OpcpContractCertProviderConfig

type OpcpContractCertProviderConfig struct {
	Url      string         `mapstructure:"url" toml:"url" validate:"required"`
	HttpAuth HttpAuthConfig `mapstructure:"auth" toml:"auth" validate:"required"`
}

type OpcpRootCertProviderConfig

type OpcpRootCertProviderConfig struct {
	Url      string         `mapstructure:"url" toml:"url" validate:"required"`
	Ttl      string         `mapstructure:"ttl" toml:"ttl" validate:"required"`
	HttpAuth HttpAuthConfig `mapstructure:"auth" toml:"auth" validate:"required"`
}

type RootCertProviderConfig

type RootCertProviderConfig struct {
	Type      string                           `mapstructure:"type" toml:"type" validate:"required,oneof=opcp file composite"`
	Opcp      *OpcpRootCertProviderConfig      `mapstructure:"opcp,omitempty" toml:"opcp,omitempty" validate:"required_if=Type opcp"`
	File      *FileRootCertProviderConfig      `mapstructure:"file,omitempty" toml:"file,omitempty" validate:"required_if=Type file"`
	Composite *CompositeRootCertProviderConfig `mapstructure:"composite,omitempty" toml:"composite,omitempty" validate:"required_if=Type composite"`
}

type StorageConfig

type StorageConfig struct {
	Type             string                  `mapstructure:"type" toml:"type" validate:"required,oneof=firestore in_memory"`
	FirestoreStorage *FirestoreStorageConfig `mapstructure:"firestore,omitempty" toml:"firestore,omitempty" validate:"required_if=Type firestore"`
	InMemoryStorage  *InMemoryStorageConfig  `mapstructure:"in_memory,omitempty" toml:"in_memory,omitempty"`
}

type TariffServiceConfig

type TariffServiceConfig struct {
	Type string `mapstructure:"type" toml:"type" validate:"required,oneof=kwh"`
}

type TransportConfig

type TransportConfig struct {
	Type string              `mapstructure:"type" toml:"type" validate:"required,oneof=mqtt"`
	Mqtt *MqttSettingsConfig `mapstructure:"mqtt,omitempty" toml:"mqtt,omitempty" validate:"required_if=Type mqtt"`
}

Jump to

Keyboard shortcuts

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