public async Task CreateSinkAsync2() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; LogSink expectedResponse = new LogSink { Name = "name3373707", DestinationAsResourceName = new BillingName("[BILLING_ACCOUNT]"), Filter = "filter-1274492040", WriterIdentity = "writerIdentity775638794", IncludeChildren = true, }; mockGrpcClient.Setup(x => x.CreateSinkAsync(request, It.IsAny <CallOptions>())) .Returns(new Grpc.Core.AsyncUnaryCall <LogSink>(Task.FromResult(expectedResponse), null, null, null, null)); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); LogSink response = await client.CreateSinkAsync(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
public void CreateSink2() { Mock <ConfigServiceV2.ConfigServiceV2Client> mockGrpcClient = new Mock <ConfigServiceV2.ConfigServiceV2Client>(MockBehavior.Strict); CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; LogSink expectedResponse = new LogSink { Name = "name3373707", DestinationAsResourceName = new ProjectName("[PROJECT]"), Filter = "filter-1274492040", WriterIdentity = "writerIdentity775638794", IncludeChildren = true, }; mockGrpcClient.Setup(x => x.CreateSink(request, It.IsAny <CallOptions>())) .Returns(expectedResponse); ConfigServiceV2Client client = new ConfigServiceV2ClientImpl(mockGrpcClient.Object, null); LogSink response = client.CreateSink(request); Assert.Same(expectedResponse, response); mockGrpcClient.VerifyAll(); }
// [END list_log_entries] // [START create_log_sink] private void CreateSink(string sinkId, string logId) { var sinkClient = ConfigServiceV2Client.Create(); CreateSinkRequest sinkRequest = new CreateSinkRequest(); LogSink myLogSink = new LogSink(); string sinkName = $"projects/{s_projectId}/sinks/{sinkId}"; myLogSink.Name = sinkId; // This creates a sink using a Google Cloud Storage bucket // named the same as the projectId. // This requires editing the bucket's permissions to add the Entity Group // named '*****@*****.**' with 'Owner' access for the bucket. // If this is being run with a Google Cloud service account, // that account will need to be granted 'Owner' access to the Project. // In Powershell, use this command: // PS > Add-GcsBucketAcl <your-bucket-name> -Role OWNER -Group [email protected] myLogSink.Destination = "storage.googleapis.com/" + s_projectId; string logName = $"projects/{s_projectId}/logs/{logId}"; myLogSink.Filter = $"logName={logName}AND severity<=ERROR"; sinkRequest.Parent = $"projects/{s_projectId}"; sinkRequest.Sink = myLogSink; sinkClient.CreateSink(sinkRequest.Parent, myLogSink); Console.WriteLine($"Created sink: {sinkId}."); }
/// <summary>Snippet for CreateSink</summary> public void CreateSink_RequestObject() { // Snippet: CreateSink(CreateSinkRequest,CallSettings) // Create client ConfigServiceV2Client configServiceV2Client = ConfigServiceV2Client.Create(); // Initialize request argument(s) CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; // Make the request LogSink response = configServiceV2Client.CreateSink(request); // End snippet }
/// <summary>Snippet for CreateSinkAsync</summary> public async Task CreateSinkAsync_RequestObject() { // Snippet: CreateSinkAsync(CreateSinkRequest,CallSettings) // Additional: CreateSinkAsync(CreateSinkRequest,CancellationToken) // Create client ConfigServiceV2Client configServiceV2Client = await ConfigServiceV2Client.CreateAsync(); // Initialize request argument(s) CreateSinkRequest request = new CreateSinkRequest { ParentAsParentNameOneof = ParentNameOneof.From(new ProjectName("[PROJECT]")), Sink = new LogSink(), }; // Make the request LogSink response = await configServiceV2Client.CreateSinkAsync(request); // End snippet }
// [END list_log_entries] // [START create_log_sink] private void CreateSink(string sinkId, string logId) { var sinkClient = ConfigServiceV2Client.Create(); CreateSinkRequest sinkRequest = new CreateSinkRequest(); LogSink myLogSink = new LogSink(); myLogSink.Name = sinkId; // This creates a sink using a Google Cloud Storage bucket // named the same as the projectId. // This requires editing the bucket's permissions to add the Entity Group // named '*****@*****.**' with 'Owner' access for the bucket. // If this is being run with a Google Cloud service account, // that account will need to be granted 'Owner' access to the Project. // In Powershell, use this command: // PS > Add-GcsBucketAcl <your-bucket-name> -Role OWNER -Group [email protected] myLogSink.Destination = "storage.googleapis.com/" + s_projectId; LogName logName = new LogName(s_projectId, logId); myLogSink.Filter = $"logName={logName.ToString()}AND severity<=ERROR"; ProjectName projectName = new ProjectName(s_projectId); sinkRequest.Sink = myLogSink; sinkClient.CreateSink(ParentNameOneof.From(projectName), myLogSink, RetryAWhile); Console.WriteLine($"Created sink: {sinkId}."); }