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

Implement centralized per venue launchpad token dispenser lambda #1

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

yenes56
Copy link

@yenes56 yenes56 commented Jan 15, 2025

Ticket: [PODAAC-6601]

Description

This PR is for initial implementation of centralized launchpad token dispenser

Overview of work done

Implement the token dispenser and integration testing.

Overview of verification done

Tested in Sandbox

Tested in SIT:

N/A

PR checklist:

  • Linted
  • Unit tests
  • Addressed Snyk vulnerabilities
  • Updated changelog
  • Tested in SIT
  • Documentation / User-Guide Updated

See Pull Request Review Checklist for pointers on reviewing this pull request

Copy link
Member

@joshgarde joshgarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey David, I think this is a good first pass! A lot of good implementation for the requirements/technical details we discussed

I have quite a few comments on the current implementation I'd like taken care of before a first release. Let me know if you have any questions or if you'd like to discuss them more in-depth

Comment on lines 39 to 42




Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's cleanup these newlines

Comment on lines 54 to 63
# Launchpad Token Dispensing Lambada timeout in secs
variable "launchpad_token_dispenser_lambda_timeout" {
type = number
default = 20
}

variable "launchpad_token_dispenser_lambda_memory_size" {
type = number
default = 128
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure we need to make these adjustable since the code is fairly minimal and deterministic. I think keeping the timeout/memory size hardcoded is fine for keeping down the number of variables to track

Comment on lines 42 to 45
# The bucket where launchpad.pfx is stored. Ex. my-sndbx-bucket
variable "launchpad_pfx_file_s3_bucket"{}
# The key to point to launchpad.pfx Ex. /folder1/folder2/launchpad.pfx
variable "launchpad_pfx_file_s3_key" {}
Copy link
Member

@joshgarde joshgarde Jan 15, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we combine these two into just "s3_uri" which combines the bucket + path as a URI?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the s3 download api requires 2 parameters - bucket name and key hence we separate them.
Otherwise, the developers using this module could configure this as
s3://bucket_name/folder1/folder2/xxx.pfx
or maybe no s3:// leading? maybe the code needs to deal with double slash or trailing slash.
It might be better to just keep bucket and key as different variables.


# sndbx, sit, uat or ops
variable "stage" {
default = "sndbx"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the default so that it has to be explicitly specified by the deployment

}

variable "region" {
default = "us-west-2"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the default so that it has to be explicitly specified by the deployment

raise e


def satisfy_minimum_alive_secs(token_json:json, minimum_alive_secs:int | None) -> bool:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minimum_alive_secs should never be None because it defaults to DEFAULT_TOKEN_MIN_ALIVE_TIME in all the function calls. Let's not make that parameter optional

try:
# When a request comes in, check dynamoDB first, if not found then get new token
token_structure_str:str = get_token_by_client_id(client_id)
if(token_structure_str is not None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't need parenthesis here

Comment on lines +139 to +142
if minimum_alive_secs is None:
logger.info(f"client passed in empty minimum_alive_secs, using default value as:"
f" {config.DEFAULT_TOKEN_MIN_ALIVE_TIME}")
minimum_alive_secs = config.DEFAULT_TOKEN_MIN_ALIVE_TIME
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need to move this logic to around line #99 so that the logic is all in one place for how this default is set?

Comment on lines 157 to 161
raise e
# return {
# "statusCode": 500,
# "body": json.dumps({"error": f"Failed to process client token. exception: {str(e)}"})
# }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this intended to be left here?

# Below code only need to deal with the case of cached entry could be found.
# The is, token_json could not be None
is_longer_than_minimum_alive_secs = satisfy_minimum_alive_secs(token_json, minimum_alive_secs)
if is_longer_than_minimum_alive_secs is True:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if this logic chain and the one above can be cleaned up a little bit. Here's what I'm thinking in (very rough) psudocode

cached_token = dynamodb.get(client_id)
if cached_token is not None and cached_token is not expired:
    return cached_token

retrieve new token from Launchpad
store new token into dynamodb
return new token

Makes the logic flow a little easier to read/follow

Copy link

@hkryeung hkryeung left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still reviewing

README.md Outdated
The installation steps involved
* Downloading the lambda artifact and placing it under the $PROJECT_ROOT/dist directory.
* Creating a tfvars file or using `TF_VAR

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo; `TF_VAR missing closing quote

README.md Outdated
| config key | description |
|--------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------|
| `stage` | prefix of lambda. If intent to deploy one TDL per env, suggested to set it as sndbx/sit/uat or ops based on the running environment |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo TDL -> LTD?

README.md Outdated
| `credentials` | full path of credential file. Ex. /User/Mynam/.aws/credentials |
| `profile` | Name of the AWS profile from the credentials file |
| `log_retention_days` | Number of days where TDL lambda will be retained |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo TDL -> LTD?

README.md Outdated
Comment on lines 116 to 118
| `launchpad_token_dispenser_lambda_memory_size` | TDL lambda memory size |
| `launchpad_token_dispenser_lambda_architectures` | TDL lambda running architecture. Current set to x86. ARM is not tested. |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo TDL -> LTD?

README.md Outdated

### Configure tfstate file
The $PROJECT_ROOT/backend directory contains sample venue.tf files being used to configure where the TDL project's tfstate file will be located.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo TDL -> LTD?


resource "aws_lambda_function" "launchpad_token_dispenser_lambda" {
filename = "../dist/token-dispenser_lambda.zip"
function_name = "${var.stage}-launchpad_token_dispenser"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make this a static name instead of a dynamic name between environments? It makes it easier to write clients against the environments if this is hardcoded

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.

4 participants