protected override LoggingBaseServiceRequest <LogSink> GetRequest(LogSink logSink)
 {
     ProjectsResource.SinksResource.CreateRequest createRequest = Service.Projects.Sinks.Create(logSink, $"projects/{Project}");
     if (UniqueWriterIdentity.IsPresent)
     {
         createRequest.UniqueWriterIdentity = UniqueWriterIdentity.ToBool();
     }
     return(createRequest);
 }
        protected override LoggingBaseServiceRequest <LogSink> GetRequest(LogSink logSink)
        {
            string formattedSinkName = PrefixProjectToSinkName(SinkName, Project);

            bool destinationNotSpecified = GcsBucketDestination == null &&
                                           BigQueryDataSetDestination == null && PubSubTopicDestination == null;

            // First checks whether the sink exists or not.
            try
            {
                ProjectsResource.SinksResource.GetRequest getRequest = Service.Projects.Sinks.Get(formattedSinkName);
                LogSink existingSink = getRequest.Execute();

                // If destinations are not given, we still have to set the destination to the existing log sink destination.
                // Otherwise, the API will throw error.
                if (destinationNotSpecified)
                {
                    logSink.Destination = existingSink.Destination;
                }
            }
            catch (GoogleApiException ex) when(ex.HttpStatusCode == HttpStatusCode.NotFound)
            {
                // If log sink does not exist to begin with, then we at least need a destination for the sink.
                // So simply throws a terminating error if we don't have that.
                if (destinationNotSpecified)
                {
                    // Here we throw terminating error because the cmdlet cannot proceed without a valid sink.
                    string exceptionMessage = $"Sink '{SinkName}' does not exist in project '{Project}'." +
                                              "Please use New-GcLogSink cmdlet to create it (Set-GcLogSink can only create a sink if you supply a destination).";
                    ErrorRecord errorRecord = new ErrorRecord(
                        new ArgumentException(exceptionMessage),
                        "SinkNotFound",
                        ErrorCategory.ResourceUnavailable,
                        SinkName);
                    ThrowTerminatingError(errorRecord);
                }

                // Otherwise, returns a create request to create the log sink.
                ProjectsResource.SinksResource.CreateRequest createRequest = Service.Projects.Sinks.Create(logSink, $"projects/{Project}");
                if (UniqueWriterIdentity.IsPresent)
                {
                    createRequest.UniqueWriterIdentity = UniqueWriterIdentity.ToBool();
                }
                return(createRequest);
            }

            ProjectsResource.SinksResource.UpdateRequest updateRequest = Service.Projects.Sinks.Update(logSink, formattedSinkName);
            if (UniqueWriterIdentity.IsPresent)
            {
                updateRequest.UniqueWriterIdentity = UniqueWriterIdentity.ToBool();
            }
            return(updateRequest);
        }