Skip to content

Request: Better/more generic handling of API credentials #765

Description

@RHammond2

Simplify and make API credential handling more consistent

The current handling of API credentials is geared exclusively towards NLR-maintained APIs, however, there are useful components within the tooling that could be made available for the integration of other API endpoints. For example in #719, a custom implementation of the EIA API credential handling was implemented (see comments: #719 (comment)) to work around the over-specified nature of the h2integrate/resource/utilities/nlr_developer_api_keys.py. Ideally, this would be a non-resource-specific module called api_handling.py (or similar) in h2integrate/tools/ that generically specificies where and how API keys should be stored that works with NLR and other third-party tooling.

Proposed solution

  • Move h2integrate/resource/utilities/nlr_developer_api_keys.py to h2integrate/tools/api_handling.py (or similar) for API handling access availability outside of the resource package.
  • Move API handling functions in h2integrate/preprocess/eia.py to the same generic API handling module.
  • Create generic API credential querying from common locations:
    • home directory dot file (e.g. ~/.env, ~/.nlrrc, ~/.h2integraterc
    • custom locations (i.e., project directories, API-specific required file locations)
    • environment variable
  • Have endpoint-specific access handling utilize generic methods as much as possible to avoid repetitive functionality.

Alternatives considered

The only other alternative that works currently is having each new API implementation handling whenever new functionality is introduced. This works from the #719 implementation, however it was brought up in both the prototyping and review stages that it would be nice to use the existing functionality, though it was mutually agreed upon that it's out of scope to refactor the existing API handling at the same time.

Additional context

Metadata

Metadata

Assignees

Labels

Tools/UtilitiesTools and utilities that are used in H2I or for pre-processing or post-processingcode cleanupenhancementNew feature or request

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions