public override void ExecuteCmdlet() { if (ParameterSetName.Equals(InputObjectParameterSet)) { this.ResourceGroupName = this.InputObject.Resourcegroup; this.Name = this.InputObject.Name; } if (ParameterSetName.Equals(ResourceIdParameterSet)) { this.ResourceGroupName = IotHubUtils.GetResourceGroupName(this.ResourceId); this.Name = IotHubUtils.GetIotHubName(this.ResourceId); } if (!string.IsNullOrEmpty(CertificateName)) { CertificateDescription certificateDescription = this.IotHubClient.Certificates.Get(this.ResourceGroupName, this.Name, this.CertificateName); this.WriteObject(IotHubUtils.ToPSCertificateDescription(certificateDescription)); } else { CertificateListDescription certificateDescriptions = this.IotHubClient.Certificates.ListByIotHub(this.ResourceGroupName, this.Name); if (certificateDescriptions.Value.Count == 1) { this.WriteObject(IotHubUtils.ToPSCertificateDescription(certificateDescriptions.Value[0])); } else { this.WriteObject(IotHubUtils.ToPSCertificates(certificateDescriptions), true); } } }
public async Task CreateAndDelete() { using MockContext context = MockContext.Start(GetType()); Initialize(context); var testName = "unitTestingDPSCertificatesCreateAndDelete"; ResourceGroup rg = await GetResourceGroupAsync(testName).ConfigureAwait(false); ProvisioningServiceDescription service = await GetServiceAsync(testName, rg.Name).ConfigureAwait(false); //add a cert await _provisioningClient.DpsCertificate .CreateOrUpdateAsync( rg.Name, testName, Constants.Certificate.Name, null, Constants.Certificate.Content) .ConfigureAwait(false); CertificateListDescription certificateList = await _provisioningClient.DpsCertificate .ListAsync(rg.Name, testName) .ConfigureAwait(false); certificateList.Value.Should().Contain(x => x.Name == Constants.Certificate.Name); // verify certificate details CertificateResponse certificateDetails = certificateList.Value.FirstOrDefault(x => x.Name == Constants.Certificate.Name); certificateDetails.Should().NotBeNull(); certificateDetails.Properties.Subject.Should().Be(Constants.Certificate.Subject); certificateDetails.Properties.Thumbprint.Should().Be(Constants.Certificate.Thumbprint); // can get a verification code VerificationCodeResponse verificationCodeResponse = await _provisioningClient.DpsCertificate .GenerateVerificationCodeAsync( certificateDetails.Name, certificateDetails.Etag, rg.Name, service.Name) .ConfigureAwait(false); verificationCodeResponse.Properties.Should().NotBeNull(); verificationCodeResponse.Properties.VerificationCode.Should().NotBeNullOrEmpty(); // delete certificate await _provisioningClient.DpsCertificate .DeleteAsync( rg.Name, verificationCodeResponse.Etag, service.Name, Constants.Certificate.Name) .ConfigureAwait(false); certificateList = await _provisioningClient.DpsCertificate .ListAsync(rg.Name, testName) .ConfigureAwait(false); certificateList.Value.Should().NotContain(x => x.Name == Constants.Certificate.Name); }
public static IEnumerable<PSCertificate> ToPSCertificates(CertificateListDescription certificateListDescription) { return ConvertObject<IEnumerable<CertificateDescription>, IEnumerable<PSCertificate>>(certificateListDescription.Value); }
public IList <CertificateResponse> GetIotDpsCertificates(string resourceGroupName, string provisioningServiceName) { CertificateListDescription certificates = this.IotDpsClient.DpsCertificates.List(resourceGroupName, provisioningServiceName); return(certificates.Value); }