public PackageUpdater(IPlugInContext context, IAutoUpdateServiceHttpClient httpClient) : base(context) { int minuteInterval = Utility.ParseInteger(_config[ConfigConstants.INTERVAL], 60); //Default to 60 minutes if (minuteInterval < 1) { minuteInterval = 1; //Set minimum to 1 minutes } this.Interval = TimeSpan.FromMinutes(minuteInterval); this.httpClient = httpClient; this.PackageVersion = Utility.ResolveVariables(_config[PACKAGE_VERSION], Utility.ResolveVariable); (this.credential, this.region) = AWSUtilities.GetAWSCredentialsRegion(context); this.productKey = _config[PRODUCT_KEY]; this.ring = _config[RING]; if (this.PackageVersion.Contains("execute-api")) // check if using AutoUpdate service { if (this.credential == null || this.region == null || string.IsNullOrWhiteSpace(this.productKey) || string.IsNullOrWhiteSpace(this.ring)) { _logger.LogError("AccessKey, SecretKey, Region, ProductKey and Ring can't be empty."); throw new Exception("AccessKey, SecretKey, Region, ProductKey and Ring can't be empty."); } } if (!int.TryParse(_config[ConfigConstants.DOWNLOAD_NETWORK_PRIORITY], out _downloadNetworkPriority)) { _downloadNetworkPriority = ConfigConstants.DEFAULT_NETWORK_PRIORITY; } }
/// <inheritdoc/> public override TAWSClient GetSecondaryRegionClient() { // Refresh Credentials // Get Client Credentials var(credentials, _) = AWSUtilities.GetAWSCredentialsRegion(_context); // Setup Client with Secondary Region // Region selection based on weighted random choice var supportedRegions = Enumerable .Zip(_supportedRegions, _supportedRegionsWeights) .Select(x => new RegionState(x.First, x.Second)) .OrderBy(x => ConsistentRandom.NextDouble()) .ToList(); while (supportedRegions.Any(x => x.IsAvailable)) { // Get Weighted Random Region var regionState = Shuffle(supportedRegions.Where(x => x.IsAvailable) .ToList()); // Mark Selected Random Region unavailable regionState.IsAvailable = false; TAWSClient client = GetOrCreateRegionClient(credentials, regionState.Region); if (client is not null) { return(client); } } return(null); }
public PackageUpdater(IPlugInContext context, IAutoUpdateServiceHttpClient httpClient, IPackageInstaller packageInstaller) : base(context) { int minuteInterval = Utility.ParseInteger(_config[ConfigConstants.INTERVAL], 60); //Default to 60 minutes if (minuteInterval < 1) { minuteInterval = 1; //Set minimum to 1 minutes } Interval = TimeSpan.FromMinutes(minuteInterval); this.httpClient = httpClient; this.packageInstaller = packageInstaller; PackageVersion = Utility.ResolveVariables(_config[PACKAGE_VERSION], Utility.ResolveVariable); (credential, region) = AWSUtilities.GetAWSCredentialsRegion(context); productKey = _config[PRODUCT_KEY]; deploymentStage = _config[DEPLOYMENT_STAGE]; if (PackageVersion.Contains("execute-api")) // check if using AutoUpdate service { if (credential == null || string.IsNullOrWhiteSpace(productKey) || string.IsNullOrWhiteSpace(deploymentStage)) { _logger.LogError("credential, productKey and deploymentStage can't be empty."); throw new Exception("credential, productKey and deploymentStage can't be empty."); } } if (!int.TryParse(_config[ConfigConstants.DOWNLOAD_NETWORK_PRIORITY], out _downloadNetworkPriority)) { _downloadNetworkPriority = ConfigConstants.DEFAULT_NETWORK_PRIORITY; } }
public Status ProcessRequest(ResolverRequest request) { Status status = new Status(); status.Id = request.Id; status.ActionId = request.ActionId; try { String cueId = request.CueId; Config config = JsonTools.Convert <Config>(request.Signal.Cues[cueId].Resolver.Config); LambdaArn arn = new LambdaArn(config.Arn); RegionEndpoint region = RegionEndpoint.GetBySystemName(System.Environment.GetEnvironmentVariable("AWS_REGION")); if (!String.IsNullOrEmpty(arn.Region)) { region = RegionEndpoint.GetBySystemName(arn.Region); } AmazonLambdaClient client = new AmazonLambdaClient(region); // Set Region InvokeResponse response = AWSUtilities.CallLambdaMethod(client, arn.Arn, JsonTools.Serialize(request)); status.NewStatus = StatusType.SentToResolver; status.Message = $"Request Sent To Lambda Function [{arn.Name}]."; } catch (Exception e) { status.NewStatus = StatusType.Error; status.Message = e.Message; } return(status); }
private async Task <GetObjectResponse> GetS3Object(string url) { (string bucketName, string key) = AWSUtilities.ParseS3Url(url); var response = await _s3Client.GetObjectAsync(new GetObjectRequest { BucketName = bucketName, Key = key }); return(response); }
/// <inheritdoc/> public virtual TAWSClient GetPrimaryRegionClient() { // Get Client Credentials and Primary Region var(credentials, regionEndpoint) = AWSUtilities.GetAWSCredentialsRegion(_context); // If RegionEndpoint is null if (regionEndpoint is null) { regionEndpoint = FallbackRegionFactory.GetRegionEndpoint(); } // Setup Client with Primary Region // Check Primary Region is available return(GetOrCreateRegionClient(credentials, regionEndpoint, true, true)); }
/// <inheritdoc/> public override TAWSClient GetPrimaryRegionClient() { // Get Client Credentials var(credentials, _) = AWSUtilities.GetAWSCredentialsRegion(_context); // Setup Client with Primary Region // Region selection based on shortest rount trip time foreach (var regionEndpoint in Sorted(credentials, _supportedRegions).Result) { TAWSClient client = GetOrCreateRegionClient(credentials, regionEndpoint, true, true); if (client is not null) { return(client); } } return(null); }
/// <inheritdoc/> public override TAWSClient GetSecondaryRegionClient() { // Refresh Credentials // Get Client Credentials var(credentials, _) = AWSUtilities.GetAWSCredentialsRegion(_context); // Setup Client with Secondary Region // Region selection based on random choice foreach (var regionEndpoint in Shuffle(_supportedRegions)) { TAWSClient client = GetOrCreateRegionClient(credentials, regionEndpoint); if (client is not null) { return(client); } } return(null); }
public S3Downloader(IPlugInContext context, IAppDataFileProvider appDataFileProvider) { Guard.ArgumentNotNull(appDataFileProvider, nameof(appDataFileProvider)); _s3Client = AWSUtilities.CreateAWSClient <AmazonS3Client>(context); _appDataFileProvider = appDataFileProvider; }
public S3Downloader(IPlugInContext context) { _s3Client = AWSUtilities.CreateAWSClient <AmazonS3Client>(context); }