Пример #1
0
    public static void Main(string[] args)
    {
        // Get credentials
        GoogleCredential credential = GoogleCredential.GetApplicationDefault()
                                      .CreateScoped(IamService.Scope.CloudPlatform);

        // Create the Cloud IAM service object
        IamService service = new IamService(new IamService.Initializer
        {
            HttpClientInitializer = credential
        });

        // Call the Cloud IAM Roles API
        ListRolesResponse response = service.Roles.List().Execute();
        IList <Role>      roles    = response.Roles;

        // Process the response
        foreach (Role role in roles)
        {
            Console.WriteLine("Title: " + role.Title);
            Console.WriteLine("Name: " + role.Name);
            Console.WriteLine("Description: " + role.Description);
            Console.WriteLine();
        }
    }
Пример #2
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonIdentityManagementServiceConfig config = new AmazonIdentityManagementServiceConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonIdentityManagementServiceClient client = new AmazonIdentityManagementServiceClient(creds, config);


            ListRolesResponse resp = new ListRolesResponse();

            do
            {
                ListRolesRequest req = new ListRolesRequest
                {
                    Marker = resp.Marker
                    ,
                    MaxItems = maxItems
                };

                resp = client.ListRoles(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.Roles)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.Marker));
        }
Пример #3
0
        private static void ListRoles(String PathPrefix)
        {
            if (String.IsNullOrEmpty(Token))
            {
                stsClient = new AmazonIdentityManagementServiceClient(AccessKeyId, SecretKey, iamconfig);
            }
            else
            {
                stsClient = new AmazonIdentityManagementServiceClient(AccessKeyId, SecretKey, Token, iamconfig);
            }

            ListRolesRequest Req = new ListRolesRequest();

            if (!String.IsNullOrEmpty(PathPrefix))
            {
                Req.PathPrefix = PathPrefix;
            }

            try
            {
                ListRolesResponse response = stsClient.ListRoles(Req);
                foreach (Role r in response.Roles)
                {
                    Console.WriteLine("Role name : {0}, Path: {1}, Create Date: {2}", r.RoleName, r.Path, r.CreateDate.ToString());
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error occured while creating user. " + ex.ToString());
            }
        }
Пример #4
0
        /// <summary>
        /// Sends ListRolesRequest to the server and reads a response.
        /// </summary>
        /// <returns>ListRolesResponse message if the function succeeds, null otherwise.</returns>
        public async Task <ListRolesResponse> SendListRolesRequest()
        {
            log.Trace("()");

            ListRolesResponse res            = null;
            Message           requestMessage = MessageBuilder.CreateListRolesRequest();

            if (await SendMessageAsync(requestMessage))
            {
                Message responseMessage = await ReceiveMessageAsync();

                if (CheckResponseMessage(requestMessage, responseMessage))
                {
                    res = responseMessage.Response.SingleResponse.ListRoles;
                }
                else
                {
                    log.Warn("Received unexpected or invalid message.");
                }
            }
            else
            {
                log.Warn("Unable to send message.");
            }

            log.Trace("(-):{0}", res);
            return(res);
        }
Пример #5
0
        public static async Task <IList <Role> > FindExistingRolesAsync(IAmazonIdentityManagementService iamClient, string assumeRolePrincpal, int maxRoles)
        {
            List <Role> roles = new List <Role>();

            ListRolesRequest  request  = new ListRolesRequest();
            ListRolesResponse response = null;

            do
            {
                if (response != null)
                {
                    request.Marker = response.Marker;
                }

                response = await iamClient.ListRolesAsync(request).ConfigureAwait(false);

                foreach (var role in response.Roles)
                {
                    if (AssumeRoleServicePrincipalSelector(role, assumeRolePrincpal))
                    {
                        roles.Add(role);
                        if (roles.Count == maxRoles)
                        {
                            break;
                        }
                    }
                }
            } while (response.IsTruncated && roles.Count < maxRoles);

            return(roles);
        }
Пример #6
0
        public async Task <Role[]> ListRolesAsync(string pathPrefx = null, CancellationToken cancellationToken = default(CancellationToken))
        {
            ListRolesResponse response = null;
            var results = new List <Role>();

            while ((response = await _IAMClient.ListRolesAsync(new ListRolesRequest()
            {
                MaxItems = 1000,
                Marker = response?.Marker,
                PathPrefix = pathPrefx
            }, cancellationToken).EnsureSuccessAsync()) != null)
            {
                if (!response.Roles.IsNullOrEmpty())
                {
                    results.AddRange(response.Roles);
                }

                if (!response.IsTruncated)
                {
                    break;
                }

                await Task.Delay(100);
            }

            return(results.ToArray());
        }
Пример #7
0
        public static ListRolesResponse Unmarshall(UnmarshallerContext _ctx)
        {
            ListRolesResponse listRolesResponse = new ListRolesResponse();

            listRolesResponse.HttpResponse = _ctx.HttpResponse;
            listRolesResponse.Paging       = _ctx.BooleanValue("ListRoles.Paging");
            listRolesResponse.RequestId    = _ctx.StringValue("ListRoles.RequestId");

            List <ListRolesResponse.ListRoles_RoleDTO> listRolesResponse_data = new List <ListRolesResponse.ListRoles_RoleDTO>();

            for (int i = 0; i < _ctx.Length("ListRoles.Data.Length"); i++)
            {
                ListRolesResponse.ListRoles_RoleDTO roleDTO = new ListRolesResponse.ListRoles_RoleDTO();
                roleDTO.Id           = _ctx.LongValue("ListRoles.Data[" + i + "].Id");
                roleDTO.Name         = _ctx.StringValue("ListRoles.Data[" + i + "].Name");
                roleDTO.ResourceType = _ctx.StringValue("ListRoles.Data[" + i + "].ResourceType");
                roleDTO.GmtCreate    = _ctx.StringValue("ListRoles.Data[" + i + "].GmtCreate");
                roleDTO.GmtModified  = _ctx.StringValue("ListRoles.Data[" + i + "].GmtModified");
                roleDTO.Description  = _ctx.StringValue("ListRoles.Data[" + i + "].Description");

                listRolesResponse_data.Add(roleDTO);
            }
            listRolesResponse.Data = listRolesResponse_data;

            return(listRolesResponse);
        }
Пример #8
0
        public static string GenerateUniqueIAMRoleName(IAmazonIdentityManagementService iamClient, string baseName)
        {
            var existingRoleNames = new HashSet <string>();
            var response          = new ListRolesResponse();

            do
            {
                var roles = iamClient.ListRolesAsync(new ListRolesRequest {
                    Marker = response.Marker
                }).Result.Roles;
                roles.ForEach(x => existingRoleNames.Add(x.RoleName));
            } while (response.IsTruncated);

            if (!existingRoleNames.Contains(baseName))
            {
                return(baseName);
            }

            for (int i = 1; true; i++)
            {
                var name = baseName + "-" + i;
                if (!existingRoleNames.Contains(name))
                {
                    return(name);
                }
            }
        }
        public static ListRolesResponse Unmarshall(UnmarshallerContext _ctx)
        {
            ListRolesResponse listRolesResponse = new ListRolesResponse();

            listRolesResponse.HttpResponse = _ctx.HttpResponse;
            listRolesResponse.RequestId    = _ctx.StringValue("ListRoles.RequestId");
            listRolesResponse.Success      = _ctx.BooleanValue("ListRoles.Success");
            listRolesResponse.Code         = _ctx.StringValue("ListRoles.Code");
            listRolesResponse.Message      = _ctx.StringValue("ListRoles.Message");

            List <ListRolesResponse.ListRoles_Role> listRolesResponse_data = new List <ListRolesResponse.ListRoles_Role>();

            for (int i = 0; i < _ctx.Length("ListRoles.Data.Length"); i++)
            {
                ListRolesResponse.ListRoles_Role role = new ListRolesResponse.ListRoles_Role();
                role.Id          = _ctx.LongValue("ListRoles.Data[" + i + "].Id");
                role.Name        = _ctx.StringValue("ListRoles.Data[" + i + "].Name");
                role.DisplayName = _ctx.StringValue("ListRoles.Data[" + i + "].DisplayName");
                role.Level       = _ctx.IntegerValue("ListRoles.Data[" + i + "].Level");
                role.CreateTime  = _ctx.StringValue("ListRoles.Data[" + i + "].CreateTime");
                role.UpdateTime  = _ctx.StringValue("ListRoles.Data[" + i + "].UpdateTime");

                listRolesResponse_data.Add(role);
            }
            listRolesResponse.Data = listRolesResponse_data;

            return(listRolesResponse);
        }
Пример #10
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ListRolesResponse response = new ListRolesResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("ListRolesResult", 2))
                    {
                        UnmarshallResult(context, response);
                        continue;
                    }

                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.Instance.Unmarshall(context);
                    }
                }
            }

            return(response);
        }
Пример #11
0
        public static ListRolesResponse Unmarshall(UnmarshallerContext context)
        {
            ListRolesResponse listRolesResponse = new ListRolesResponse();

            listRolesResponse.HttpResponse = context.HttpResponse;
            listRolesResponse.RequestId    = context.StringValue("ListRoles.RequestId");
            listRolesResponse.IsTruncated  = context.BooleanValue("ListRoles.IsTruncated");
            listRolesResponse.Marker       = context.StringValue("ListRoles.Marker");

            List <ListRolesResponse.ListRoles_Role> listRolesResponse_roles = new List <ListRolesResponse.ListRoles_Role>();

            for (int i = 0; i < context.Length("ListRoles.Roles.Length"); i++)
            {
                ListRolesResponse.ListRoles_Role role = new ListRolesResponse.ListRoles_Role();
                role.RoleId             = context.StringValue("ListRoles.Roles[" + i + "].RoleId");
                role.RoleName           = context.StringValue("ListRoles.Roles[" + i + "].RoleName");
                role.Arn                = context.StringValue("ListRoles.Roles[" + i + "].Arn");
                role.Description        = context.StringValue("ListRoles.Roles[" + i + "].Description");
                role.CreateDate         = context.StringValue("ListRoles.Roles[" + i + "].CreateDate");
                role.UpdateDate         = context.StringValue("ListRoles.Roles[" + i + "].UpdateDate");
                role.MaxSessionDuration = context.LongValue("ListRoles.Roles[" + i + "].MaxSessionDuration");

                listRolesResponse_roles.Add(role);
            }
            listRolesResponse.Roles = listRolesResponse_roles;

            return(listRolesResponse);
        }
        public static ListRolesResponse Unmarshall(UnmarshallerContext context)
        {
            ListRolesResponse listRolesResponse = new ListRolesResponse();

            listRolesResponse.HttpResponse   = context.HttpResponse;
            listRolesResponse.RequestId      = context.StringValue("ListRoles.RequestId");
            listRolesResponse.Success        = context.BooleanValue("ListRoles.Success");
            listRolesResponse.Code           = context.StringValue("ListRoles.Code");
            listRolesResponse.Message        = context.StringValue("ListRoles.Message");
            listRolesResponse.HttpStatusCode = context.IntegerValue("ListRoles.HttpStatusCode");

            List <ListRolesResponse.ListRoles_Role> listRolesResponse_roles = new List <ListRolesResponse.ListRoles_Role>();

            for (int i = 0; i < context.Length("ListRoles.Roles.Length"); i++)
            {
                ListRolesResponse.ListRoles_Role role = new ListRolesResponse.ListRoles_Role();
                role.RoleId          = context.StringValue("ListRoles.Roles[" + i + "].RoleId");
                role.InstanceId      = context.StringValue("ListRoles.Roles[" + i + "].InstanceId");
                role.RoleName        = context.StringValue("ListRoles.Roles[" + i + "].RoleName");
                role.RoleDescription = context.StringValue("ListRoles.Roles[" + i + "].RoleDescription");

                listRolesResponse_roles.Add(role);
            }
            listRolesResponse.Roles = listRolesResponse_roles;

            return(listRolesResponse);
        }
Пример #13
0
        // [END iam_get_role]

        // [START iam_list_roles]
        public static IList <Role> ListRoles(string projectId)
        {
            ListRolesResponse response = s_service.Projects.Roles
                                         .List("projects/" + projectId).Execute();

            foreach (var role in response?.Roles)
            {
                Console.WriteLine(role.Name);
            }
            return(response.Roles);
        }
Пример #14
0
        public static ListRolesResponse Unmarshall(UnmarshallerContext context)
        {
            ListRolesResponse listRolesResponse = new ListRolesResponse();

            listRolesResponse.HttpResponse = context.HttpResponse;
            listRolesResponse.PageSize     = context.IntegerValue("ListRoles.PageSize");
            listRolesResponse.TotalCount   = context.IntegerValue("ListRoles.TotalCount");
            listRolesResponse.PageNumber   = context.IntegerValue("ListRoles.PageNumber");
            listRolesResponse.RequestId    = context.StringValue("ListRoles.RequestId");
            listRolesResponse.Success      = context.BooleanValue("ListRoles.Success");

            List <ListRolesResponse.ListRoles_SysRoleModel> listRolesResponse_roles = new List <ListRolesResponse.ListRoles_SysRoleModel>();

            for (int i = 0; i < context.Length("ListRoles.Roles.Length"); i++)
            {
                ListRolesResponse.ListRoles_SysRoleModel sysRoleModel = new ListRolesResponse.ListRoles_SysRoleModel();
                sysRoleModel.MerchantId = context.LongValue("ListRoles.Roles[" + i + "].MerchantId");
                sysRoleModel.RoleId     = context.IntegerValue("ListRoles.Roles[" + i + "].RoleId");
                sysRoleModel.Remark     = context.StringValue("ListRoles.Roles[" + i + "].Remark");
                sysRoleModel.Name       = context.StringValue("ListRoles.Roles[" + i + "].Name");
                sysRoleModel.Status     = context.IntegerValue("ListRoles.Roles[" + i + "].Status");

                List <ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel> sysRoleModel_apis = new List <ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel>();
                for (int j = 0; j < context.Length("ListRoles.Roles[" + i + "].Apis.Length"); j++)
                {
                    ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel baseModel = new ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel();
                    baseModel.Id   = context.IntegerValue("ListRoles.Roles[" + i + "].Apis[" + j + "].Id");
                    baseModel.Name = context.StringValue("ListRoles.Roles[" + i + "].Apis[" + j + "].Name");
                    baseModel.Code = context.StringValue("ListRoles.Roles[" + i + "].Apis[" + j + "].Code");

                    sysRoleModel_apis.Add(baseModel);
                }
                sysRoleModel.Apis = sysRoleModel_apis;

                List <ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel> sysRoleModel_menus = new List <ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel>();
                for (int j = 0; j < context.Length("ListRoles.Roles[" + i + "].Menus.Length"); j++)
                {
                    ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel baseModel = new ListRolesResponse.ListRoles_SysRoleModel.ListRoles_BaseModel();
                    baseModel.Id   = context.IntegerValue("ListRoles.Roles[" + i + "].Menus[" + j + "].Id");
                    baseModel.Name = context.StringValue("ListRoles.Roles[" + i + "].Menus[" + j + "].Name");
                    baseModel.Code = context.StringValue("ListRoles.Roles[" + i + "].Menus[" + j + "].Code");

                    sysRoleModel_menus.Add(baseModel);
                }
                sysRoleModel.Menus = sysRoleModel_menus;

                listRolesResponse_roles.Add(sysRoleModel);
            }
            listRolesResponse.Roles = listRolesResponse_roles;

            return(listRolesResponse);
        }
Пример #15
0
        public static void LoginAsServiceAccountWithJson(string credentialsJson)
        {
            // Create credentials from the JSON file that we receive from GCP.
            GoogleCredential credential = GoogleCredential.FromJson(credentialsJson)
                                          .CreateScoped(IamService.Scope.CloudPlatform);

            s_service = new IamService(new IamService.Initializer
            {
                HttpClientInitializer = credential
            });

            ListRolesResponse response = s_service.Roles.List().Execute();
        }
        private static void UnmarshallResult(XmlUnmarshallerContext context, ListRolesResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.Read())
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("Roles/member", targetDepth))
                    {
                        response.Roles.Add(RoleUnmarshaller.GetInstance().Unmarshall(context));

                        continue;
                    }
                    if (context.TestExpression("IsTruncated", targetDepth))
                    {
                        response.IsTruncated = BoolUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                    if (context.TestExpression("Marker", targetDepth))
                    {
                        response.Marker = StringUnmarshaller.GetInstance().Unmarshall(context);

                        continue;
                    }
                }
                else if (context.IsEndElement && context.CurrentDepth < originalDepth)
                {
                    return;
                }
            }



            return;
        }
Пример #17
0
        public static ListRolesResponse Unmarshall(UnmarshallerContext _ctx)
        {
            ListRolesResponse listRolesResponse = new ListRolesResponse();

            listRolesResponse.HttpResponse = _ctx.HttpResponse;
            listRolesResponse.Code         = _ctx.StringValue("ListRoles.Code");
            listRolesResponse.Message      = _ctx.StringValue("ListRoles.Message");
            listRolesResponse.RequestId    = _ctx.StringValue("ListRoles.RequestId");

            List <string> listRolesResponse_data = new List <string>();

            for (int i = 0; i < _ctx.Length("ListRoles.Data.Length"); i++)
            {
                listRolesResponse_data.Add(_ctx.StringValue("ListRoles.Data[" + i + "]"));
            }
            listRolesResponse.Data = listRolesResponse_data;

            return(listRolesResponse);
        }
Пример #18
0
        private static void UnmarshallResult(XmlUnmarshallerContext context, ListRolesResponse response)
        {
            int originalDepth = context.CurrentDepth;
            int targetDepth   = originalDepth + 1;

            if (context.IsStartOfDocument)
            {
                targetDepth += 2;
            }

            while (context.ReadAtDepth(originalDepth))
            {
                if (context.IsStartElement || context.IsAttribute)
                {
                    if (context.TestExpression("IsTruncated", targetDepth))
                    {
                        var unmarshaller = BoolUnmarshaller.Instance;
                        response.IsTruncated = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("Marker", targetDepth))
                    {
                        var unmarshaller = StringUnmarshaller.Instance;
                        response.Marker = unmarshaller.Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("Roles/member", targetDepth))
                    {
                        var unmarshaller = RoleUnmarshaller.Instance;
                        var item         = unmarshaller.Unmarshall(context);
                        response.Roles.Add(item);
                        continue;
                    }
                }
            }

            return;
        }
Пример #19
0
        public override AmazonWebServiceResponse Unmarshall(XmlUnmarshallerContext context)
        {
            ListRolesResponse response = new ListRolesResponse();

            while (context.Read())
            {
                if (context.IsStartElement)
                {
                    if (context.TestExpression("ListRolesResult", 2))
                    {
                        response.ListRolesResult = ListRolesResultUnmarshaller.GetInstance().Unmarshall(context);
                        continue;
                    }
                    if (context.TestExpression("ResponseMetadata", 2))
                    {
                        response.ResponseMetadata = ResponseMetadataUnmarshaller.GetInstance().Unmarshall(context);
                    }
                }
            }


            return(response);
        }
        public static ListRolesResponse Unmarshall(UnmarshallerContext _ctx)
        {
            ListRolesResponse listRolesResponse = new ListRolesResponse();

            listRolesResponse.HttpResponse   = _ctx.HttpResponse;
            listRolesResponse.Code           = _ctx.StringValue("ListRoles.Code");
            listRolesResponse.HttpStatusCode = _ctx.IntegerValue("ListRoles.HttpStatusCode");
            listRolesResponse.Message        = _ctx.StringValue("ListRoles.Message");
            listRolesResponse.RequestId      = _ctx.StringValue("ListRoles.RequestId");

            List <ListRolesResponse.ListRoles_Role> listRolesResponse_data = new List <ListRolesResponse.ListRoles_Role>();

            for (int i = 0; i < _ctx.Length("ListRoles.Data.Length"); i++)
            {
                ListRolesResponse.ListRoles_Role role = new ListRolesResponse.ListRoles_Role();
                role.Name   = _ctx.StringValue("ListRoles.Data[" + i + "].Name");
                role.RoleId = _ctx.StringValue("ListRoles.Data[" + i + "].RoleId");

                listRolesResponse_data.Add(role);
            }
            listRolesResponse.Data = listRolesResponse_data;

            return(listRolesResponse);
        }
Пример #21
0
 public ListRolesResponse ListRoles(ListRolesRequest request, string jsonRpcCallId)
 {
     ListRolesResponse result = new ListRolesResponse();
     WireRequest(0, jsonRpcCallId, "system.list_roles", (writer) =>
         {
             request.Write(writer, false);
         }, (reader) =>
         {
             result.Read(reader);
         }
     );
     return result;
 }