File tree Expand file tree Collapse file tree 5 files changed +23
-8
lines changed
Expand file tree Collapse file tree 5 files changed +23
-8
lines changed Original file line number Diff line number Diff line change 55 "protocolVersion" : " 1.6" ,
66 "serverUri" : " example.com" ,
77 "maxChargingTime" : 5 ,
8+ "basicAuthUser" : " " ,
9+ "basicAuthPass" : " " ,
810 "ocpp" : {
911 "vendor" : " UL FE" ,
1012 "model" : " ChargePi"
Original file line number Diff line number Diff line change @@ -66,6 +66,8 @@ Example settings:
6666 "id" : " ChargePi" ,
6767 "protocolVersion" : " 1.6" ,
6868 "serverUri" : " example.com" ,
69+ "basicAuthUser" : " " ,
70+ "basicAuthPass" : " " ,
6971 "maxChargingTime" : 5 ,
7072 "ocpp" : {
7173 "vendor" : " UL FE" ,
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ package util
22
33import (
44 "fmt"
5+ "github.com/agrison/go-commons-lang/stringUtils"
56 ocpp16 "github.com/lorenzodonini/ocpp-go/ocpp1.6"
67 "github.com/lorenzodonini/ocpp-go/ocpp1.6/core"
78 "github.com/lorenzodonini/ocpp-go/ocpp1.6/firmware"
@@ -35,7 +36,7 @@ func CreateConnectionUrl(point settings.ChargePoint) string {
3536}
3637
3738// CreateClient creates a Websocket client based on the settings.
38- func CreateClient (tlsConfig settings.TLS ) * ws.Client {
39+ func CreateClient (basicAuthUser , basicAuthPass string , tlsConfig settings.TLS ) * ws.Client {
3940 var (
4041 client = ws .NewClient ()
4142 clientConfig = ws .NewClientTimeoutConfig ()
@@ -54,6 +55,11 @@ func CreateClient(tlsConfig settings.TLS) *ws.Client {
5455 client = tls .GetTLSClient (tlsConfig .CACertificatePath , tlsConfig .ClientCertificatePath , tlsConfig .ClientKeyPath )
5556 }
5657
58+ // If HTTP basic auth is provided, set it in the Websocket client
59+ if stringUtils .IsNoneEmpty (basicAuthUser , basicAuthPass ) {
60+ client .SetBasicAuth (basicAuthUser , basicAuthPass )
61+ }
62+
5763 client .SetTimeoutConfig (clientConfig )
5864 return client
5965}
Original file line number Diff line number Diff line change @@ -84,8 +84,11 @@ func (cp *ChargePoint) Init(settings *settings.Settings) {
8484 var (
8585 info = settings .ChargePoint .Info
8686 tlsConfig = settings .ChargePoint .TLS
87- wsClient = chargePointUtil .CreateClient (tlsConfig )
88- logInfo = log .WithFields (log.Fields {
87+ wsClient = chargePointUtil .CreateClient (
88+ settings .ChargePoint .Info .BasicAuthUsername ,
89+ settings .ChargePoint .Info .BasicAuthPassword ,
90+ tlsConfig )
91+ logInfo = log .WithFields (log.Fields {
8992 "chargePointId" : info .Id ,
9093 })
9194 )
Original file line number Diff line number Diff line change @@ -14,11 +14,13 @@ type (
1414 }
1515
1616 Info struct {
17- Id string `fig:"Id" validate:"required" json:"id,omitempty" yaml:"id" mapstructure:"id"`
18- ProtocolVersion string `fig:"ProtocolVersion" default:"1.6" json:"ProtocolVersion,omitempty" yaml:"ProtocolVersion" mapstructure:"ProtocolVersion"`
19- ServerUri string `fig:"ServerUri" validate:"required" json:"ServerUri,omitempty" yaml:"ServerUri" mapstructure:"ServerUri"`
20- MaxChargingTime int `fig:"MaxChargingTime" default:"180" json:"MaxChargingTime,omitempty" yaml:"MaxChargingTime" mapstructure:"MaxChargingTime"`
21- OCPPInfo OCPPInfo `fig:"ocpp" json:"ocpp" yaml:"ocpp" mapstructure:"ocpp"`
17+ Id string `fig:"Id" validate:"required" json:"id,omitempty" yaml:"id" mapstructure:"id"`
18+ ProtocolVersion string `fig:"ProtocolVersion" default:"1.6" json:"ProtocolVersion,omitempty" yaml:"ProtocolVersion" mapstructure:"ProtocolVersion"`
19+ ServerUri string `fig:"ServerUri" validate:"required" json:"ServerUri,omitempty" yaml:"ServerUri" mapstructure:"ServerUri"`
20+ BasicAuthUsername string `fig:"basicAuthUser" json:"basicAuthUser,omitempty" yaml:"basicAuthUser" mapstructure:"basicAuthUser"`
21+ BasicAuthPassword string `fig:"basicAuthPass" json:"basicAuthPass,omitempty" yaml:"basicAuthPass" mapstructure:"basicAuthPass"`
22+ MaxChargingTime int `fig:"MaxChargingTime" default:"180" json:"MaxChargingTime,omitempty" yaml:"MaxChargingTime" mapstructure:"MaxChargingTime"`
23+ OCPPInfo OCPPInfo `fig:"ocpp" json:"ocpp" yaml:"ocpp" mapstructure:"ocpp"`
2224 }
2325
2426 TLS struct {
You can’t perform that action at this time.
0 commit comments