-
Notifications
You must be signed in to change notification settings - Fork 71
Feature/595 outdated link to web platform download installer in prerequisites.json file #603
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
Merged
AndreyFilchenkov
merged 4 commits into
develop
from
feature/595-Outdated_link_to_WebPlatformDownload_installer_in_Prerequisites.json_file
Sep 16, 2021
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0e11bc0
#595 Implement validator for Prerequisites download links
DmitryKolinchuk 499988f
#595 Add unit tests
DmitryKolinchuk 312f02d
#595 Create a separate property for the known issue link
DmitryKolinchuk d0cc051
#595 Update warning messages to be more informative
DmitryKolinchuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
88 changes: 88 additions & 0 deletions
88
src/SIM.Sitecore9Installer/Validation/Validators/PrerequisitesDownloadLinksValidator.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| using System; | ||
| using System.Collections.Generic; | ||
| using System.Linq; | ||
| using System.Net.Http; | ||
| using SIM.Sitecore9Installer.Tasks; | ||
|
|
||
| namespace SIM.Sitecore9Installer.Validation.Validators | ||
| { | ||
| public class PrerequisitesDownloadLinksValidator : BaseValidator | ||
| { | ||
| public override string SuccessMessage => "Prerequisites download links are valid."; | ||
|
|
||
| protected virtual string TaskName => "Prerequisites"; | ||
|
|
||
| // parameter to validate the following known issue: https://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer | ||
| public virtual string WebPlatformDownload => "WebPlatformDownload"; | ||
|
|
||
| protected override IEnumerable<ValidationResult> GetErrorsForTask(Task task, IEnumerable<InstallParam> paramsToValidate) | ||
| { | ||
| string paramNamePostfix = string.Empty; | ||
| if (this.Data.ContainsKey("ParamNamePostfix")) | ||
| { | ||
| paramNamePostfix = this.Data["ParamNamePostfix"]; | ||
| } | ||
|
|
||
| List<string> paramValuePrefixes = new List<string>(); | ||
| if (this.Data.ContainsKey("ParamValuePrefixes")) | ||
| { | ||
| paramValuePrefixes = this.Data["ParamValuePrefixes"].Split('|').ToList(); | ||
| } | ||
|
|
||
| if (!string.IsNullOrEmpty(paramNamePostfix) && paramValuePrefixes.Count > 0) | ||
| { | ||
| if (task.Name.Equals(TaskName, StringComparison.InvariantCultureIgnoreCase)) | ||
| { | ||
| foreach (InstallParam installParam in paramsToValidate) | ||
| { | ||
| if (paramValuePrefixes.Any(paramValuePrefix => installParam.Value.StartsWith(paramValuePrefix, StringComparison.InvariantCultureIgnoreCase))) | ||
| { | ||
| if (!this.IsDownloadLinkValid(installParam.Value)) | ||
| { | ||
| if (installParam.Name == this.WebPlatformDownload) | ||
| { | ||
| yield return new ValidationResult(ValidatorState.Warning, | ||
| $"{TaskName}: the '{installParam.Name}' parameter contains the following invalid link that is not accessible:\n\n{installParam.Value}\n\nThis behavior looks to be related to the following known issue:\n\nhttps://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer\n\nPlease try to apply the solution mentioned there.", | ||
| null); | ||
| } | ||
| else | ||
| { | ||
| yield return new ValidationResult(ValidatorState.Warning, | ||
| $"{TaskName}: the '{installParam.Name}' parameter contains the following invalid link that is not accessible:\n\n{installParam.Value}\n\nThis behavior may occur due to similar symptoms described in the following known issue:\n\nhttps://github.com/Sitecore/Sitecore-Instance-Manager/wiki/Known-Issue-Outdated-Download-Link-to-Microsoft-Web-Platform-Installer", | ||
| null); | ||
| } | ||
| } | ||
| } | ||
| else if (installParam.Name.EndsWith(paramNamePostfix, StringComparison.InvariantCultureIgnoreCase)) | ||
| { | ||
| yield return new ValidationResult(ValidatorState.Warning, | ||
| $"{TaskName}: the '{installParam.Name}' parameter contains the following invalid value:\n\n{installParam.Value}\n\nIt should contain download link that starts with '{string.Join("' or '", paramValuePrefixes)}'.", | ||
| null); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private bool IsDownloadLinkValid(string link) | ||
| { | ||
| using (HttpClient authClient = new HttpClient()) | ||
| { | ||
| try | ||
| { | ||
| var response = authClient.SendAsync(new HttpRequestMessage(HttpMethod.Head, new Uri(link))).Result; | ||
| if (response.IsSuccessStatusCode) | ||
| { | ||
| return true; | ||
| } | ||
| } | ||
| catch | ||
| { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.