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

CDS download #3976

Merged
merged 5 commits into from
Jun 29, 2020
Merged

CDS download #3976

merged 5 commits into from
Jun 29, 2020

Conversation

lancewf
Copy link
Contributor

@lancewf lancewf commented Jun 24, 2020

🔩 Description: What code changed, and why?

When the "download" button is clicked on a content item that item will be downloaded to the browser. This is streaming the file from a third-party source and streaming it to the user's browser.

⛓️ Related Resources

#3899

👟 How to Build and Test the Change

  1. build components/automate-gateway && build components/automate-cds && build components/automate-ui-devproxy && start_all_services && start_automate_ui_background && ui_logs
  2. Go to https://a2-dev.test/cds
  3. Click download on the three different content items listed and ensure that they download and have different file names. (The filename will be different but they all download this file https://github.com/dev-sec/apache-baseline/archive/master.tar.gz)

✅ Checklist

Signed-off-by: Lance Finfrock <[email protected]>
@lancewf lancewf self-assigned this Jun 24, 2020
@lancewf lancewf changed the title init CDS download Jun 24, 2020
@@ -20,3 +20,7 @@ message ContentItem {
message InstallContentItem {

}

message DownloadContentItem {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Delete this. It is not needed.

Lance Finfrock added 4 commits June 26, 2020 13:36
Signed-off-by: Lance Finfrock <[email protected]>
Signed-off-by: Lance Finfrock <[email protected]>
Signed-off-by: Lance Finfrock <[email protected]>
Signed-off-by: Lance Finfrock <[email protected]>
@@ -15,6 +15,7 @@ message ContentItem {
string version = 5;
repeated string platforms = 6;
bool can_be_installed = 7;
string filename = 8;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For a content item, added a filename field so when it is downloaded it can have the correct name.

)

// Chosen somewhat arbitrarily to be a "good enough" value.
// See: https://github.com/chef/automate/pull/1143#discussion_r170428374
const streamBufferSize = 262144
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copied from

log.Infof("DownloadContentItem: Downloading content item with ID %s ...", request.Id)

// Get the data
resp, err := http.Get("https://github.com/dev-sec/apache-baseline/archive/master.tar.gz")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This will later be updated to pull from the SaaS CDS with the token.


reader := bufio.NewReaderSize(resp.Body, streamBufferSize)

_, err = reader.WriteTo(writer)
Copy link
Contributor Author

@lancewf lancewf Jun 29, 2020

Choose a reason for hiding this comment

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

This streams down and streams up the data. To test this change the streamBufferSize to 100.

}
w.Write(data.GetContent()) // nolint: errcheck
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Streaming from automate-cds -> automate-gateway -> client.

@@ -9,7 +9,10 @@ export enum CdsActionTypes {
GET_CONTENT_ITEMS_FAILURE = 'CDS::GET::CONTENT_ITEMS::FAILURE',
INSTALL_CONTENT_ITEM = 'CDS::INSTALL::CONTENT_ITEM',
INSTALL_CONTENT_ITEM_SUCCESS = 'CDS::INSTALL::CONTENT_ITEM::SUCCESS',
INSTALL_CONTENT_ITEM_FAILURE = 'CDS::INSTALL::CONTENT_ITEM::FAILURE'
INSTALL_CONTENT_ITEM_FAILURE = 'CDS::INSTALL::CONTENT_ITEM::FAILURE',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

For all the UI code below. The file is downloaded in the effects file. For an error or success, a message is shown in the banner.

@lancewf lancewf requested a review from a team June 29, 2020 20:40
@lancewf lancewf marked this pull request as ready for review June 29, 2020 20:40
Copy link

@vjeffrey vjeffrey left a comment

Choose a reason for hiding this comment

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

🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants