From b9ddf421010c8fb02ffdf462ef25c6cab6469f96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Sim=C3=B5es?= Date: Wed, 24 Mar 2021 13:45:35 +0000 Subject: [PATCH] Replace Bintray repo with Cloudsmith (#48) --- nanoFirmwareFlasher/CC13x26x2Firmware.cs | 2 +- ...ackageInfo.cs => CloudsmithPackageInfo.cs} | 9 ++-- nanoFirmwareFlasher/Esp32Firmware.cs | 2 +- nanoFirmwareFlasher/ExitCodes.cs | 4 +- nanoFirmwareFlasher/FirmwarePackage.cs | 52 ++++++++++++------- nanoFirmwareFlasher/Options.cs | 2 +- nanoFirmwareFlasher/Program.cs | 6 +-- nanoFirmwareFlasher/Stm32Firmware.cs | 2 +- version.json | 2 +- 9 files changed, 48 insertions(+), 33 deletions(-) rename nanoFirmwareFlasher/{BintrayPackageInfo.cs => CloudsmithPackageInfo.cs} (54%) diff --git a/nanoFirmwareFlasher/CC13x26x2Firmware.cs b/nanoFirmwareFlasher/CC13x26x2Firmware.cs index 7ad67dab..fc4c69db 100644 --- a/nanoFirmwareFlasher/CC13x26x2Firmware.cs +++ b/nanoFirmwareFlasher/CC13x26x2Firmware.cs @@ -9,7 +9,7 @@ namespace nanoFramework.Tools.FirmwareFlasher { /// - /// Class that handles the download of STM32 firmware files from Bintray. + /// Class that handles the download of STM32 firmware files from Cloudsmith. /// internal class CC13x26x2Firmware : FirmwarePackage { diff --git a/nanoFirmwareFlasher/BintrayPackageInfo.cs b/nanoFirmwareFlasher/CloudsmithPackageInfo.cs similarity index 54% rename from nanoFirmwareFlasher/BintrayPackageInfo.cs rename to nanoFirmwareFlasher/CloudsmithPackageInfo.cs index d30a16d0..1c277c4b 100644 --- a/nanoFirmwareFlasher/BintrayPackageInfo.cs +++ b/nanoFirmwareFlasher/CloudsmithPackageInfo.cs @@ -9,9 +9,12 @@ namespace nanoFramework.Tools.FirmwareFlasher { [Serializable] - internal class BintrayPackageInfo + internal class CloudsmithPackageInfo { - [JsonProperty("latest_version")] - public string LatestVersion { get; set; } + [JsonProperty("version")] + public string Version { get; set; } + + [JsonProperty("cdn_url")] + public string DownloadUrl { get; set; } } } diff --git a/nanoFirmwareFlasher/Esp32Firmware.cs b/nanoFirmwareFlasher/Esp32Firmware.cs index 6775f2ca..0cced5a2 100644 --- a/nanoFirmwareFlasher/Esp32Firmware.cs +++ b/nanoFirmwareFlasher/Esp32Firmware.cs @@ -12,7 +12,7 @@ namespace nanoFramework.Tools.FirmwareFlasher { /// - /// Class that handles the download of ESP32 firmware files from Bintray. + /// Class that handles the download of ESP32 firmware files from Cloudsmith. /// internal class Esp32Firmware : FirmwarePackage { diff --git a/nanoFirmwareFlasher/ExitCodes.cs b/nanoFirmwareFlasher/ExitCodes.cs index a5b9e6c6..2559a9e4 100644 --- a/nanoFirmwareFlasher/ExitCodes.cs +++ b/nanoFirmwareFlasher/ExitCodes.cs @@ -202,9 +202,9 @@ public enum ExitCodes : int E9004 = 9004, /// - /// Can't find the target in the Bintray repository. + /// Can't find the target in Cloudsmith repository. /// - [Display(Name = "Can't find the target in the Bintray repository.")] + [Display(Name = "Can't find the target in Cloudsmith repository.")] E9005 = 9005, /// diff --git a/nanoFirmwareFlasher/FirmwarePackage.cs b/nanoFirmwareFlasher/FirmwarePackage.cs index 9183c2b9..f303aa4d 100644 --- a/nanoFirmwareFlasher/FirmwarePackage.cs +++ b/nanoFirmwareFlasher/FirmwarePackage.cs @@ -5,27 +5,28 @@ using Newtonsoft.Json; using System; +using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; -using System.Net; using System.Net.Http; using System.Text.RegularExpressions; +using System.Web; namespace nanoFramework.Tools.FirmwareFlasher { /// - /// Abstract base class that handles the download and extraction of firmware file from Bintray. + /// Abstract base class that handles the download and extraction of firmware file from Cloudsmith. /// internal abstract class FirmwarePackage : IDisposable { // HttpClient is intended to be instantiated once per application, rather than per-use. - static HttpClient _bintrayClient = new HttpClient(); + static HttpClient _cloudsmithClient = new HttpClient(); /// - /// Uri of Bintray API + /// Uri of Cloudsmith API /// - internal const string _bintrayApiPackages = "https://api.bintray.com/packages/nfbot"; + internal const string _cloudsmithPackages = "https://api.cloudsmith.io/v1/packages/net-nanoframework"; internal const string _refTargetsDevRepo = "nanoframework-images-dev"; internal const string _refTargetsStableRepo = "nanoframework-images"; @@ -68,9 +69,17 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() { string fwFileName = null; + // query URL + // https://api.cloudsmith.io/v1/packages/net-nanoframework/REPO-NAME-HERE/?page=1&query=/PACKAGE-NAME-HERE latest + + // download URL + // https://dl.cloudsmith.io/public/net-nanoframework/REPO-NAME-HERE/raw/names/PACKAGE-NAME-HERE/versions/VERSION-HERE/ST_STM32F429I_DISCOVERY-1.6.2-preview.9.zip + // reference targets var repoName = _stable ? _refTargetsStableRepo : _refTargetsDevRepo; - string requestUri = $"{_bintrayApiPackages}/{repoName}/{_targetName}"; + string requestUri = $"{_cloudsmithPackages}/{repoName}/?page=1&query={_targetName} latest"; + + string downloadUrl = string.Empty; // flag to signal if the work-flow step was successful bool stepSuccesful = false; @@ -134,9 +143,12 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() Console.Write($"Trying to find {_targetName} in {(_stable ? "stable" : "developement")} repository..."); } - HttpResponseMessage response = await _bintrayClient.GetAsync(requestUri); + HttpResponseMessage response = await _cloudsmithClient.GetAsync(requestUri); - if (response.StatusCode == HttpStatusCode.NotFound) + var responseBody = await response.Content.ReadAsStringAsync(); + + // check for empty array + if (responseBody == "[]") { if (Verbosity >= VerbosityLevel.Normal) { @@ -145,12 +157,12 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() } // try with community targets - requestUri = $"{_bintrayApiPackages}/{_communityTargetsepo}/{_targetName}"; + requestUri = $"{_cloudsmithPackages}/{_communityTargetsepo}/?page=1&query={_targetName} latest"; repoName = _communityTargetsepo; - response = await _bintrayClient.GetAsync(requestUri); + response = await _cloudsmithClient.GetAsync(requestUri); - if (response.StatusCode == HttpStatusCode.NotFound) + if (responseBody == "[]") { if (Verbosity >= VerbosityLevel.Normal) { @@ -167,16 +179,18 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() Console.WriteLine($"OK"); } - // read and parse response - string responseBody = await response.Content.ReadAsStringAsync(); - BintrayPackageInfo packageInfo = JsonConvert.DeserializeObject(responseBody); + // parse response + List packageInfo = JsonConvert.DeserializeObject>(responseBody); // if no specific version was requested, use latest available if (string.IsNullOrEmpty(_fwVersion)) { - _fwVersion = packageInfo.LatestVersion; + _fwVersion = packageInfo.ElementAt(0).Version; } + // grab download URL + downloadUrl = packageInfo.ElementAt(0).DownloadUrl; + // set exposed property Version = _fwVersion; @@ -184,7 +198,7 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() } catch { - // exception with download, assuming it's something with network connection or Bintray API + // exception with download, assuming it's something with network connection or Cloudsmith API } } @@ -222,9 +236,7 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() try { // setup and perform download request - requestUri = $"https://dl.bintray.com/nfbot/{repoName}/{fwFileName}"; - - using (var fwFileResponse = await _bintrayClient.GetAsync(requestUri)) + using (var fwFileResponse = await _cloudsmithClient.GetAsync(downloadUrl)) { if (fwFileResponse.IsSuccessStatusCode) { @@ -253,7 +265,7 @@ protected async System.Threading.Tasks.Task DownloadAndExtractAsync() } catch { - // exception with download, assuming it's something with network connection or Bintray API + // exception with download, assuming it's something with network connection or Cloudsmith API } } else diff --git a/nanoFirmwareFlasher/Options.cs b/nanoFirmwareFlasher/Options.cs index a0ab882c..980b9aae 100644 --- a/nanoFirmwareFlasher/Options.cs +++ b/nanoFirmwareFlasher/Options.cs @@ -120,7 +120,7 @@ public class Options "target", Required = false, Default = null, - HelpText = "Target name. This is the target name used in the GitHub and Bintray repositories.")] + HelpText = "Target name. This is the target name used in the GitHub and Cloudsmith repositories.")] public string TargetName { get; set; } [Option( diff --git a/nanoFirmwareFlasher/Program.cs b/nanoFirmwareFlasher/Program.cs index e5fc240d..31dda090 100644 --- a/nanoFirmwareFlasher/Program.cs +++ b/nanoFirmwareFlasher/Program.cs @@ -168,7 +168,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) else { // other supported platforms will go here - // in case a wacky target is entered by the user, the package name will be checked against Bintray repo + // in case a wacky target is entered by the user, the package name will be checked against Cloudsmith repo } } @@ -587,7 +587,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) // update operation requested? if (o.Update) { - // this to update the device with fw from Bintray + // this to update the device with fw from Cloudsmith // need to take care of flash address string appFlashAddress = null; @@ -681,7 +681,7 @@ static async Task RunOptionsAndReturnExitCodeAsync(Options o) // update operation requested? if (o.Update) { - // this to update the device with fw from Bintray + // this to update the device with fw from Cloudsmith // need to take care of flash address string appFlashAddress = null; diff --git a/nanoFirmwareFlasher/Stm32Firmware.cs b/nanoFirmwareFlasher/Stm32Firmware.cs index 63ec6cf4..723b287b 100644 --- a/nanoFirmwareFlasher/Stm32Firmware.cs +++ b/nanoFirmwareFlasher/Stm32Firmware.cs @@ -11,7 +11,7 @@ namespace nanoFramework.Tools.FirmwareFlasher { /// - /// Class that handles the download of STM32 firmware files from Bintray. + /// Class that handles the download of STM32 firmware files from Cloudsmith. /// internal class Stm32Firmware : FirmwarePackage { diff --git a/version.json b/version.json index 485e5ff7..2cab12be 100644 --- a/version.json +++ b/version.json @@ -1,6 +1,6 @@ { "$schema": "https://raw.githubusercontent.com/dotnet/Nerdbank.GitVersioning/master/src/NerdBank.GitVersioning/version.schema.json", - "version": "1.18.0-preview.{height}", + "version": "1.19.0-preview.{height}", "assemblyVersion": { "precision": "revision" },