blob: e9ae6e97bbe7bfd6c7852109372ed070d58dcbbc (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
using Microsoft.Azure.Management.AppService.Fluent;
using Microsoft.Azure.Management.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent;
using Microsoft.Azure.Management.ResourceManager.Fluent.Authentication;
using Microsoft.Azure.Storage;
using Microsoft.Azure.Storage.Blob;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Tango.AzureUtils.Deployment
{
public class DeploymentManager
{
private AzureUtilsCredentials _credentials;
private IAzure _azure;
public DeploymentManager(AzureUtilsCredentials credentials)
{
_credentials = credentials;
}
private static string app_id = "be33437c-5052-449f-ab9d-a88d008eae24";
private static string client_secret = "bf67fb6f-4d06-4893-988c-6b347aff23d6";
private static string tenant_id = "2ebd63a5-bc2f-41dc-9066-4409ed5e5dd4";
private static string subscription_id = "10c8aa60-3b15-4e0d-b412-6aeef90e5e91";
private IAzure GetOrCreateAzure()
{
if (_azure == null)
{
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
_credentials.ClientID,
_credentials.ClientSecret,
_credentials.TenantID,
AzureEnvironment.AzureGlobalCloud);
_azure = Azure.Authenticate(credentials).WithSubscription(_credentials.SubscriptionID);
}
return _azure;
}
public List<IWebApp> GetAllWebApps()
{
return GetOrCreateAzure().WebApps.List().ToList();
}
public void UpdateSlot(IDeploymentSlot slot)
{
}
public void Deploy()
{
var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(
app_id,
client_secret,
tenant_id,
AzureEnvironment.AzureGlobalCloud);
var azure = Azure.Authenticate(credentials).WithSubscription(subscription_id);
var webApps = azure.WebApps.List();
var machineService = webApps.SingleOrDefault(x => x.Name == "MachineService");
var devSlot = machineService.DeploymentSlots.GetByName("MachineService-DEV");
var devProfile = devSlot.GetPublishingProfile();
String ftpAddress = devProfile.FtpUrl;
String ftpUser = devProfile.FtpUsername;
String ftpPassword = devProfile.FtpPassword;
foreach (var ds in machineService.DeploymentSlots.List())
{
Console.WriteLine(ds.Name);
}
CloudStorageAccount sourceAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=tangostorage;AccountKey=S4z/D+Yg6mwMis+bs/VpcDLA9yE1iZaYq23shQlRIi2KmM9E7JY8zdZjeAPOPdG3gONHoNDEpsgH6D4cqQ/bsA==;EndpointSuffix=core.windows.net");
CloudBlobClient sourceClient = sourceAccount.CreateCloudBlobClient();
var sourceContainer = sourceClient.GetContainerReference("machine-studio-versions-test");
var sourceBlob = sourceContainer.GetBlockBlobReference("Machine Studio v4.0.34.0.zip");
var targetContainer = sourceClient.GetContainerReference("machine-studio-versions-dev");
CloudBlockBlob targetBlob = targetContainer.GetBlockBlobReference(sourceBlob.Name);
using (MemoryStream ms = new MemoryStream())
{
targetBlob.UploadFromStream(ms);//Empty memory stream. Will create an empty blob.
}
targetBlob.StartCopy(sourceBlob);
}
}
}
|