Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new attachment between a steering policy and a domain, giving the policy permission to answer queries for the specified domain.
        /// A steering policy must be attached to a domain for the policy to answer DNS queries for that domain.
        ///
        /// For the purposes of access control, the attachment is automatically placed into the same compartment as the domain's zone.
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public CreateSteeringPolicyAttachmentResponse CreateSteeringPolicyAttachment(CreateSteeringPolicyAttachmentRequest request)
        {
            var uri = new Uri($"{GetEndPoint(DNSServices.SteeringPolicyAttachments, this.Region)}");

            using (var webResponse = this.RestClient.Post(uri, request.CreateSteeringPolicyAttachmentDetails, new HttpRequestHeaderParam()
            {
                OpcRetryToken = request.OpcRetryToken
            }))
                using (var stream = webResponse.GetResponseStream())
                    using (var reader = new StreamReader(stream))
                    {
                        var response = reader.ReadToEnd();

                        return(new CreateSteeringPolicyAttachmentResponse()
                        {
                            SteeringPolicyAttachment = this.JsonSerializer.Deserialize <SteeringPolicyAttachmentDetails>(response),
                            OpcRequestId = webResponse.Headers.Get("opc-request-id"),
                            ETag = webResponse.Headers.Get("ETag")
                        });
                    }
        }
        protected override void ProcessRecord()
        {
            base.ProcessRecord();
            CreateSteeringPolicyAttachmentRequest request;

            try
            {
                request = new CreateSteeringPolicyAttachmentRequest
                {
                    CreateSteeringPolicyAttachmentDetails = CreateSteeringPolicyAttachmentDetails,
                    OpcRetryToken = OpcRetryToken,
                    OpcRequestId  = OpcRequestId
                };

                response = client.CreateSteeringPolicyAttachment(request).GetAwaiter().GetResult();
                WriteOutput(response, response.SteeringPolicyAttachment);
                FinishProcessing(response);
            }
            catch (Exception ex)
            {
                TerminatingErrorDuringExecution(ex);
            }
        }