Skip to content

Commit 8ef5dc2

Browse files
yoshi-automationjskeet
authored andcommitted
feat: add AnalyzeIamPolicy and ExportIamPolicyAnalysis RPCs
PiperOrigin-RevId: 328059685 Source-Author: Google APIs <noreply@google.com> Source-Date: Sun Aug 23 17:12:48 2020 -0700 Source-Repo: googleapis/googleapis Source-Sha: 72eb54c45231d84266ca059473bc1793c394fcb2 Source-Link: googleapis/googleapis@72eb54c
1 parent 203d711 commit 8ef5dc2

7 files changed

Lines changed: 5514 additions & 99 deletions

File tree

apis/Google.Cloud.Asset.V1/Google.Cloud.Asset.V1.Snippets/AssetServiceClientSnippets.g.cs

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -870,5 +870,107 @@ await response.AsRawResponses().ForEachAsync((SearchAllIamPoliciesResponse page)
870870
string nextPageToken = singlePage.NextPageToken;
871871
// End snippet
872872
}
873+
874+
/// <summary>Snippet for AnalyzeIamPolicy</summary>
875+
public void AnalyzeIamPolicyRequestObject()
876+
{
877+
// Snippet: AnalyzeIamPolicy(AnalyzeIamPolicyRequest, CallSettings)
878+
// Create client
879+
AssetServiceClient assetServiceClient = AssetServiceClient.Create();
880+
// Initialize request argument(s)
881+
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
882+
{
883+
AnalysisQuery = new IamPolicyAnalysisQuery(),
884+
ExecutionTimeout = new Duration(),
885+
};
886+
// Make the request
887+
AnalyzeIamPolicyResponse response = assetServiceClient.AnalyzeIamPolicy(request);
888+
// End snippet
889+
}
890+
891+
/// <summary>Snippet for AnalyzeIamPolicyAsync</summary>
892+
public async Task AnalyzeIamPolicyRequestObjectAsync()
893+
{
894+
// Snippet: AnalyzeIamPolicyAsync(AnalyzeIamPolicyRequest, CallSettings)
895+
// Additional: AnalyzeIamPolicyAsync(AnalyzeIamPolicyRequest, CancellationToken)
896+
// Create client
897+
AssetServiceClient assetServiceClient = await AssetServiceClient.CreateAsync();
898+
// Initialize request argument(s)
899+
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
900+
{
901+
AnalysisQuery = new IamPolicyAnalysisQuery(),
902+
ExecutionTimeout = new Duration(),
903+
};
904+
// Make the request
905+
AnalyzeIamPolicyResponse response = await assetServiceClient.AnalyzeIamPolicyAsync(request);
906+
// End snippet
907+
}
908+
909+
/// <summary>Snippet for ExportIamPolicyAnalysis</summary>
910+
public void ExportIamPolicyAnalysisRequestObject()
911+
{
912+
// Snippet: ExportIamPolicyAnalysis(ExportIamPolicyAnalysisRequest, CallSettings)
913+
// Create client
914+
AssetServiceClient assetServiceClient = AssetServiceClient.Create();
915+
// Initialize request argument(s)
916+
ExportIamPolicyAnalysisRequest request = new ExportIamPolicyAnalysisRequest
917+
{
918+
AnalysisQuery = new IamPolicyAnalysisQuery(),
919+
OutputConfig = new IamPolicyAnalysisOutputConfig(),
920+
};
921+
// Make the request
922+
Operation<ExportIamPolicyAnalysisResponse, ExportIamPolicyAnalysisRequest> response = assetServiceClient.ExportIamPolicyAnalysis(request);
923+
924+
// Poll until the returned long-running operation is complete
925+
Operation<ExportIamPolicyAnalysisResponse, ExportIamPolicyAnalysisRequest> completedResponse = response.PollUntilCompleted();
926+
// Retrieve the operation result
927+
ExportIamPolicyAnalysisResponse result = completedResponse.Result;
928+
929+
// Or get the name of the operation
930+
string operationName = response.Name;
931+
// This name can be stored, then the long-running operation retrieved later by name
932+
Operation<ExportIamPolicyAnalysisResponse, ExportIamPolicyAnalysisRequest> retrievedResponse = assetServiceClient.PollOnceExportIamPolicyAnalysis(operationName);
933+
// Check if the retrieved long-running operation has completed
934+
if (retrievedResponse.IsCompleted)
935+
{
936+
// If it has completed, then access the result
937+
ExportIamPolicyAnalysisResponse retrievedResult = retrievedResponse.Result;
938+
}
939+
// End snippet
940+
}
941+
942+
/// <summary>Snippet for ExportIamPolicyAnalysisAsync</summary>
943+
public async Task ExportIamPolicyAnalysisRequestObjectAsync()
944+
{
945+
// Snippet: ExportIamPolicyAnalysisAsync(ExportIamPolicyAnalysisRequest, CallSettings)
946+
// Additional: ExportIamPolicyAnalysisAsync(ExportIamPolicyAnalysisRequest, CancellationToken)
947+
// Create client
948+
AssetServiceClient assetServiceClient = await AssetServiceClient.CreateAsync();
949+
// Initialize request argument(s)
950+
ExportIamPolicyAnalysisRequest request = new ExportIamPolicyAnalysisRequest
951+
{
952+
AnalysisQuery = new IamPolicyAnalysisQuery(),
953+
OutputConfig = new IamPolicyAnalysisOutputConfig(),
954+
};
955+
// Make the request
956+
Operation<ExportIamPolicyAnalysisResponse, ExportIamPolicyAnalysisRequest> response = await assetServiceClient.ExportIamPolicyAnalysisAsync(request);
957+
958+
// Poll until the returned long-running operation is complete
959+
Operation<ExportIamPolicyAnalysisResponse, ExportIamPolicyAnalysisRequest> completedResponse = await response.PollUntilCompletedAsync();
960+
// Retrieve the operation result
961+
ExportIamPolicyAnalysisResponse result = completedResponse.Result;
962+
963+
// Or get the name of the operation
964+
string operationName = response.Name;
965+
// This name can be stored, then the long-running operation retrieved later by name
966+
Operation<ExportIamPolicyAnalysisResponse, ExportIamPolicyAnalysisRequest> retrievedResponse = await assetServiceClient.PollOnceExportIamPolicyAnalysisAsync(operationName);
967+
// Check if the retrieved long-running operation has completed
968+
if (retrievedResponse.IsCompleted)
969+
{
970+
// If it has completed, then access the result
971+
ExportIamPolicyAnalysisResponse retrievedResult = retrievedResponse.Result;
972+
}
973+
// End snippet
974+
}
873975
}
874976
}

apis/Google.Cloud.Asset.V1/Google.Cloud.Asset.V1.Tests/AssetServiceClientTest.g.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -708,5 +708,59 @@ public void DeleteFeedResourceNames()
708708
await client.DeleteFeedAsync(request.FeedName, st::CancellationToken.None);
709709
mockGrpcClient.VerifyAll();
710710
}
711+
712+
[xunit::FactAttribute]
713+
public void AnalyzeIamPolicyRequestObject()
714+
{
715+
moq::Mock<AssetService.AssetServiceClient> mockGrpcClient = new moq::Mock<AssetService.AssetServiceClient>(moq::MockBehavior.Strict);
716+
mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock<lro::Operations.OperationsClient>().Object);
717+
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
718+
{
719+
AnalysisQuery = new IamPolicyAnalysisQuery(),
720+
ExecutionTimeout = new wkt::Duration(),
721+
};
722+
AnalyzeIamPolicyResponse expectedResponse = new AnalyzeIamPolicyResponse
723+
{
724+
MainAnalysis = new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
725+
ServiceAccountImpersonationAnalysis =
726+
{
727+
new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
728+
},
729+
FullyExplored = false,
730+
};
731+
mockGrpcClient.Setup(x => x.AnalyzeIamPolicy(request, moq::It.IsAny<grpccore::CallOptions>())).Returns(expectedResponse);
732+
AssetServiceClient client = new AssetServiceClientImpl(mockGrpcClient.Object, null);
733+
AnalyzeIamPolicyResponse response = client.AnalyzeIamPolicy(request);
734+
xunit::Assert.Same(expectedResponse, response);
735+
mockGrpcClient.VerifyAll();
736+
}
737+
738+
[xunit::FactAttribute]
739+
public async stt::Task AnalyzeIamPolicyRequestObjectAsync()
740+
{
741+
moq::Mock<AssetService.AssetServiceClient> mockGrpcClient = new moq::Mock<AssetService.AssetServiceClient>(moq::MockBehavior.Strict);
742+
mockGrpcClient.Setup(x => x.CreateOperationsClient()).Returns(new moq::Mock<lro::Operations.OperationsClient>().Object);
743+
AnalyzeIamPolicyRequest request = new AnalyzeIamPolicyRequest
744+
{
745+
AnalysisQuery = new IamPolicyAnalysisQuery(),
746+
ExecutionTimeout = new wkt::Duration(),
747+
};
748+
AnalyzeIamPolicyResponse expectedResponse = new AnalyzeIamPolicyResponse
749+
{
750+
MainAnalysis = new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
751+
ServiceAccountImpersonationAnalysis =
752+
{
753+
new AnalyzeIamPolicyResponse.Types.IamPolicyAnalysis(),
754+
},
755+
FullyExplored = false,
756+
};
757+
mockGrpcClient.Setup(x => x.AnalyzeIamPolicyAsync(request, moq::It.IsAny<grpccore::CallOptions>())).Returns(new grpccore::AsyncUnaryCall<AnalyzeIamPolicyResponse>(stt::Task.FromResult(expectedResponse), null, null, null, null));
758+
AssetServiceClient client = new AssetServiceClientImpl(mockGrpcClient.Object, null);
759+
AnalyzeIamPolicyResponse responseCallSettings = await client.AnalyzeIamPolicyAsync(request, gaxgrpc::CallSettings.FromCancellationToken(st::CancellationToken.None));
760+
xunit::Assert.Same(expectedResponse, responseCallSettings);
761+
AnalyzeIamPolicyResponse responseCancellationToken = await client.AnalyzeIamPolicyAsync(request, st::CancellationToken.None);
762+
xunit::Assert.Same(expectedResponse, responseCancellationToken);
763+
mockGrpcClient.VerifyAll();
764+
}
711765
}
712766
}

0 commit comments

Comments
 (0)