aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
diff options
context:
space:
mode:
authorVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-18 13:27:02 +0200
committerVictoria Plitt <Victoria.Plitt@twine-s.com>2019-12-18 13:27:02 +0200
commit41129873d38034c5679eeaf46f48e4f67fd38ba2 (patch)
tree94109a9602e91bcf7f114e3491bc8018e60bef4c /Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
parent70e3f2699a500666d1ca4e4d5db2dbaafb339e80 (diff)
parenta61a911d1ebde107ba7bf210af7e753e692d93e2 (diff)
downloadTango-41129873d38034c5679eeaf46f48e4f67fd38ba2.tar.gz
Tango-41129873d38034c5679eeaf46f48e4f67fd38ba2.zip
Merge branch 'master' of https://twinetfs.visualstudio.com/Tango/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs')
-rw-r--r--Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs76
1 files changed, 75 insertions, 1 deletions
diff --git a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
index 2eeaa6e0e..da5ce16f7 100644
--- a/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
+++ b/Software/Visual_Studio/Web/Tango.MachineService/Controllers/MachineStudioController.cs
@@ -23,6 +23,10 @@ using Tango.Web.ActiveDirectory;
using Tango.MachineService.Filters;
using Tango.MachineService.Security;
using Tango.Web.SQLServer;
+using Tango.Core;
+using Tango.Web.SMO;
+using Tango.Core.DB;
+using System.Threading.Tasks;
namespace Tango.MachineService.Controllers
{
@@ -281,7 +285,16 @@ namespace Tango.MachineService.Controllers
[HttpPost]
public LoginResponse Login(LoginRequest request)
{
- var authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
+ AuthenticationResult authResult = null;
+
+ try
+ {
+ authResult = _ad_manager.ValidateUserCredentials(request.Email, request.Password);
+ }
+ catch (Exception ex)
+ {
+ throw new AuthenticationException(ex.FlattenMessage());
+ }
if (!_ad_manager.CanUserAccessCurrentEnvironment(request.Email))
{
@@ -425,6 +438,67 @@ namespace Tango.MachineService.Controllers
};
}
+ [HttpPost]
+ [JwtTokenFilter]
+ public DownloadLatestPPCVersionResponse DownloadLatestPPCVersion(DownloadLatestPPCVersionRequest request)
+ {
+ DownloadLatestPPCVersionResponse response = new DownloadLatestPPCVersionResponse();
+
+ using (ObservablesContext db = ObservablesContextHelper.CreateContext())
+ {
+ var machine = db.Machines.SingleOrDefault(x => x.SerialNumber == request.SerialNumber);
+
+ if (machine == null)
+ {
+ throw new AuthenticationException("The specified serial number could not be found.");
+ }
+
+ var machine_version = db.MachineVersions.SingleOrDefault(x => x.Guid == machine.MachineVersionGuid);
+
+ var latest_machine_version = db.TangoVersions.Where(x => x.MachineVersionGuid == machine_version.Guid).ToList().OrderByDescending(x => Version.Parse(x.Version)).FirstOrDefault();
+
+ response.Version = latest_machine_version.Version;
+
+ var manager = new BlobStorageManager();
+ var container = manager.GetContainer(MachineServiceConfig.TANGO_VERSIONS_CONTAINER);
+ var blob = container.GetBlockBlobReference(latest_machine_version.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;
+ }
+
#endregion
}
}