@@ -14,6 +14,8 @@ import (
1414
1515 "github.com/brocaar/chirpstack-api/go/v3/common"
1616 "github.com/brocaar/chirpstack-api/go/v3/gw"
17+ "github.com/brocaar/chirpstack-application-server/internal/logging"
18+ log "github.com/sirupsen/logrus"
1719)
1820
1921const (
@@ -35,21 +37,27 @@ type Client struct {
3537 uri string
3638 token string
3739 requestTimeout time.Duration
40+ migrated bool
3841}
3942
4043// New creates a new Geolocation client.
41- func New (uri string , token string ) * Client {
44+ func New (migrated bool , uri string , token string ) * Client {
4245 return & Client {
4346 uri : uri ,
4447 token : token ,
4548 requestTimeout : time .Second ,
49+ migrated : migrated ,
4650 }
4751}
4852
4953// TDOASingleFrame request.
5054func (c * Client ) TDOASingleFrame (ctx context.Context , rxInfo []* gw.UplinkRXInfo ) (common.Location , error ) {
5155 req := NewTDOASingleFrameRequest (rxInfo )
52- resp , err := c .apiRequest (ctx , tdoaSingleFrameEndpoint , req )
56+ endpoint := tdoaSingleFrameEndpoint
57+ if c .migrated {
58+ endpoint = "%s/api/v1/solve/tdoa"
59+ }
60+ resp , err := c .apiRequest (ctx , endpoint , req )
5361 if err != nil {
5462 return common.Location {}, errors .Wrap (err , "api request error" )
5563 }
@@ -60,7 +68,11 @@ func (c *Client) TDOASingleFrame(ctx context.Context, rxInfo []*gw.UplinkRXInfo)
6068// TDOAMultiFrame request.
6169func (c * Client ) TDOAMultiFrame (ctx context.Context , rxInfo [][]* gw.UplinkRXInfo ) (common.Location , error ) {
6270 req := NewTDOAMultiFrameRequest (rxInfo )
63- resp , err := c .apiRequest (ctx , tdoaMultiFrameEndpoint , req )
71+ endpoint := tdoaMultiFrameEndpoint
72+ if c .migrated {
73+ endpoint = "%s/api/v1/solve/tdoaMultiframe"
74+ }
75+ resp , err := c .apiRequest (ctx , endpoint , req )
6476 if err != nil {
6577 return common.Location {}, errors .Wrap (err , "api request error" )
6678 }
@@ -71,7 +83,11 @@ func (c *Client) TDOAMultiFrame(ctx context.Context, rxInfo [][]*gw.UplinkRXInfo
7183// RSSISingleFrame request.
7284func (c * Client ) RSSISingleFrame (ctx context.Context , rxInfo []* gw.UplinkRXInfo ) (common.Location , error ) {
7385 req := NewRSSISingleFrameRequest (rxInfo )
74- resp , err := c .apiRequest (ctx , rssiSingleFrameEndpoint , req )
86+ endpoint := rssiSingleFrameEndpoint
87+ if c .migrated {
88+ endpoint = "%s/api/v1/solve/rssi"
89+ }
90+ resp , err := c .apiRequest (ctx , endpoint , req )
7591 if err != nil {
7692 return common.Location {}, errors .Wrap (err , "api request error" )
7793 }
@@ -82,7 +98,11 @@ func (c *Client) RSSISingleFrame(ctx context.Context, rxInfo []*gw.UplinkRXInfo)
8298// RSSIMultiFrame request.
8399func (c * Client ) RSSIMultiFrame (ctx context.Context , rxInfo [][]* gw.UplinkRXInfo ) (common.Location , error ) {
84100 req := NewRSSIMultiFrameRequest (rxInfo )
85- resp , err := c .apiRequest (ctx , rssiMultiFrameEndpoint , req )
101+ endpoint := rssiMultiFrameEndpoint
102+ if c .migrated {
103+ endpoint = "%s/api/v1/solve/rssiMultiframe"
104+ }
105+ resp , err := c .apiRequest (ctx , endpoint , req )
86106 if err != nil {
87107 return common.Location {}, errors .Wrap (err , "api request error" )
88108 }
@@ -93,7 +113,11 @@ func (c *Client) RSSIMultiFrame(ctx context.Context, rxInfo [][]*gw.UplinkRXInfo
93113// WifiTDOASingleFrame request.
94114func (c * Client ) WifiTDOASingleFrame (ctx context.Context , rxInfo []* gw.UplinkRXInfo , aps []WifiAccessPoint ) (common.Location , error ) {
95115 req := NewWifiTDOASingleFrameRequest (rxInfo , aps )
96- resp , err := c .apiRequest (ctx , wifiTDOASingleFrameEndpoint , req )
116+ endpoint := wifiTDOASingleFrameEndpoint
117+ if c .migrated {
118+ endpoint = "%s/api/v1/solve/loraWifi"
119+ }
120+ resp , err := c .apiRequest (ctx , endpoint , req )
97121 if err != nil {
98122 return common.Location {}, errors .Wrap (err , "api request error" )
99123 }
@@ -104,7 +128,11 @@ func (c *Client) WifiTDOASingleFrame(ctx context.Context, rxInfo []*gw.UplinkRXI
104128// GNSSLR1110SingleFrame request.
105129func (c * Client ) GNSSLR1110SingleFrame (ctx context.Context , rxInfo []* gw.UplinkRXInfo , useRxTime bool , pl []byte ) (common.Location , error ) {
106130 req := NewGNSSLR1110SingleFrameRequest (rxInfo , useRxTime , pl )
107- resp , err := c .v3APIRequest (ctx , gnssLR1110SingleFrameEndpoint , req )
131+ endpoint := gnssLR1110SingleFrameEndpoint
132+ if c .migrated {
133+ endpoint = "%s/api/v1/solve/gnss_lr1110_singleframe"
134+ }
135+ resp , err := c .v3APIRequest (ctx , endpoint , req )
108136 if err != nil {
109137 return common.Location {}, errors .Wrap (err , "api request error" )
110138 }
@@ -167,12 +195,23 @@ func (c *Client) apiRequest(ctx context.Context, endpoint string, v interface{})
167195 }
168196
169197 req .Header .Set ("Content-Type" , "application/json" )
170- req .Header .Set ("Ocp-Apim-Subscription-Key" , c .token )
198+
199+ if c .migrated {
200+ req .Header .Set ("Authorization" , c .token )
201+ } else {
202+ req .Header .Set ("Ocp-Apim-Subscription-Key" , c .token )
203+ }
171204
172205 reqCtx , cancel := context .WithTimeout (ctx , c .requestTimeout )
173206 defer cancel ()
174-
175207 req = req .WithContext (reqCtx )
208+
209+ log .WithFields (log.Fields {
210+ "ctx_id" : ctx .Value (logging .ContextIDKey ),
211+ "endpoint" : endpoint ,
212+ "migrated" : c .migrated ,
213+ }).Debug ("integration/das/geolocation: making API request" )
214+
176215 httpResp , err := http .DefaultClient .Do (req )
177216 if err != nil {
178217 return resp , errors .Wrap (err , "http request error" )
@@ -210,8 +249,14 @@ func (c *Client) v3APIRequest(ctx context.Context, endpoint string, v interface{
210249
211250 reqCtx , cancel := context .WithTimeout (ctx , c .requestTimeout )
212251 defer cancel ()
213-
214252 req = req .WithContext (reqCtx )
253+
254+ log .WithFields (log.Fields {
255+ "ctx_id" : ctx .Value (logging .ContextIDKey ),
256+ "endpoint" : endpoint ,
257+ "migrated" : c .migrated ,
258+ }).Debug ("integration/das/geolocation: making API request" )
259+
215260 httpResp , err := http .DefaultClient .Do (req )
216261 if err != nil {
217262 return resp , errors .Wrap (err , "http request error" )
0 commit comments