Skip to content

Commit

Permalink
Merge pull request #3 from ChargePi/extension-keys
Browse files Browse the repository at this point in the history
Security extension and Plug and Charge configuration variables
  • Loading branch information
xBlaz3kx authored Apr 1, 2024
2 parents fe1b922 + 28332f2 commit 4926267
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ A library for managing OCPP 1.6 and 2.0.1 variables, with mandatory key and cust
## Installing

```bash
go get github.com/xBlaz3kx/ocppManager-go
go get github.com/ChargePi/ocppManager-go
```

## ⚡ Usage
Expand All @@ -19,7 +19,7 @@ import (
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
log "github.com/sirupsen/logrus"
"github.com/xBlaz3kx/ocppManager-go/ocpp_v16"
"github.com/ChargePi/ocppManager-go/ocpp_v16"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion examples/v16/example.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package main

import (
"github.com/ChargePi/ocppManager-go/ocpp_v16"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
"github.com/lorenzodonini/ocpp-go/ocpp1.6/smartcharging"
log "github.com/sirupsen/logrus"
"github.com/xBlaz3kx/ocppManager-go/ocpp_v16"
)

func main() {
Expand Down
14 changes: 8 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
module github.com/xBlaz3kx/ocppManager-go
module github.com/ChargePi/ocppManager-go

go 1.18

replace github.com/lorenzodonini/ocpp-go v0.18.0 => github.com/ChargePi/ocpp-go v0.18.1

require (
github.com/lorenzodonini/ocpp-go v0.16.0
github.com/samber/lo v1.38.1
github.com/lorenzodonini/ocpp-go v0.18.0
github.com/samber/lo v1.39.0
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.7.0
github.com/stretchr/testify v1.9.0
)

require (
Expand All @@ -18,7 +20,7 @@ require (
github.com/leodido/go-urn v1.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 // indirect
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 // indirect
gopkg.in/go-playground/validator.v9 v9.30.0 // indirect
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
17 changes: 17 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/ChargePi/ocpp-go v0.0.0-20240329224858-e5ac6a569a7f/go.mod h1:ZynYDWGw6CslG3vyPuucLsy6AyE+h3XXYlr39jhNiQY=
github.com/ChargePi/ocpp-go v0.18.1/go.mod h1:ZynYDWGw6CslG3vyPuucLsy6AyE+h3XXYlr39jhNiQY=
github.com/Shopify/toxiproxy v2.1.4+incompatible h1:TKdv8HiTLgE5wdJuEML90aBgNWsokNbMijUGhmcoBJc=
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand All @@ -21,25 +23,39 @@ github.com/leodido/go-urn v1.1.0 h1:Sm1gr51B1kKyfD2BlRcLSiEkffoG96g6TPv6eRoEiB8=
github.com/leodido/go-urn v1.1.0/go.mod h1:+cyI34gQWZcE1eQU7NVgKkkzdXDQHr1dBMtdAPozLkw=
github.com/lorenzodonini/ocpp-go v0.16.0 h1:+MsMvmZfUi0ac5jXS/Bevn7afM8UNUUiGjMbtwv4SgI=
github.com/lorenzodonini/ocpp-go v0.16.0/go.mod h1:EiMdBqW0YO2Yq1JICuNxBZBaV5V4ygZM+C/h/6Xqu44=
github.com/lorenzodonini/ocpp-go v0.18.0 h1:XhsKAzrG/1QJym2SYyiwTzr4cOa8geN8qSid3MFuiQ4=
github.com/lorenzodonini/ocpp-go v0.18.0/go.mod h1:ZynYDWGw6CslG3vyPuucLsy6AyE+h3XXYlr39jhNiQY=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/relvacode/iso8601 v1.3.0/go.mod h1:FlNp+jz+TXpyRqgmM7tnzHHzBnz776kmAH2h3sZCn0I=
github.com/samber/lo v1.38.1 h1:j2XEAqXKb09Am4ebOg31SpvzUTTs6EN3VfgeLUhPdXM=
github.com/samber/lo v1.38.1/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/samber/lo v1.39.0 h1:4gTz1wUhNYLhFSKl6O+8peW0v2F4BCY034GRpU9WnuA=
github.com/samber/lo v1.39.0/go.mod h1:+m/ZKRl6ClXCE2Lgf3MsQlWfh4bn1bz6CXEOxnEXnEA=
github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.4.0 h1:M2gUjqZET1qApGOWNSnZ49BAIMX4F/1plDv3+l31EJ4=
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM=
golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8 h1:0A+M6Uqn+Eje4kHMK80dtF3JCXC4ykBgQG4Fe06QRhQ=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418 h1:9vYwv7OjYaky/tlAeD7C4oC9EsPTlaFl1H2jS++V+ME=
golang.org/x/sys v0.0.0-20220804214406-8e32c043e418/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
Expand All @@ -50,3 +66,4 @@ gopkg.in/go-playground/validator.v9 v9.30.0/go.mod h1:+c9/zcJMFNgbLvly1L1V+PpxWd
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
24 changes: 20 additions & 4 deletions ocpp_v16/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func DefaultCoreConfiguration() []core.ConfigurationKey {
},
{
Key: NumberOfConnectors.String(),
Readonly: false,
Readonly: true,
Value: lo.ToPtr("1"),
},
{
Expand All @@ -122,7 +122,7 @@ func DefaultCoreConfiguration() []core.ConfigurationKey {
},
{
Key: ConnectorPhaseRotation.String(),
Readonly: false,
Readonly: true,
Value: lo.ToPtr("Unknown"),
},
{
Expand Down Expand Up @@ -190,12 +190,12 @@ func DefaultLocalAuthConfiguration() []core.ConfigurationKey {
{
Key: LocalAuthListMaxLength.String(),
Readonly: true,
Value: lo.ToPtr("10"),
Value: lo.ToPtr("100"),
},
{
Key: SendLocalListMaxLength.String(),
Readonly: true,
Value: lo.ToPtr("10"),
Value: lo.ToPtr("100"),
},
}
}
Expand Down Expand Up @@ -255,6 +255,22 @@ func (config *Config) UpdateKey(key string, value *string) error {
return nil
}

// UpdateKeyReadability updates whether the key is updatable or not.
func (config *Config) UpdateKeyReadability(key string, readable bool) error {
log.Debugf("Updating key readability %s", key)

// Find the index of the key
_, index, isFound := lo.FindIndexOf(config.Keys, func(item core.ConfigurationKey) bool {
return item.Key == key
})
if !isFound {
return ErrKeyNotFound
}

config.Keys[index].Readonly = readable
return nil
}

// GetConfigurationValue Get the value of specified configuration variable in String format.
func (config *Config) GetConfigurationValue(key string) (*string, error) {
log.Debugf("Getting key %s", key)
Expand Down
23 changes: 23 additions & 0 deletions ocpp_v16/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ const (
ChargingScheduleMaxPeriods = Key("ChargingScheduleMaxPeriods")
MaxChargingProfilesInstalled = Key("MaxChargingProfilesInstalled")
ConnectorSwitch3to1PhaseSupported = Key("ConnectorSwitch3to1PhaseSupported")

/* ----------------- ISO15118 keys ----------------------- */
CentralContractValidationAllowed = Key("CentralContractValidationAllowed")
CertificateSignedMaxChainSize = Key("CertificateSignedMaxChainSize")
CertSigningWaitMinimum = Key("CertSigningWaitMinimum")
CertSigningRepeatTimes = Key("CertSigningRepeatTimes")
CertificateStoreMaxLength = Key("CertificateStoreMaxLength")
ContractValidationOffline = Key("ContractValidationOffline")
ISO15118PnCEnabled = Key("ISO15118PnCEnabled")

/* ----------------- Security extension keys ----------------------- */
AuthorizationData = Key("AuthorizationData")
AdditionalRootCertificateCheck = Key("AdditionalRootCertificateCheck")
CpoName = Key("CpoName")
SecurityProfile = Key("SecurityProfile")
)

var (
Expand Down Expand Up @@ -108,6 +123,13 @@ var (
MandatoryFirmwareKeys = []Key{
SupportedFileTransferProtocols,
}

MandatoryISO15118Keys = []Key{
ISO15118PnCEnabled,
ContractValidationOffline,
}

// Security extension does not have any mandatory keys
)

func GetMandatoryKeysForProfile(profiles ...string) []Key {
Expand All @@ -123,6 +145,7 @@ func GetMandatoryKeysForProfile(profiles ...string) []Key {
mandatoryKeys = append(mandatoryKeys, MandatoryLocalAuthKeys...)
case firmware.ProfileName:
mandatoryKeys = append(mandatoryKeys, MandatoryFirmwareKeys...)
// todo IS15118 mandatory keys validation
}
}

Expand Down
24 changes: 12 additions & 12 deletions ocpp_v16/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type (
GetConfiguration() ([]core.ConfigurationKey, error)
}

ManagerV1 struct {
ManagerV16 struct {
supportedProfiles []string
ocppConfig *Config
mandatoryKeys []Key
Expand All @@ -34,7 +34,7 @@ type (
}
)

func NewV16ConfigurationManager(defaultConfiguration Config, profiles ...string) (*ManagerV1, error) {
func NewV16ConfigurationManager(defaultConfiguration Config, profiles ...string) (*ManagerV16, error) {
mandatoryKeys := GetMandatoryKeysForProfile(profiles...)

// Validate default configuration
Expand All @@ -43,7 +43,7 @@ func NewV16ConfigurationManager(defaultConfiguration Config, profiles ...string)
return nil, err
}

return &ManagerV1{
return &ManagerV16{
ocppConfig: &defaultConfiguration,
mandatoryKeys: mandatoryKeys,
onUpdateHandlers: make(map[Key]OnUpdateHandler),
Expand All @@ -52,7 +52,7 @@ func NewV16ConfigurationManager(defaultConfiguration Config, profiles ...string)
}

// SetConfiguration validates the provided and overwrites the current configuration
func (m *ManagerV1) SetConfiguration(configuration Config) error {
func (m *ManagerV16) SetConfiguration(configuration Config) error {
m.mu.Lock()
defer m.mu.Unlock()

Expand All @@ -67,17 +67,17 @@ func (m *ManagerV1) SetConfiguration(configuration Config) error {
}

// RegisterCustomKeyValidator registers a custom key validator
func (m *ManagerV1) RegisterCustomKeyValidator(validator KeyValidator) {
func (m *ManagerV16) RegisterCustomKeyValidator(validator KeyValidator) {
m.keyValidator = validator
}

// GetMandatoryKeys returns the mandatory keys for the configuration
func (m *ManagerV1) GetMandatoryKeys() []Key {
func (m *ManagerV16) GetMandatoryKeys() []Key {
return m.mandatoryKeys
}

// SetMandatoryKeys sets the mandatory keys for the configuration
func (m *ManagerV1) SetMandatoryKeys(mandatoryKeys []Key) error {
func (m *ManagerV16) SetMandatoryKeys(mandatoryKeys []Key) error {
m.mu.Lock()
defer m.mu.Unlock()

Expand All @@ -97,7 +97,7 @@ func (m *ManagerV1) SetMandatoryKeys(mandatoryKeys []Key) error {
}

// UpdateKey updates the value of a specific key
func (m *ManagerV1) UpdateKey(key Key, value *string) error {
func (m *ManagerV16) UpdateKey(key Key, value *string) error {
m.mu.Lock()
defer m.mu.Unlock()

Expand Down Expand Up @@ -128,23 +128,23 @@ func (m *ManagerV1) UpdateKey(key Key, value *string) error {
}

// GetConfiguration returns the full current configuration
func (m *ManagerV1) GetConfiguration() ([]core.ConfigurationKey, error) {
func (m *ManagerV16) GetConfiguration() ([]core.ConfigurationKey, error) {
m.mu.Lock()
defer m.mu.Unlock()

return m.ocppConfig.GetConfig(), nil
}

// GetConfigurationValue returns the value of a specific key
func (m *ManagerV1) GetConfigurationValue(key Key) (*string, error) {
func (m *ManagerV16) GetConfigurationValue(key Key) (*string, error) {
m.mu.Lock()
defer m.mu.Unlock()

return m.ocppConfig.GetConfigurationValue(key.String())
}

// ValidateKey validates a specific key by checking if there is a custom validator registered
func (m *ManagerV1) ValidateKey(key Key, value *string) error {
func (m *ManagerV16) ValidateKey(key Key, value *string) error {
if m.keyValidator == nil {
return nil
}
Expand All @@ -158,7 +158,7 @@ func (m *ManagerV1) ValidateKey(key Key, value *string) error {
}

// OnUpdateKey registers a function to call after a specific key has been updated.
func (m *ManagerV1) OnUpdateKey(key Key, handler OnUpdateHandler) error {
func (m *ManagerV16) OnUpdateKey(key Key, handler OnUpdateHandler) error {
_, err := m.ocppConfig.GetConfigurationValue(key.String())
if err != nil {
return err
Expand Down

0 comments on commit 4926267

Please sign in to comment.