Ejemplo n.º 1
0
        private SA_Subnet ConvertSubnet(Subnet awsSubnet)
        {
            SA_Subnet saSubnet = ModelTransformer <Subnet, SA_Subnet> .TransformAwsModelToSafeArrivalModel(awsSubnet);

            saSubnet.DisplayName = awsSubnet.Tags.Find(o => o.Key == "Name").Value;
            return(saSubnet);
        }
Ejemplo n.º 2
0
        private SA_Stack ConvertStack(Stack awsStack)
        {
            try
            {
                var saStack = ModelTransformer <Stack, SA_Stack> .
                              TransformAwsModelToSafeArrivalModel(awsStack);

                //saListener.Rule = awsListener.DefaultActions[0].Type.ToString() +
                //    " to " + awsListener.DefaultActions[0].TargetGroupArn;
                if (awsStack.Tags.Count > 0 && awsStack.Tags.Find(o => o.Key == "Name") != null)
                {
                    saStack.DisplayName = awsStack.Tags.Find(o => o.Key == "Name").Value;
                }
                else
                {
                    saStack.DisplayName = awsStack.StackName;
                }
                return(saStack);
            }
            catch (Exception ex)
            {
                var x = awsStack;
                throw;
            }
        }
Ejemplo n.º 3
0
        private SA_Listener ConvertListener(Listener awsListener)
        {
            var saListener = ModelTransformer <Listener, SA_Listener> .
                             TransformAwsModelToSafeArrivalModel(awsListener);

            //saListener.Rule = awsListener.DefaultActions[0].Type.ToString() +
            //    " to " + awsListener.DefaultActions[0].TargetGroupArn;
            saListener.TargetArn = awsListener.DefaultActions[0].TargetGroupArn;
            return(saListener);
        }
Ejemplo n.º 4
0
        private SA_SecurityGroup ConvertSecurityGroup(SecurityGroup awsSecurityGroup)
        {
            try
            {
                SA_SecurityGroup saSecurityGroup = ModelTransformer <SecurityGroup, SA_SecurityGroup> .TransformAwsModelToSafeArrivalModel(awsSecurityGroup);

                saSecurityGroup.DisplayName = awsSecurityGroup.Tags.Find(o => o.Key == "Name").Value;
                return(saSecurityGroup);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Ejemplo n.º 5
0
        public async Task <SA_TargetGroup> CreateTargetGroup(
            string name, string vpcId, string protocol, int port)
        {
            var request = new CreateTargetGroupRequest()
            {
                Name     = name,
                VpcId    = vpcId,
                Protocol = new ProtocolEnum(protocol),
                Port     = 80
            };
            var response = await client.CreateTargetGroupAsync(request);

            return(ModelTransformer <TargetGroup, SA_TargetGroup> .TransformAwsModelToSafeArrivalModel(response.TargetGroups[0]));
        }
Ejemplo n.º 6
0
        //public async Task<string> CreateLoadBalancer(
        //    string name, List<string> securityGroups, List<string> subnets)
        //{
        //    var request = new CreateLoadBalancerRequest()
        //    {
        //        LoadBalancerName = name,
        //        SecurityGroups = securityGroups,
        //        Subnets = subnets,

        //        IpAddressType = IpAddressType.Ipv4,
        //        Scheme = LoadBalancerSchemeEnum.InternetFacing,
        //        //Type = LoadBalancerTypeEnum.Application
        //    };
        //    var response = await client.CreateLoadBalancerAsync(request);

        //    return response.LoadBalancers[0].LoadBalancerArn;
        //}

        public async Task <List <SA_LoadBalancer> > GetLoadBalancerList()
        {
            List <SA_LoadBalancer> lstLoadBalancers = new List <SA_LoadBalancer>();
            var request  = new DescribeLoadBalancersRequest();
            var response = await client.DescribeLoadBalancersAsync(request);

            var lstSourceELBs = response.LoadBalancerDescriptions;
            var reqTags       = new DescribeTagsRequest()
            {
                LoadBalancerNames = response.LoadBalancerDescriptions.Select(o => o.LoadBalancerName).ToList()
            };
            var respTags = await client.DescribeTagsAsync(reqTags);

            //LoadBalancer name like "awseb-e-c-AWSEBLoa-G25T4NILK22Q", need to get name from tag.
            foreach (var sourceELB in lstSourceELBs)
            {
                string tagName = string.Empty;
                //try
                //{
                //    var tags = respTags.TagDescriptions.Find
                //    (o => o.LoadBalancerName == sourceELB.LoadBalancerName).Tags.Find(o => o.Key == "Name").Value;
                //}
                //catch
                //{
                //    continue;
                //}
                var tags = respTags.TagDescriptions.Find
                               (o => o.LoadBalancerName == sourceELB.LoadBalancerName).Tags;
                var nameTag = tags.Find(o => o.Key == "Name");
                if (nameTag == null)
                {
                    continue;
                }

                tagName = nameTag.Value;
                if (!(tagName.IndexOf($"{environment}-{color}") == 0))   //check
                {
                    continue;
                }
                var elb = ModelTransformer <LoadBalancerDescription, SA_LoadBalancer> .
                          TransformAwsModelToSafeArrivalModel(sourceELB);

                elb.LoadBalancerName = tagName;
                lstLoadBalancers.Add(elb);
            }

            //lstLoadBalancers = lstLoadBalancers.FindAll(o => o.LoadBalancerName.Contains($"{environment}-"));
            return(lstLoadBalancers);
        }
Ejemplo n.º 7
0
        public async Task <List <ConfigurationOptionSettingModel> > GetScheduledActionSettingItems()
        {
            var ret             = new List <ConfigurationOptionSettingModel>();
            var requestSettings = new DescribeConfigurationSettingsRequest()
            {
                ApplicationName = $"Safe-Arrival-{ environment.ToString()}-{GlobalVariables.Color}",
                EnvironmentName = $"{ environment.ToString()}-{GlobalVariables.Color}-API",
            };
            var response = await client.DescribeConfigurationSettingsAsync(requestSettings);

            var sourceSettings = response.ConfigurationSettings[0].OptionSettings.FindAll(
                o => o.Namespace == "aws:autoscaling:scheduledaction");

            foreach (var settings in sourceSettings)
            {
                ret.Add(ModelTransformer <ConfigurationOptionSetting, ConfigurationOptionSettingModel> .
                        TransformAwsModelToSafeArrivalModel(settings));
            }
            return(ret);
        }