コード例 #1
0
        private static List <ResourceRecord> GetResourceRecords(IAwsClient awsClient, IEnumerable <StackResource> stackResources, AwsStack awsStack, string hostedZoneName)
        {
            var resourceRecords = new List <ResourceRecord>();

            if (stackResources.Any(x => x.ResourceType == ResourceTypeConstants.RecordSet))
            {
                string     zoneName   = hostedZoneName.Trim(new[] { '.' });
                HostedZone hostedZone = awsClient.DnsService.GetHostedZoneByName(zoneName);

                IEnumerable <ResourceRecordSet> resourceRecordSets = awsClient.DnsService.GetResourceRecordSets(hostedZone);
                string nameFilter = string.Format("{0}.{1}", awsStack.StackName, zoneName);

                resourceRecords = resourceRecordSets
                                  .Where(x => x.Name.ToLower().Contains(nameFilter.ToLower()))
                                  .Select(x => new ResourceRecord
                {
                    FullyQualifiedDomainName = x.Name,
                    TimeToLive = (int)x.TTL,
                    Type       = x.Type,
                    Values     = x.ResourceRecords.Select(rr => rr.Value).ToList(),
                    ResourceId = x.Name                             // resource records don't have an ID in AWS, but this is unique so it's good enough for now
                }).ToList();
            }

            return(resourceRecords);
        }
コード例 #2
0
        private static List<ResourceRecord> GetResourceRecords(IAwsClient awsClient, IEnumerable<StackResource> stackResources, AwsStack awsStack, string hostedZoneName)
        {
            var resourceRecords = new List<ResourceRecord>();
            if (stackResources.Any(x => x.ResourceType == ResourceTypeConstants.RecordSet))
            {
                string zoneName = hostedZoneName.Trim(new[] {'.'});
                HostedZone hostedZone = awsClient.DnsService.GetHostedZoneByName(zoneName);

                IEnumerable<ResourceRecordSet> resourceRecordSets = awsClient.DnsService.GetResourceRecordSets(hostedZone);
                string nameFilter = string.Format("{0}.{1}", awsStack.StackName, zoneName);

                resourceRecords = resourceRecordSets
                    .Where(x => x.Name.ToLower().Contains(nameFilter.ToLower()))
                    .Select(x => new ResourceRecord
                    {
                        FullyQualifiedDomainName = x.Name,
                        TimeToLive = (int) x.TTL,
                        Type = x.Type,
                        Values = x.ResourceRecords.Select(rr => rr.Value).ToList(),
                        ResourceId = x.Name // resource records don't have an ID in AWS, but this is unique so it's good enough for now
                    }).ToList();
            }

            return resourceRecords;
        }
コード例 #3
0
        protected bool TryInitializeClient(Guid profileId, out IAwsClient awsClient)
        {
            var profile = ProfileRepository.Find(profileId);
            if (profile == null)
            {
                awsClient = null;
                return false;
            }

            awsClient = _clientFactory.GetClient(profile);
            return true;
        }
コード例 #4
0
        protected bool TryInitializeClient(Guid profileId, out IAwsClient awsClient)
        {
            var profile = ProfileRepository.Find(profileId);

            if (profile == null)
            {
                awsClient = null;
                return(false);
            }

            awsClient = _clientFactory.GetClient(profile);
            return(true);
        }
コード例 #5
0
        protected bool TryInitialize(Guid profileId, out IAwsClient awsClient, out AwsProfile profile)
        {
            var localProfile = ProfileRepository.Find(profileId);
            if (localProfile == null)
            {
                profile = null;
                awsClient = null;
                return false;
            }

            awsClient = _clientFactory.GetClient(localProfile);
            profile = localProfile;
            return true;
        }
コード例 #6
0
        private static List <StackEvent> GetStackEvents(IAwsClient awsClient, AwsStack awsStack)
        {
            IEnumerable <AwsStackEvent> awsEvents = awsClient.StackService.GetStackEvents(awsStack);
            List <StackEvent>           events    = awsEvents.Select(x => new StackEvent
            {
                LogicalId = x.LogicalResourceId,
                Reason    = x.ResourceStatusReason,
                Status    = x.ResourceStatus,
                TimeStamp = x.Timestamp,
                Type      = x.ResourceType
            }).ToList();

            return(events);
        }
コード例 #7
0
        protected bool TryInitialize(Guid profileId, out IAwsClient awsClient, out AwsProfile profile)
        {
            var localProfile = ProfileRepository.Find(profileId);

            if (localProfile == null)
            {
                profile   = null;
                awsClient = null;
                return(false);
            }

            awsClient = _clientFactory.GetClient(localProfile);
            profile   = localProfile;
            return(true);
        }
コード例 #8
0
        private void RefreshDataForPeriod(AwsProfile profile, string period, IAwsClient client, DateTime currentTime)
        {
            string s3Url = MonthlyCsvUrl.Create(profile.DetailedBillingS3Bucket, profile.Account, period);

            var lastModified = new DateTime();

            if (profile.BillingMetadata.ContainsKey(period))
            {
                lastModified = profile.BillingMetadata[period].LastModified;
            }

            DateTime newLastModified;
            Stream   file = client.StorageService.GetFileIfChangedSince(s3Url, lastModified, out newLastModified);

            if (file == null)
            {
                return;
            }

            using (file)
            {
                using (Stream zipStream = OpenFirstZipEntry(file))
                {
                    using (var streamReader = new StreamReader(zipStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 32768, leaveOpen: true))
                    {
                        using (var parser = new LineItemCsvParser(streamReader))
                        {
                            _billingManager.LoadLineItems(parser.GetLineItems(), period);
                        }
                    }
                }
            }

            BillingMetadata metadata;

            if (!profile.BillingMetadata.ContainsKey(period))
            {
                metadata = new BillingMetadata();
                profile.BillingMetadata.Add(period, metadata);
            }
            else
            {
                metadata = profile.BillingMetadata[period];
            }
            metadata.LastModified = newLastModified;
            metadata.LastLoaded   = currentTime;
        }
コード例 #9
0
        public void LoadStack(IAwsClient awsClient, AwsStack stack, string hostedZone, Guid profileId)
        {
            Stack dbStack = _stackRepository.FindAll().FirstOrDefault(x => x.Name == stack.StackName);

            IEnumerable <StackResource> stackResources  = awsClient.StackService.GetResources(stack).ToList();
            List <ResourceRecord>       resourceRecords = GetResourceRecords(awsClient, stackResources, stack, hostedZone);
            List <Guid> instanceIds = GetInstanceIds(stackResources).ToList();

            Stack        stackToPersist = dbStack ?? new Stack();
            SaveMechanic saveMechanic   = dbStack == null ? SaveMechanic.Add : SaveMechanic.Update;

            Map(stack, stackToPersist);
            stackToPersist.ResourceRecords = resourceRecords;
            if (!stackToPersist.CreatedByApplication)
            {
                stackToPersist.InstanceIds = instanceIds;
            }
            stackToPersist.StackEvents    = GetStackEvents(awsClient, stack);
            stackToPersist.OwnerProfileId = profileId;
            Persist(stackToPersist, saveMechanic);
        }
コード例 #10
0
        public void LoadStack(IAwsClient awsClient, AwsStack stack, string hostedZone, Guid profileId)
        {
            Stack dbStack = _stackRepository.FindAll().FirstOrDefault(x => x.Name == stack.StackName);

            IEnumerable<StackResource> stackResources = awsClient.StackService.GetResources(stack).ToList();
            List<ResourceRecord> resourceRecords = GetResourceRecords(awsClient, stackResources, stack, hostedZone);
            List<Guid> instanceIds = GetInstanceIds(stackResources).ToList();

            Stack stackToPersist = dbStack ?? new Stack();
            SaveMechanic saveMechanic = dbStack == null ? SaveMechanic.Add : SaveMechanic.Update;

            Map(stack, stackToPersist);
            stackToPersist.ResourceRecords = resourceRecords;
            if (!stackToPersist.CreatedByApplication)
            {
                stackToPersist.InstanceIds = instanceIds;
            }
            stackToPersist.StackEvents = GetStackEvents(awsClient, stack);
            stackToPersist.OwnerProfileId = profileId;
            Persist(stackToPersist, saveMechanic);
        }
コード例 #11
0
 public AwsAccountService(IAwsClient client)
 {
     Client = client;
 }
コード例 #12
0
ファイル: AwsProductProvider.cs プロジェクト: abatishchev/ab
		public AwsProductProvider(IAwsClient client, IFactory<Product, XElement, SearchCriteria> factory)
		{
			_client = client;
			_factory = factory;
		}
コード例 #13
0
 private static List<StackEvent> GetStackEvents(IAwsClient awsClient, AwsStack awsStack)
 {
     IEnumerable<AwsStackEvent> awsEvents = awsClient.StackService.GetStackEvents(awsStack);
     List<StackEvent> events = awsEvents.Select(x => new StackEvent
     {
         LogicalId = x.LogicalResourceId,
         Reason = x.ResourceStatusReason,
         Status = x.ResourceStatus,
         TimeStamp = x.Timestamp,
         Type = x.ResourceType
     }).ToList();
     return events;
 }
コード例 #14
0
        private void RefreshDataForPeriod(AwsProfile profile, string period, IAwsClient client, DateTime currentTime)
        {
            string s3Url = MonthlyCsvUrl.Create(profile.DetailedBillingS3Bucket, profile.Account, period);

            var lastModified = new DateTime();
            if (profile.BillingMetadata.ContainsKey(period))
            {
                lastModified = profile.BillingMetadata[period].LastModified;
            }

            DateTime newLastModified;
            Stream file = client.StorageService.GetFileIfChangedSince(s3Url, lastModified, out newLastModified);
            if (file == null)
            {
                return;
            }

            using (file)
            {
                using (Stream zipStream = OpenFirstZipEntry(file))
                {
                    using (var streamReader = new StreamReader(zipStream, Encoding.UTF8, detectEncodingFromByteOrderMarks: true, bufferSize: 32768, leaveOpen: true))
                    {
                        using (var parser = new LineItemCsvParser(streamReader))
                        {
                            _billingManager.LoadLineItems(parser.GetLineItems(), period);
                        }
                    }
                }
            }

            BillingMetadata metadata;
            if (! profile.BillingMetadata.ContainsKey(period))
            {
                metadata = new BillingMetadata();
                profile.BillingMetadata.Add(period, metadata);
            }
            else
            {
                metadata = profile.BillingMetadata[period];
            }
            metadata.LastModified = newLastModified;
            metadata.LastLoaded = currentTime;
        }