Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: new account loader plugin with http auth #32

Merged
merged 4 commits into from
Jul 3, 2024

Conversation

pkazmier
Copy link
Contributor

@pkazmier pkazmier commented Jul 3, 2024

The existing account loaders in the awsrun.acctload and their respective
CLI-counterparts in awsrun.plugins.accts do not support HTTP auth:

  • awsrun.acctload.JSONAccountLoader (awsrun.plugins.accts.JSON)
  • awsrun.acctload.YAMLAccountLoader (awsrun.plugins.accts.YAML)
  • awsrun.acctload.CSVAccountLoader (awsrun.plugins.accts.CSV)

This change introduces a new account loader, which will eventually
replace those mentioned above:

  • awsrun.acctload.URLAccountLoader (awsrun.plugins.accts.URLLoader)

The new loader can parse JSON, YAML, and CSV data depending on the
parser provided (library usage) or parser specified via the parser
configuration key (CLI usage).

In addition, the new loader supports HTTP basic, digest, ntlm, and
oauth2 authentication methods depending on the auth method provided
(library usage) or auth method specified via the auth configuration
key (CLI usage).

Sample usage via the library:

# Library usage
from awsrun.acctload import *

# JSON example with basic HTTP auth
loader = URLAccountLoader(
    "https://example.com/data.json",
    parser=JSONFormatter(),
    auth=HTTPBasic(user, pw),
)

# CSV example with OAuth2 HTTP auth
loader = URLAccountLoader(
    "https://example.com/data.csv",
    parser=CSVFormatter(delimiter=","),
    auth=HTTPOAuth2("https://token.example.com", user, pw),
)

Sample usage via the CLI configuration file:

Accounts:
  plugin: awsrun.plugins.accts.URLLoader
  options:
    url: https://example.com/data.json
    parser: json
    auth: oauth2
    auth_options:
      token_url: https://token.example.com

The existing account loaders in the awsrun.acctload and their respective
CLI-counterparts in awsrun.plugins.accts do not support HTTP auth:

- awsrun.acctload.JSONAccountLoader (awsrun.plugins.accts.JSON)
- awsrun.acctload.YAMLAccountLoader (awsrun.plugins.accts.YAML)
- awsrun.acctload.CSVAccountLoader  (awsrun.plugins.accts.CSV)

This change introduces a new account loader, which will eventually
replace those mentioned above:

- awsrun.acctload.URLAccountLoader  (awsrun.plugins.accts.URLLoader)

The new loader can parse JSON, YAML, and CSV data depending on the
parser provided (library usage) or parser specified via the `parser`
configuration key (CLI usage).

In addition, the new loader supports HTTP basic, digest, ntlm, and
oauth2 authentication methods depending on the auth method provided
(library usage) or auth method specified via the `auth` configuration
key (CLI usage).

Sample usage via the library:

    # Library usage
    from awsrun.acctload import *

    # JSON example with basic HTTP auth
    loader = URLAccountLoader(
        "https://example.com/data.json",
        parser=JSONFormatter(),
        auth=HTTPBasic(user, pw),
    )

    # CSV example with OAuth2 HTTP auth
    loader = URLAccountLoader(
        "https://example.com/data.csv",
        parser=CSVFormatter(delimiter=","),
        auth=HTTPOAuth2("https://token.example.com", user, pw),
    )

Sample usage via the CLI configuration file:

    Accounts:
      plugin: awsrun.plugins.accts.URLLoader
      options:
        url: https://example.com/data.json
        parser: json
        auth: oauth2
        auth_options:
          token_url: https://token.example.com
At the time the URLLoader plug-in is instantiated, we don't know if
the URLAccountLoader will even need to make an HTTP call as it may
have cached data. So, if the user has not specified a password via
CLI args, env vars, or config file, we don't want to prematurely
prompt them unless URLAccountLoader really needs to make an HTTP
request.
@pkazmier pkazmier changed the title Plugin acctloader v2 feat: new account loader plugin with http auth Jul 3, 2024
@pkazmier pkazmier closed this Jul 3, 2024
@pkazmier pkazmier reopened this Jul 3, 2024
@pkazmier pkazmier merged commit c3c9ea1 into master Jul 3, 2024
8 checks passed
@pkazmier pkazmier deleted the plugin-acctloader-v2 branch July 3, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants