Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pikumar mab1 #3

Merged
merged 12 commits into from
Apr 14, 2016
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,27 @@ public ASRVaultCreds GenerateVaultCredential(X509Certificate2 managementCert, AR
return asrVaultCreds;
}

/// <summary>
/// Upload cert to idmgmt
/// </summary>
/// <param name="managementCert">certificate to be uploaded</param>
/// <param name="vault">vault object</param>
/// <returns>Upload Certificate Response</returns>
public UploadCertificateResponse UploadCertificate(X509Certificate2 managementCert, ARSVault vault)
{
var certificateArgs = new CertificateArgs();
certificateArgs.Properties = new Dictionary<string, string>();
certificateArgs.Properties.Add("certificate", Convert.ToBase64String(managementCert.GetRawCertData()));

var response = this.recoveryServicesClient.VaultExtendedInfo.UploadCertificateAsync(
vault.ResouceGroupName,
vault.Name,
certificateArgs, managementCert.FriendlyName,
this.GetRequestHeaders());
response.Wait();
return response.Result;
}

/// <summary>
/// Changes the Vault context
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -358,10 +358,11 @@ public VaultCreds()
/// <param name="resourceName">resource name</param>
/// <param name="managementCert">management cert</param>
/// <param name="acsNamespace">authenticating service namespace</param>
public VaultCreds(string subscriptionId, string resourceName, string managementCert, AcsNamespace acsNamespace)
/// <param name="resourceType">resource type backup vault or ASR vault</param>
public VaultCreds(string subscriptionId, string resourceName, string managementCert, AcsNamespace acsNamespace, string resourceType = null)
{
this.SubscriptionId = subscriptionId;
this.ResourceType = Constants.ASRVaultType;
this.ResourceType = string.IsNullOrEmpty(resourceType) ? Constants.ASRVaultType : resourceType;
this.ResourceName = resourceName;
this.ManagementCert = managementCert;
this.AcsNamespace = acsNamespace;
Expand Down Expand Up @@ -504,6 +505,54 @@ public ASRVaultCreds(
#endregion
}

/// <summary>
/// Class to define backup vault credentials
/// </summary>
[DataContract]
public class BackupVaultCreds : VaultCreds
{
/// <summary>
/// Gets or sets the agent links
/// </summary>
[DataMember(Order = 0)]
public string AgentLinks { get; set; }

#region Constructors

/// <summary>
/// Initializes a new instance of the BackupVaultCreds class
/// </summary>
public BackupVaultCreds() { }

/// <summary>
/// Initializes a new instance of the BackupVaultCreds class
/// </summary>
/// <param name="subscriptionId">subscription Id</param>
/// <param name="resourceType">resource type</param>
/// <param name="resourceName">resource name</param>
/// <param name="managementCert">management cert</param>
/// <param name="acsNamespace">acs namespace</param>
public BackupVaultCreds(string subscriptionId, string resourceName, string managementCert, AcsNamespace acsNamespace)
: base(subscriptionId, resourceName, managementCert, acsNamespace, Constants.BackupVaultType) { }

/// <summary>
/// Initializes a new instance of the BackupVaultCreds class
/// </summary>
/// <param name="subscriptionId">subscription Id</param>
/// <param name="resourceType">resource type</param>
/// <param name="resourceName">resource name</param>
/// <param name="managementCert">management cert</param>
/// <param name="acsNamespace">acs namespace</param>
/// <param name="agentLinks">agent links</param>
public BackupVaultCreds(string subscriptionId, string resourceName, string managementCert, AcsNamespace acsNamespace, string agentLinks)
: this(subscriptionId, resourceName, managementCert, acsNamespace)
{
AgentLinks = agentLinks;
}

#endregion
}

/// <summary>
/// Class to define ACS name space
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ public class Constants
/// </summary>
public const string ASRVaultType = "HyperVRecoveryManagerVault";

/// <summary>
/// Backup vault type
/// </summary>
public const string BackupVaultType = "Vaults";

/// <summary>
/// Vault Credential version.
/// </summary>
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,22 @@ Please provide a storage account with the same location as that of the vault.</v
<data name="SiteNotFound" xml:space="preserve">
<value>Site {0} is not associated with the Vault {1}</value>
</data>
<data name="BackupVaultSerialized" xml:space="preserve">
<value>RecoveryService - Backup Vault - Successfully serialized the file content</value>
</data>
<data name="ExecutingGetVaultCredCmdlet" xml:space="preserve">
<value>Executing cmdlet with SubscriptionId = {0}, ResourceGroupName = {1}, ResourceName = {2}, TargetLocation = {3}</value>
</data>
<data name="SavingVaultCred" xml:space="preserve">
<value>Saving Vault Credentials to file : {0}</value>
</data>
<data name="UploadedCertToIdmgmt" xml:space="preserve">
<value>RecoveryService - Successfully uploaded the certificate</value>
</data>
<data name="UploadingCertToIdmgmt" xml:space="preserve">
<value>RecoveryService - Going to upload the certificate</value>
</data>
<data name="VaultCredPathException" xml:space="preserve">
<value>The target location provided is not a directory. Please provide a directory.</value>
</data>
</root>
Original file line number Diff line number Diff line change
Expand Up @@ -221,5 +221,16 @@ private static CngKey Create2048RsaKey()

return CngKey.Create(CngAlgorithm2.Rsa, null, keyCreationParameters);
}

/// <summary>
/// Returns serialized certificate - Base64 encoded based on the content type
/// </summary>
/// <param name="cert">The certificate provided</param>
/// <param name="contentType">Cert content type</param>
/// <returns>The serialized cert value in string</returns>
public static string SerializeCert(X509Certificate2 cert, X509ContentType contentType)
{
return Convert.ToBase64String(cert.Export(contentType));
}
}
}
Loading