Skip to content

Commit

Permalink
fix: use service host names instead of OS-specific host.docker.internal
Browse files Browse the repository at this point in the history
  • Loading branch information
neinkeinkaffee committed Sep 4, 2023
1 parent aa90f9a commit 29914ec
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/manager/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ urls = ["mqtt://mqtt:1883"]

[ocpi]
addr = ":9411"
external_url = "http://host.docker.internal:9411"
external_url = "http://lb:9411"
country_code = "GB"
party_id = "TWK"

Expand Down
3 changes: 3 additions & 0 deletions manager/ocpi/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@ import (
"errors"
"fmt"
"github.com/thoughtworks/maeve-csms/manager/store"
"golang.org/x/exp/slog"
"io"
"math/big"
"net/http"
)

func (o *OCPI) RegisterNewParty(ctx context.Context, url, token string) error {
reg, err := o.store.GetRegistrationDetails(ctx, token)
slog.Info("registering", "reg", reg)
if err != nil {
return err
}
if reg != nil && reg.Status == store.OcpiRegistrationStatusRegistered {
slog.Error("already registered", "token", token)
return errors.New("already registered")
}

Expand Down
2 changes: 2 additions & 0 deletions manager/ocpi/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/json"
"fmt"
"github.com/go-chi/render"
"golang.org/x/exp/slog"
"k8s.io/utils/clock"
"net/http"
"time"
Expand Down Expand Up @@ -79,6 +80,7 @@ func (s *Server) PostCredentials(w http.ResponseWriter, r *http.Request, params

err := s.ocpi.SetCredentials(r.Context(), matches[1], *creds)
if err != nil {
slog.Error("Error setting credentials", "err", err)
_ = render.Render(w, r, ErrInternalError(err))
return
}
Expand Down
4 changes: 4 additions & 0 deletions manager/store/firestore/ocpi.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import (
"context"
"fmt"
"github.com/thoughtworks/maeve-csms/manager/store"
"golang.org/x/exp/slog"
"google.golang.org/api/iterator"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)

func (s *Store) SetRegistrationDetails(ctx context.Context, token string, registration *store.OcpiRegistration) error {
slog.Info("setting registration", "token", token, "status", registration.Status)
regRef := s.client.Doc(fmt.Sprintf("OcpiRegistration/%s", token))
_, err := regRef.Set(ctx, registration)
if err != nil {
Expand All @@ -21,6 +23,7 @@ func (s *Store) SetRegistrationDetails(ctx context.Context, token string, regist
}

func (s *Store) GetRegistrationDetails(ctx context.Context, token string) (*store.OcpiRegistration, error) {
slog.Info("checking registration", "token", token)
regRef := s.client.Doc(fmt.Sprintf("OcpiRegistration/%s", token))
snap, err := regRef.Get(ctx)
if err != nil {
Expand All @@ -31,6 +34,7 @@ func (s *Store) GetRegistrationDetails(ctx context.Context, token string) (*stor
}
var registration store.OcpiRegistration
err = snap.DataTo(&registration)
slog.Info("found registration", "status", registration.Status)
if err != nil {
return nil, fmt.Errorf("map registration %s: %w", token, err)
}
Expand Down

0 comments on commit 29914ec

Please sign in to comment.