mirror of
https://github.com/tobiasehlert/teslamateapi.git
synced 2026-02-27 09:54:18 +08:00
changing from commands path to command
moving function checkArrayContainsString
This commit is contained in:
@@ -63,8 +63,8 @@ func TeslaMateAPICarsCommandV1(c *gin.Context) {
|
||||
// it would be nice to find a way to retrieve api.Group
|
||||
command = (c.Request.RequestURI[len("/api/v1/cars/"+ParamCarID):])
|
||||
|
||||
if !contains(allowList, command) {
|
||||
log.Print("[warning] TeslaMateAPICarsCommand command: " + command + " not allowed")
|
||||
if !checkArrayContainsString(allowList, command) {
|
||||
c.JSON(http.StatusUnauthorized, gin.H{"error": "unauthroized"})
|
||||
return
|
||||
}
|
||||
@@ -141,15 +141,6 @@ func TeslaMateAPICarsCommandV1(c *gin.Context) {
|
||||
c.JSON(resp.StatusCode, jsonData)
|
||||
}
|
||||
|
||||
func contains(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getCommandToken() string {
|
||||
// get token from environment variable COMMAND_TOKEN
|
||||
token := getEnv("COMMAND_TOKEN", "")
|
||||
|
||||
+12
-2
@@ -80,8 +80,8 @@ func main() {
|
||||
v1.GET("/cars/:CarID/charges/:ChargeID", TeslaMateAPICarsChargesDetailsV1)
|
||||
|
||||
// v1 /api/v1/cars/:CarID/command endpoints
|
||||
v1.GET("/cars/:CarID/commands", TeslaMateAPICarsCommandV1)
|
||||
v1.POST("/cars/:CarID/commands/:Command", TeslaMateAPICarsCommandV1)
|
||||
v1.GET("/cars/:CarID/command", TeslaMateAPICarsCommandV1)
|
||||
v1.POST("/cars/:CarID/command/:Command", TeslaMateAPICarsCommandV1)
|
||||
|
||||
// v1 /api/v1/cars/:CarID/drives endpoints
|
||||
v1.GET("/cars/:CarID/drives", TeslaMateAPICarsDrivesV1)
|
||||
@@ -303,3 +303,13 @@ func fahrenheitToCelsiusNilSupport(f NullFloat64) NullFloat64 {
|
||||
f.Float64 = ((f.Float64 - 32) * 5 / 9)
|
||||
return (f)
|
||||
}
|
||||
|
||||
// checkArrayContainsString func - check if string is inside stringarray
|
||||
func checkArrayContainsString(s []string, e string) bool {
|
||||
for _, a := range s {
|
||||
if a == e {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user