Compare commits

...

5 Commits

Author SHA1 Message Date
e906efdb6c fix traefik auth plugin base config 2023-02-24 01:44:01 +01:00
e3f8352a73 fix traefik auth plugin base config 2023-02-24 00:57:02 +01:00
db07562c5a fix traefik auth plugin base config 2023-02-24 00:50:55 +01:00
57f12d3563 added traefik auth plugin base config 2023-02-24 00:43:27 +01:00
2e40ca75c9 API fix 2022-12-25 22:59:04 +01:00
4 changed files with 14 additions and 16 deletions

View File

@@ -7,8 +7,8 @@ import (
"github.com/go-redis/redis/v8"
)
func NewBasketAPI(redis *redis.Client) *BasketAPI {
return &BasketAPI{NewHttpClient(redis)}
func NewBasketAPI(ua string, redis *redis.Client) *BasketAPI {
return &BasketAPI{NewHttpClient(ua, redis)}
}
type BasketAPI struct {
@@ -18,7 +18,7 @@ type BasketAPI struct {
func (a *BasketAPI) GetBasket(basketID string) (*def.GetBasketResponse, error) {
req := &def.GetBasketRequest{BasketID: basketID}
res := new(def.GetBasketResponse)
if err := a.httpClient.SendGet("basket", "/api/v1/basket", req, res); err != nil {
if err := a.httpClient.SendGet("basket-svc", "/api/v1/basket", req, res); err != nil {
return nil, err
}
@@ -28,7 +28,7 @@ func (a *BasketAPI) GetBasket(basketID string) (*def.GetBasketResponse, error) {
func (a *BasketAPI) GetBasketItems(basketID string) ([]*def.GetBasketItemsResponse, error) {
url := fmt.Sprintf("/api/v1/basket/%s/items", basketID)
var res []*def.GetBasketItemsResponse
if err := a.httpClient.SendGet("basket", url, nil, &res); err != nil {
if err := a.httpClient.SendGet("basket-svc", url, nil, &res); err != nil {
return nil, err
}

View File

@@ -10,16 +10,13 @@ import (
"github.com/go-redis/redis/v8"
)
const (
HEADER_USER_AGENT = "order-httpclient"
)
type HttpClient struct {
ua string
redis *redis.Client
}
func NewHttpClient(redis *redis.Client) *HttpClient {
return &HttpClient{redis}
func NewHttpClient(ua string, redis *redis.Client) *HttpClient {
return &HttpClient{ua, redis}
}
func (c *HttpClient) SendGet(api, url string, data, out any) error {
@@ -67,7 +64,7 @@ func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Respo
}
req.Header.Set("Content-Type", "application/json")
req.Header.Set("User-Agent", HEADER_USER_AGENT)
req.Header.Set("User-Agent", c.ua)
res, err := client.Do(req)
if err != nil {
return nil, err
@@ -78,7 +75,7 @@ func (c *HttpClient) sendRequest(api, url, method string, data any) (*http.Respo
}
func (c *HttpClient) getApiUrl(api string) string {
ctx, key, apiAddr := context.Background(), "internal__"+api+"_ips", api
ctx, key, apiAddr := context.Background(), "internal__"+api+"__ips", api
// FIXME: key name ^^
cmd := c.redis.LLen(ctx, key)
if cmd.Err() == nil {

View File

@@ -7,8 +7,8 @@ import (
"github.com/go-redis/redis/v8"
)
func NewPricingAPI(redis *redis.Client) *PricingAPI {
return &PricingAPI{NewHttpClient(redis)}
func NewPricingAPI(ua string, redis *redis.Client) *PricingAPI {
return &PricingAPI{NewHttpClient(ua, redis)}
}
type PricingAPI struct {
@@ -18,7 +18,7 @@ type PricingAPI struct {
func (a *PricingAPI) GetProductPrice(productID int) (*def.ProductPriceResponse, error) {
url := fmt.Sprintf("/api/v1/product/%d", productID)
res := new(def.ProductPriceResponse)
if err := a.httpClient.SendGet("pricing", url, nil, res); err != nil {
if err := a.httpClient.SendGet("pricing-svc", url, nil, res); err != nil {
return nil, err
}

View File

@@ -151,10 +151,11 @@ func (s *Service) getTags() []string {
"traefik.http.routers." + s.Name + ".entryPoints=https",
"traefik.http.routers." + s.Name + ".tls=true",
"traefik.http.routers." + s.Name + ".service=" + s.Name,
"traefik.http.routers." + s.Name + ".middlewares=requestid,stripprefix_" + s.Name,
"traefik.http.routers." + s.Name + ".middlewares=auth,requestid,stripprefix_" + s.Name,
"traefik.http.services." + s.Name + ".loadbalancer.server.scheme=http",
"traefik.http.services." + s.Name + ".loadbalancer.server.port=" + strconv.Itoa(s.port),
"traefik.http.services." + s.Name + ".loadbalancer.passhostheader=false",
"traefik.http.middlewares.auth.forwardauth.address=http://identity-svc/api/v1/traefik",
"traefik.http.middlewares.requestid.plugin.requestid.headerName=X-Request-ID",
"traefik.http.middlewares.stripprefix_" + s.Name + ".stripprefix.prefixes=" + s.pathPrefix,
"traefik.tls.certificates.certfile=/certs/client.cert",