petrbroz / svf-utils

Utilities for working with the SVF file format used by Autodesk Platform Services.
https://petrbroz.github.io/svf-utils/
MIT License
123 stars 53 forks source link

Add Support for Parsing APS_REGION Environment Variable #82

Open yasotnik opened 3 months ago

yasotnik commented 3 months ago

Describe the bug The svf-utils library currently does not support parsing the APS_REGION environment variable. As a result, the default region is set to US. Users who need to configure the region to EMEA or other regions are unable to do so using the current implementation.

To Reproduce Steps to reproduce the behavior:

  1. Set the APS_REGION environment variable to EMEA.
  2. Run the svf-utils library.
  3. Get back 404 along with ModelDerivativeApiError: getManifest Request failed with status : 404 and error message: undefined Observe in the logs that the region is still set to US. Which is expected because there is no way to set the region to EMEA. The resource does not exist on the US region and we always get 404 back.

More detailed error messages:

_header: 
  'GET //modelderivative/v2/designdata/{URN}/manifest HTTP/1.1\r\n' +
  'Accept: application/json, text/plain, */*\r\n' +
  'Authorization: Bearer ...' +
  'region: US\r\n' +
  'User-Agent: axios/1.7.2\r\n' +
  'Accept-Encoding: gzip, compress, deflate, br\r\n' +
  'Host: developer.api.autodesk.com\r\n' +
  'Connection: keep-alive\r\n' +
  '\r\n'
info: 03-06-2024 12:29:08:      Initializing resiliency config:  ResiliencyConfiguration (TimeOutValue: 15000) RetryCount: 5) (BackoffInterval: 10)  (CircuitBreakerInterval: 60000) 
info: 03-06-2024 12:29:08:      Entered into fetchToken 
info: 03-06-2024 12:29:08:      fetchToken Request completed successfully with status code: 200
info: 03-06-2024 12:29:08:      Entered into getManifest 
error: 03-06-2024 12:29:09:     getManifest Request failed with status : 404 and statusText : Not Found and error message: undefined
ModelDerivativeApiError: getManifest Request failed with status : 404 and error message: undefined
    at ManifestApi.<anonymous> (...svf-utils/node_modules/@aps_sdk/model-derivative/dist/api/manifest-api.js:204:27)
    at Generator.throw (<anonymous>)
    at rejected (...svf-utils/node_modules/@aps_sdk/model-derivative/dist/api/manifest-api.js:8:65)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  axiosError: AxiosError: Request failed with status code 404
      at settle (...svf-utils/node_modules/axios/dist/node/axios.cjs:1983:12)
      at IncomingMessage.handleStreamEnd (...svf-utils/node_modules/axios/dist/node/axios.cjs:3085:11)
      at IncomingMessage.emit (node:events:530:35)
      at endReadableNT (node:internal/streams/readable:1696:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
      at Axios.request (...svf-utils/node_modules/axios/dist/node/axios.cjs:4224:41)
      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
      at async ExecuteWrapper.invoke (...svf-utils/node_modules/cockatiel/dist/common/Executor.js:40:27)
      at async TimeoutPolicy.execute (...svf-utils/node_modules/cockatiel/dist/TimeoutPolicy.js:69:20)
      at async ExecuteWrapper.invoke (...svf-utils/node_modules/cockatiel/dist/common/Executor.js:40:27)
      at async RetryPolicy.execute (...svf-utils/node_modules/cockatiel/dist/RetryPolicy.js:55:28)
      at async ExecuteWrapper.invoke (...svf-utils/node_modules/cockatiel/dist/common/Executor.js:40:27)
      at async CircuitBreakerPolicy.execute (...svf-utils/node_modules/cockatiel/dist/CircuitBreakerPolicy.js:115:32) {
    code: 'ERR_BAD_REQUEST'
response: {
  status: 404,
  statusText: 'Not Found',
  headers: [Object [AxiosHeaders]],
  config: [Object],
  request: [ClientRequest],
  data: ''
}

While using something like postman and passing region=EMEA we can retrieve our resource successfully.

Expected behavior The svf-utils library should correctly parse the APS_REGION environment variable and configure the region accordingly. For example, if APS_REGION is set to EMEA, the library should use the EMEA region instead of the default US region.

Environment :

Proposed Solution Add a mechanism to parse the APS_REGION environment variable and configure the region accordingly. Ensure that this variable can override the default region settings in the library. Which can be done by utilising region parameter in readers.ts::213 FromDerivativeService function.

Thank you for your attention and thank you for a great library! I will try to fix it and open a PR.