/// <summary> /// Initializes a new instance of the HDInsightCertificateCredential class. /// </summary> /// <param name="credential">The credentials to copy.</param> public HDInsightCertificateCredential(HDInsightCertificateCredential credential) { credential.ArgumentNotNull("credentials"); this.SubscriptionId = credential.SubscriptionId; this.Certificate = credential.Certificate; this.Endpoint = credential.Endpoint; this.DeploymentNamespace = credential.DeploymentNamespace; }
public static void TestRunSetup() { // Sets the simulator var runManager = ServiceLocator.Instance.Locate<IServiceLocationSimulationManager>(); ServiceLocator.Instance.Locate<ILogger>().AddWriter(new ConsoleLogWriter(Severity.None, Verbosity.Diagnostic)); runManager.RegisterType<IAsvValidatorClientFactory, AsvValidatorSimulatorClientFactory>(); runManager.RegisterType<IHDInsightManagementRestClientFactory, HDInsightManagementRestSimulatorClientFactory>(); runManager.RegisterType<IRdfeServiceRestClientFactory, RdfeServiceRestSimulatorClientFactory>(); runManager.RegisterType<IAzureHDInsightClusterConfigurationAccessorFactory, AzureHDInsightClusterConfigurationAccessorSimulatorFactory>(); runManager.RegisterInstance<IWabStorageAbstractionFactory>(StorageAccountSimulatorFactory.Instance); runManager.RegisterType<IRemoteHadoopJobSubmissionPocoClientFactory, HadoopJobSubmissionPocoSimulatorClientFactory>(); runManager.RegisterType<IHDInsightJobSubmissionPocoClientFactory, HadoopJobSubmissionPocoSimulatorClientFactory>(); runManager.RegisterType<ISubscriptionRegistrationClientFactory, SubscriptionRegistrationSimulatorClientFactory>(); var testManager = new IntegrationTestManager(); if (!testManager.RunAzureTests()) { Assert.Inconclusive("Azure tests are not configured on this machine."); } IntegrationTestBase.TestCredentials = testManager.GetCredentials("default"); if (IntegrationTestBase.TestCredentials == null) { Assert.Inconclusive("No entry was found in the credential config file for the specified test configuration."); } // Sets the certificate var defaultCertificate = new X509Certificate2(IntegrationTestBase.TestCredentials.Certificate); // Sets the test static properties IntegrationTestBase.ClusterPrefix = string.Format("CLITest-{0}", Environment.GetEnvironmentVariable("computername") ?? "unknown"); // Sets the credential objects var tempCredentials = new HDInsightCertificateCredential() { SubscriptionId = TestCredentials.SubscriptionId, Certificate = defaultCertificate, Endpoint = new Uri(TestCredentials.Endpoint) }; IntegrationTestBase.validCredentials = ServiceLocator.Instance .Locate<IHDInsightSubscriptionCredentialsFactory>() .Create(tempCredentials); tempCredentials = new HDInsightCertificateCredential() { SubscriptionId = Guid.NewGuid(), Certificate = defaultCertificate }; IntegrationTestBase.invalidSubscriptionId = ServiceLocator.Instance .Locate<IHDInsightSubscriptionCredentialsFactory>() .Create(tempCredentials); tempCredentials = new HDInsightCertificateCredential() { SubscriptionId = TestCredentials.SubscriptionId, Certificate = new X509Certificate2(TestCredentials.InvalidCertificate), Endpoint = new Uri(TestCredentials.Endpoint) }; IntegrationTestBase.invalidCertificate = ServiceLocator.Instance .Locate<IHDInsightSubscriptionCredentialsFactory>() .Create(tempCredentials); // Prepares the environment IntegrationTestBase.CleanUpClusters(); }
public static void TestRunSetup() { // This is to ensure that all key assemblies are loaded before IOC registration is required. // This is only necessary for the test system as load order is correct for a production run. // types.Add(typeof(GetAzureHDInsightClusterCmdlet)); var cmdletRunManager = ServiceLocator.Instance.Locate<IServiceLocationSimulationManager>(); cmdletRunManager.RegisterType<IAzureHDInsightConnectionSessionManagerFactory, AzureHDInsightConnectionSessionManagerSimulatorFactory>(); cmdletRunManager.RegisterType<IBufferingLogWriterFactory, BufferingLogWriterFactory>(); cmdletRunManager.RegisterType<IAzureHDInsightStorageHandlerFactory, AzureHDInsightStorageHandlerSimulatorFactory>(); cmdletRunManager.RegisterType<IAzureHDInsightSubscriptionResolverFactory, AzureHDInsightSubscriptionResolverSimulatorFactory>(); cmdletRunManager.RegisterType<IAzureHDInsightClusterManagementClientFactory, AzureHDInsightClusterManagementClientSimulatorFactory>(); cmdletRunManager.RegisterType<IAzureHDInsightJobSubmissionClientFactory, AzureHDInsightJobSubmissionClientSimulatorFactory>(); var testManager = new IntegrationTestManager(); AzureSession.DataStore = new MemoryDataStore(); var profile = new AzureProfile(Path.Combine(AzureSession.ProfileDirectory, AzureSession.ProfileFile)); AzurePSCmdlet.CurrentProfile = profile; TestCredentials = testManager.GetCredentials("default"); if (TestCredentials == null) { Assert.Inconclusive("No entry was found in the credential config file for the specified test configuration."); } // Sets the certificate var defaultCertificate = new X509Certificate2( Convert.FromBase64String(TestCredentials.Certificate), string.Empty); // Sets the test static properties ClusterPrefix = string.Format("CLITest-{0}", Environment.GetEnvironmentVariable("computername") ?? "unknown"); // Sets the credential objects var tempCredentials = new HDInsightCertificateCredential { SubscriptionId = TestCredentials.SubscriptionId, Certificate = defaultCertificate }; validCredentials = tempCredentials; tempCredentials = new HDInsightCertificateCredential { SubscriptionId = Guid.NewGuid(), Certificate = defaultCertificate }; invalidSubscriptionId = tempCredentials; invalidCertificate = tempCredentials; }
/// <summary> /// Initializes a new instance of the JobSubmissionCertificateCredential class. /// </summary> /// <param name="credentials">HDInsightSubscriptionCertificateCredentials to be used.</param> /// <param name="cluster">The cluster to connect to.</param> public JobSubmissionCertificateCredential(HDInsightCertificateCredential credentials, string cluster) : base(credentials) { this.Cluster = cluster; }
public void TestWithCertificateCredentials() { IHDInsightSubscriptionCredentials credentials = new HDInsightCertificateCredential() { Certificate = new X509Certificate2(IntegrationTestBase.TestCredentials.Certificate), DeploymentNamespace = "hdinsight", Endpoint = new Uri("http://notrdfe.com/"), SubscriptionId = Guid.NewGuid() }; Exception error = null; try { //Should not have token header set when using a certificate IHttpClientAbstraction validAbstraction = ServiceLocator.Instance.Locate<IHDInsightHttpClientAbstractionFactory>().Create(credentials, false); Assert.IsFalse(validAbstraction.RequestHeaders.ContainsKey("Authorization")); } catch (NotSupportedException e) { error = e; } Assert.IsNull(error); }
/// <summary> /// Enumerate all the clusters this user is subscribed to. /// </summary> /// <returns>The list of clusters this user is subscribed to.</returns> public static List<ClusterConfiguration> EnumerateAzureDfsSubscribedClusters() { List<ClusterConfiguration> configList = new List<ClusterConfiguration>(); var store = new X509Store(); store.Open(OpenFlags.ReadOnly); var configDir = Path.Combine( Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Windows Azure Powershell"); var defaultFile = Path.Combine(configDir, "WindowsAzureProfile.xml"); if (File.Exists(defaultFile)) { using (FileStream s = new FileStream(defaultFile, FileMode.Open, FileAccess.Read)) { XDocument doc = XDocument.Load(s); XNamespace ns = doc.Root.GetDefaultNamespace(); IEnumerable<XElement> subs = doc.Descendants(ns + "AzureSubscriptionData"); foreach (XElement sub in subs) { string thumbprint = sub.Descendants(ns + "ManagementCertificate").Single().Value; string subId = sub.Descendants(ns + "SubscriptionId").Single().Value; Guid subGuid = new Guid(subId); X509Certificate2 cert = store.Certificates.Cast<X509Certificate2>().First(item => item.Thumbprint == thumbprint); HDInsightCertificateCredential sCred = new HDInsightCertificateCredential(subGuid, cert); IHDInsightClient sClient = HDInsightClient.Connect(sCred); var clusters = sClient.ListClusters(); foreach (var cluster in clusters) { var account = cluster.DefaultStorageAccount; var accountName = account.Name.Split('.').First(); Console.WriteLine("Cluster " + cluster.Name + " uses account " + accountName + " with key " + account.Key); AzureDfsClusterConfiguration config = null; try { config = new AzureDfsClusterConfiguration(); config.AzureClient = new AzureDfsClient(accountName, account.Key, config.Container); config.Name = cluster.Name; } catch (Exception ex) { Console.WriteLine("Exception while reconstructing cluster " + cluster.Name + ": " + ex); } if (config != null) configList.Add(config); } } } } return configList; }