public QueueProvider(AwsConfig config) { _serviceUrl = config.SqsServiceUrl; _accessKey = config.AccessKey; _secretKey = config.SecretKey; _baseUrl = config.SqsBaseUrl; }
/// <summary> /// Generate AWS Settings file(s) /// </summary> /// <param name="settingsOptions"></param> /// <returns></returns> public static int RunSettings(SettingsOptions settingsOptions) { var logger = new Logger(); try { if (string.IsNullOrEmpty(settingsOptions.StackName)) { throw new Exception($"Error: no StackName provided"); } var json = (settingsOptions.MethodMap) ? AwsConfig.GenerateMethodMapJsonAsync( settingsOptions.ProfileName, settingsOptions.StackName).GetAwaiter().GetResult() : AwsConfig.GenerateSettingsJsonAsync( settingsOptions.ProfileName, settingsOptions.StackName).GetAwaiter().GetResult(); if (string.IsNullOrEmpty(settingsOptions.OutputFilePath)) { Console.Write(json); } else { File.WriteAllText(settingsOptions.OutputFilePath, json); } } catch (Exception e) { logger.Error(e, e.Message); return(-1); } return(1); }
private static void Send() { var config = new AwsConfig { Region = "eu-west-1", Service = "ses", AccessId = "<ACCESSID>", Secret = "<SECRET>" }; var from = "*****@*****.**"; var to = "*****@*****.**"; var request = new HttpRequestMessage { Method = HttpMethod.Get, // Optional content //Content = new StringContent(string.Empty, Encoding.UTF8, "application/x-www-form-urlencoded"), RequestUri = new Uri($"https://email.eu-west-1.amazonaws.com?Action=SendEmail&Source={from}&Destination.ToAddresses.member.1={to}&Message.Subject.Data=AmazonMail&Message.Body.Text.Data=SigningTest&ConfigurationSetName=ExtraInfo") }; AwsSigner.SignRequest(config, request).GetAwaiter().GetResult(); var client = new HttpClient(); var result = client.SendAsync(request).GetAwaiter().GetResult(); result.EnsureSuccessStatusCode(); Console.WriteLine("All good"); }
public NoSqlProvider(IOptions <AwsConfig> config) { _config = config.Value; var credentials = new BasicAWSCredentials(_config.AccessKey, _config.SecretKey); _client = new AmazonDynamoDBClient(credentials, RegionEndpoint.EUWest1); }
/// <summary> /// Helper class to create a signature using the config and request /// </summary> /// <param name="config"></param> /// <param name="request"></param> /// <param name="dateTime"></param> /// <returns></returns> public async Task <string> CreateSignature(AwsConfig config, HttpRequestMessage request, DateTimeOffset dateTime) { var signString = await CreateSignString(config.Region, config.Service, request, dateTime); var signingKey = CreateSigningKey(config.Secret, dateTime, config.Region, config.Service); var signature = CreateSignature(signingKey, signString); return(signature); }
/// <summary> /// Signs an httprequestmessage with the given config /// </summary> /// <param name="config"></param> /// <param name="request"></param> /// <param name="dateTime"></param> /// <returns></returns> public static async Task SignRequest(AwsConfig config, HttpRequestMessage request, DateTimeOffset?dateTime = null) { using (var signer = new AwsSigner()) { if (dateTime == null) { dateTime = DateTimeOffset.UtcNow + TimeSpan.FromMinutes(5); } const string scheme = "AWS4-HMAC-SHA256"; request.Headers.Add("X-Amz-Date", dateTime.Value.ToString("yyyyMMddTHHmmssZ")); var signedHeaders = signer.BuildSignedHeaders(signer.BuildCanonicalHeaders(request)); var signature = await signer.CreateSignature(config, request, dateTime.Value); var parameter = signer.CreateAuthorizationHeader(config.AccessId, dateTime.Value, config.Region, config.Service, signedHeaders, signature); request.Headers.Authorization = new AuthenticationHeaderValue(scheme, parameter); } }
public async Task InitializeDatabaseConnection() { AmazonDynamoDBFactory.ResetFactory(); string localApplicationDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string subPath = "Beste.Core" + Path.DirectorySeparatorChar + "Tests"; string configFileName = "configAws.xml"; string directoryOfTestConfigAws = System.IO.Path.Combine(localApplicationDataPath, subPath); string pathToTestConfigAws = System.IO.Path.Combine(localApplicationDataPath, subPath, configFileName); if (!Directory.Exists(directoryOfTestConfigAws) || !File.Exists(pathToTestConfigAws)) { AwsConfig awsConfigPattern = new AwsConfig() { RegionEndpoint = "REGIONENDPOINT", AccessKey = "YOURACCESSKEY", SecretKey = "YOURSECRETKEY" }; if (!Directory.Exists(directoryOfTestConfigAws)) { Directory.CreateDirectory(directoryOfTestConfigAws); } string pathToTestConfigAwsPattern = System.IO.Path.Combine(localApplicationDataPath, subPath, "configAws_pattern.xml"); awsConfigPattern.SaveToFile(pathToTestConfigAwsPattern); Assert.Fail("For AWS tests the to test config file must be found in: '" + pathToTestConfigAws + "'. Please create the file with valid endpoint+key+secret\n" + "A pattern was saved in: '" + pathToTestConfigAwsPattern + "'"); } AwsConfig awsConfig = AwsConfig.LoadFromFile <AwsConfig>(pathToTestConfigAws); string pathToConfig = "config" + Path.DirectorySeparatorChar; if (!Directory.Exists(pathToConfig)) { Directory.CreateDirectory(pathToConfig); } if (File.Exists(pathToConfig + configFileName)) { File.Delete(pathToConfig + configFileName); } awsConfig.SaveToFile(pathToConfig + configFileName); await WriteInTestTableFunctionalProgramming_User(); }
public async Task ConfigureAsync_shoud_not_listen_twice() { var jsRuntimeMock = new Mock <IJSRuntime>(); var awsHelperMock = new Mock <IAwsHelper>(); var config = new AwsConfig(); jsRuntimeMock.Setup(m => m.InvokeAsync <object>(It.Is <string>(s => s == "amplifyWrapper.configure"), It.Is <AwsConfig>(c => c == config))) .ReturnsAsync(new object()) .Verifiable(); var sut = new AwsJsInterop(jsRuntimeMock.Object, awsHelperMock.Object); await sut.ConfigureAsync(config); await sut.ConfigureAsync(config); jsRuntimeMock.Verify(m => m.InvokeAsync <object>(It.Is <string>(s => s == "amplifyWrapper.configure"), It.Is <AwsConfig>(c => c == config)), Times.Exactly(1)); }
public static void DownloadModelFiles() { var jsonFile = Path.Combine("..", "credential", "safemail-credhub-values.json"); var myJsonString = File.ReadAllText(jsonFile); var myS3Config = new AwsConfig(myJsonString); var basicCredentials = new Amazon.Runtime.BasicAWSCredentials(myS3Config.AccessKey, myS3Config.SecretKey); AmazonS3Client s3Client = new AmazonS3Client(basicCredentials, Amazon.RegionEndpoint.GetBySystemName(myS3Config.Region)); var fileTransferUtility = new TransferUtility(s3Client); var request = new ListObjectsRequest(); var response = s3Client.ListObjectsAsync(myS3Config.Bucket, myS3Config.Folder).Result; foreach (S3Object obj in response.S3Objects) { try { var dirList = new List <string> { "tmp" }; var fnames = obj.Key.Replace(myS3Config.Folder, "").Split("/", StringSplitOptions.RemoveEmptyEntries); dirList.AddRange(fnames); var filePath = Path.Combine(dirList.ToArray()); // if file not changed ,skip download if (File.Exists(filePath)) { FileInfo fi = new FileInfo(filePath); if (fi.Length == obj.Size && fi.CreationTime > obj.LastModified) { continue; } } Console.WriteLine("download {0} to {1}", obj.Key, filePath); fileTransferUtility.Download(filePath, myS3Config.Bucket, obj.Key); } catch (Exception Excep) { Console.WriteLine(Excep.Message, Excep.InnerException); } } }
private static void Verify() { var config = new AwsConfig { Region = "eu-west-1", Service = "ses", AccessId = "<ACCESS_ID>", Secret = "<SECRET>" }; const string input = "<EXAMPLE_INPUT>"; var request = new HttpRequestMessage { Content = new StringContent(input, Encoding.UTF8, "application/json") }; request.Headers.Add("x-amz-sns-message-type", "Notification"); //var result = AwsValidator.Verify(request).GetAwaiter().GetResult(); //Console.WriteLine(result); }
public void SetEnvironmentVariables() { Environment.SetEnvironmentVariable("KEY", "accessKey"); Environment.SetEnvironmentVariable("SECRET", "secretKey"); Environment.SetEnvironmentVariable("REGION", "region"); Environment.SetEnvironmentVariable("Table", "tableName"); Environment.SetEnvironmentVariable("Bucket", "bucketName"); Environment.SetEnvironmentVariable("Queue", "sqsQueueUrl"); var awsConfig = new AwsConfig { AccessKey = Environment.GetEnvironmentVariable("KEY"), SecretKey = Environment.GetEnvironmentVariable("SECRET"), Region = Environment.GetEnvironmentVariable("REGION"), Bucket = Environment.GetEnvironmentVariable("Bucket"), Table = Environment.GetEnvironmentVariable("Table"), Queue = Environment.GetEnvironmentVariable("Queue") }; aws = new AwsManagers(awsConfig); hlp = new Helpers(awsConfig); }
public async Task SignRequestEmail() { var config = new AwsConfig { Region = "eu-west-1", Service = "ses", AccessId = "AKIDEXAMPLE", Secret = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY" }; var request = Helpers.CreateExampleRequest(); request.Content = new StringContent(string.Empty, Encoding.ASCII, "application/x-www-form-urlencoded"); //Remove the X-Amz-Date header since the authorize method should do this request.Headers.Remove("X-Amz-Date"); var expectedDateTime = DateTimeOffset.Parse("2018-06-12T20:58:15Z"); await AwsSigner.SignRequest(config, request, expectedDateTime); var expectedScheme = "AWS4-HMAC-SHA256"; const string expectedContent = "Credential=AKIDEXAMPLE/20180612/eu-west-1/ses/aws4_request, SignedHeaders=content-type;host;x-amz-date, Signature=8675e236d7864e374cb7d8986204275cb191680357c7b1897103a9c4e2547b2c"; Assert.AreEqual(expectedScheme, request.Headers.Authorization.Scheme, "Authorization scheme does not match"); Assert.AreEqual(expectedContent, request.Headers.Authorization.Parameter, "Authorization content does not match"); }
public void OneTimeSetUp() { client = AwsConfig.CreateAmazonS3Client(); }
internal Helpers(AwsConfig config) { aws = new AwsManagers(config); }
public SimpleDbProvider(AwsConfig config) { _serviceUrl = config.SdbServiceUrl; _accessKey = config.AccessKey; _secretKey = config.SecretKey; }
public EmailProvider(AwsConfig config) { _accessKey = config.AccessKey; _secretKey = config.SecretKey; _serviceUrl = config.SesServiceUrl; }
protected override async Task OnAfterRenderAsync(bool firstRender) { if (firstRender) { var config = new AwsConfig { Aws_cognito_identity_pool_id = "eu-west-2:5ad8c79a-2cdc-4da4-a94c-1c42becdf301", Aws_cognito_region = "eu-west-2", Aws_user_pools_id = "eu-west-2_MUFO3Qdac", Aws_user_pools_web_client_id = "1ou6jkhe2u8j7sj14rek4a6mcq", Oauth = new AwsOAuth { Domain = "football-championship-dev.auth.eu-west-2.amazoncognito.com", Scope = new string[] { "phone", "email", "openid", "profile", "aws.cognito.signin.user.admin" }, RedirectSignIn = NavigationManager.BaseUri, RedirectSignOut = NavigationManager.BaseUri, ResponseType = "code" }, FederationTarget = "COGNITO_USER_POOLS", Aws_appsync_graphqlEndpoint = "https://pod5c66d6ze73b62evt7xqpn4q.appsync-api.eu-west-2.amazonaws.com/graphql", Aws_appsync_region = "eu-west-2", Aws_appsync_authenticationType = "AMAZON_COGNITO_USER_POOLS" }; await AwsJsInterop.ConfigureAsync(config); await AwsJsInterop.ListenAsync(); if (AwsHelper.IsConnected) { await BrowserJsInterop.NotificationOptIn(); var matches = new List <Match>(); GraphQlSubscriber.MatchUpdated += async(e, match) => { if (match.MatchTeams?.Items == null || match.Scores == null) { return; } var homeTeam = match.MatchTeams.Items.First(t => t.IsHome).Team; var awayTeam = match.MatchTeams.Items.First(t => !t.IsHome).Team; var homeScore = match.Scores.First(s => s.IsHome).Value; var awayScore = match.Scores.First(s => !s.IsHome).Value; if (!matches.Any(m => m.Id == match.Id)) { matches.Add(match); return; } var started = matches.First(m => m.Id == match.Id); var message = $"{homeTeam.LocalizedNames.GetLocalizedValue()} - {awayTeam.LocalizedNames.GetLocalizedValue()}\n{homeScore} - {awayScore}"; if (match.IsFinished != started.IsFinished) { started.IsFinished = match.IsFinished; await BrowserJsInterop.Notify(Resources["Finished"], message); return; } foreach (var score in match.Scores) { if (started.Scores.Any(s => s.IsHome == score.IsHome && s.Value != score.Value)) { started.Scores = match.Scores; await BrowserJsInterop.Notify("Gooooal!", message); return; } } }; await AwsJsInterop.GraphSubscribeAsync(Subscriptions.ON_UPDATE_MATCH, GraphQlSubscriber, nameof(GraphQlSubscriber.OnMatchUpdated)); } } await base.OnAfterRenderAsync(firstRender); }
public AmazonSesEmailDispatcherService(AwsConfig awsConfig) { _awsConfig = awsConfig; }
public OpenApiRepository(IAmazonS3 amazonS3, AwsConfig awsConfig) { _amazonS3 = amazonS3; _awsConfig = awsConfig; }