public static void Main(string[] args) { var credential = GoogleCredential.GetApplicationDefault() .CreateScoped(IamService.Scope.CloudPlatform); var service = new IamService(new IamService.Initializer { HttpClientInitializer = credential }); string fullResourceName = args[0]; // [START iam_view_grantable_roles] var request = new QueryGrantableRolesRequest { FullResourceName = fullResourceName }; var response = service.Roles.QueryGrantableRoles(request).Execute(); foreach (var role in response.Roles) { Console.WriteLine("Title: " + role.Title); Console.WriteLine("Name: " + role.Name); Console.WriteLine("Description: " + role.Description); Console.WriteLine(); } // [END iam_view_grantable_roles] }
public static IList <Role> ViewGrantableRoles(string fullResourceName) { var credential = GoogleCredential.GetApplicationDefault() .CreateScoped(IamService.Scope.CloudPlatform); var service = new IamService(new IamService.Initializer { HttpClientInitializer = credential }); var request = new QueryGrantableRolesRequest { FullResourceName = fullResourceName }; var response = service.Roles.QueryGrantableRoles(request).Execute(); foreach (var role in response.Roles) { Console.WriteLine("Title: " + role.Title); Console.WriteLine("Name: " + role.Name); Console.WriteLine("Description: " + role.Description); Console.WriteLine(); } return(response.Roles); }
/// <summary> /// Queries roles that can be granted on a particular resource. A role is grantable if it can be used as the role in a binding for a policy for that resource. /// Documentation https://developers.google.com/iam/v1/reference/roles/queryGrantableRoles /// Generation Note: This does not always build corectly. Google needs to standardise things I need to figuer out which ones are wrong. /// </summary> /// <param name="service">Authenticated iam service.</param> /// <param name="body">A valid iam v1 body.</param> /// <returns>QueryGrantableRolesResponseResponse</returns> public static QueryGrantableRolesResponse QueryGrantableRoles(iamService service, QueryGrantableRolesRequest body) { try { // Initial validation. if (service == null) { throw new ArgumentNullException("service"); } if (body == null) { throw new ArgumentNullException("body"); } // Make the request. return(service.Roles.QueryGrantableRoles(body).Execute()); } catch (Exception ex) { throw new Exception("Request Roles.QueryGrantableRoles failed.", ex); } }