Made the url used to check the token a config option
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2022-11-22 03:33:00 +01:00
parent 501775654f
commit 6f5b3d13f7
5 changed files with 14 additions and 9 deletions

View File

@@ -3,6 +3,7 @@ package google
import (
"automation/device"
"encoding/json"
"fmt"
"io"
"log"
"net/http"
@@ -34,8 +35,8 @@ type syncResponse struct {
type queryResponse struct {
RequestID string `json:"requestId"`
Payload struct {
ErrorCode string `json:"errorCode,omitempty"`
DebugString string `json:"debugString,omitempty"`
ErrorCode string `json:"errorCode,omitempty"`
DebugString string `json:"debugString,omitempty"`
Devices map[string]DeviceState `json:"devices"`
} `json:"payload"`
}
@@ -66,7 +67,7 @@ func (s *Service) getUser(authorization string) (string, int) {
return cached.Value(), http.StatusOK
}
req, err := http.NewRequest("GET", "https://login.huizinga.dev/api/oidc/userinfo", nil)
req, err := http.NewRequest("GET", fmt.Sprintf("%s/userinfo", s.oauthUrl), nil)
if err != nil {
log.Println("Failed to make request to to login server")
return "", http.StatusInternalServerError
@@ -219,7 +220,7 @@ func (s *Service) FullfillmentHandler(w http.ResponseWriter, r *http.Request) {
for errCode, details := range response.FailedDevices {
c := executeRespPayload{
Status: StatusError,
Status: StatusError,
ErrorCode: errCode,
}

View File

@@ -32,13 +32,16 @@ type Provider interface {
type Service struct {
provider Provider
deviceService *homegraph.DevicesService
cache *ttlcache.Cache[string, string]
oauthUrl string
cache *ttlcache.Cache[string, string]
}
func NewService(provider Provider, service *homegraph.Service) *Service {
func NewService(provider Provider, service *homegraph.Service, oauthUrl string) *Service {
s := Service{
provider: provider,
deviceService: homegraph.NewDevicesService(service),
oauthUrl: oauthUrl,
cache: ttlcache.New(
ttlcache.WithTTL[string, string](30 * time.Minute),
),