Microsoft.Azure.Commands.RecoveryServices.PSRecoveryServicesClient.GenerateVaultCredential C# (CSharp) Method

GenerateVaultCredential() public method

Gets the vault credential object
public GenerateVaultCredential ( X509Certificate2 managementCert, ARSVault vault, ASRSite site ) : ASRVaultCreds
managementCert System.Security.Cryptography.X509Certificates.X509Certificate2 certificate to be uploaded
vault ARSVault vault object
site ASRSite
return Microsoft.Azure.Portal.RecoveryServices.Models.Common.ASRVaultCreds
        public ASRVaultCreds GenerateVaultCredential(X509Certificate2 managementCert, ARSVault vault, ASRSite site)
        {
            ASRVaultCreds currentVaultContext = PSRecoveryServicesClient.arsVaultCreds;

            string resourceProviderNamespace = string.Empty;
            string resourceType = string.Empty;
            Utilities.GetResourceProviderNamespaceAndType(vault.ID, out resourceProviderNamespace, out resourceType);
            // Update vault settings with the working vault to generate file
            Utilities.UpdateCurrentVaultContext(new ASRVaultCreds()
            {
                ResourceGroupName = vault.ResourceGroupName,
                ResourceName = vault.Name,
                ResourceNamespace = resourceProviderNamespace,
                ARMResourceType = resourceType
            });

            // Get Channel Integrity key
            string channelIntegrityKey;
            Task<string> getChannelIntegrityKey = this.GetChannelIntegrityKey();

            // Making sure we can generate the file, once the SDK and portal are inter-operable
            // upload certificate and fetch of ACIK can be made parallel to improvve the performace.
            getChannelIntegrityKey.Wait();

            // Upload certificate
            UploadCertificateResponse acsDetails;
            Task<UploadCertificateResponse> uploadCertificate = this.UpdateVaultCertificate(managementCert);
            uploadCertificate.Wait();

            acsDetails = uploadCertificate.Result;
            channelIntegrityKey = getChannelIntegrityKey.Result;

            ASRVaultCreds arsVaultCreds = this.GenerateCredentialObject(
                                                managementCert,
                                                acsDetails,
                                                channelIntegrityKey,
                                                vault,
                                                site);

            // Update back the original vault settings
            Utilities.UpdateCurrentVaultContext(currentVaultContext);

            return arsVaultCreds;
        }