Fetcher returns a fetch.Interface based on the configuration. If no configuration source is set, this method returns nil, nil.
( ctx context.Context, blobConf BlobConfig, httpClientProvider httpclient.Provider, )
| 347 | // Fetcher returns a fetch.Interface based on the configuration. |
| 348 | // If no configuration source is set, this method returns nil, nil. |
| 349 | func (c FrequencyPlansConfig) Fetcher( |
| 350 | ctx context.Context, blobConf BlobConfig, httpClientProvider httpclient.Provider, |
| 351 | ) (fetch.Interface, error) { |
| 352 | // TODO: Remove detection mechanism (https://github.com/TheThingsNetwork/lorawan-stack/issues/1450) |
| 353 | configSource := c.ConfigSource |
| 354 | if configSource == "" { |
| 355 | switch { |
| 356 | case c.Static != nil: |
| 357 | configSource = "static" |
| 358 | case c.Directory != "": |
| 359 | if stat, err := os.Stat(c.Directory); err == nil && stat.IsDir() { |
| 360 | configSource = "directory" |
| 361 | break |
| 362 | } |
| 363 | fallthrough |
| 364 | case c.URL != "": |
| 365 | configSource = "url" |
| 366 | case !c.Blob.IsZero(): |
| 367 | configSource = "blob" |
| 368 | } |
| 369 | } |
| 370 | switch configSource { |
| 371 | case "static": |
| 372 | return fetch.NewMemFetcher(c.Static), nil |
| 373 | case "directory": |
| 374 | return fetch.FromFilesystem(c.Directory), nil |
| 375 | case "url": |
| 376 | httpClient, err := httpClientProvider.HTTPClient(ctx, httpclient.WithCache(true)) |
| 377 | if err != nil { |
| 378 | return nil, err |
| 379 | } |
| 380 | return fetch.FromHTTP(httpClient, c.URL) |
| 381 | case "blob": |
| 382 | b, err := blobConf.Bucket(ctx, c.Blob.Bucket, httpClientProvider) |
| 383 | if err != nil { |
| 384 | return nil, err |
| 385 | } |
| 386 | return fetch.FromBucket(ctx, b, c.Blob.Path), nil |
| 387 | default: |
| 388 | return nil, nil |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | // InteropClient represents the client-side interoperability through LoRaWAN Backend Interfaces configuration. |
| 393 | type InteropClient struct { |