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: Update stage-deadline script with new version index #139

Merged
merged 4 commits into from
Oct 8, 2020

Conversation

kozlove-aws
Copy link
Contributor

@kozlove-aws kozlove-aws commented Sep 29, 2020

Problem:

We need to update our stage-deadline script to use index file with installers URLs, so customers can specify a version, such as 10.1.9 or 10.1.9.2, or latest and not have to enter the URL's themselves, or have the script attempt to form them on its own. The updated script should access the index, parse the JSON, and use that to determine where to download the customer's requested version.

Solution

  1. Was created lambda script that consume index file and return URLs for required product and platform.
  2. Was modified stage-script to use lambda for getting URLs to Deadline client and Docker recipe.

Testing

Were created unit tests for lambda script that covered 100% of functionality.
Was built project and tested that stage-script correctly download deadline client and Docker recipe in next cases:

  • latest versions without any parameters.
  • correct version when version is specified
  • latest possible version when specified partial version (like '10.1' or '10.1.8')

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@jusiskin jusiskin added the contribution/core This is a PR that came from AWS. label Sep 29, 2020
packages/aws-rfdk/bin/stage-deadline.ts Show resolved Hide resolved
packages/aws-rfdk/bin/stage-deadline.ts Outdated Show resolved Hide resolved
private implementsIVersionProviderProperties(value: any): boolean {
if (!value || typeof(value) !== 'object') { return false; }

// TODO: Ignore case
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you either implement these TODO's or are you going to create issues to fix them.

const productionInfoURL = 'https://downloads.thinkboxsoftware.com/version_info.json';

// eslint-disable-next-line @typescript-eslint/no-require-imports
const parsedUrl = require('url').parse(productionInfoURL);
Copy link
Contributor

Choose a reason for hiding this comment

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

do we have to use require imports here? or can we just do a normal import at the top of the file.


return new Promise((resolve, reject) => {
// eslint-disable-next-line @typescript-eslint/no-require-imports
require('https').get(options, (res: IncomingMessage) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same question for imports.

}

/**
* This method reads index file.
Copy link
Contributor

Choose a reason for hiding this comment

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

This docstring is not very useful since all it says is the name of the function.

What do we do with the read file return it ? throw it out? what do we return it as? a string? json blob?

}

private parseVersionString(versionString: string): RegExpExecArray | null {
const VALID_VERSION_REGEX = /^(0|[1-9]\d*)(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?(?:\.(0|[1-9]\d*))?$/;
Copy link
Contributor

Choose a reason for hiding this comment

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

Since this REGEX is constant could we make this a class level constant.

Also could we use /^(0|[1-9]\d*)(?:.(0|[1-9]\d*)){0,3}$/ instead. the {0,3} means 0-3 copies of the preceeding so we can use this instead of repeating the same section 3 times with the ? quantifier.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Your expression work great for validation but it return only first and last part as result of exec

export async function handler(event: CfnRequestEvent, context: LambdaContext): Promise<string> {
const versionProvider = new VersionProvider();
return await versionProvider.handler(event, context);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

missing a new line at the end of the file.

@horsmand horsmand added the pr/do-not-merge This PR should not be merged at this time. label Oct 5, 2020
@horsmand
Copy link
Contributor

horsmand commented Oct 5, 2020

Added the do not merge label because this is dependent on the version index file being made available on the downloads website first.

@kozlove-aws kozlove-aws force-pushed the consuming_index_file branch 4 times, most recently from e1a8396 to 002f8be Compare October 6, 2020 00:30
horsmand
horsmand previously approved these changes Oct 7, 2020
@horsmand horsmand removed the pr/do-not-merge This PR should not be merged at this time. label Oct 7, 2020
@horsmand
Copy link
Contributor

horsmand commented Oct 7, 2020

The index file has been published, I've removed the do not merge label. Everything looks good, approved.

// and get the matching version from the indexed version map.
for (let versionIndex = 0; versionIndex < 4; versionIndex++) {
let version: string;
if (null === requestedVersion
Copy link
Contributor

Choose a reason for hiding this comment

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

can this be changed to using optional chaining something along the lines of

requestedVersion?.[versionIndex + 1] == null

}

/**
* @inheritdoc
Copy link
Contributor

Choose a reason for hiding this comment

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

inheritdoc from what? This is a base class

Copy link
Contributor

@horsmand horsmand left a comment

Choose a reason for hiding this comment

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

Grant's comments are still unresolved, but I can see they've been addressed. Looks good to me!

@grbartel grbartel merged commit 9cbf99f into aws:mainline Oct 8, 2020
kozlove-aws referenced this pull request in kozlove-aws/aws-rfdk Oct 8, 2020
* feat: add version-provider

* feat: update stage-deadline script with new version index

* fix: move version provider logic in separate script from handler

Co-authored-by: Eugene Kozlov <kozlove@dev-dsk-kozlove-2b-2198d727.us-west-2.amazon.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants