Skip to content

Commit

Permalink
Feature/SI-2449: Add Tesla Fleet API implementation to register Tesla…
Browse files Browse the repository at this point in the history
… Device implementation (#269)

* Persist auth response from tesla to redis and write tests for new function

* Add Tesla Fleet API implementation to register Tesla Device implementation

* Fix issus from PR review and implement api calls for GetVehicle and WakeUpVehicle for new fleet API, generate swagger schema

* Make version field naming consistent
  • Loading branch information
0xdev22 authored Feb 29, 2024
1 parent cb2d7e8 commit 7ef306a
Show file tree
Hide file tree
Showing 18 changed files with 717 additions and 72 deletions.
2 changes: 1 addition & 1 deletion cmd/devices-api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ func startWebAPI(logger zerolog.Logger, settings *config.Settings, pdb db.Store,
userDeviceController := controllers.NewUserDevicesController(settings, pdb.DBS, &logger, ddSvc, ddIntSvc, eventService,
smartcarClient, scTaskSvc, teslaSvc, teslaTaskService, cipher, autoPiSvc, services.NewNHTSAService(), autoPiIngest,
deviceDefinitionRegistrar, autoPiTaskService, producer, s3NFTServiceClient, autoPi, redisCache, openAI, usersClient,
ddaSvc, natsSvc, wallet, userDeviceSvc, valuationsSvc)
ddaSvc, natsSvc, wallet, userDeviceSvc, valuationsSvc, teslaFleetAPISvc)
geofenceController := controllers.NewGeofencesController(settings, pdb.DBS, &logger, producer, ddSvc)
webhooksController := controllers.NewWebhooksController(settings, pdb.DBS, &logger, autoPiSvc, ddIntSvc)
documentsController := controllers.NewDocumentsController(settings, &logger, s3ServiceClient, pdb.DBS)
Expand Down
110 changes: 109 additions & 1 deletion docs/docs.go

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

107 changes: 107 additions & 0 deletions docs/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,54 @@
}
}
},
"/integration/:tokenID/credentials": {
"post": {
"security": [
{
"ApiKeyAuth": []
},
{
"BearerAuth": []
}
],
"description": "Complete Tesla auth and get devices for authenticated user",
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"user-devices"
],
"parameters": [
{
"type": "string",
"description": "token id for integration",
"name": "tokenID",
"in": "path",
"required": true
},
{
"description": "all fields are required",
"name": "user_device",
"in": "body",
"required": true,
"schema": {
"$ref": "#/definitions/internal_controllers.CompleteOAuthExchangeRequest"
}
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/internal_controllers.CompleteOAuthExchangeResponseWrapper"
}
}
}
}
},
"/integrations": {
"get": {
"security": [
Expand Down Expand Up @@ -2985,6 +3033,45 @@
}
}
},
"internal_controllers.CompleteOAuthExchangeRequest": {
"type": "object",
"properties": {
"authorizationCode": {
"type": "string"
},
"redirectUri": {
"type": "string"
},
"region": {
"type": "string"
}
}
},
"internal_controllers.CompleteOAuthExchangeResponse": {
"type": "object",
"properties": {
"definition": {
"$ref": "#/definitions/internal_controllers.DeviceDefinition"
},
"externalId": {
"type": "string"
},
"vin": {
"type": "string"
}
}
},
"internal_controllers.CompleteOAuthExchangeResponseWrapper": {
"type": "object",
"properties": {
"vehicles": {
"type": "array",
"items": {
"$ref": "#/definitions/internal_controllers.CompleteOAuthExchangeResponse"
}
}
}
},
"internal_controllers.CreateGeofence": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3012,6 +3099,23 @@
}
}
},
"internal_controllers.DeviceDefinition": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"make": {
"type": "string"
},
"model": {
"type": "string"
},
"year": {
"type": "integer"
}
}
},
"internal_controllers.DeviceOffer": {
"type": "object",
"properties": {
Expand Down Expand Up @@ -3538,6 +3642,9 @@
},
"refreshToken": {
"type": "string"
},
"version": {
"type": "integer"
}
}
},
Expand Down
67 changes: 67 additions & 0 deletions docs/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,31 @@ definitions:
requestId:
type: string
type: object
internal_controllers.CompleteOAuthExchangeRequest:
properties:
authorizationCode:
type: string
redirectUri:
type: string
region:
type: string
type: object
internal_controllers.CompleteOAuthExchangeResponse:
properties:
definition:
$ref: '#/definitions/internal_controllers.DeviceDefinition'
externalId:
type: string
vin:
type: string
type: object
internal_controllers.CompleteOAuthExchangeResponseWrapper:
properties:
vehicles:
items:
$ref: '#/definitions/internal_controllers.CompleteOAuthExchangeResponse'
type: array
type: object
internal_controllers.CreateGeofence:
properties:
h3Indexes:
Expand All @@ -435,6 +460,17 @@ definitions:
type: string
type: array
type: object
internal_controllers.DeviceDefinition:
properties:
id:
type: string
make:
type: string
model:
type: string
year:
type: integer
type: object
internal_controllers.DeviceOffer:
properties:
offerSets:
Expand Down Expand Up @@ -812,6 +848,8 @@ definitions:
type: string
refreshToken:
type: string
version:
type: integer
type: object
internal_controllers.RegisterUserDevice:
properties:
Expand Down Expand Up @@ -1426,6 +1464,35 @@ paths:
type: array
tags:
- integrations
/integration/:tokenID/credentials:
post:
consumes:
- application/json
description: Complete Tesla auth and get devices for authenticated user
parameters:
- description: token id for integration
in: path
name: tokenID
required: true
type: string
- description: all fields are required
in: body
name: user_device
required: true
schema:
$ref: '#/definitions/internal_controllers.CompleteOAuthExchangeRequest'
produces:
- application/json
responses:
"200":
description: OK
schema:
$ref: '#/definitions/internal_controllers.CompleteOAuthExchangeResponseWrapper'
security:
- ApiKeyAuth: []
- BearerAuth: []
tags:
- user-devices
/integrations:
get:
description: gets list of integrations we have defined
Expand Down
2 changes: 1 addition & 1 deletion internal/config/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ func (s *Settings) IsProduction() bool {
type Tesla struct {
ClientID string `yaml:"CLIENT_ID"`
ClientSecret string `yaml:"CLIENT_SECRET"`
TokenURL string `yaml:"TOKEN_URL"`
TokenURL string `yaml:"TOKEN_AUTH_URL"`
FleetAPI string `yaml:"FLEET_API"`
}
Loading

0 comments on commit 7ef306a

Please sign in to comment.