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); }
public void Execute(Guid profileId, string subnetId) { AwsProfile profile = _profileRepository.Find(profileId); if (profile == null) { return; } INetworkService networkService = _awsClientFactory.GetClient(profile).NetworkService; string cidrRange; try { cidrRange = networkService.GetCidrBySubnetId(subnetId); } catch (AmazonEC2Exception e) { Debug.WriteLine(e.Message); return; } if (_ipRangeRepository.FindAll().Any(x => x.Cidr == cidrRange)) { return; } DateTime utcNow = DateTime.UtcNow; IPNetwork network = IPNetwork.Parse(cidrRange); List <SubnetIpAddress> subnetIpAddresses = IPNetwork.ListIPAddress(network) .Skip(5) // Amazon reserves the first four IP addresses... (x.x.x.1 - x.x.x.4) .Select(x => new SubnetIpAddress { Address = x, IsInUse = false, LastUpdateTime = utcNow }).ToList(); if (subnetIpAddresses.Any()) { subnetIpAddresses.RemoveAt(subnetIpAddresses.Count - 1); // and last IP address. } var ipRange = new IPRange { AwsProfileId = profileId, Cidr = cidrRange, Addresses = subnetIpAddresses.ToDictionary(x => x.Address.ToString()) }; _ipRangeRepository.Add(ipRange); }
private bool ValidateAccountProfileCredentials(string account, string accessKey, string secretKey) { var client = _awsClientFactory.GetClient(new BasicAWSCredentials(accessKey, secretKey)); return(client.IdentityService.ValidateProfileOwnership(account)); }