diff --git a/.doc_gen/metadata/iam_metadata.yaml b/.doc_gen/metadata/iam_metadata.yaml index 88796e10c81..383f52d39ff 100644 --- a/.doc_gen/metadata/iam_metadata.yaml +++ b/.doc_gen/metadata/iam_metadata.yaml @@ -2662,18 +2662,6 @@ iam_DetachUserPolicy: - ruby.iam.DetachUserPolicy services: iam: {DetachUserPolicy} -iam_PutGroupPolicy: - languages: - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/IAM - excerpts: - - description: - snippet_tags: - - IAM.dotnetv3.PutGroupPolicy - services: - iam: {PutGroupPolicy} iam_PutUserPolicy: languages: Go: @@ -2972,15 +2960,6 @@ iam_DeleteServerCertificate: iam: {DeleteServerCertificate} iam_CreateGroup: languages: - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/IAM - sdkguide: - excerpts: - - description: - snippet_tags: - - IAM.dotnetv3.CreateGroup JavaScript: versions: - sdk_version: 3 @@ -2992,43 +2971,8 @@ iam_CreateGroup: - javascript.v3.iam.actions.CreateGroup services: iam: {CreateGroup} -iam_AddUserToGroup: - languages: - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/IAM - sdkguide: - excerpts: - - description: - snippet_tags: - - IAM.dotnetv3.AddUserToGroup - services: - iam: {AddUserToGroup} -iam_RemoveUserFromGroup: - languages: - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/IAM - sdkguide: - excerpts: - - description: - snippet_tags: - - IAM.dotnetv3.RemoveUserFromGroup - services: - iam: {RemoveUserFromGroup} iam_DeleteGroup: languages: - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/IAM - sdkguide: - excerpts: - - description: - snippet_tags: - - IAM.dotnetv3.DeleteGroup JavaScript: versions: - sdk_version: 3 @@ -3040,19 +2984,6 @@ iam_DeleteGroup: - javascript.v3.iam.actions.DeleteGroup services: iam: {DeleteGroup} -iam_DeleteGroupPolicy: - languages: - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/IAM - sdkguide: - excerpts: - - description: - snippet_tags: - - IAM.dotnetv3.DeleteGroupPolicy - services: - iam: {DeleteGroupPolicy} iam_ListGroups: languages: .NET: @@ -3329,31 +3260,6 @@ iam_DeleteInstanceProfile: - javascript.v3.wkflw.resilient.DeleteInstanceProfile services: iam: {DeleteInstanceProfile} -iam_Scenario_GroupBasics: - title: Create an &IAM; group and add a user to the group using an &AWS; SDK - title_abbrev: Create a group and add a user - synopsis_list: - - Create a group and grant full &S3; access permissions to it. - - Create a new user with no permissions to access &S3;. - - Add the user to the group and show that they now have permissions for &S3;, then clean up resources. - category: Scenarios - languages: - .NET: - versions: - - sdk_version: 3 - github: dotnetv3/IAM - sdkguide: - excerpts: - - description: - snippet_tags: - - IAM.dotnetv3.IAMGroups.Usings - - IAM.dotnetv3.IAMWrapper - - IAM.dotnetv3.IAMGroups - - IAM.dotnetv3.IAMCommon.S3Wrapper - - IAM.dotnetv3.IAMCommon.UIWrapper - services: - iam: {AddUserToGroup, CreateGroup, CreateUser, CreateAccessKey, CreateRole, CreatePolicy, AttachRolePolicy, PutGroupPolicy, - DeleteGroup, DeleteGroupPolicy, DeleteAccessKey, DeleteUser, RemoveUserFromGroup} iam_Scenario_CreateUserAssumeRole: synopsis: create a user and assume a role. &aws_sec_sdk_use-federation-warning; synopsis_list: diff --git a/dotnetv3/DotNetV3Examples.sln b/dotnetv3/DotNetV3Examples.sln index e9f78615f91..df23b2d6cf3 100644 --- a/dotnetv3/DotNetV3Examples.sln +++ b/dotnetv3/DotNetV3Examples.sln @@ -219,8 +219,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Scenarios", "Scenarios", "{ EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IamScenariosCommon", "IAM\Scenarios\IamScenariosCommon\IamScenariosCommon.csproj", "{7A9C0470-3F46-4ABF-8C27-C481C900F0D7}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IAMGroups", "IAM\Scenarios\IAMGroups\IAMGroups.csproj", "{9903CF83-4346-4E05-B6D3-5D89D08A9AC9}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IAMBasics", "IAM\Scenarios\IAMBasics\IAMBasics.csproj", "{65F86381-CA92-4257-9826-0CA369F9CEED}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IAMActions", "IAM\Actions\IAMActions.csproj", "{566ACFAF-FDCB-4013-9C0D-4886869528DC}" @@ -1093,10 +1091,6 @@ Global {7A9C0470-3F46-4ABF-8C27-C481C900F0D7}.Debug|Any CPU.Build.0 = Debug|Any CPU {7A9C0470-3F46-4ABF-8C27-C481C900F0D7}.Release|Any CPU.ActiveCfg = Release|Any CPU {7A9C0470-3F46-4ABF-8C27-C481C900F0D7}.Release|Any CPU.Build.0 = Release|Any CPU - {9903CF83-4346-4E05-B6D3-5D89D08A9AC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9903CF83-4346-4E05-B6D3-5D89D08A9AC9}.Debug|Any CPU.Build.0 = Debug|Any CPU - {9903CF83-4346-4E05-B6D3-5D89D08A9AC9}.Release|Any CPU.ActiveCfg = Release|Any CPU - {9903CF83-4346-4E05-B6D3-5D89D08A9AC9}.Release|Any CPU.Build.0 = Release|Any CPU {65F86381-CA92-4257-9826-0CA369F9CEED}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {65F86381-CA92-4257-9826-0CA369F9CEED}.Debug|Any CPU.Build.0 = Debug|Any CPU {65F86381-CA92-4257-9826-0CA369F9CEED}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -2032,7 +2026,6 @@ Global {1F56F380-B3EF-490C-973B-A9ABA6054151} = {13BBCDD1-667E-4A15-9586-72746FE08716} {098747DB-270D-4F9D-AECD-0F545F3F219B} = {13BBCDD1-667E-4A15-9586-72746FE08716} {7A9C0470-3F46-4ABF-8C27-C481C900F0D7} = {098747DB-270D-4F9D-AECD-0F545F3F219B} - {9903CF83-4346-4E05-B6D3-5D89D08A9AC9} = {098747DB-270D-4F9D-AECD-0F545F3F219B} {65F86381-CA92-4257-9826-0CA369F9CEED} = {098747DB-270D-4F9D-AECD-0F545F3F219B} {566ACFAF-FDCB-4013-9C0D-4886869528DC} = {13BBCDD1-667E-4A15-9586-72746FE08716} {0557715C-76F2-4B76-B223-E1ACEC252B35} = {7A6E328B-09BD-41D8-B64D-B30229B00C1B} diff --git a/dotnetv3/IAM/Actions/IAMWrapper.cs b/dotnetv3/IAM/Actions/IAMWrapper.cs index d68783436a4..9cd03a82962 100644 --- a/dotnetv3/IAM/Actions/IAMWrapper.cs +++ b/dotnetv3/IAM/Actions/IAMWrapper.cs @@ -19,26 +19,6 @@ public IAMWrapper(IAmazonIdentityManagementService IAMService) _IAMService = IAMService; } - // snippet-start:[IAM.dotnetv3.AddUserToGroup] - /// - /// Add an existing IAM user to an existing IAM group. - /// - /// The username of the user to add. - /// The name of the group to add the user to. - /// A Boolean value indicating the success of the action. - public async Task AddUserToGroupAsync(string userName, string groupName) - { - var response = await _IAMService.AddUserToGroupAsync(new AddUserToGroupRequest - { - GroupName = groupName, - UserName = userName, - }); - - return response.HttpStatusCode == HttpStatusCode.OK; - } - - // snippet-end:[IAM.dotnetv3.AddUserToGroup] - // snippet-start:[IAM.dotnetv3.AttachRolePolicy] /// /// Attach an IAM policy to a role. @@ -79,20 +59,6 @@ public async Task CreateAccessKeyAsync(string userName) // snippet-end:[IAM.dotnetv3.CreateAccessKey] - // snippet-start:[IAM.dotnetv3.CreateGroup] - /// - /// Create an IAM group. - /// - /// The name to give the IAM group. - /// The IAM group that was created. - public async Task CreateGroupAsync(string groupName) - { - var response = await _IAMService.CreateGroupAsync(new CreateGroupRequest { GroupName = groupName }); - return response.Group; - } - - // snippet-end:[IAM.dotnetv3.CreateGroup] - // snippet-start:[IAM.dotnetv3.CreatePolicy] /// /// Create an IAM policy. @@ -191,42 +157,6 @@ public async Task DeleteAccessKeyAsync(string accessKeyId, string userName // snippet-end:[IAM.dotnetv3.DeleteAccessKey] - // snippet-start:[IAM.dotnetv3.DeleteGroup] - /// - /// Delete an IAM group. - /// - /// The name of the IAM group to delete. - /// A Boolean value indicating the success of the action. - public async Task DeleteGroupAsync(string groupName) - { - var response = await _IAMService.DeleteGroupAsync(new DeleteGroupRequest { GroupName = groupName }); - return response.HttpStatusCode == HttpStatusCode.OK; - } - - // snippet-end:[IAM.dotnetv3.DeleteGroup] - - // snippet-start:[IAM.dotnetv3.DeleteGroupPolicy] - /// - /// Delete an IAM policy associated with an IAM group. - /// - /// The name of the IAM group associated with the - /// policy. - /// The name of the policy to delete. - /// A Boolean value indicating the success of the action. - public async Task DeleteGroupPolicyAsync(string groupName, string policyName) - { - var request = new DeleteGroupPolicyRequest() - { - GroupName = groupName, - PolicyName = policyName, - }; - - var response = await _IAMService.DeleteGroupPolicyAsync(request); - return response.HttpStatusCode == System.Net.HttpStatusCode.OK; - } - - // snippet-end:[IAM.dotnetv3.DeleteGroupPolicy] - // snippet-start:[IAM.dotnetv3.DeletePolicy] /// /// Delete an IAM policy. @@ -523,51 +453,6 @@ public async Task> ListUsersAsync() // snippet-end:[IAM.dotnetv3.ListUsers] - // snippet-start:[IAM.dotnetv3.RemoveUserFromGroup] - /// - /// Remove a user from an IAM group. - /// - /// The username of the user to remove. - /// The name of the IAM group to remove the user from. - /// A Boolean value indicating the success of the action. - public async Task RemoveUserFromGroupAsync(string userName, string groupName) - { - // Remove the user from the group. - var removeUserRequest = new RemoveUserFromGroupRequest() - { - UserName = userName, - GroupName = groupName, - }; - - var response = await _IAMService.RemoveUserFromGroupAsync(removeUserRequest); - return response.HttpStatusCode == HttpStatusCode.OK; - } - - // snippet-end:[IAM.dotnetv3.RemoveUserFromGroup] - - // snippet-start:[IAM.dotnetv3.PutGroupPolicy] - /// - /// Add or update an inline policy document that is embedded in an IAM group. - /// - /// The name of the IAM group. - /// The name of the IAM policy. - /// The policy document defining the IAM policy. - /// A Boolean value indicating the success of the action. - public async Task PutGroupPolicyAsync(string groupName, string policyName, string policyDocument) - { - var request = new PutGroupPolicyRequest - { - GroupName = groupName, - PolicyName = policyName, - PolicyDocument = policyDocument - }; - - var response = await _IAMService.PutGroupPolicyAsync(request); - return response.HttpStatusCode == System.Net.HttpStatusCode.OK; - } - - // snippet-end:[IAM.dotnetv3.PutGroupPolicy] - // snippet-start:[IAM.dotnetv3.PutRolePolicy] /// /// Update the inline policy document embedded in a role. diff --git a/dotnetv3/IAM/IAMExamples.sln b/dotnetv3/IAM/IAMExamples.sln index 96f9fc0e214..d4482eb9e8c 100644 --- a/dotnetv3/IAM/IAMExamples.sln +++ b/dotnetv3/IAM/IAMExamples.sln @@ -15,9 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IAMBasics", "Scenarios\IAMB EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IAMTests", "Tests\IAMTests.csproj", "{6046A2FC-6A39-4C2D-8DD9-AA3740B17B88}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IAMGroups", "Scenarios\IAMGroups\IAMGroups.csproj", "{B2B9BC93-7C77-4B11-A435-F017D5940F76}" -EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IamScenariosCommon", "Scenarios\IamScenariosCommon\IamScenariosCommon.csproj", "{E2A9A321-23AA-4F1F-B109-549A93222793}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IamScenariosCommon", "Scenarios\IamScenariosCommon\IamScenariosCommon.csproj", "{E2A9A321-23AA-4F1F-B109-549A93222793}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,10 +35,6 @@ Global {6046A2FC-6A39-4C2D-8DD9-AA3740B17B88}.Debug|Any CPU.Build.0 = Debug|Any CPU {6046A2FC-6A39-4C2D-8DD9-AA3740B17B88}.Release|Any CPU.ActiveCfg = Release|Any CPU {6046A2FC-6A39-4C2D-8DD9-AA3740B17B88}.Release|Any CPU.Build.0 = Release|Any CPU - {B2B9BC93-7C77-4B11-A435-F017D5940F76}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B2B9BC93-7C77-4B11-A435-F017D5940F76}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B2B9BC93-7C77-4B11-A435-F017D5940F76}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B2B9BC93-7C77-4B11-A435-F017D5940F76}.Release|Any CPU.Build.0 = Release|Any CPU {E2A9A321-23AA-4F1F-B109-549A93222793}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E2A9A321-23AA-4F1F-B109-549A93222793}.Debug|Any CPU.Build.0 = Debug|Any CPU {E2A9A321-23AA-4F1F-B109-549A93222793}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -53,7 +47,6 @@ Global {796910FA-6E94-460B-8CB4-97DF01B9ADC8} = {7907FB6A-1353-4735-95DC-EEC5DF8C0649} {B1731AE1-381F-4044-BEBE-269FF7E24B1F} = {B987097B-189C-4D0B-99BC-E67CD705BCA0} {6046A2FC-6A39-4C2D-8DD9-AA3740B17B88} = {5455D423-2AFC-4BC6-B79D-9DC4270D8F7D} - {B2B9BC93-7C77-4B11-A435-F017D5940F76} = {B987097B-189C-4D0B-99BC-E67CD705BCA0} {E2A9A321-23AA-4F1F-B109-549A93222793} = {B987097B-189C-4D0B-99BC-E67CD705BCA0} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution diff --git a/dotnetv3/IAM/README.md b/dotnetv3/IAM/README.md index 789f50a279b..8dc69617fda 100644 --- a/dotnetv3/IAM/README.md +++ b/dotnetv3/IAM/README.md @@ -45,39 +45,33 @@ Code examples that show you how to perform the essential operations within a ser Code excerpts that show you how to call individual service functions. -- [AddUserToGroup](Actions/IAMWrapper.cs#L22) -- [AttachRolePolicy](Actions/IAMWrapper.cs#L42) -- [CreateAccessKey](Actions/IAMWrapper.cs#L62) -- [CreateGroup](Actions/IAMWrapper.cs#L82) +- [AttachRolePolicy](Actions/IAMWrapper.cs#L22) +- [CreateAccessKey](Actions/IAMWrapper.cs#L42) - [CreateInstanceProfile](../cross-service/ResilientService/AutoScalerActions/AutoScalerWrapper.cs#L86) -- [CreatePolicy](Actions/IAMWrapper.cs#L96) -- [CreateRole](Actions/IAMWrapper.cs#L116) -- [CreateServiceLinkedRole](Actions/IAMWrapper.cs#L138) -- [CreateUser](Actions/IAMWrapper.cs#L159) -- [DeleteAccessKey](Actions/IAMWrapper.cs#L173) -- [DeleteGroup](Actions/IAMWrapper.cs#L194) -- [DeleteGroupPolicy](Actions/IAMWrapper.cs#L208) +- [CreatePolicy](Actions/IAMWrapper.cs#L62) +- [CreateRole](Actions/IAMWrapper.cs#L82) +- [CreateServiceLinkedRole](Actions/IAMWrapper.cs#L104) +- [CreateUser](Actions/IAMWrapper.cs#L125) +- [DeleteAccessKey](Actions/IAMWrapper.cs#L139) - [DeleteInstanceProfile](../cross-service/ResilientService/AutoScalerActions/AutoScalerWrapper.cs#L504) -- [DeletePolicy](Actions/IAMWrapper.cs#L230) -- [DeleteRole](Actions/IAMWrapper.cs#L245) -- [DeleteRolePolicy](Actions/IAMWrapper.cs#L259) -- [DeleteUser](Actions/IAMWrapper.cs#L279) -- [DeleteUserPolicy](Actions/IAMWrapper.cs#L294) -- [DetachRolePolicy](Actions/IAMWrapper.cs#L310) -- [GetAccountPasswordPolicy](Actions/IAMWrapper.cs#L330) -- [GetPolicy](Actions/IAMWrapper.cs#L343) -- [GetRole](Actions/IAMWrapper.cs#L358) -- [GetUser](Actions/IAMWrapper.cs#L377) -- [ListAttachedRolePolicies](Actions/IAMWrapper.cs#L391) -- [ListGroups](Actions/IAMWrapper.cs#L412) -- [ListPolicies](Actions/IAMWrapper.cs#L432) -- [ListRolePolicies](Actions/IAMWrapper.cs#L452) -- [ListRoles](Actions/IAMWrapper.cs#L473) -- [ListSAMLProviders](Actions/IAMWrapper.cs#L493) -- [ListUsers](Actions/IAMWrapper.cs#L506) -- [PutGroupPolicy](Actions/IAMWrapper.cs#L548) -- [PutRolePolicy](Actions/IAMWrapper.cs#L571) -- [RemoveUserFromGroup](Actions/IAMWrapper.cs#L526) +- [DeletePolicy](Actions/IAMWrapper.cs#L160) +- [DeleteRole](Actions/IAMWrapper.cs#L175) +- [DeleteRolePolicy](Actions/IAMWrapper.cs#L189) +- [DeleteUser](Actions/IAMWrapper.cs#L209) +- [DeleteUserPolicy](Actions/IAMWrapper.cs#L224) +- [DetachRolePolicy](Actions/IAMWrapper.cs#L240) +- [GetAccountPasswordPolicy](Actions/IAMWrapper.cs#L260) +- [GetPolicy](Actions/IAMWrapper.cs#L273) +- [GetRole](Actions/IAMWrapper.cs#L288) +- [GetUser](Actions/IAMWrapper.cs#L307) +- [ListAttachedRolePolicies](Actions/IAMWrapper.cs#L321) +- [ListGroups](Actions/IAMWrapper.cs#L342) +- [ListPolicies](Actions/IAMWrapper.cs#L362) +- [ListRolePolicies](Actions/IAMWrapper.cs#L382) +- [ListRoles](Actions/IAMWrapper.cs#L403) +- [ListSAMLProviders](Actions/IAMWrapper.cs#L423) +- [ListUsers](Actions/IAMWrapper.cs#L436) +- [PutRolePolicy](Actions/IAMWrapper.cs#L456) ### Scenarios @@ -85,7 +79,6 @@ Code examples that show you how to accomplish a specific task by calling multipl functions within the same service. - [Build and manage a resilient service](../cross-service/ResilientService/ResilientServiceWorkflow/ResilientServiceWorkflow.cs) -- [Create a group and add a user](Scenarios/IamScenariosCommon/S3Wrapper.cs) @@ -157,21 +150,6 @@ This example shows you how to create a load-balanced web service that returns bo -#### Create a group and add a user - -This example shows you how to do the following: - -- Create a group and grant full Amazon S3 access permissions to it. -- Create a new user with no permissions to access Amazon S3. -- Add the user to the group and show that they now have permissions for Amazon S3, then clean up resources. - - - - - - - - ### Tests ⚠ Running tests might result in charges to your AWS account. diff --git a/dotnetv3/IAM/Scenarios/IAMGroups/IAMGroups.cs b/dotnetv3/IAM/Scenarios/IAMGroups/IAMGroups.cs deleted file mode 100644 index 9458dcd51dc..00000000000 --- a/dotnetv3/IAM/Scenarios/IAMGroups/IAMGroups.cs +++ /dev/null @@ -1,169 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -// snippet-start:[IAM.dotnetv3.IAMGroups] -using Microsoft.Extensions.Configuration; - -namespace IAMGroups; - -public class IAMGroups -{ - private static ILogger logger = null!; - - // Represents JSON code for AWS full access policy for Amazon Simple - // Storage Service (Amazon S3). - private const string S3FullAccessPolicyDocument = "{" + - " \"Statement\" : [{" + - " \"Action\" : [\"s3:*\"]," + - " \"Effect\" : \"Allow\"," + - " \"Resource\" : \"*\"" + - "}]" + - "}"; - - - static async Task Main(string[] args) - { - // Set up dependency injection for the AWS service. - using var host = Host.CreateDefaultBuilder(args) - .ConfigureLogging(logging => - logging.AddFilter("System", LogLevel.Debug) - .AddFilter("Microsoft", LogLevel.Information) - .AddFilter("Microsoft", LogLevel.Trace)) - .ConfigureServices((_, services) => - services.AddAWSService() - .AddTransient() - .AddTransient() - ) - .Build(); - - logger = LoggerFactory.Create(builder => { builder.AddConsole(); }) - .CreateLogger(); - - IConfiguration configuration = new ConfigurationBuilder() - .SetBasePath(Directory.GetCurrentDirectory()) - .AddJsonFile("settings.json") // Load test settings from .json file. - .AddJsonFile("settings.local.json", - true) // Optionally load local settings. - .Build(); - - var groupUserName = configuration["GroupUserName"]; - var groupName = configuration["GroupName"]; - var groupPolicyName = configuration["GroupPolicyName"]; - var groupBucketName = configuration["GroupBucketName"]; - - var wrapper = host.Services.GetRequiredService(); - var uiWrapper = host.Services.GetRequiredService(); - - uiWrapper.DisplayGroupsOverview(); - uiWrapper.PressEnter(); - - // Create an IAM group. - uiWrapper.DisplayTitle("Create IAM group"); - Console.WriteLine("Let's begin by creating a new IAM group."); - var group = await wrapper.CreateGroupAsync(groupName); - - // Add an inline IAM policy to the group. - uiWrapper.DisplayTitle("Add policy to group"); - Console.WriteLine("Add an inline policy to the group that allows members to have full access to"); - Console.WriteLine("Amazon Simple Storage Service (Amazon S3) buckets."); - - await wrapper.PutGroupPolicyAsync(group.GroupName, groupPolicyName, S3FullAccessPolicyDocument); - - uiWrapper.PressEnter(); - - // Now create a new user. - uiWrapper.DisplayTitle("Create an IAM user"); - Console.WriteLine("Now let's create a new IAM user."); - var groupUser = await wrapper.CreateUserAsync(groupUserName); - - // Add the new user to the group. - uiWrapper.DisplayTitle("Add the user to the group"); - Console.WriteLine("Adding the user to the group, which will give the user the same permissions as the group."); - await wrapper.AddUserToGroupAsync(groupUser.UserName, group.GroupName); - - Console.WriteLine($"User, {groupUser.UserName}, has been added to the group, {group.GroupName}."); - uiWrapper.PressEnter(); - - Console.WriteLine("Now that we have created a user, and added the user to the group, let's create an IAM access key."); - - // Create access and secret keys for the user. - var accessKey = await wrapper.CreateAccessKeyAsync(groupUserName); - Console.WriteLine("Key created."); - uiWrapper.WaitABit(15, "Waiting for the access key to be ready for use."); - - uiWrapper.DisplayTitle("List buckets"); - Console.WriteLine("To prove that the user has access to Amazon S3, list the S3 buckets for the account."); - - var s3Client = new AmazonS3Client(accessKey.AccessKeyId, accessKey.SecretAccessKey); - var stsClient = new AmazonSecurityTokenServiceClient(accessKey.AccessKeyId, accessKey.SecretAccessKey); - - var s3Wrapper = new S3Wrapper(s3Client, stsClient); - - var buckets = await s3Wrapper.ListMyBucketsAsync(); - - if (buckets is not null) - { - buckets.ForEach(bucket => - { - Console.WriteLine($"{bucket.BucketName}\tcreated on: {bucket.CreationDate}"); - }); - } - - // Show that the user also has write access to Amazon S3 by creating - // a new bucket. - uiWrapper.DisplayTitle("Create a bucket"); - Console.WriteLine("Since group members have full access to Amazon S3, let's create a bucket."); - var success = await s3Wrapper.PutBucketAsync(groupBucketName); - - if (success) - { - Console.WriteLine($"Successfully created the bucket: {groupBucketName}."); - } - - uiWrapper.PressEnter(); - - Console.WriteLine("Let's list the user's S3 buckets again to show the new bucket."); - - buckets = await s3Wrapper.ListMyBucketsAsync(); - - if (buckets is not null) - { - buckets.ForEach(bucket => - { - Console.WriteLine($"{bucket.BucketName}\tcreated on: {bucket.CreationDate}"); - }); - } - - uiWrapper.PressEnter(); - - uiWrapper.DisplayTitle("Clean up resources"); - Console.WriteLine("First delete the bucket we created."); - await s3Wrapper.DeleteBucketAsync(groupBucketName); - - Console.WriteLine($"Now remove the user, {groupUserName}, from the group, {groupName}."); - await wrapper.RemoveUserFromGroupAsync(groupUserName, groupName); - - Console.WriteLine("Delete the user's access key."); - await wrapper.DeleteAccessKeyAsync(accessKey.AccessKeyId, groupUserName); - - // Now we can safely delete the user. - Console.WriteLine("Now we can delete the user."); - await wrapper.DeleteUserAsync(groupUserName); - - uiWrapper.PressEnter(); - - Console.WriteLine("Now we will delete the IAM policy attached to the group."); - await wrapper.DeleteGroupPolicyAsync(groupName, groupPolicyName); - - Console.WriteLine("Now we delete the IAM group."); - await wrapper.DeleteGroupAsync(groupName); - - uiWrapper.PressEnter(); - - Console.WriteLine("The IAM groups demo has completed."); - - uiWrapper.PressEnter(); - } -} - -// snippet-end:[IAM.dotnetv3.IAMGroups] \ No newline at end of file diff --git a/dotnetv3/IAM/Scenarios/IAMGroups/IAMGroups.csproj b/dotnetv3/IAM/Scenarios/IAMGroups/IAMGroups.csproj deleted file mode 100644 index 4280ffb2410..00000000000 --- a/dotnetv3/IAM/Scenarios/IAMGroups/IAMGroups.csproj +++ /dev/null @@ -1,34 +0,0 @@ - - - - Exe - net6.0 - enable - enable - - - - - - - - - - - - - - - - - - - PreserveNewest - - - PreserveNewest - settings.json - - - - diff --git a/dotnetv3/IAM/Scenarios/IAMGroups/Usings.cs b/dotnetv3/IAM/Scenarios/IAMGroups/Usings.cs deleted file mode 100644 index 20f136dca54..00000000000 --- a/dotnetv3/IAM/Scenarios/IAMGroups/Usings.cs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. -// SPDX-License-Identifier: Apache-2.0 - -// snippet-start:[IAM.dotnetv3.IAMGroups.Usings] -global using Amazon.IdentityManagement; -global using Amazon.S3; -global using Amazon.SecurityToken; -global using IAMActions; -global using IamScenariosCommon; -global using Microsoft.Extensions.DependencyInjection; -global using Microsoft.Extensions.Hosting; -global using Microsoft.Extensions.Logging; -global using Microsoft.Extensions.Logging.Console; -global using Microsoft.Extensions.Logging.Debug; - -// snippet-end:[IAM.dotnetv3.IAMGroups.Usings] \ No newline at end of file diff --git a/dotnetv3/IAM/Scenarios/IAMGroups/settings.json b/dotnetv3/IAM/Scenarios/IAMGroups/settings.json deleted file mode 100644 index 07467a72a31..00000000000 --- a/dotnetv3/IAM/Scenarios/IAMGroups/settings.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "GroupUserName": "iam-group-user", - "GroupPolicyName": "group-policy", - "GroupBucketName": "my-group-bucket", - "GroupName": "s3-full-access-group" -} diff --git a/dotnetv3/IAM/Tests/IamWrapperTests.cs b/dotnetv3/IAM/Tests/IamWrapperTests.cs index b802eaac3ce..5356491b04f 100644 --- a/dotnetv3/IAM/Tests/IamWrapperTests.cs +++ b/dotnetv3/IAM/Tests/IamWrapperTests.cs @@ -96,24 +96,6 @@ public async Task GetAccountPasswordPolicy() Assert.NotNull(passwordPolicy); } - /// - /// Test the call to create an AWS Identity and Access Management (IAM) - /// group. The resulting group object should not be null. - /// - /// Async Task. - [Fact()] - [Order(1)] - [Trait("Category", "Integration")] - public async Task CreateGroupAsyncTest() - { - if (_groupName is not null) - { - var group = await _iamWrapper.CreateGroupAsync(_groupName); - Assert.Equal(_groupName, group.GroupName); - Assert.NotNull(group); - } - } - /// /// Tests the call to create an IAM user. The IAM user returned should /// not be null. @@ -232,24 +214,10 @@ public async Task ListGroupsAsyncTest() Assert.NotNull(groups); } - /// - /// Test the call to add an IAM policy to a group. Success should - /// be true. - /// - /// Async Task. - [Fact()] - [Order(8)] - [Trait("Category", "Integration")] - public async Task PutGroupPolicyAsyncTest() - { - var success = await _iamWrapper.PutGroupPolicyAsync(_groupName, _groupPolicyName, _listBucketsPolicyDocument); - Assert.True(success, $"Could not embed policy {_s3ListBucketsPolicyName} to {_groupName}"); - } - [Fact()] [Order(9)] [Trait("Category", "Integration")] - public async Task PutRolePollicyTest() + public async Task PutRolePolicyTest() { var success = await _iamWrapper.PutRolePolicyAsync(_rolePolicyName, _roleName, _listBucketsPolicyDocument); Assert.True(success, "Could not embed policy {_s3ListBucketsPolicyName}."); @@ -320,20 +288,6 @@ public async Task ListUsersAsyncTest() Assert.True(users.Count >= 1, "No users to list."); } - /// - /// Tests the call to add an IAM user to a group. Success should be - /// true. - /// - /// Async Task. - [Fact()] - [Order(15)] - [Trait("Category", "Integration")] - public async Task AddUserToGroupTest() - { - var success = await _iamWrapper.AddUserToGroupAsync(_userName, _groupName); - Assert.True(success, $"Couldn't add user, {_userName}, to group, {_groupName}."); - } - /// /// Tests the call to create an IAM access key for a user. The returned /// key should not be null. @@ -423,20 +377,6 @@ public async Task DeleteAccessKeyAsyncTest() Assert.True(success); } - /// - /// Tests the call to remove an IAM user from a group. Success should - /// be true. - /// - /// Async Task. - [Fact] - [Order(22)] - [Trait("Category", "Integration")] - public async Task RemoveUserFromGroupTest() - { - var success = await _iamWrapper.RemoveUserFromGroupAsync(_userName, _groupName); - Assert.True(success, $"Couldn't remove user {_userName} from the group {_groupName}"); - } - /// /// Tests the ability to delete an IAM user policy. The value success /// should be true. @@ -531,22 +471,5 @@ public async Task DeletePolicyAsyncTest() Assert.True(success, "Could not delete the policy."); } - [Fact()] - [Order(29)] - [Trait("Category", "Integration")] - public async Task DeleteGroupPolicyAsyncTest() - { - var success = await _iamWrapper.DeleteGroupPolicyAsync(_groupName, _groupPolicyName); - Assert.True(success); - } - - [Fact()] - [Order(30)] - [Trait("Category", "Integration")] - public async Task DeleteGroupAsyncTest() - { - var success = await _iamWrapper.DeleteGroupAsync(_groupName); - Assert.True(success, $"Couldn't delete the IAM group {_groupName}"); - } } } \ No newline at end of file