Skip to content

Commit

Permalink
first pass at script
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesReate committed Feb 3, 2025
1 parent ee15ce0 commit 54a775d
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/devices-api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func main() {
subcommands.Register(&autoPiKTableDeleteCmd{logger: logger, container: deps}, "device integrations")
subcommands.Register(&startSDTask{logger: logger, container: deps, settings: settings, pdb: pdb}, "device integrations")
subcommands.Register(&startIntegrationTask{logger: logger, container: deps, settings: settings, pdb: pdb}, "device integrations")
subcommands.Register(&smartcarStopConnectionsCmd{logger: logger, settings: settings, pdb: pdb, smartcarTaskSvc: services.NewSmartcarTaskService(&settings, deps.getKafkaProducer())}, "device integrations")

subcommands.Register(&populateESDDDataCmd{logger: logger, settings: settings, pdb: pdb, esInstance: deps.getElasticSearchService(), ddSvc: deps.getDeviceDefinitionService()}, "populate data")
subcommands.Register(&populateESRegionDataCmd{logger: logger, settings: settings, pdb: pdb, esInstance: deps.getElasticSearchService(), ddSvc: deps.getDeviceDefinitionService()}, "populate data")
Expand Down
60 changes: 60 additions & 0 deletions cmd/devices-api/smartcar_stop_connections.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package main

import (
"context"
"flag"
"fmt"
"github.com/DIMO-Network/devices-api/internal/config"
"github.com/DIMO-Network/devices-api/internal/services"
"github.com/DIMO-Network/devices-api/models"
"github.com/DIMO-Network/shared/db"
"github.com/google/subcommands"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"

Check failure on line 13 in cmd/devices-api/smartcar_stop_connections.go

View workflow job for this annotation

GitHub Actions / tests

"github.com/rs/zerolog/log" imported and not used

Check failure on line 13 in cmd/devices-api/smartcar_stop_connections.go

View workflow job for this annotation

GitHub Actions / tests

"github.com/rs/zerolog/log" imported and not used

Check failure on line 13 in cmd/devices-api/smartcar_stop_connections.go

View workflow job for this annotation

GitHub Actions / lint

"github.com/rs/zerolog/log" imported and not used
"github.com/volatiletech/sqlboiler/v4/boil"
)

type smartcarStopConnectionsCmd struct {
logger zerolog.Logger
settings config.Settings
pdb db.Store
smartcarTaskSvc services.SmartcarTaskService
}

func (*smartcarStopConnectionsCmd) Name() string { return "smartcar-stop-connections" }
func (*smartcarStopConnectionsCmd) Synopsis() string {
return "stops smartcar connections from a csv file with SC VIN's. Stops Polling. Marks integration as auth failure."
}
func (*smartcarStopConnectionsCmd) Usage() string {
return `smartcar-stop-connections`
}

func (p *smartcarStopConnectionsCmd) SetFlags(_ *flag.FlagSet) {

}

func (p *smartcarStopConnectionsCmd) Execute(ctx context.Context, _ *flag.FlagSet, _ ...interface{}) subcommands.ExitStatus {
const filename = "smartcar_stop_connections.csv"
// open csv file
// read VIN's, get the user device api integration filtered by smartcar and get the relation to userdevice

return subcommands.ExitSuccess
}

func (p *smartcarStopConnectionsCmd) stopConnections(ctx context.Context, scInt *models.UserDeviceAPIIntegration) error {
if scInt.R.UserDevice == nil {
return fmt.Errorf("failed to find user device %s for integration %s", scInt.UserDeviceID, scInt.IntegrationID)
}
if !scInt.TaskID.Valid {
return fmt.Errorf("failed to stop device integration polling; invalid task id")
}
err := p.smartcarTaskSvc.StopPoll(scInt)
if err != nil {
return fmt.Errorf("failed to stop smartcar poll: %w", err)
}

scInt.Status = models.UserDeviceAPIIntegrationStatusAuthenticationFailure
if _, err := scInt.Update(ctx, p.pdb.DBS().Writer, boil.Infer()); err != nil {
return fmt.Errorf("failed to update integration table; task id: %s; %w", scInt.TaskID.String, err)
}
}

Check failure on line 60 in cmd/devices-api/smartcar_stop_connections.go

View workflow job for this annotation

GitHub Actions / tests

missing return

Check failure on line 60 in cmd/devices-api/smartcar_stop_connections.go

View workflow job for this annotation

GitHub Actions / tests

missing return

Check failure on line 60 in cmd/devices-api/smartcar_stop_connections.go

View workflow job for this annotation

GitHub Actions / lint

missing return (typecheck)

0 comments on commit 54a775d

Please sign in to comment.