示例#1
0
        /// <summary>
        /// Creates a new Certificate.
        ///
        /// </summary>
        /// <param name="request">The request object containing the details to send. Required.</param>
        /// <param name="retryConfiguration">The retry configuration that will be used by to send this request. Optional.</param>
        /// <param name="cancellationToken">The cancellation token to cancel this operation. Optional.</param>
        /// <returns>A response object containing details about the completed operation</returns>
        /// <example>Click <a href="https://docs.cloud.oracle.com/en-us/iaas/tools/dot-net-examples/latest/apigateway/CreateCertificate.cs.html">here</a> to see an example of how to use CreateCertificate API.</example>
        public async Task <CreateCertificateResponse> CreateCertificate(CreateCertificateRequest request, RetryConfiguration retryConfiguration = null, CancellationToken cancellationToken = default)
        {
            logger.Trace("Called createCertificate");
            Uri                uri            = new Uri(this.restClient.GetEndpoint(), System.IO.Path.Combine(basePathWithoutHost, "/certificates".Trim('/')));
            HttpMethod         method         = new HttpMethod("POST");
            HttpRequestMessage requestMessage = Converter.ToHttpRequestMessage(uri, method, request);

            requestMessage.Headers.Add("Accept", "application/json");
            GenericRetrier      retryingClient = Retrier.GetPreferredRetrier(retryConfiguration, this.retryConfiguration);
            HttpResponseMessage responseMessage;

            try
            {
                if (retryingClient != null)
                {
                    responseMessage = await retryingClient.MakeRetryingCall(this.restClient.HttpSend, requestMessage, cancellationToken).ConfigureAwait(false);
                }
                else
                {
                    responseMessage = await this.restClient.HttpSend(requestMessage).ConfigureAwait(false);
                }
                this.restClient.CheckHttpResponseMessage(requestMessage, responseMessage);

                return(Converter.FromHttpResponseMessage <CreateCertificateResponse>(responseMessage));
            }
            catch (Exception e)
            {
                logger.Error($"CreateCertificate failed with error: {e.Message}");
                throw;
            }
        }
示例#2
0
        public async Task When_CreatingCertificateRecord_CallsInternalApi_Then_ReturnCertificateWithResponseCode200(
            CreateCertificateRequest request,
            IEnumerable <CreateCertificateResponse> response)
        {
            //Arrange
            CreateBatchCertificateRequest transformedRequest = null;
            var requests = new List <CreateCertificateRequest> {
                request
            };

            _mockApiClient.Setup(s => s.CreateCertificates(It.IsAny <IEnumerable <CreateBatchCertificateRequest> >()))
            .Callback <IEnumerable <CreateBatchCertificateRequest> >((input) => transformedRequest = input.First())
            .ReturnsAsync(response);

            //Act
            var result = await _controller.CreateCertificates(requests) as ObjectResult;

            //Assert
            result.StatusCode.Value.Should().Be((int)HttpStatusCode.OK);
            transformedRequest.Should().NotBeNull();
            transformedRequest.Should().BeEquivalentTo(new
            {
                UkPrn = _headerInfo.Object.Ukprn,
                request.RequestId,
                CertificateData = new
                {
                    request.Standard,
                    request.Learner,
                    request.LearningDetails,
                    request.PostalContact
                }
            });

            result.Value.Should().Be(response);
        }
示例#3
0
        /// <summary>
        /// 创建证书
        /// </summary>
        public CreateCertificateResponse CreateCertificate(CreateCertificateRequest createCertificateRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();
            string              urlPath          = HttpUtils.AddUrlPath("/v3/{project_id}/elb/certificates", urlParam);
            SdkRequest          request          = HttpUtils.InitSdkRequest(urlPath, "application/json;charset=UTF-8", createCertificateRequest);
            HttpResponseMessage response         = DoHttpRequestSync("POST", request);

            return(JsonUtils.DeSerialize <CreateCertificateResponse>(response));
        }
示例#4
0
        /// <summary>
        /// 创建SSL证书
        /// </summary>
        public async Task <CreateCertificateResponse> CreateCertificateAsync(CreateCertificateRequest createCertificateRequest)
        {
            Dictionary <string, string> urlParam = new Dictionary <string, string>();
            string              urlPath          = HttpUtils.AddUrlPath("/v2/{project_id}/elb/certificates", urlParam);
            SdkRequest          request          = HttpUtils.InitSdkRequest(urlPath, "application/json", createCertificateRequest);
            HttpResponseMessage response         = await DoHttpRequestAsync("POST", request);

            return(JsonUtils.DeSerialize <CreateCertificateResponse>(response));
        }
示例#5
0
        /// <summary>
        /// Activates the device.
        /// </summary>
        /// <param name="activation">The activation.</param>
        /// <returns></returns>
        public async Task <OperationResultDto <Device, ActivateDeviceStatus> > ActivateDevice(Activation activation)
        {
            var device = await this.GetDevice(activation.ActivationCode, activation.BirthDate);

            if (device == null)
            {
                return(new OperationResultDto <Device, ActivateDeviceStatus>()
                {
                    Status = ActivateDeviceStatus.DeviceNotFound,
                    Content = null
                });
            }

            if (device.Status != Status.NotActivated)
            {
                return(new OperationResultDto <Device, ActivateDeviceStatus>()
                {
                    Status = ActivateDeviceStatus.InvalidaDeviceStatus,
                    Content = null
                });
            }

            var certificateRequest = new CreateCertificateRequest
            {
                Certificate = activation.Certificate,
                Thumbprint  = activation.Thumbprint,
                CustomerId  = device.CustomerId,
                PatientId   = device.PatientId
            };

            await this.usersDataProvider.CreateCertificate(certificateRequest);

            device.Status         = Status.Activated;
            device.DeviceId       = activation.DeviceId;
            device.DeviceType     = activation.DeviceType;
            device.DeviceIdType   = activation.DeviceIdType;
            device.Certificate    = activation.Certificate;
            device.Thumbprint     = activation.Thumbprint;
            device.DeviceModel    = string.IsNullOrEmpty(activation.DeviceModel) ? device.DeviceModel : activation.DeviceModel;
            device.ActivationCode = null;
            //This is commented because it causes an exception in case of updating activated device.
            //Note that BirthDate is required in UpdateDeviceRequestDto
            //device.BirthDate = null;

            await this.unitOfWork.SaveAsync();

            return(new OperationResultDto <Device, ActivateDeviceStatus>()
            {
                Status = ActivateDeviceStatus.Success,
                Content = device
            });
        }
示例#6
0
 /// <summary>
 /// 本接口(CreateCertificate)用于创建付费证书。
 /// </summary>
 /// <param name="req"><see cref="CreateCertificateRequest"/></param>
 /// <returns><see cref="CreateCertificateResponse"/></returns>
 public CreateCertificateResponse CreateCertificateSync(CreateCertificateRequest req)
 {
      JsonResponseModel<CreateCertificateResponse> rsp = null;
      try
      {
          var strResp = this.InternalRequestSync(req, "CreateCertificate");
          rsp = JsonConvert.DeserializeObject<JsonResponseModel<CreateCertificateResponse>>(strResp);
      }
      catch (JsonSerializationException e)
      {
          throw new TencentCloudSDKException(e.Message);
      }
      return rsp.Response;
 }
示例#7
0
        public async Task CreateCertificate()
        {
            // arrange
            var certificateData = Builder <CertificateData> .CreateNew().With(cd => cd.Learner = Builder <Learner> .CreateNew().Build())
                                  .With(cd => cd.Standard        = Builder <Standard> .CreateNew().Build())
                                  .With(cd => cd.LearningDetails = Builder <LearningDetails> .CreateNew().Build())
                                  .With(cd => cd.PostalContact   = Builder <PostalContact> .CreateNew().Build())
                                  .Build();

            var status = new Status {
                CurrentStatus = "Draft"
            };
            var created = new Created {
                CreatedAt = DateTime.UtcNow, CreatedBy = "Test"
            };

            var certificate = new Certificate {
                CertificateData = certificateData, Status = status, Created = created
            };
            var certificateRequest = new CreateCertificateRequest
            {
                Learner         = certificate.CertificateData.Learner,
                Standard        = certificate.CertificateData.Standard,
                LearningDetails = certificate.CertificateData.LearningDetails,
                PostalContact   = certificate.CertificateData.PostalContact
            };

            var expectedResponse = new List <CreateCertificateResponse>
            {
                new CreateCertificateResponse {
                    Certificate = certificate
                }
            };

            _MockHttp.When(HttpMethod.Post, $"{apiBaseAddress}/api/v1/certificate")
            .Respond(HttpStatusCode.OK, "application/json", JsonConvert.SerializeObject(expectedResponse));

            // act
            var actual = await _ApiClient.CreateCertificates(new List <CreateCertificateRequest> {
                certificateRequest
            });

            // assert
            Assert.That(actual, Has.Count.EqualTo(1));
            Assert.That(actual.First().ValidationErrors, Has.Count.EqualTo(0));
            Assert.That(actual.First().Certificate, Is.EqualTo(expectedResponse.First().Certificate));
        }
示例#8
0
        public async Task <ICertificate> CreateAsync(CreateCertificateRequest request)
        {
            Ensure.NotNull(request, nameof(request));

            var cert = new X509Certificate2(request.Data);

            var certificateId = await db.Certificates.Sequence.NextAsync();

            if (request.ParentId != null)
            {
                // Ensure the parent exist...
                var parent = await GetAsync(request.ParentId.Value);
            }

            var certificate = new CertificateInfo(
                id: certificateId,
                ownerId: request.OwnerId,
                data: request.Data,
                parentId: request.ParentId,
                encryptedPrivateKey: request.EncryptedPrivateKey,
                expires: cert.NotAfter.ToUniversalTime()
                );

            var subjects = new CertificateSubject[request.Subjects.Length];

            for (var i = 0; i < subjects.Length; i++)
            {
                subjects[i] = new CertificateSubject(
                    certificateId: certificate.Id,
                    path: request.Subjects[i],
                    flags: i == 0 ? CertificateSubjectFlags.Primary : CertificateSubjectFlags.None
                    );
            }

            // TODO: Execute inside of a transaction

            await db.Certificates.InsertAsync(certificate);

            await db.CertificateSubjects.InsertAsync(subjects);

            return(certificate);
        }
        public async Task CreateCertificatesExample()
        {
            long   uln               = 1234567890;
            string firstName         = "Fred";
            string lastName          = "Blogs";
            int    standardCode      = 1;
            string standardReference = "ST0127";
            string overallGrade      = "PASS";
            string contactName       = "Shreya Smith";
            string organisation      = "Contoso Ltd";
            string address           = "123 Test Road";
            string city              = "Townsville";
            string postcode          = "ZY9 9ZY";

            CreateCertificateRequest newCertificate = new CreateCertificateRequest
            {
                Learner = new Learner {
                    Uln = uln, GivenNames = firstName, FamilyName = lastName
                },
                Standard = new Standard {
                    StandardCode = standardCode, StandardReference = standardReference
                },
                LearningDetails = new LearningDetails {
                    OverallGrade = overallGrade, AchievementDate = DateTime.UtcNow
                },
                PostalContact = new PostalContact {
                    ContactName = contactName, Organisation = organisation, AddressLine1 = address, City = city, PostCode = postcode
                }
            };

            if (newCertificate.IsValid(out _))
            {
                // NOTE: The External API performs validation, however it is a good idea to check beforehand
                await _CertificateApiClient.CreateCertificates(new List <CreateCertificateRequest> {
                    newCertificate
                });
            }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CreateCertificateRequest request;

            try
            {
                request = new CreateCertificateRequest
                {
                    CreateCertificateDetails = CreateCertificateDetails,
                    OpcRetryToken            = OpcRetryToken,
                    OpcRequestId             = OpcRequestId
                };

                response = client.CreateCertificate(request).GetAwaiter().GetResult();
                WriteOutput(response, response.Certificate);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }
示例#11
0
 /// <summary>
 /// Save info about patient device certificate
 /// in token service.
 /// </summary>
 /// <returns></returns>
 public async Task CreateCertificate(CreateCertificateRequest request)
 {
     await _apiClient.SendRequestAsync("api/certificates", request, Method.POST, null);
 }
示例#12
0
 CreateCertificateResponse IOnVifDevice.CreateCertificate(CreateCertificateRequest request)
 {
     throw new NotImplementedException();
 }