Skip to content

Commit

Permalink
My improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Bre77 committed Aug 29, 2024
1 parent d184c7c commit ddb7bb9
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions cmd/tesla-http-proxy/main.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"bytes"
"context"
"flag"
"fmt"
Expand Down Expand Up @@ -103,15 +102,6 @@ func main() {
return
}

if tlsPublicKey, err := protocol.LoadPublicKey(httpConfig.keyFilename); err == nil {
if bytes.Equal(tlsPublicKey.Bytes(), skey.PublicBytes()) {
fmt.Fprintln(os.Stderr, "It is unsafe to use the same private key for TLS and command authentication.")
fmt.Fprintln(os.Stderr, "")
fmt.Fprintln(os.Stderr, "Generate a new TLS key for this server.")
return
}
}

log.Debug("Creating proxy")
p, err := proxy.New(context.Background(), skey, cacheSize)
if err != nil {
Expand All @@ -126,7 +116,7 @@ func main() {
// method of your implementation can perform your business logic and then, if the request is
// authorized, invoke p.ServeHTTP. Finally, replace p in the below ListenAndServeTLS call with
// an object of your newly created type.
log.Error("Server stopped: %s", http.ListenAndServeTLS(addr, httpConfig.certFilename, httpConfig.keyFilename, p))
log.Error("Server stopped: %s", http.ListenAndServe(addr, p))
}

// readConfig applies configuration from environment variables.
Expand Down
4 changes: 2 additions & 2 deletions pkg/proxy/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,12 +178,12 @@ func ExtractCommandAction(ctx context.Context, command string, params RequestPar
case "front":
return func(v *vehicle.Vehicle) error { return v.OpenFrunk(ctx) }, nil
case "rear":
return func(v *vehicle.Vehicle) error { return v.OpenTrunk(ctx) }, nil
return func(v *vehicle.Vehicle) error { return v.ActuateTrunk(ctx) }, nil
default:
return nil, &protocol.NominalError{Details: protocol.NewError("invalid_value", false, false)}
}
}
return func(v *vehicle.Vehicle) error { return v.OpenTrunk(ctx) }, nil
return func(v *vehicle.Vehicle) error { return v.ActuateTrunk(ctx) }, nil
case "charge_port_door_open":
return func(v *vehicle.Vehicle) error { return v.ChargePortOpen(ctx) }, nil
case "charge_port_door_close":
Expand Down

0 comments on commit ddb7bb9

Please sign in to comment.