Conversation
Co-authored-by: Tyler Burdsall <tylerburdsall@users.noreply.github.com>
Requested-by: Tyler Burdsall <tylerburdsall@users.noreply.github.com>
tylerburdsall
left a comment
There was a problem hiding this comment.
Looks good so far! We discussed offline regarding details, looks like it would be great to apply this new global override to all the available commands, along with centralizing the actual credentials provider logic since that seems to be inconsistent across commands. A great new feature nonetheless, can't wait for this to ship 💪
| data, | ||
| } => { | ||
| let cache_name = cache_name.unwrap_or(config.cache); | ||
| let auth_token = args.momento_api_key.unwrap_or(profile_auth_token); |
There was a problem hiding this comment.
TODO add similar logic to all commands that use the args.profileand credential_provider, per @tylerburdsall's comment. (Totally forgot to do this, thanks for catching that!)
| let (creds, config) = get_creds_and_config(&args.profile).await?; | ||
| let credential_provider = creds.authenticate()?; |
There was a problem hiding this comment.
TODO if possible, centralize the credential_provider logic to be shared across all commands, per @tylerburdsall's comment
There was a problem hiding this comment.
yeah, seems like you'd want to source the auth token in get_creds_and_config and/or authenticate. That way the credential provider still provides the credential!
(particularly relevant because the argument is marked global)
This PR supports a
--momento-api-keyoption for all CLI commands (exceptconfigure). If specified, the--momento-api-keyoverrides the one retrieved from the--profile(or the default profile).Huge thank-you to @tylerburdsall for the additional suggestions and use cases to expand my implementation!
Purpose
Easier to verify the scopes of temporary tokens and to test functions that require a vended, specifically formatted token. We no longer need to configure a separate Momento profile for quick tests.
Verification
1. Usage Example:
invokefunction that requires metadata-embedded tokenIn
token-vending-machinefrom the Momento Function examples, add invocation permission:After you build
web-function-token-metadataand your updatedtoken-vending-machineinto$FUNCTION_EXAMPLE_WASMS, put them to a$MOMENTO_PROFILEwith a normal, console-generated API key (super user v1 or owner v2, whatever you have handy):Finally, confirm that
token_metadatacan be invoked with your$MOMENTO_PROFILEendpoint/cache and a temporary API key:2. Usage Example: checking temporary token's scope
3. Rejection Verification:
configure --momento-api-keyBecause
configureacts differently (guides the user through creating a new profile with API key/token, endpoint, etc. instead of using an existing profile/token/endpoint), I decided to leave its implementation as-is and have it reject the--momento-api-keyoption.As seen below,
configurehides the otherwise-global--momento-api-keyhelp text and fails if it's still specified:Usage Note
If you specify the
--momento-api-keyfor any command other thaninvoke-functionand with a token generated differently than above:base64-encode the API key with your endpoint, either in your token vendor or as follows (Thank you, @kvcache and @tylerburdsall!):TMP_MOMENTO_TOKEN=$(echo '{"endpoint": "$MOMENTO_ENDPOINT", "api_key": "'$TMP_MOMENTO_TOKEN'"}' | base64 -w0)