public List<AzureSubscription> GetSubscriptions(AzureProfile profile) { string subscriptions = string.Empty; List<AzureSubscription> subscriptionsList = new List<AzureSubscription>(); if (Properties.ContainsKey(Property.Subscriptions)) { subscriptions = Properties[Property.Subscriptions]; } foreach (var subscription in subscriptions.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries)) { try { Guid subscriptionId = new Guid(subscription); Debug.Assert(profile.Subscriptions.ContainsKey(subscriptionId)); subscriptionsList.Add(profile.Subscriptions[subscriptionId]); } catch { // Skip } } return subscriptionsList; }
private static void UpgradeProfile() { string oldProfileFilePath = System.IO.Path.Combine(AzurePowerShell.ProfileDirectory, AzurePowerShell.OldProfileFile); string newProfileFilePath = System.IO.Path.Combine(AzurePowerShell.ProfileDirectory, AzurePowerShell.ProfileFile); if (DataStore.FileExists(oldProfileFilePath)) { string oldProfilePath = System.IO.Path.Combine(AzurePowerShell.ProfileDirectory, AzurePowerShell.OldProfileFile); AzureProfile oldProfile = new AzureProfile(DataStore, oldProfilePath); if (DataStore.FileExists(newProfileFilePath)) { // Merge profile files AzureProfile newProfile = new AzureProfile(DataStore, newProfileFilePath); foreach (var environment in newProfile.Environments.Values) { oldProfile.Environments[environment.Name] = environment; } foreach (var subscription in newProfile.Subscriptions.Values) { oldProfile.Subscriptions[subscription.Id] = subscription; } DataStore.DeleteFile(newProfileFilePath); } // Save the profile to the disk oldProfile.Save(); // Rename WindowsAzureProfile.xml to WindowsAzureProfile.json DataStore.RenameFile(oldProfilePath, newProfileFilePath); } }
public List <AzureSubscription> GetSubscriptions(AzureProfile profile) { string subscriptions = string.Empty; List <AzureSubscription> subscriptionsList = new List <AzureSubscription>(); if (Properties.ContainsKey(Property.Subscriptions)) { subscriptions = Properties[Property.Subscriptions]; } foreach (var subscription in subscriptions.Split(new [] { ',' }, StringSplitOptions.RemoveEmptyEntries)) { try { Guid subscriptionId = new Guid(subscription); Debug.Assert(profile.Subscriptions.ContainsKey(subscriptionId)); subscriptionsList.Add(profile.Subscriptions[subscriptionId]); } catch { // Skip } } return(subscriptionsList); }
public bool Deserialize(string contents, AzureProfile profile) { ProfileData data = null; Debug.Assert(profile != null); DeserializeErrors = new List<string>(); DataContractSerializer serializer = new DataContractSerializer(typeof(ProfileData)); using (MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(contents ?? ""))) { data = (ProfileData)serializer.ReadObject(s); } if (data != null) { foreach (AzureEnvironmentData oldEnv in data.Environments) { profile.Environments[oldEnv.Name] = oldEnv.ToAzureEnvironment(); } List<AzureEnvironment> envs = profile.Environments.Values.ToList(); foreach (AzureSubscriptionData oldSubscription in data.Subscriptions) { try { var newSubscription = oldSubscription.ToAzureSubscription(envs); if (newSubscription.Account == null) { continue; } var newAccounts = oldSubscription.ToAzureAccounts(); foreach (var account in newAccounts) { if (profile.Accounts.ContainsKey(account.Id)) { profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Tenants, account.GetPropertyAsArray(AzureAccount.Property.Tenants)); profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Subscriptions, account.GetPropertyAsArray(AzureAccount.Property.Subscriptions)); } else { profile.Accounts[account.Id] = account; } } profile.Subscriptions[newSubscription.Id] = newSubscription; } catch (Exception ex) { // Skip subscription if failed to load DeserializeErrors.Add(ex.Message); } } } return DeserializeErrors.Count == 0; }
public string Serialize(AzureProfile profile) { return(JsonConvert.SerializeObject(new { Environments = profile.Environments.Values.ToList(), Subscriptions = profile.Subscriptions.Values.ToList(), Accounts = profile.Accounts.Values.ToList() }, Formatting.Indented)); }
public string Serialize(AzureProfile profile) { return JsonConvert.SerializeObject(new { Environments = profile.Environments.Values.ToList(), Subscriptions = profile.Subscriptions.Values.ToList(), Accounts = profile.Accounts.Values.ToList() }, Formatting.Indented); }
private void Copy(AzureProfile other) { // Copy environments // Copy subscriptions // Copy certificates // Ignore copying the cached tokens as we require users to login again }
private void Copy(AzureProfile other) { // Copy environments // Copy subscriptions // Copy certificates // Ignore copying the cached tokens as we require users to login again }
public bool Deserialize(string contents, AzureProfile profile) { DeserializeErrors = new List<string>(); try { var jsonProfile = JObject.Parse(contents); foreach (var env in jsonProfile["Environments"]) { try { profile.Environments[(string) env["Name"]] = JsonConvert.DeserializeObject<AzureEnvironment>(env.ToString()); } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } } foreach (var subscription in jsonProfile["Subscriptions"]) { try { profile.Subscriptions[new Guid((string) subscription["Id"])] = JsonConvert.DeserializeObject<AzureSubscription>(subscription.ToString()); } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } } foreach (var account in jsonProfile["Accounts"]) { try { profile.Accounts[(string) account["Id"]] = JsonConvert.DeserializeObject<AzureAccount>(account.ToString()); } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } } } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } return DeserializeErrors.Count == 0; }
public bool Deserialize(string contents, AzureProfile profile) { DeserializeErrors = new List <string>(); try { var jsonProfile = JObject.Parse(contents); foreach (var env in jsonProfile["Environments"]) { try { profile.Environments[(string)env["Name"]] = JsonConvert.DeserializeObject <AzureEnvironment>(env.ToString()); } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } } foreach (var subscription in jsonProfile["Subscriptions"]) { try { profile.Subscriptions[new Guid((string)subscription["Id"])] = JsonConvert.DeserializeObject <AzureSubscription>(subscription.ToString()); } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } } foreach (var account in jsonProfile["Accounts"]) { try { profile.Accounts[(string)account["Id"]] = JsonConvert.DeserializeObject <AzureAccount>(account.ToString()); } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } } } catch (Exception ex) { DeserializeErrors.Add(ex.Message); } return(DeserializeErrors.Count == 0); }
public void Deserialize(string contents, AzureProfile profile) { ProfileData data = null; Debug.Assert(profile != null); try { DataContractSerializer serializer = new DataContractSerializer(typeof(ProfileData)); using (MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(contents ?? ""))) { data = (ProfileData)serializer.ReadObject(s); } if (data != null) { foreach (AzureEnvironmentData oldEnv in data.Environments) { profile.Environments[oldEnv.Name] = oldEnv.ToAzureEnvironment(); } List <AzureEnvironment> envs = profile.Environments.Values.ToList(); foreach (AzureSubscriptionData oldSubscription in data.Subscriptions) { var newSubscription = oldSubscription.ToAzureSubscription(envs); if (newSubscription.Account == null) { continue; } var newAccounts = oldSubscription.ToAzureAccounts(); foreach (var account in newAccounts) { if (profile.Accounts.ContainsKey(account.Id)) { profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Tenants, account.GetPropertyAsArray(AzureAccount.Property.Tenants)); profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Subscriptions, account.GetPropertyAsArray(AzureAccount.Property.Subscriptions)); } else { profile.Accounts[account.Id] = account; } } profile.Subscriptions[newSubscription.Id] = newSubscription; } } } catch (XmlException) { /* The profile XML was malformed ignore parsing the file */ } }
public void Deserialize(string contents, AzureProfile profile) { ProfileData data = null; Debug.Assert(profile != null); try { DataContractSerializer serializer = new DataContractSerializer(typeof(ProfileData)); using (MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(contents ?? ""))) { data = (ProfileData)serializer.ReadObject(s); } if (data != null) { foreach (AzureEnvironmentData oldEnv in data.Environments) { profile.Environments[oldEnv.Name] = oldEnv.ToAzureEnvironment(); } List<AzureEnvironment> envs = profile.Environments.Values.ToList(); foreach (AzureSubscriptionData oldSubscription in data.Subscriptions) { var newSubscription = oldSubscription.ToAzureSubscription(envs); if (newSubscription.Account == null) { continue; } var newAccounts = oldSubscription.ToAzureAccounts(); foreach (var account in newAccounts) { if (profile.Accounts.ContainsKey(account.Id)) { profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Tenants, account.GetPropertyAsArray(AzureAccount.Property.Tenants)); profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Subscriptions, account.GetPropertyAsArray(AzureAccount.Property.Subscriptions)); } else { profile.Accounts[account.Id] = account; } } profile.Subscriptions[newSubscription.Id] = newSubscription; } } } catch (XmlException) { /* The profile XML was malformed ignore parsing the file */ } }
private void LoadProfile() { JsonProfileSerializer jsonSerializer = new JsonProfileSerializer(); XmlProfileSerializer xmlSerializer = new XmlProfileSerializer(); string xmlProfilePath = Path.Combine(DefaultProfilePath, xmlSerializer.ProfileFile); string jsonProfilePath = Path.Combine(DefaultProfilePath, jsonSerializer.ProfileFile); if (store.FileExists(xmlProfilePath)) { AzureProfile profile = xmlSerializer.Deserialize(store.ReadFile(xmlProfilePath)); Copy(profile); SaveProfile(); } else if (store.FileExists(jsonProfilePath)) { // Do JSON parsing } }
public void Deserialize(string contents, AzureProfile profile) { var jsonProfile = JObject.Parse(contents); foreach (var env in jsonProfile["Environments"]) { profile.Environments[(string)env["Name"]] = JsonConvert.DeserializeObject<AzureEnvironment>(env.ToString()); } foreach (var subscription in jsonProfile["Subscriptions"]) { profile.Subscriptions[new Guid((string)subscription["Id"])] = JsonConvert.DeserializeObject<AzureSubscription>(subscription.ToString()); } foreach (var account in jsonProfile["Accounts"]) { profile.Accounts[(string)account["Id"]] = JsonConvert.DeserializeObject<AzureAccount>(account.ToString()); } }
public void Deserialize(string contents, AzureProfile profile) { var jsonProfile = JObject.Parse(contents); foreach (var env in jsonProfile["Environments"]) { profile.Environments[(string)env["Name"]] = JsonConvert.DeserializeObject <AzureEnvironment>(env.ToString()); } foreach (var subscription in jsonProfile["Subscriptions"]) { profile.Subscriptions[new Guid((string)subscription["Id"])] = JsonConvert.DeserializeObject <AzureSubscription>(subscription.ToString()); } foreach (var account in jsonProfile["Accounts"]) { profile.Accounts[(string)account["Id"]] = JsonConvert.DeserializeObject <AzureAccount>(account.ToString()); } }
public void CanGetBasicAuthCredentialFromCredentials() { var getClustersCommand = new GetAzureHDInsightJobCommand(); getClustersCommand.Credential = GetPSCredential(TestCredentials.AzureUserName, TestCredentials.AzurePassword); var waSubscription = new AzureSubscription() { Id = IntegrationTestBase.TestCredentials.SubscriptionId, }; waSubscription.Account = "test"; var profile = new AzureProfile(); var accessTokenCreds = getClustersCommand.GetJobSubmissionClientCredentials( waSubscription, AzureSession.CurrentContext.Environment, IntegrationTestBase.TestCredentials.WellKnownCluster.DnsName, profile); Assert.IsInstanceOfType(accessTokenCreds, typeof(BasicAuthCredential)); var asBasicAuthCredentials = accessTokenCreds as BasicAuthCredential; Assert.IsNotNull(asBasicAuthCredentials); Assert.AreEqual(IntegrationTestBase.TestCredentials.AzureUserName, asBasicAuthCredentials.UserName); Assert.AreEqual(IntegrationTestBase.TestCredentials.AzurePassword, asBasicAuthCredentials.Password); }
public AzureProfile Deserialize(string contents) { ProfileData data = null; AzureProfile profile = new AzureProfile(new VirtualDiskDataStore()); try { DataContractSerializer serializer = new DataContractSerializer(typeof(ProfileData)); using (MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(contents ?? ""))) { data = (ProfileData)serializer.ReadObject(s); } } catch (XmlException) { } if (data != null) { foreach (AzureEnvironmentData oldEnv in data.Environments) { profile.AddEnvironment(oldEnv.ToAzureEnvironment()); } List<AzureEnvironment> envs = profile.Environments; foreach (AzureSubscriptionData oldSubscription in data.Subscriptions) { profile.AddSubscription(oldSubscription.ToAzureSubscription(envs)); if (!string.IsNullOrEmpty(oldSubscription.ManagementCertificate)) { profile.AddCertificate(GeneralUtilities.GetCertificateFromStore(oldSubscription.ManagementCertificate)); } } } return profile; }
public AzureProfile Deserialize(string contents) { ProfileData data = null; AzureProfile profile = new AzureProfile(new VirtualDiskDataStore()); try { DataContractSerializer serializer = new DataContractSerializer(typeof(ProfileData)); using (MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(contents ?? ""))) { data = (ProfileData)serializer.ReadObject(s); } } catch (XmlException) { } if (data != null) { foreach (AzureEnvironmentData oldEnv in data.Environments) { profile.AddEnvironment(oldEnv.ToAzureEnvironment()); } List <AzureEnvironment> envs = profile.Environments; foreach (AzureSubscriptionData oldSubscription in data.Subscriptions) { profile.AddSubscription(oldSubscription.ToAzureSubscription(envs)); if (!string.IsNullOrEmpty(oldSubscription.ManagementCertificate)) { profile.AddCertificate(GeneralUtilities.GetCertificateFromStore(oldSubscription.ManagementCertificate)); } } } return(profile); }
public IAzureHDInsightSubscriptionResolver Create(AzureProfile profile) { return new AzureHDInsightSubscriptionResolver(profile); }
public string Serialize(AzureProfile obj) { throw new NotImplementedException(); }
public ProfileClient(string profilePath) { ProfileClient.UpgradeProfile(); Profile = new AzureProfile(DataStore, profilePath); WarningLog = (s) => Debug.WriteLine(s); }
public string Serialize(AzureProfile obj) { // We do not use the serialize for xml serializer anymore and rely solely on the JSON serializer. throw new NotImplementedException(); }
public string Serialize(AzureProfile obj) { // We do not use the serialize for xml serializer anymore and rely solely on the JSON serializer. throw new NotImplementedException(); }
public ProfileClient(string profilePath) { try { ProfileClient.UpgradeProfile(); Profile = new AzureProfile(DataStore, profilePath); } catch { // Should never fail in constructor } WarningLog = (s) => Debug.WriteLine(s); }
public string Serialize(AzureProfile obj) { throw new NotImplementedException(); }
public AzureHDInsightSubscriptionResolver(AzureProfile profile) { this.profile = profile; }
private static void UpgradeProfile() { string oldProfileFilePath = System.IO.Path.Combine(AzurePowerShell.ProfileDirectory, AzurePowerShell.OldProfileFile); string oldProfileFilePathBackup = System.IO.Path.Combine(AzurePowerShell.ProfileDirectory, AzurePowerShell.OldProfileFileBackup); string newProfileFilePath = System.IO.Path.Combine(AzurePowerShell.ProfileDirectory, AzurePowerShell.ProfileFile); if (DataStore.FileExists(oldProfileFilePath)) { string oldProfilePath = System.IO.Path.Combine(AzurePowerShell.ProfileDirectory, AzurePowerShell.OldProfileFile); try { // Try to backup old profile try { DataStore.CopyFile(oldProfilePath, oldProfileFilePathBackup); } catch { // Ignore any errors here } AzureProfile oldProfile = new AzureProfile(DataStore, oldProfilePath); if (DataStore.FileExists(newProfileFilePath)) { // Merge profile files AzureProfile newProfile = new AzureProfile(DataStore, newProfileFilePath); foreach (var environment in newProfile.Environments.Values) { oldProfile.Environments[environment.Name] = environment; } foreach (var subscription in newProfile.Subscriptions.Values) { oldProfile.Subscriptions[subscription.Id] = subscription; } DataStore.DeleteFile(newProfileFilePath); } // If there were no load errors - delete backup file if (oldProfile.ProfileLoadErrors.Count == 0) { try { DataStore.DeleteFile(oldProfileFilePathBackup); } catch { // Give up } } // Save the profile to the disk oldProfile.Save(); // Rename WindowsAzureProfile.xml to WindowsAzureProfile.json DataStore.RenameFile(oldProfilePath, newProfileFilePath); } catch { // Something really bad happened - try to delete the old profile try { DataStore.DeleteFile(oldProfilePath); } catch { // Ignore any errors } } } }
public bool Deserialize(string contents, AzureProfile profile) { ProfileData data = null; Debug.Assert(profile != null); DeserializeErrors = new List <string>(); DataContractSerializer serializer = new DataContractSerializer(typeof(ProfileData)); using (MemoryStream s = new MemoryStream(Encoding.UTF8.GetBytes(contents ?? ""))) { data = (ProfileData)serializer.ReadObject(s); } if (data != null) { foreach (AzureEnvironmentData oldEnv in data.Environments) { profile.Environments[oldEnv.Name] = oldEnv.ToAzureEnvironment(); } List <AzureEnvironment> envs = profile.Environments.Values.ToList(); foreach (AzureSubscriptionData oldSubscription in data.Subscriptions) { try { var newSubscription = oldSubscription.ToAzureSubscription(envs); if (newSubscription.Account == null) { continue; } var newAccounts = oldSubscription.ToAzureAccounts(); foreach (var account in newAccounts) { if (profile.Accounts.ContainsKey(account.Id)) { profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Tenants, account.GetPropertyAsArray(AzureAccount.Property.Tenants)); profile.Accounts[account.Id].SetOrAppendProperty(AzureAccount.Property.Subscriptions, account.GetPropertyAsArray(AzureAccount.Property.Subscriptions)); } else { profile.Accounts[account.Id] = account; } } profile.Subscriptions[newSubscription.Id] = newSubscription; } catch (Exception ex) { // Skip subscription if failed to load DeserializeErrors.Add(ex.Message); } } } return(DeserializeErrors.Count == 0); }