/// <summary> /// This overrides the default subscription and default account. This allows the /// test to get the tenant id in the test. /// </summary> public void SetupEnvironment() { base.SetupEnvironment(AzureModule.AzureResourceManager); TestEnvironment csmEnvironment = new CSMTestEnvironmentFactory().GetTestEnvironment(); if (csmEnvironment.SubscriptionId != null) { //Overwrite the default subscription and default account //with ones using user ID and tenant ID from auth context var user = GetUser(csmEnvironment); var tenantId = GetTenantId(csmEnvironment); // Existing test will not have a user or tenant id set if (tenantId != null && user != null) { var testSubscription = new AzureSubscription() { Id = new Guid(csmEnvironment.SubscriptionId), Name = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name, Environment = AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment, Account = user, Properties = new Dictionary<AzureSubscription.Property, string> { { AzureSubscription.Property.Default, "True" }, { AzureSubscription.Property.StorageAccount, Environment.GetEnvironmentVariable("AZURE_STORAGE_ACCOUNT") }, { AzureSubscription.Property.Tenants, tenantId }, } }; var testAccount = new AzureAccount() { Id = user, Type = AzureAccount.AccountType.User, Properties = new Dictionary<AzureAccount.Property, string> { { AzureAccount.Property.Subscriptions, csmEnvironment.SubscriptionId }, } }; AzureRmProfileProvider.Instance.Profile.Context.Subscription.Name = testSubscription.Name; AzureRmProfileProvider.Instance.Profile.Context.Subscription.Id = testSubscription.Id; AzureRmProfileProvider.Instance.Profile.Context.Subscription.Account = testSubscription.Account; var environment = AzureRmProfileProvider.Instance.Profile.Environments[AzureRmProfileProvider.Instance.Profile.Context.Subscription.Environment]; environment.Endpoints[AzureEnvironment.Endpoint.Graph] = csmEnvironment.Endpoints.GraphUri.AbsoluteUri; environment.Endpoints[AzureEnvironment.Endpoint.StorageEndpointSuffix] = "core.windows.net"; AzureRmProfileProvider.Instance.Profile.Save(); } } }
public bool IsStorageServiceAvailable(AzureSubscription subscription, string name) { EnsureCloudServiceClientInitialized(subscription); bool available = this.CloudServiceClient.CheckStorageServiceAvailability(name); WriteObject(!available); return available; }
/// <summary> /// Creates new WebsitesClient /// </summary> /// <param name="subscription">Subscription containing websites to manipulate</param> /// <param name="logger">The logger action</param> public WebsitesClient(AzureProfile profile, AzureSubscription subscription, Action<string> logger) { Logger = logger; cloudServiceClient = new CloudServiceClient(profile, subscription, debugStream: logger); WebsiteManagementClient = AzureSession.ClientFactory.CreateClient<WebSiteManagementClient>(profile, subscription, AzureEnvironment.Endpoint.ServiceManagement); this.subscription = subscription; }
public void ProcessShowWebsiteTest() { // Setup var mockClient = new Mock<IWebsitesClient>(); mockClient.Setup(c => c.GetWebsite("website1", null)) .Returns(new Site { Name = "website1", WebSpace = "webspace1", HostNames = new[] {"website1.cloudapp.com"} }); // Test ShowAzureWebsiteCommand showAzureWebsiteCommand = new ShowAzureWebsiteCommand { CommandRuntime = new MockCommandRuntime(), Name = "website1", WebsitesClient = mockClient.Object }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; // Show existing website showAzureWebsiteCommand.ExecuteCmdlet(); }
public void DisableAzureWebsiteApplicationDiagnosticApplication() { // Setup websitesClientMock.Setup(f => f.DisableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.FileSystem, null)); disableAzureWebsiteApplicationDiagnosticCommand = new DisableAzureWebsiteApplicationDiagnosticCommand() { CommandRuntime = commandRuntimeMock.Object, Name = websiteName, WebsitesClient = websitesClientMock.Object, File = true, }; currentProfile = new AzureProfile(); var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; // Test disableAzureWebsiteApplicationDiagnosticCommand.ExecuteCmdlet(); // Assert websitesClientMock.Verify(f => f.DisableApplicationDiagnostic( websiteName, WebsiteDiagnosticOutput.FileSystem, null), Times.Once()); commandRuntimeMock.Verify(f => f.WriteObject(true), Times.Never()); }
public void ListWebHostingPlansTest() { // Setup var clientMock = new Mock<IWebsitesClient>(); clientMock.Setup(c => c.ListWebSpaces()) .Returns(new[] {new WebSpace {Name = "webspace1"}, new WebSpace {Name = "webspace2"}}); clientMock.Setup(c => c.ListWebHostingPlans()) .Returns(new List<WebHostingPlan> { new WebHostingPlan {Name = "Plan1", WebSpace = "webspace1"}, new WebHostingPlan { Name = "Plan2", WebSpace = "webspace2" } }); // Test var command = new GetAzureWebHostingPlanCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = clientMock.Object }; currentProfile = new AzureProfile(); var subscription = new AzureSubscription{Id = new Guid(subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(subscriptionId)] = subscription; command.ExecuteCmdlet(); var plans = System.Management.Automation.LanguagePrimitives.GetEnumerable(((MockCommandRuntime)command.CommandRuntime).OutputPipeline).Cast<WebHostingPlan>(); Assert.NotNull(plans); Assert.Equal(2, plans.Count()); Assert.True(plans.Any(p => (p).Name.Equals("Plan1") && (p).WebSpace.Equals("webspace1"))); Assert.True(plans.Any(p => (p).Name.Equals("Plan2") && (p).WebSpace.Equals("webspace2"))); }
/// <summary> /// Constructs a database adapter /// </summary> /// <param name="profile">The current azure profile</param> /// <param name="subscription">The current azure subscription</param> public AzureSqlDatabaseAdapter(AzureProfile Profile, AzureSubscription subscription) { this.Profile = Profile; this._subscription = subscription; Communicator = new AzureSqlDatabaseCommunicator(Profile, subscription); ElasticPoolCommunicator = new AzureSqlElasticPoolCommunicator(Profile, subscription); }
public void RestartsWebsiteSlot() { // Setup const string websiteName = "website1"; const string slot = "staging"; Mock<IWebsitesClient> websitesClientMock = new Mock<IWebsitesClient>(); websitesClientMock.Setup(f => f.RestartWebsite(websiteName, slot)); // Test RestartAzureWebsiteCommand restartAzureWebsiteCommand = new RestartAzureWebsiteCommand() { CommandRuntime = new MockCommandRuntime(), Name = websiteName, WebsitesClient = websitesClientMock.Object, Slot = slot }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription{Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; restartAzureWebsiteCommand.ExecuteCmdlet(); websitesClientMock.Verify(f => f.RestartWebsite(websiteName, slot), Times.Once()); }
/// <summary> /// Constructs a database adapter /// </summary> /// <param name="profile">The current azure profile</param> /// <param name="subscription">The current azure subscription</param> public AzureSqlDatabaseAdapter(AzureContext context) { Context = context; _subscription = context.Subscription; Communicator = new AzureSqlDatabaseCommunicator(Context); ElasticPoolCommunicator = new AzureSqlElasticPoolCommunicator(Context); }
public static AzureSubscription GetCurrentSubscription() { string certificateThumbprint1 = "jb245f1d1257fw27dfc402e9ecde37e400g0176r"; var newSubscription = new AzureSubscription() { Id = IntegrationTestBase.TestCredentials.SubscriptionId, // Use fake certificate thumbprint Account = certificateThumbprint1, Environment = "AzureCloud" }; newSubscription.Properties[AzureSubscription.Property.Default] = "True"; ProfileClient profileClient = new ProfileClient(new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile))); profileClient.Profile.Accounts[certificateThumbprint1] = new AzureAccount() { Id = certificateThumbprint1, Type = AzureAccount.AccountType.Certificate }; profileClient.Profile.Subscriptions[newSubscription.Id] = newSubscription; profileClient.Profile.Save(); return profileClient.Profile.Subscriptions[newSubscription.Id]; }
public override void ExecuteCmdlet() { switch (ParameterSetName) { case "ByName": IEnumerable<AzureSubscription> subscriptions = new AzureSubscription[0]; if (Profile.Context != null && Profile.Context.Environment != null) { subscriptions = ProfileClient.RefreshSubscriptions(Profile.Context.Environment) .Where( s => SubscriptionName == null || s.Name.Equals(SubscriptionName, StringComparison.InvariantCultureIgnoreCase)); } WriteSubscriptions(subscriptions); break; case "ById": WriteSubscriptions(ProfileClient.GetSubscription(new Guid(SubscriptionId))); break; case "Default": GetDefault(); break; case "Current": GetCurrent(); break; } }
public static AzureSMProfile CreateAzureSMProfile(string storageAccount) { var profile = new AzureSMProfile(); var client = new ProfileClient(profile); var tenantId = Guid.NewGuid(); var subscriptionId = Guid.NewGuid(); var account = new AzureAccount { Id = "*****@*****.**", Type = AzureAccount.AccountType.User }; account.SetProperty(AzureAccount.Property.Tenants, tenantId.ToString()); account.SetProperty(AzureAccount.Property.Subscriptions, subscriptionId.ToString()); var subscription = new AzureSubscription() { Id = subscriptionId, Name = "Test Subscription 1", Environment = EnvironmentName.AzureCloud, Account = account.Id, }; subscription.SetProperty(AzureSubscription.Property.Tenants, tenantId.ToString()); subscription.SetProperty(AzureSubscription.Property.StorageAccount, storageAccount); client.AddOrSetAccount(account); client.AddOrSetSubscription(subscription); client.SetSubscriptionAsDefault(subscriptionId, account.Id); return profile; }
public void SwitchesSlots() { // Setup var mockClient = new Mock<IWebsitesClient>(); string slot1 = WebsiteSlotName.Production.ToString(); string slot2 = "staging"; mockClient.Setup(c => c.GetWebsiteSlots("website1")) .Returns(new List<Site> { new Site { Name = "website1", WebSpace = "webspace1" }, new Site { Name = "website1(staging)", WebSpace = "webspace1" } }); mockClient.Setup(f => f.GetSlotName("website1")).Returns(slot1); mockClient.Setup(f => f.GetSlotName("website1(staging)")).Returns(slot2); mockClient.Setup(f => f.SwitchSlots("webspace1", "website1(staging)", slot1, slot2)).Verifiable(); mockClient.Setup(f => f.GetWebsiteNameFromFullName("website1")).Returns("website1"); // Test SwitchAzureWebsiteSlotCommand switchAzureWebsiteCommand = new SwitchAzureWebsiteSlotCommand { CommandRuntime = new MockCommandRuntime(), WebsitesClient = mockClient.Object, Name = "website1", Force = true }; currentProfile = new AzureSMProfile(); var subscription = new AzureSubscription { Id = new Guid(base.subscriptionId) }; subscription.Properties[AzureSubscription.Property.Default] = "True"; currentProfile.Subscriptions[new Guid(base.subscriptionId)] = subscription; // Switch existing website switchAzureWebsiteCommand.ExecuteCmdlet(); mockClient.Verify(c => c.SwitchSlots("webspace1", "website1", slot1, slot2), Times.Once()); }
public AutomationClient(AzureSubscription subscription, AutomationManagement.IAutomationManagementClient automationManagementClient) { Requires.Argument("automationManagementClient", automationManagementClient).NotNull(); this.Subscription = subscription; this.automationManagementClient = automationManagementClient; }
/// <summary> /// Constructs a database adapter /// </summary> /// <param name="profile">The current azure profile</param> /// <param name="subscription">The current azure subscription</param> public AzureSqlDatabaseReplicationAdapter(AzureProfile Profile, AzureSubscription subscription) { this.Profile = Profile; this._subscription = subscription; ReplicationCommunicator = new AzureSqlDatabaseReplicationCommunicator(Profile, subscription); DatabaseCommunicator = new AzureSqlDatabaseCommunicator(Profile, subscription); ServerCommunicator = new AzureSqlServerCommunicator(Profile, subscription); }
/// <summary> /// Validates that the given subscription is valid. /// </summary> /// <param name="subscription">The <see cref="AzureSubscription"/> to validate.</param> public static void ValidateSubscription(AzureSubscription subscription) { if (subscription == null) { throw new ArgumentException( Common.Properties.Resources.InvalidDefaultSubscription); } }
public SqlAuditAdapter(AzureProfile profile, AzureSubscription subscription) { Profile = profile; Subscription = subscription; Communicator = new AuditingEndpointsCommunicator(Profile, subscription); AzureCommunicator = new AzureEndpointsCommunicator(Profile, subscription); IgnoreStorage = false; }
/// <summary> /// Constructs a database adapter /// </summary> /// <param name="profile">The current azure profile</param> /// <param name="subscription">The current azure subscription</param> public AzureSqlDatabaseReplicationAdapter(AzureContext context) { Context = context; _subscription = context.Subscription; ReplicationCommunicator = new AzureSqlDatabaseReplicationCommunicator(Context); DatabaseCommunicator = new AzureSqlDatabaseCommunicator(Context); ServerCommunicator = new AzureSqlServerCommunicator(Context); }
public DataMaskingEndpointsCommunicator(AzureProfile profile, AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
/// <summary> /// Creates a communicator for Azure Sql Databases TransparentDataEncryption /// </summary> /// <param name="profile"></param> /// <param name="subscription"></param> public AzureSqlDatabaseTransparentDataEncryptionCommunicator(AzureProfile profile, AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
/// <summary> /// Creates a communicator for Azure SQL Server Active Directory administrator /// </summary> /// <param name="profile"></param> /// <param name="subscription"></param> public AzureSqlServerActiveDirectoryAdministratorCommunicator(AzureProfile profile, AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
public SecureConnectionEndpointsCommunicator(AzureProfile profile , AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
/// <summary> /// Creates a communicator for Azure Sql Databases /// </summary> /// <param name="profile"></param> /// <param name="subscription"></param> public AzureSqlServerCommunicator(AzureProfile profile, AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
/// <summary> /// Creates a communicator for Azure Sql Recommended Elastic Pool /// </summary> /// <param name="profile"></param> /// <param name="subscription"></param> public AzureSqlElasticPoolRecommendationCommunicator(AzureProfile profile, AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
/// <summary> /// Initializes a new instance of the <see cref="ServerDataServiceCertAuth"/> class /// </summary> /// <param name="subscription">The subscription used to connect and authenticate.</param> /// <param name="serverName">The name of the server to connect to.</param> private ServerDataServiceCertAuth( AzureSMProfile profile, AzureSubscription subscription, string serverName) { this.profile = profile; this.serverName = serverName; this.subscription = subscription; }
/// <summary> /// Creates a communicator for Azure Sql Databases /// </summary> /// <param name="profile"></param> /// <param name="subscription"></param> public AzureSqlDatabaseIndexRecommendationCommunicator(AzureProfile profile, AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
/// <summary> /// Creates a communicator for Azure Sql Database backup REST endpoints. /// </summary> /// <param name="profile">Azure profile</param> /// <param name="subscription">Associated subscription</param> public AzureSqlDatabaseBackupCommunicator(AzureProfile profile, AzureSubscription subscription) { Profile = profile; if (subscription != Subscription) { Subscription = subscription; SqlClient = null; } }
private void EnsureCloudServiceClientInitialized(AzureSubscription subscription) { this.CloudServiceClient = this.CloudServiceClient ?? new CloudServiceClient( Profile, subscription, SessionState.Path.CurrentLocation.Path, WriteDebug, WriteVerbose, WriteWarning); }
public static IHDInsightSubscriptionCredentials GetSubscriptionCertificateCredentials(this IAzureHDInsightCommonCommandBase command, AzureSubscription currentSubscription, AzureAccount azureAccount, AzureEnvironment environment) { return new HDInsightCertificateCredential { SubscriptionId = currentSubscription.Id, Certificate = AzureSession.DataStore.GetCertificate(currentSubscription.Account), Endpoint = environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement), }; }
public StorSimpleClient(AzureSMProfile AzureSMProfile, AzureSubscription currentSubscription) { // Temp code to be able to test internal env. ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };//IgnoreCertificateErrorHandler;//delegate { return true; }; this.Profile = AzureSMProfile; this.cloudServicesClient = AzureSession.ClientFactory.CreateClient<CloudServiceManagementClient>(AzureSMProfile, currentSubscription, AzureEnvironment.Endpoint.ServiceManagement); ResourceCachetimeoutPolicy.AbsoluteExpiration = DateTimeOffset.Now.AddHours(1.0d); }
/// <summary> /// Creates new instance of AzureContext. /// </summary> /// <param name="subscription">The azure subscription object</param> /// <param name="account">The azure account object</param> /// <param name="environment">The azure environment object</param> public AzureContext(AzureSubscription subscription, AzureAccount account, AzureEnvironment environment) : this(subscription, account, environment, null) { }