public void TestUpdateDistReference(string expected, string uri, string reference) { var config = new Mock <Config>(true, null); var actual = BucketUri.UpdateDistReference(config.Object, uri, reference); Assert.AreEqual(expected, actual); }
/// <summary> /// Process the download url, compatibility adjustments can be made in it. /// </summary> protected virtual string ProcessUri(IPackage package, string uri) { if (!string.IsNullOrEmpty(package.GetDistReference())) { uri = BucketUri.UpdateDistReference(config, uri, package.GetDistReference()); } return(uri); }
public void TestUpdateDistReferenceWithConfigDomains(string expected, string uri, string reference) { var config = new Mock <Config>(true, null); config.Setup((o) => o.Get(It.IsIn(Settings.GithubDomains), ConfigOptions.None)) .Returns(new[] { "github.example.com" }); config.Setup((o) => o.Get(It.IsIn(Settings.GitlabDomains), ConfigOptions.None)) .Returns(new[] { "gitlab.example.com" }); var actual = BucketUri.UpdateDistReference(config.Object, uri, reference); Assert.AreEqual(expected, actual); }
private void CaptureAuthentication(string uri) { var match = Regex.Match(uri, @"^https?://(?<user>[^:/]+):(?<pass>[^@/]+)@([^/]+)", RegexOptions.IgnoreCase); if (!match.Success) { return; } var origin = BucketUri.GetOrigin(config, uri); var username = match.Groups["user"].Value; var password = match.Groups["pass"].Value; io.SetAuthentication(origin, Uri.UnescapeDataString(username), Uri.UnescapeDataString(password)); }
/// <inheritdoc /> protected override int Execute(IInput input, IOutput output) { var io = GetIO(); var versionUtility = new BucketVersions(io, config, transport); Channel?storedChannel = null; foreach (var channel in new[] { Channel.Stable, Channel.Preview, Channel.Dev }) { // An unstable version will overwrite a stable version. if (input.GetOption(channel.ToString().ToLower())) { versionUtility.SetChannel(channel); storedChannel = channel; } } if (input.GetOption("set-channel-only")) { if (storedChannel != null) { io.WriteError($"Channel {storedChannel.ToString().ToLower()} has been saved."); } else { io.WriteError($"Channel not stored."); } return(ExitCodes.Normal); } if (input.GetOption("update-keys")) { return(FetchKeys(io, config)); } if (input.GetOption("rollback")) { return(Rollback(io, installDir, backupDir)); } var(lastedVersion, remoteFileUri, lastedVersionPretty, _) = versionUtility.GetLatest(); var updateVersion = input.GetArgument("version") ?? lastedVersion; var updatingWithDev = versionUtility.GetChannel() == Channel.Dev; // If it is the latest version we end the update. if (Bucket.GetVersion() == updateVersion) { io.WriteError($"<info>You are already using bucket version <comment>{Bucket.GetVersionPretty()}</comment> ({Bucket.GetVersion()},{versionUtility.GetChannel().ToString().ToLower()} channel).</info>"); CheckCleanupBackups(io, input, backupDir); return(ExitCodes.Normal); } if (string.IsNullOrEmpty(remoteFileUri)) { var remoteRelativePath = updatingWithDev ? $"/snapshot/{updateVersion}/bucket.zip" : $"/releases/{updateVersion}/bucket.zip"; remoteFileUri = $"{baseUri}{remoteRelativePath}"; } else if (!BucketUri.IsAbsoluteUri(remoteFileUri)) { remoteFileUri = new Uri(new Uri(baseUri), remoteFileUri).ToString(); } var tempFile = Path.Combine(tempDir, Path.GetFileName(remoteFileUri)); var signatureFile = updatingWithDev ? $"{home}/keys.dev.pem" : $"{home}/keys.tags.pem"; tempFile = DownloadRemoteFile(io, remoteFileUri, tempFile, signatureFile); // Clean up the backup first, so that the current version // will be the last version. CheckCleanupBackups(io, input, backupDir); try { InstalltionBucket(installDir, tempFile, backupFile); } #pragma warning disable CA1031 catch (SException ex) #pragma warning restore CA1031 { fileSystem.Delete(tempFile); io.WriteError($"<error>The file is corrupted ({ex.Message}).</error>"); io.WriteError("<error>Please re-run the self-update command to try again.</error>"); return(ExitCodes.GeneralException); } // The version number may be entered by the user. if (updateVersion == lastedVersion) { io.WriteError($"Bucket has been successfully upgraded to: <comment>{Bucket.ParseVersionPretty(lastedVersionPretty)}</comment> ({lastedVersion})"); } else { io.WriteError($"Bucket has been successfully upgraded to: <comment>{updateVersion}</comment>"); } if (fileSystem.Exists(backupFile, FileSystemOptions.File)) { io.WriteError($"Use <info>bucket self-update --rollback</info> to return to version <comment>{Bucket.GetVersionPretty()}</comment> ({Bucket.GetVersion()})"); } else { io.WriteError($"<warning>A backup of the current version could not be written to {backupFile}, no rollback possible</warning>"); } return(ExitCodes.Normal); }