Skip to content

Commit

Permalink
feat: add AnalyzeIamPolicy and AnalyzeIamPolicyLongrunning RPCs
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 339708980

Source-Author: Google APIs <noreply@google.com>
Source-Date: Thu Oct 29 11:23:44 2020 -0700
Source-Repo: googleapis/googleapis
Source-Sha: 00bbad4dfd6633cf4b5f9596c1f93b756bb5c776
Source-Link: googleapis/googleapis@00bbad4
  • Loading branch information
yoshi-automation authored and jskeet committed Oct 30, 2020
1 parent 9f1759d commit c42363f
Show file tree
Hide file tree
Showing 7 changed files with 6,101 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -870,5 +870,107 @@ await response.AsRawResponses().ForEachAsync((SearchAllIamPoliciesResponse page)
string nextPageToken = singlePage.NextPageToken;
// End snippet
}

/// <summary>Snippet for AnalyzeIamPolicy</summary>
public void AnalyzeIamPolicyRequestObject()
{
// Snippet: AnalyzeIamPolicy(AnalyzeIamPolicyRequest, CallSettings)
// Create client
AssetServiceClient assetServiceClient = AssetServiceClient.Create();
// Initialize request argument(s)
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
{
AnalysisQuery = new IamPolicyAnalysisQuery(),
ExecutionTimeout = new Duration(),
};
// Make the request
AnalyzeIamPolicyResponse response = assetServiceClient.AnalyzeIamPolicy(request);
// End snippet
}

/// <summary>Snippet for AnalyzeIamPolicyAsync</summary>
public async Task AnalyzeIamPolicyRequestObjectAsync()
{
// Snippet: AnalyzeIamPolicyAsync(AnalyzeIamPolicyRequest, CallSettings)
// Additional: AnalyzeIamPolicyAsync(AnalyzeIamPolicyRequest, CancellationToken)
// Create client
AssetServiceClient assetServiceClient = await AssetServiceClient.CreateAsync();
// Initialize request argument(s)
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
{
AnalysisQuery = new IamPolicyAnalysisQuery(),
ExecutionTimeout = new Duration(),
};
// Make the request
AnalyzeIamPolicyResponse response = await assetServiceClient.AnalyzeIamPolicyAsync(request);
// End snippet
}

/// <summary>Snippet for AnalyzeIamPolicyLongrunning</summary>
public void AnalyzeIamPolicyLongrunningRequestObject()
{
// Snippet: AnalyzeIamPolicyLongrunning(AnalyzeIamPolicyLongrunningRequest, CallSettings)
// Create client
AssetServiceClient assetServiceClient = AssetServiceClient.Create();
// Initialize request argument(s)
AnalyzeIamPolicyLongrunningRequest request = new AnalyzeIamPolicyLongrunningRequest
{
AnalysisQuery = new IamPolicyAnalysisQuery(),
OutputConfig = new IamPolicyAnalysisOutputConfig(),
};
// Make the request
Operation<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest> response = assetServiceClient.AnalyzeIamPolicyLongrunning(request);

// Poll until the returned long-running operation is complete
Operation<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest> completedResponse = response.PollUntilCompleted();
// Retrieve the operation result
AnalyzeIamPolicyLongrunningResponse result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest> retrievedResponse = assetServiceClient.PollOnceAnalyzeIamPolicyLongrunning(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
AnalyzeIamPolicyLongrunningResponse retrievedResult = retrievedResponse.Result;
}
// End snippet
}

/// <summary>Snippet for AnalyzeIamPolicyLongrunningAsync</summary>
public async Task AnalyzeIamPolicyLongrunningRequestObjectAsync()
{
// Snippet: AnalyzeIamPolicyLongrunningAsync(AnalyzeIamPolicyLongrunningRequest, CallSettings)
// Additional: AnalyzeIamPolicyLongrunningAsync(AnalyzeIamPolicyLongrunningRequest, CancellationToken)
// Create client
AssetServiceClient assetServiceClient = await AssetServiceClient.CreateAsync();
// Initialize request argument(s)
AnalyzeIamPolicyLongrunningRequest request = new AnalyzeIamPolicyLongrunningRequest
{
AnalysisQuery = new IamPolicyAnalysisQuery(),
OutputConfig = new IamPolicyAnalysisOutputConfig(),
};
// Make the request
Operation<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest> response = await assetServiceClient.AnalyzeIamPolicyLongrunningAsync(request);

// Poll until the returned long-running operation is complete
Operation<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest> completedResponse = await response.PollUntilCompletedAsync();
// Retrieve the operation result
AnalyzeIamPolicyLongrunningResponse result = completedResponse.Result;

// Or get the name of the operation
string operationName = response.Name;
// This name can be stored, then the long-running operation retrieved later by name
Operation<AnalyzeIamPolicyLongrunningResponse, AnalyzeIamPolicyLongrunningRequest> retrievedResponse = await assetServiceClient.PollOnceAnalyzeIamPolicyLongrunningAsync(operationName);
// Check if the retrieved long-running operation has completed
if (retrievedResponse.IsCompleted)
{
// If it has completed, then access the result
AnalyzeIamPolicyLongrunningResponse retrievedResult = retrievedResponse.Result;
}
// End snippet
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -708,5 +708,59 @@ public void DeleteFeedResourceNames()
await client.DeleteFeedAsync(request.FeedName, st::CancellationToken.None);
mockGrpcClient.VerifyAll();
}

[xunit::FactAttribute]
public void AnalyzeIamPolicyRequestObject()
{
moq::Mock<AssetService.AssetServiceClient> mockGrpcClient = new moq::Mock<AssetService.AssetServiceClient>(moq::MockBehavior.Strict);
mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock<lro::Operations.OperationsClient>().Object);
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
{
AnalysisQuery = new IamPolicyAnalysisQuery(),
ExecutionTimeout = new wkt::Duration(),
};
AnalyzeIamPolicyResponse expectedResponse = new AnalyzeIamPolicyResponse
{
MainAnalysis = new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
ServiceAccountImpersonationAnalysis =
{
new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
},
FullyExplored = false,
};
mockGrpcClient.Setup(x => x.AnalyzeIamPolicy(request, moq::It.IsAny<grpccore::CallOptions>())).Returns(expectedResponse);
AssetServiceClient client = new AssetServiceClientImpl(mockGrpcClient.Object, null);
AnalyzeIamPolicyResponse response = client.AnalyzeIamPolicy(request);
xunit::Assert.Same(expectedResponse, response);
mockGrpcClient.VerifyAll();
}

[xunit::FactAttribute]
public async stt::Task AnalyzeIamPolicyRequestObjectAsync()
{
moq::Mock<AssetService.AssetServiceClient> mockGrpcClient = new moq::Mock<AssetService.AssetServiceClient>(moq::MockBehavior.Strict);
mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock<lro::Operations.OperationsClient>().Object);
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
{
AnalysisQuery = new IamPolicyAnalysisQuery(),
ExecutionTimeout = new wkt::Duration(),
};
AnalyzeIamPolicyResponse expectedResponse = new AnalyzeIamPolicyResponse
{
MainAnalysis = new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
ServiceAccountImpersonationAnalysis =
{
new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
},
FullyExplored = false,
};
mockGrpcClient.Setup(x => x.AnalyzeIamPolicyAsync(request, moq::It.IsAny<grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall<AnalyzeIamPolicyResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
AssetServiceClient client = new AssetServiceClientImpl(mockGrpcClient.Object, null);
AnalyzeIamPolicyResponse responseCallSettings = await client.AnalyzeIamPolicyAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));
xunit::Assert.Same(expectedResponse, responseCallSettings);
AnalyzeIamPolicyResponse responseCancellationToken = await client.AnalyzeIamPolicyAsync(request, st::CancellationToken.None);
xunit::Assert.Same(expectedResponse, responseCancellationToken);
mockGrpcClient.VerifyAll();
}
}
}
Loading

0 comments on commit c42363f

Please sign in to comment.