public UserFlairContextFactory(BerbotConnectionFactory connectionFactory) { this.connectionFactory = connectionFactory; this.auditClient = connectionFactory.CreateAuditClient(); this.modRedditClient = connectionFactory.CreateModRedditClient(); this.subreddit = modRedditClient.Subreddit(BerbotConfiguration.RedditSubredditName); }
/// <summary> /// /// </summary> /// <param name="token">OAuth 2.0 token obtained from Egnyte</param> /// <param name="domain">Domain on which you connect to egnyte, /// i.e.: domain is 'mydomain', when url looks like: mydomain.egnyte.com</param> /// <param name="httpClient">You can provide your own httpClient. Optional</param> /// <param name="requestTimeout">You can provide timeout for calling Egnyte API, /// by default it's 10 minutes. This parameter is optional</param> /// <param name="host">Full host name on which you connect to egnyte, /// i.e.: host is 'my.custom.host.com', when url looks like: my.custom.host.com</param> public EgnyteClient( string token, string domain = "", HttpClient httpClient = null, TimeSpan?requestTimeout = null, string host = "") { if (string.IsNullOrWhiteSpace(token)) { throw new ArgumentNullException(nameof(token)); } if (string.IsNullOrWhiteSpace(domain) && string.IsNullOrWhiteSpace(host)) { throw new ArgumentNullException("domain", "Domain or host has to specified"); } httpClient = httpClient ?? new HttpClient(); httpClient.Timeout = TimeSpan.FromMinutes(10); if (requestTimeout.HasValue) { httpClient.Timeout = requestTimeout.Value; } httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token); Files = new FilesClient(httpClient, domain, host); Users = new UsersClient(httpClient, domain, host); Links = new LinksClient(httpClient, domain, host); Groups = new GroupsClient(httpClient, domain, host); Permissions = new PermissionsClient(httpClient, domain, host); Search = new SearchClient(httpClient, domain, host); Audit = new AuditClient(httpClient, domain, host); }
protected override void ProcessRecord() { base.ProcessRecord(); try { client?.Dispose(); int timeout = GetPreferredTimeout(); WriteDebug($"Cmdlet Timeout : {timeout} milliseconds."); client = new AuditClient(AuthProvider, new Oci.Common.ClientConfiguration { RetryConfiguration = retryConfig, TimeoutMillis = timeout, ClientUserAgent = PSUserAgent }); string region = GetPreferredRegion(); if (region != null) { WriteDebug("Choosing Region:" + region); client.SetRegion(region); } if (Endpoint != null) { WriteDebug("Choosing Endpoint:" + Endpoint); client.SetEndpoint(Endpoint); } } catch (Exception ex) { TerminatingErrorDuringExecution(ex); } }
public static async Task <ListEventsResponse> NoRetryExample(AuditClient client, ListEventsRequest request) { logger.Info("Starting NoRetryExample"); try { return(await client.ListEvents(request)); } catch (Exception e) { logger.Error($"Failed at NoRetryExample:\n{e}"); throw; } }
public static async Task <ListEventsResponse> RetryExample(AuditClient client, ListEventsRequest request) { logger.Info("Starting RetryExample"); try { return(await client.ListEvents(request, new RetryConfiguration { MaxAttempts = 5 })); } catch (Exception e) { logger.Error($"Failed at RetryExample:\n{e}"); throw; } }
public static async Task <ListEventsResponse> GetEvents(AuditClient client, ListEventsRequest request) { logger.Info("Get events"); try { return(await client.ListEvents(request)); } catch (Exception e) { logger.Error($"Failed at GetEvents:\n{e}"); throw; } }
public UserFlairContext(AuditClient auditClient, Flairs flairsController, string username, string text, string flairCssClass) { username.ThrowIfNull(nameof(username)); text ??= ""; flairCssClass ??= ""; this.auditClient = auditClient; this.flairsController = flairsController; Username = username; remoteText = text; remoteCssClass = flairCssClass; Text = text; FlairCssClass = flairCssClass; }
public static async Task MainChangeRegion() { logger.Info("Starting example"); AuditClient client = null; try { // Assumption: the compartment id has been set in environment variable. var compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID"); logger.Info(compartmentId); // ListEvents var listEventsRequest = new ListEventsRequest { CompartmentId = compartmentId, StartTime = DateTime.Now.AddDays(-1), EndTime = DateTime.Now }; // Create AuditClient var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT"); using (client = new AuditClient(provider, new ClientConfiguration())) { logger.Info($"AuditClient created. Region is set to: {provider.Region}"); ListEventsResponse listEventsResp = await GetEvents(client, listEventsRequest); logger.Info($"Received {listEventsResp?.Items.Count} items"); } // Change the region to US_ASHBURN_1 using SetRegion Call // We cannot use the same client to change the region. See: // https://stackoverflow.com/questions/51478525/httpclient-this-instance-has-already-started-one-or-more-requests-properties-ca using (client = new AuditClient(provider, new ClientConfiguration())) { client.SetRegion(Region.US_ASHBURN_1); logger.Info("Changing region to US_ASHBURN_1"); ListEventsResponse listEventsRespDiffRegion = await GetEvents(client, listEventsRequest); logger.Info($"Received {listEventsRespDiffRegion?.Items.Count} items"); } } catch (Exception e) { logger.Error($"Failed Change Region example: {e.Message}"); } }
public static async Task <ListEventsResponse> CancellationTokenExample(AuditClient client, ListEventsRequest request) { logger.Info("Starting CancellationToken Example"); var cts = new CancellationTokenSource(); cts.Cancel(); // Pass cancelled cancellation token to the list events list events operations and verify that // OperationCanceledException is thrown! try { return(await client.ListEvents(request, null, cts.Token)); } catch (OperationCanceledException e) { logger.Info(e.Message); return(null); } catch (Exception e) { logger.Error($"Failed at CancellationTokenExample:\n{e}"); throw; } }
public static async Task Main() { logger.Info("Starting example"); AuditClient client = null; try { // Assumption: the compartment id has been set in environment variable. var compartmentId = Environment.GetEnvironmentVariable("OCI_COMPARTMENT_ID"); logger.Info(compartmentId); // ListEvents var listEventsRequest = new ListEventsRequest { CompartmentId = compartmentId, StartTime = DateTime.Now.AddDays(-1), EndTime = DateTime.Now }; // Create AuditClient var provider = new ConfigFileAuthenticationDetailsProvider("DEFAULT"); using (client = new AuditClient(provider, new ClientConfiguration())) { logger.Info("AuditClient created."); ListEventsResponse listEventsResp = await NoRetryExample(client, listEventsRequest); logger.Info($"Received {listEventsResp?.Items.Count} items"); ListEventsResponse listEventsRespFromRetry = await RetryExample(client, listEventsRequest); logger.Info($"Received {listEventsRespFromRetry?.Items.Count} items"); await CancellationTokenExample(client, listEventsRequest); // GetConfiguration var getConfigurationRequest = new GetConfigurationRequest { CompartmentId = compartmentId }; logger.Info("GetConfigurationRequest created."); GetConfigurationResponse getConfigurationResp = await client.GetConfiguration(getConfigurationRequest); logger.Info($"Retention period days: {getConfigurationResp?.Configuration.RetentionPeriodDays}"); // UpdateConfiguration var updateConfigurationRequest = new UpdateConfigurationRequest { CompartmentId = compartmentId, UpdateConfigurationDetails = new UpdateConfigurationDetails { RetentionPeriodDays = 90 } }; logger.Info("UpdateConfigurationRequest created."); UpdateConfigurationResponse updateConfigurationResp = await client.UpdateConfiguration(updateConfigurationRequest); logger.Info($"opc work request id: {updateConfigurationResp.OpcRequestId}"); } } catch (Exception e) { logger.Error($"Failed Audit example: {e.Message}"); } }