From bf5cbf5a6972cd8d725cc03fd6375b1eccbfe31c Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sat, 11 Apr 2020 05:02:18 +0300 Subject: Started working on FSE TUP management. --- .../Controllers/FSEController.cs | 62 ++++++++++++++++++++++ .../Controllers/MachineStudioController.cs | 2 - 2 files changed, 62 insertions(+), 2 deletions(-) (limited to 'Software/Visual_Studio/Web') diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs index dccf2d24c..27d93f467 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/FSEController.cs @@ -4,17 +4,22 @@ using System.Linq; using System.Net; using System.Net.Http; using System.Security.Authentication; +using System.Threading.Tasks; using System.Web.Http; +using Tango.BL; using Tango.BL.Builders; using Tango.BL.Entities; using Tango.Core; using Tango.Core.Cryptography; +using Tango.Core.DB; using Tango.FSE.Web.Messages; using Tango.MachineService.Filters; using Tango.Web.Controllers; using Tango.Web.Helpers; using Tango.Web.Security; +using Tango.Web.SMO; using Tango.Web.SQLServer; +using Tango.Web.Storage; namespace Tango.MachineService.Controllers { @@ -117,5 +122,62 @@ namespace Tango.MachineService.Controllers UserEmail = MachineServiceConfig.FSE_TFS_USER_EMAIL }; } + + [HttpPost] + [JwtTokenFilter] + public DownloadTangoVersionResponse DownloadTangoVersion(DownloadTangoVersionRequest request) + { + DownloadTangoVersionResponse response = new DownloadTangoVersionResponse(); + + using (ObservablesContext db = ObservablesContextHelper.CreateContext()) + { + var tangoVersion = db.TangoVersions.SingleOrDefault(x => x.Guid == request.TangoVersionGuid); + + if (tangoVersion == null) + { + throw new ArgumentException("Could not locate the specified Tango version."); + } + + response.Version = tangoVersion.Version; + + var manager = new BlobStorageManager(); + var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER); + var blob = container.GetBlockBlobReference(tangoVersion.BlobName); + + response.BlobAddress = blob.GenerateReadSignature(TimeSpan.FromMinutes(60)); + + if (!String.IsNullOrWhiteSpace(MachineServiceConfig.CDN_ENDPOINT)) + { + response.CdnAddress = MachineServiceConfig.CDN_ENDPOINT + blob.Uri.AbsolutePath; + } + + DbCredentials credentials = new DbCredentials(); + + using (SmoManager smo = new SmoManager()) + { + credentials = smo.CreateRandomLoginAndUser(); + + Task.Delay(TimeSpan.FromMinutes(PPCController.SQL_TEMP_CREDENTIALS_EXP_MINUTS)).ContinueWith((x) => + { + using (SmoManager m = new SmoManager()) + { + m.DeleteLoginAndUser(credentials.UserName); + } + }); + } + + response.DataSource = new DataSource() + { + Address = MachineServiceConfig.DB_ADDRESS, + Catalog = MachineServiceConfig.DB_CATALOG, + UserName = credentials.UserName, + Password = credentials.Password, + IntegratedSecurity = false, + Type = DataSourceType.SQLServer, + }; + } + + return response; + } } } diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs index f508fea15..5f697f979 100644 --- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs +++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs @@ -120,8 +120,6 @@ namespace Tango.MachineService.Controllers [JwtTokenFilter] public DownloadLatestVersionResponse DownloadLatestVersion(DownloadLatestVersionRequest request) { - LogManager.Log("Request received..."); - DownloadLatestVersionResponse response = new DownloadLatestVersionResponse(); using (ObservablesContext db = ObservablesContextHelper.CreateContext()) -- cgit v1.3.1