Ejemplo n.º 1
0
        /// <summary>
        /// Creates a waiter using the provided configuration.
        /// </summary>
        /// <param name="request">Request to send.</param>
        /// <param name="config">Wait Configuration</param>
        /// <param name="targetStates">Desired resource states. If multiple states are provided then the waiter will return once the resource reaches any of the provided states</param>
        /// <returns>a new Oci.common.Waiter instance</returns>
        public Waiter <GetUserRequest, GetUserResponse> ForUser(GetUserRequest request, WaiterConfiguration config, params User.LifecycleStateEnum[] targetStates)
        {
            var agent = new WaiterAgent <GetUserRequest, GetUserResponse>(
                request,
                request => client.GetUser(request),
                response => targetStates.Contains(response.User.LifecycleState.Value),
                targetStates.Contains(User.LifecycleStateEnum.Deleted)
                );

            return(new Waiter <GetUserRequest, GetUserResponse>(config, agent));
        }
        private static async void DisplayAudit(ClientConfig config, AuditClientAsync client, IdentityClient identityClinet, string compartmentId, string startDate, string endDate, string requestId, string pageId)
        {
            // get Audit Events
            var listEventsRequest = new ListEventsRequest()
            {
                CompartmentId = compartmentId,
                StartTime     = startDate,
                EndTime       = endDate,
                //Page = pageId
                //CompartmentId = "ocid1.compartment.oc1..aaaaaaaarj2edeedyk4o7rvcpdh6fckmeevwyog3k7zd4wjlyzcejib53yuq",
                //StartTime = "2019-10-29T09:33:57Z",
                //EndTime = "2019-10-29T11:33:57Z",
                OpcRequestId = requestId,
                Page         = pageId
            };

            var events = await client.ListEvents(listEventsRequest);

            if (!string.IsNullOrEmpty(events.OpcNextPage))
            {
                DisplayAudit(config, client, identityClinet, compartmentId, startDate, endDate, events.OpcRequestId, events.OpcNextPage);
            }

            if (events.Items.Count > 0)
            {
                events.Items.ForEach(e => {
                    Console.WriteLine($"* eventName:{e.Data.EventName}");
                    Console.WriteLine($"\t id:{e.EventId}");
                    Console.WriteLine($"\t type:{e.EventType}");
                    Console.WriteLine($"\t source:{e.Source}");
                    Console.WriteLine($"\t time:{e.EventTime}");
                    Console.WriteLine($"\t resourceName:{e.Data.ResourceName}");
                    if (e.Data.Identity != null)
                    {
                        Console.WriteLine($"\t principal:{e.Data.Identity.PrincipalId}");

                        try
                        {
                            var getUserRequest = new GetUserRequest()
                            {
                                UserId = e.Data.Identity.PrincipalId
                            };
                            var user = identityClinet.GetUser(getUserRequest);
                            Console.WriteLine($"\t user:{user.User.Name}");
                        }
                        catch (WebException we)
                        {
                            if (we.Status.Equals(WebExceptionStatus.ProtocolError))
                            {
                                var code = ((HttpWebResponse)we.Response).StatusCode;
                                if (code == HttpStatusCode.NotFound)
                                {
                                    // エラーだけ残す
                                    Console.WriteLine($"\t user not found");
                                    return;
                                }
                            }
                        }
                    }
                });
            }
        }