Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions charts/device-definitions-api/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@ spec:
- remoteRef:
key: {{ .Release.Namespace }}/definitions/17vin/password
secretKey: JAPAN17_VIN_PASSWORD
- remoteRef:
key: {{ .Release.Namespace }}/definitions/carvx/userid
secretKey: CAR_VX_USER_ID
- remoteRef:
key: {{ .Release.Namespace }}/definitions/carvx/apikey
secretKey: CAR_VX_API_KEY
secretStoreRef:
kind: ClusterSecretStore
name: aws-secretsmanager-secret-store
Expand Down
7 changes: 0 additions & 7 deletions cmd/device-definitions-api/bulk_update_powertrain.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,6 @@ func (p *bulkUpdatePowertrain) Execute(ctx context.Context, _ *flag.FlagSet, _ .
update, err := onChainSvc.Update(ctx, manufName, updateContract)
if err != nil {
fmt.Printf("%s: Error updating device definition: %v\n", definitionID, err)
if strings.Contains(err.Error(), "nonce too low:") {
time.Sleep(10 * time.Second)
update, err = onChainSvc.Update(ctx, manufName, updateContract)
if err != nil {
fmt.Printf("%s: Error updating device definition: %v\n", definitionID, err)
}
}
return subcommands.ExitFailure
}
fmt.Printf("%s: Updated device definition trx id: %s\nWaiting 10 seconds before next update\n", definitionID, *update)
Expand Down
26 changes: 18 additions & 8 deletions cmd/device-definitions-api/decode_vin.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,23 @@ type decodeVINCmd struct {
japan17vin bool
fromFile bool
persistToDB bool
carvx bool
}

func (*decodeVINCmd) Name() string { return "decodevin" }
func (*decodeVINCmd) Synopsis() string {
return "tries decoding a vin with chosen provider - does not insert in our db"
}
func (*decodeVINCmd) Usage() string {
return `decodevin [-dat|-drivly|-vincario|-japan17vin|-from-file] <vin 17 chars OR filaname in /tmp> <country two letter iso>`
return `decodevin [-dat|-drivly|-vincario|-japan17vin|carvx|-from-file] <vin 17 chars OR filaname in /tmp> <country two letter iso>`
}

func (p *decodeVINCmd) SetFlags(f *flag.FlagSet) {
f.BoolVar(&p.datGroup, "dat", false, "use dat group vin decoder")
f.BoolVar(&p.drivly, "drivly", false, "use drivly vin decoder")
f.BoolVar(&p.vincario, "vincario", false, "use vincario vin decoder")
f.BoolVar(&p.japan17vin, "japan17vin", false, "use japan17vin vin decoder")
f.BoolVar(&p.carvx, "carvx", false, "use carvx vin decoder")
f.BoolVar(&p.fromFile, "from-file", false, "read vin from file in /tmp directory")
f.BoolVar(&p.persistToDB, "persist-to-db", false, "persist successful vin decodings to db, table vin_numbers")
}
Expand Down Expand Up @@ -106,15 +108,15 @@ func (p *decodeVINCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interf
if wmi != nil {
dbVin.ManufacturerName = wmi.ManufacturerName
}
dt, err := models.DeviceTypes(models.DeviceTypeWhere.ID.EQ(common.DefaultDeviceType)).One(ctx, pdb.DBS().Reader)
_, err := models.DeviceTypes(models.DeviceTypeWhere.ID.EQ(common.DefaultDeviceType)).One(ctx, pdb.DBS().Reader)
if err != nil {
fmt.Println(err.Error())
return subcommands.ExitFailure
}
vinInfo := &coremodels.VINDecodingInfoData{VIN: vin}

if p.datGroup {
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, dt, coremodels.DATGroupProvider, country)
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, coremodels.DATGroupProvider, country)
// use the dat group service to decode
if err != nil {
fmt.Println(err.Error())
Expand All @@ -124,7 +126,7 @@ func (p *decodeVINCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interf
fmt.Printf("\n\nVIN Response: %+v\n", vinInfo)
}
if p.drivly {
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, dt, coremodels.DrivlyProvider, country)
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, coremodels.DrivlyProvider, country)
if err != nil {
fmt.Println(err.Error())
continue
Expand All @@ -133,16 +135,23 @@ func (p *decodeVINCmd) Execute(ctx context.Context, f *flag.FlagSet, _ ...interf
fmt.Printf("VIN Response: %+v\n", vinInfo)
}
if p.vincario {
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, dt, coremodels.VincarioProvider, country)
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, coremodels.VincarioProvider, country)
if err != nil {
fmt.Println(err.Error())
continue
}
fmt.Printf("VIN Response: %+v\n", vinInfo)
}
if p.carvx {
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, coremodels.CarVXVIN, country)
if err != nil {
fmt.Println(err.Error())
continue
}

fmt.Printf("VIN Response: %+v\n", vinInfo)
}
if p.japan17vin {
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, dt, coremodels.Japan17VIN, country)
vinInfo, err = vinDecodingService.GetVIN(ctx, vin, coremodels.Japan17VIN, country)
if err != nil {
fmt.Println(err.Error())
continue
Expand Down Expand Up @@ -240,6 +249,7 @@ func instantiateVINDecodingSvc(ctx context.Context, settings *config.Settings, l
drivlyAPI := gateways.NewDrivlyAPIService(settings)
vincarioAPI := gateways.NewVincarioAPIService(settings, logger)
jp17vinAPI := gateways.NewJapan17VINAPI(logger, settings)
carvxAPI := gateways.NewCarVxVINAPI(logger, settings)

send, err := createSender(ctx, settings, logger)
if err != nil {
Expand All @@ -257,7 +267,7 @@ func instantiateVINDecodingSvc(ctx context.Context, settings *config.Settings, l
}
deviceDefinitionOnChainService := gateways.NewDeviceDefinitionOnChainService(settings, logger, ethClient, chainID, send, pdb.DBS)

vinDecodingService := services.NewVINDecodingService(drivlyAPI, vincarioAPI, nil, logger, deviceDefinitionOnChainService, datAPI, pdb.DBS, jp17vinAPI)
vinDecodingService := services.NewVINDecodingService(drivlyAPI, vincarioAPI, nil, logger, deviceDefinitionOnChainService, datAPI, pdb.DBS, jp17vinAPI, carvxAPI)

return vinDecodingService
}
3 changes: 2 additions & 1 deletion internal/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ func Run(ctx context.Context, logger zerolog.Logger, settings *config.Settings,
fuelAPIService := gateways.NewFuelAPIService(settings, &logger)
autoIsoAPIService := gateways.NewAutoIsoAPIService(settings.AutoIsoAPIUid, settings.AutoIsoAPIKey)
japan17VINAPI := gateways.NewJapan17VINAPI(&logger, settings)
carvxAPI := gateways.NewCarVxVINAPI(&logger, settings)
registryInstance, err := contracts.NewRegistry(settings.EthereumRegistryAddress, ethClient)
if err != nil {
logger.Fatal().Err(err).Msg("Failed to create registry query instance.")
Expand All @@ -74,7 +75,7 @@ func Run(ctx context.Context, logger zerolog.Logger, settings *config.Settings,
vinRepository := repositories.NewVINRepository(pdb.DBS, registryInstance, identityAPI)

//cache services
vincDecodingService := services.NewVINDecodingService(drivlyAPIService, vincarioAPIService, autoIsoAPIService, &logger, ddOnChainService, datGroupWSService, pdb.DBS, japan17VINAPI)
vincDecodingService := services.NewVINDecodingService(drivlyAPIService, vincarioAPIService, autoIsoAPIService, &logger, ddOnChainService, datGroupWSService, pdb.DBS, japan17VINAPI, carvxAPI)
powerTrainTypeService, err := services.NewPowerTrainTypeService("powertrain_type_rule.yaml", &logger, ddOnChainService)
searchService := search.NewTypesenseAPIService(settings, &logger)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ type Settings struct {
GoogleSheetsCredentials string `yaml:"GOOGLE_SHEETS_CREDENTIALS"`
Japan17VINUser string `yaml:"JAPAN17_VIN_USER"`
Japan17VINPassword string `yaml:"JAPAN17_VIN_PASSWORD"`
CarVxUserID string `yaml:"CAR_VX_USER_ID"`
CarVxAPIKey string `yaml:"CAR_VX_API_KEY"`
}

func (s *Settings) IsProd() bool {
Expand Down
20 changes: 20 additions & 0 deletions internal/core/models/vin_decoding_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const (
AllProviders DecodeProviderEnum = ""
TeslaProvider DecodeProviderEnum = "tesla"
Japan17VIN DecodeProviderEnum = "japan17vin"
CarVXVIN DecodeProviderEnum = "carvxvin"
)

type VINDecodingInfoData struct {
Expand Down Expand Up @@ -413,3 +414,22 @@ type Japan17MMY struct {
ModelName string `json:"modelName"`
Year int `json:"year"`
}

// nolint
type CarVxResponse struct {
Data []struct {
Make string `json:"make"`
Model string `json:"model"`
Grade string `json:"grade"`
Body string `json:"body"`
Engine string `json:"engine"`
Drive string `json:"drive"`
Transmission string `json:"transmission"`
Fuel string `json:"fuel"`
ManufactureDate struct {
Year string `json:"year"`
Month string `json:"month"`
} `json:"manufacture_date"`
} `json:"data"`
Error string `json:"error"`
}
6 changes: 3 additions & 3 deletions internal/core/queries/decode_vin.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func (dc DecodeVINQueryHandler) Handle(ctx context.Context, query mediator.Messa
return resp, nil
}

dt, err := models.DeviceTypes(models.DeviceTypeWhere.ID.EQ(common.DefaultDeviceType)).One(ctx, dc.dbs().Reader)
_, err = models.DeviceTypes(models.DeviceTypeWhere.ID.EQ(common.DefaultDeviceType)).One(ctx, dc.dbs().Reader)
if err != nil {
metrics.InternalError.With(prometheus.Labels{"method": VinErrors}).Inc()
return nil, errors.Wrap(err, "failed to get device_type")
Expand All @@ -201,13 +201,13 @@ func (dc DecodeVINQueryHandler) Handle(ctx context.Context, query mediator.Messa
dbWMI, err := models.Wmis(models.WmiWhere.Wmi.EQ(wmi)).One(ctx, dc.dbs().Reader)
if err == nil && dbWMI != nil {
if dbWMI.ManufacturerName == "Tesla" {
vinInfo, err = dc.vinDecodingService.GetVIN(ctx, vin.String(), dt, coremodels.TeslaProvider, qry.Country)
vinInfo, err = dc.vinDecodingService.GetVIN(ctx, vin.String(), coremodels.TeslaProvider, qry.Country)
resp.Manufacturer = "Tesla"
}
}
// not a tesla, regular decode path
if vinInfo == nil || vinInfo.Model == "" {
vinInfo, err = dc.vinDecodingService.GetVIN(ctx, vin.String(), dt, coremodels.AllProviders, qry.Country) // this will try drivly first unless of japan
vinInfo, err = dc.vinDecodingService.GetVIN(ctx, vin.String(), coremodels.AllProviders, qry.Country) // this will try drivly first unless of japan
}

// if no luck decoding VIN, try buildingVinInfo from known data passed in, typically smartcar or software connections
Expand Down
20 changes: 10 additions & 10 deletions internal/core/queries/decode_vin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_WithExistingDD_UpdatesAt
metaData, _ := json.Marshal(metaDataInfo)
vinDecodingInfoData.MetaData = null.JSONFrom(metaData)
definitionID := dd.ID
s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo(vinDecodingInfoData.StyleName, vinDecodingInfoData.FuelType).Return("ICE")
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
buildTestTblDD(definitionID, dd.Model, int(dd.Year)), nil, nil)
Expand Down Expand Up @@ -262,7 +262,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_CreatesDD_WithMismatchWM
styleLevelPT := "PHEV"
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
nil, nil, nil) // should return nil b/c doesn't exist
s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo(vinDecodingInfoData.StyleName, vinDecodingInfoData.FuelType).Return(styleLevelPT)

trxHashHex := "0xa90868fe9364dbf41695b3b87e630f6455cfd63a4711f56b64f631b828c02b35"
Expand Down Expand Up @@ -416,7 +416,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_CreatesDD() {
styleLevelPT := "PHEV"
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
nil, nil, nil) // should return nil b/c doesn't exist
s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo(vinDecodingInfoData.StyleName, vinDecodingInfoData.FuelType).Return(styleLevelPT)

trxHashHex := "0xa90868fe9364dbf41695b3b87e630f6455cfd63a4711f56b64f631b828c02b35"
Expand Down Expand Up @@ -530,7 +530,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_WithExistingDD_AndStyleA
vinDecodingInfoData.MetaData = null.JSONFrom(metaData)
definitionID := dd.ID

s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo(vinDecodingInfoData.StyleName, vinDecodingInfoData.FuelType).Return("HEV")
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
buildTestTblDD(definitionID, dd.Model, int(dd.Year)), nil, nil)
Expand Down Expand Up @@ -624,7 +624,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_WithExistingWMI() {
vinDecodingInfoData.MetaData = null.JSONFrom(metaData)
definitionID := dd.ID

s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo(vinDecodingInfoData.StyleName, vinDecodingInfoData.FuelType).Return("HEV")
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
buildTestTblDD(definitionID, dd.Model, int(dd.Year)), nil, nil)
Expand Down Expand Up @@ -677,7 +677,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_TeslaDecode() {

definitionID := dd.ID

s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.TeslaProvider, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.TeslaProvider, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo(vinDecodingInfoData.StyleName, vinDecodingInfoData.FuelType).Return("BEV")
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
buildTestTblDD(definitionID, dd.Model, dd.Year), nil, nil)
Expand Down Expand Up @@ -775,7 +775,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_InvalidVINYear_AutoIso()
Model: "Escape",
}
definitionID := "ford_escape_2017"
s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo("", "").Return("ICE") // normally this would return ""
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
buildTestTblDD(definitionID, "Escape", 2021), nil, nil)
Expand Down Expand Up @@ -817,7 +817,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_InvalidStyleName_AutoIso
StyleName: "1",
}
definitionID := "ford_escape_2017"
s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(vinDecodingInfoData, nil)
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo("1", "").Return("ICE")
s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
buildTestTblDD(definitionID, "Escape", 2017), nil, nil)
Expand Down Expand Up @@ -857,7 +857,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Fail_DecodeErr() {
_ = dbtesthelper.SetupCreateAutoPiIntegration(s.T(), s.pdb)
_ = dbtesthelper.SetupCreateMake("Ford")

s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(nil, fmt.Errorf("unable to decode"))
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(nil, fmt.Errorf("unable to decode"))

qryResult, err := s.queryHandler.Handle(s.ctx, &DecodeVINQuery{VIN: vin, Country: country})
assert.Nil(s.T(), qryResult)
Expand All @@ -873,7 +873,7 @@ func (s *DecodeVINQueryHandlerSuite) TestHandle_Success_DecodeKnownFallback() {
_ = dbtesthelper.SetupCreateWMI(s.T(), "1FM", dm.Name, s.pdb)

definitionID := "ford_bronco_2022"
s.mockVINService.EXPECT().GetVIN(ctx, vin, gomock.Any(), coremodels.AllProviders, "USA").Times(1).Return(nil, fmt.Errorf("unable to decode"))
s.mockVINService.EXPECT().GetVIN(ctx, vin, coremodels.AllProviders, "USA").Times(1).Return(nil, fmt.Errorf("unable to decode"))
s.mockPowerTrainTypeService.EXPECT().ResolvePowerTrainFromVinInfo("", "").Return("ICE")

s.mockDeviceDefinitionOnChainService.EXPECT().GetDefinitionByID(gomock.Any(), definitionID).Return(
Expand Down
10 changes: 5 additions & 5 deletions internal/core/services/mocks/vin_decoding_service_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading