/// <summary> /// Returns the Region the bucket resides in. /// </summary> /// <param name="request"></param> /// <returns></returns> public List <string> GetBucketLocation(GetBucketLocationRequest request) { ListRegionSubscriptionsRequest listRegionSubscriptionsRequest = new ListRegionSubscriptionsRequest { TenancyId = base.Config.TenancyId }; var regions = IdentityClient.ListRegionSubscriptions(listRegionSubscriptionsRequest); var nameSpaceName = GetNamespace(request); List <string> res = new List <string>(); foreach (var region in regions.Items) { ObjectStorageClient.SetRegion(region.RegionName); GetBucketRequest getBucketRequest = new GetBucketRequest { NamespaceName = nameSpaceName, BucketName = request.BucketName }; try { var b = ObjectStorageClient.GetBucket(getBucketRequest); if (b.Bucket != null) { res.Add(region.RegionName); } } catch (WebException we) { if (!(we.Status.Equals(WebExceptionStatus.ProtocolError) && ((HttpWebResponse)we.Response).StatusCode == HttpStatusCode.NotFound)) { throw; } } } if (res.Count <= 0) { throw new Exception("NoSuchBucket"); } return(res); }
private static async Task ListOciRegionSubscriptions(IdentityClient client, string tenantId) { // List RegionSubscriptions ListRegionSubscriptionsRequest listRegionSubscriptionsRequest = new ListRegionSubscriptionsRequest { TenancyId = tenantId }; ListRegionSubscriptionsResponse listRegionSubscriptionsResponse = await client.ListRegionSubscriptions(listRegionSubscriptionsRequest); List <RegionSubscription> regionSubscriptions = listRegionSubscriptionsResponse.Items; logger.Info("List RegionSubscriptions"); logger.Info("========================="); foreach (RegionSubscription regionSubscription in regionSubscriptions) { logger.Info($"{regionSubscription.RegionName} : {regionSubscription.RegionKey}"); } }
private static async Task ListOciRegionSubscriptions(IdentityClient client, string compartmentId) { // List RegionSubscriptions ListRegionSubscriptionsRequest listRegionSubscriptionsRequest = new ListRegionSubscriptionsRequest { TenancyId = compartmentId }; RetryConfiguration retryConfiguration = new RetryConfiguration { // Enable exponential backoff with Full Jitter. GetNextDelayInSeconds = GetJitterDelayInSeconds }; ListRegionSubscriptionsResponse listRegionSubscriptionsResponse = await client.ListRegionSubscriptions(listRegionSubscriptionsRequest, retryConfiguration); List <RegionSubscription> regionSubscriptions = listRegionSubscriptionsResponse.Items; logger.Info("List RegionSubscriptions"); logger.Info("========================="); foreach (RegionSubscription regionSubscription in regionSubscriptions) { logger.Info($"{regionSubscription.RegionName} : {regionSubscription.RegionKey}"); } }
public static void AuditDisplay(ClientConfig config) { ThreadSafeSigner threadSafeSigner = new ThreadSafeSigner(new OciSigner(config)); // create client IdentityClient identityClinet = new IdentityClient(config, threadSafeSigner) { Region = Regions.US_ASHBURN_1 }; var executeStart = DateTime.Now; var listRegionSubscriptionsRequest = new ListRegionSubscriptionsRequest() { TenancyId = config.TenancyId }; var regions = identityClinet.ListRegionSubscriptions(listRegionSubscriptionsRequest).Items.Where(r => r.Status.Equals("READY")); // get compartment var listCompartmentRequest = new ListCompartmentRequest() { CompartmentId = config.TenancyId, CompartmentIdInSubtree = true, AccessLevel = ListCompartmentRequest.AccessLevels.ACCESSIBLE }; var compartments = identityClinet.ListCompartment(listCompartmentRequest).Items; // get Audit Events Console.WriteLine("* Audit Events-------------------"); var acquisitionMaxRange = 12; // 長時間化を見込んで時間を分割しながら取得する var endDate = new DateTime(2020, 3, 11); var startDate = new DateTime(2020, 3, 9); var client = new AuditClientAsync(config, threadSafeSigner); var option = client.GetRestOption(); option.TimeoutSeconds = 200; client.SetRestOption(option); foreach (var region in regions) { client.SetRegion(region.RegionName); while (startDate < endDate) { var valiableDay = startDate.AddDays(1); var start = startDate; bool finished = false; while (!finished) { var progressEndDate = start.AddHours(acquisitionMaxRange); if (progressEndDate > valiableDay) { progressEndDate = valiableDay; finished = true; } if (start == progressEndDate) { continue; } foreach (var compartment in compartments) { if (!compartment.LifecycleState.Equals("ACTIVE", StringComparison.OrdinalIgnoreCase)) { continue; } Console.WriteLine($"region:{region.RegionName}, compartment:{compartment.Name}"); AddTasks(DisplayAudit(client, identityClinet, compartment, start.ToString("yyyy-MM-ddTHH:mm:ssZ"), progressEndDate.ToString("yyyy-MM-ddTHH:mm:ssZ"))); } start = progressEndDate; } ExecuteTasks(); startDate = valiableDay; } } ExecuteTasks(); Console.WriteLine($"Count:{Count}"); var executeEnd = DateTime.Now; var saDate = executeEnd - executeStart; Console.WriteLine($"{saDate.Hours}:{saDate.Minutes}:{saDate.Seconds}"); Console.WriteLine("******************************************"); Console.WriteLine("******** All Audit Task Completed ********"); Console.WriteLine("******************************************"); }
public static void CompartmentConsoleDisplay(ClientConfig config) { IdentityClient identityClient = new IdentityClient(config) { Region = config.HomeRegion }; Console.WriteLine("* GetTenacy------------------------"); GetTenancyRequest getTenancyRequest = new GetTenancyRequest() { TenancyId = identityClient.Config.TenancyId }; var getTenacy = identityClient.GetTenancy(getTenancyRequest); Console.WriteLine(" name:" + getTenacy.Tenancy.Name + ","); Console.WriteLine(" id:" + getTenacy.Tenancy.Id + ","); Console.WriteLine(" description:" + getTenacy.Tenancy.Description + ","); Console.WriteLine(" homeregion:" + config.GetRegionName(getTenacy.Tenancy.HomeRegionKey) + ","); // tagNamespaces get in tetancy(root compartment) Console.WriteLine(" tagNamespaces:"); var listTagNamespacesRequest = new ListTagNamespacesRequest() { CompartmentId = getTenacy.Tenancy.Id, Limit = 50 }; var listTagNs = identityClient.ListTagNamespaces(listTagNamespacesRequest); listTagNs.Items.ForEach(tagNs => { Console.WriteLine("\t|- name: " + tagNs.Name); Console.WriteLine("\t| id: " + tagNs.Id); Console.WriteLine("\t| description: " + tagNs.Description); //tag list var listTagsRequest = new ListTagsRequest() { TagNamespaceId = tagNs.Id, Limit = 50 }; var listTags = identityClient.ListTags(listTagsRequest); listTags.Items.ForEach(tag => { Console.WriteLine("\t|\t|- * " + tag.Name); Console.WriteLine("\t|\t| id: " + tag.Id); Console.WriteLine("\t|\t| costTracking: " + tag.IsCostTracking); }); }); // tagDefaults get in tetancy(root compartment) Console.WriteLine(" tagDefaults:"); var listTagsDefaultRequest = new ListTagDefaultsRequest() { CompartmentId = getTenacy.Tenancy.Id, Limit = 50 }; var listDefaultTags = identityClient.ListTagDefaults(listTagsDefaultRequest); listDefaultTags.Items.ForEach(tag => { Console.WriteLine("\t|- DefaultTags"); Console.WriteLine("\t| id: " + tag.Id); Console.WriteLine("\t| tagDefinitionName: " + tag.TagDefinitionName); Console.WriteLine("\t| tagNamespaceId: " + tag.TagNamespaceId); Console.WriteLine("\t| tagDefinitionId: " + tag.TagDefinitionId); Console.WriteLine("\t| lifecycleState: " + tag.LifecycleState); }); var listCostTrackingTagsRequest = new ListCostTrackingTagsRequest() { CompartmentId = getTenacy.Tenancy.Id, Limit = 100 }; var listCostTrackingTags = identityClient.ListCostTrackingTags(listCostTrackingTagsRequest); listCostTrackingTags.Items.ForEach(tag => { Console.WriteLine("\t|- CostTackingTags"); Console.WriteLine("\t| id: " + tag.Id); Console.WriteLine("\t| isCostTracking: " + tag.IsCostTracking); Console.WriteLine("\t| tagNamespaceId: " + tag.TagNamespaceId); Console.WriteLine("\t| tagNamespaceName: " + tag.TagNamespaceName); Console.WriteLine("\t| name: " + tag.Name); }); Console.WriteLine(); Console.WriteLine("* ListRegions------------------------"); var listRegion = identityClient.ListRegions(); listRegion.Items.ForEach(r => { Console.WriteLine("\tname: " + r.Name); Console.WriteLine("\tkey: " + r.Key); }); Console.WriteLine("* ListRegionsSubscriptions------------------------"); var listRegionSubscriptionsRequest = new ListRegionSubscriptionsRequest() { TenancyId = getTenacy.Tenancy.Id, }; var listRegionSubscriptions = identityClient.ListRegionSubscriptions(listRegionSubscriptionsRequest); listRegionSubscriptions.Items.ForEach(r => { Console.WriteLine("\tname: " + r.RegionKey); Console.WriteLine("\tkey: " + r.RegionName); Console.WriteLine("\tstatus: " + r.Status); Console.WriteLine("\thome: " + r.IsHomeRegion); }); Console.WriteLine(); Console.WriteLine("* ListAvailabilityDomain------------------------"); var listAvailabilityDomainRequest = new ListAvailabilityDomainsRequest() { CompartmentId = getTenacy.Tenancy.Id }; var listAD = identityClient.ListAvailabilityDomains(listAvailabilityDomainRequest); listAD.Items.ForEach(ad => { Console.WriteLine("\tname: " + ad.Name); Console.WriteLine("\tid: " + ad.Id); }); Console.WriteLine(); Console.WriteLine("* ListCompartment------------------------"); var listCompartmenRequest = new ListCompartmentRequest() { CompartmentId = getTenacy.Tenancy.Id, CompartmentIdInSubtree = true, AccessLevel = ListCompartmentRequest.AccessLevels.ACCESSIBLE, Limit = 10 }; var listCompartment = identityClient.ListCompartment(listCompartmenRequest); listCompartment.Items.ForEach(comp => { // compartment detail get var getCompartmentRequest = new GetCompartmentRequest() { CompartmentId = comp.Id }; var getCompartment = identityClient.GetCompartment(getCompartmentRequest); Console.WriteLine("\t|- name: " + getCompartment.Compartment.Name); Console.WriteLine("\t|\t id: " + getCompartment.Compartment.Id); Console.WriteLine("\t|\t lifecycleState: " + getCompartment.Compartment.LifecycleState); Console.WriteLine("\t|\t timeCreated: " + getCompartment.Compartment.TimeCreated); Console.WriteLine("\t|\t inactiveStatus: " + getCompartment.Compartment.InactiveStatus); var path = GetCompartmetPath(identityClient, getCompartment.Compartment.Id); Console.WriteLine("\t|\t path: " + path); getCompartmentRequest = new GetCompartmentRequest() { CompartmentId = getCompartment.Compartment.CompartmentId }; getCompartment = identityClient.GetCompartment(getCompartmentRequest); Console.WriteLine("\t|\t parent: " + getCompartment.Compartment.Name); // tagNamespaces get in compartment Console.WriteLine("\t|\t tgaNamespaces:"); listTagNamespacesRequest = new ListTagNamespacesRequest() { CompartmentId = comp.Id, Limit = 50 }; listTagNs = identityClient.ListTagNamespaces(listTagNamespacesRequest); listTagNs.Items.ForEach(tagNs => { Console.WriteLine("\t|\t |- name: " + tagNs.Name); Console.WriteLine("\t|\t | id: " + tagNs.Id); Console.WriteLine("\t|\t | description: " + tagNs.Description); Console.WriteLine("\t|\t | timeCreated: " + tagNs.TimeCreated); }); }); }