public void Should_Able_To_Create_AmazonAPIGatewayClient() { AmazonServiceClient amazonApiGatewayClient = Session.CreateClientByInterface <IAmazonAPIGateway>(); Assert.NotNull(amazonApiGatewayClient); AssertAmazonClient.AssertClientConfiguration(amazonApiGatewayClient); }
public void Should_Able_To_Create_AmazonServerlessApplicationRepositoryClient() { AmazonServiceClient amazonServiceServerlessApplicationRepositoryClient = Session.CreateClientByInterface <IAmazonServerlessApplicationRepository>(); Assert.NotNull(amazonServiceServerlessApplicationRepositoryClient); AssertAmazonClient.AssertClientConfiguration(amazonServiceServerlessApplicationRepositoryClient); }
public void Should_Able_To_Create_AmazonCognitoIdentityProviderClient() { AmazonServiceClient amazonCognitoIdentityProviderClient = Session.CreateClientByInterface <IAmazonCognitoIdentityProvider>(); Assert.NotNull(amazonCognitoIdentityProviderClient); AssertAmazonClient.AssertClientConfiguration(amazonCognitoIdentityProviderClient); }
public void Should_Able_To_Create_AmazonTimestreamWriteClient() { AmazonServiceClient amazonTimestreamWriteClient = Session.CreateClientByInterface <IAmazonTimestreamWrite>(); Assert.NotNull(amazonTimestreamWriteClient); AssertAmazonClient.AssertClientConfiguration(amazonTimestreamWriteClient); }
public void Should_Able_To_Create_AmazonElasticLoadBalancingV2Client() { AmazonServiceClient amazonElasticLoadBalancingV2Client = Session.CreateClientByInterface <IAmazonElasticLoadBalancingV2>(); Assert.NotNull(amazonElasticLoadBalancingV2Client); AssertAmazonClient.AssertClientConfiguration(amazonElasticLoadBalancingV2Client); }
public void Should_Able_To_Create_AmazonKinesisAnalyticsClient() { AmazonServiceClient amazonKinesisAnalyticsClient = Session.CreateClientByInterface <IAmazonKinesisAnalytics>(); Assert.NotNull(amazonKinesisAnalyticsClient); AssertAmazonClient.AssertClientConfiguration(amazonKinesisAnalyticsClient); }
public void Should_Able_To_Create_AmazonRedshiftDataAPIServiceClient() { AmazonServiceClient amazonRedshiftDataApiServiceClient = Session.CreateClientByInterface <IAmazonRedshiftDataAPIService>(); Assert.NotNull(amazonRedshiftDataApiServiceClient); AssertAmazonClient.AssertClientConfiguration(amazonRedshiftDataApiServiceClient); }
public void Should_Able_To_Create_AmazonCertificateManagerClient() { AmazonServiceClient amazonCertificateManagerClient = Session.CreateClientByInterface <IAmazonCertificateManager>(); Assert.NotNull(amazonCertificateManagerClient); AssertAmazonClient.AssertClientConfiguration(amazonCertificateManagerClient); }
public void Should_Able_To_Create_AmazonMediaStoreDataClient() { AmazonServiceClient amazonMediaStoreDataClient = Session.CreateClientByInterface <IAmazonMediaStoreData>(); Assert.NotNull(amazonMediaStoreDataClient); AssertAmazonClient.AssertClientConfiguration(amazonMediaStoreDataClient); }
public void Should_Able_To_Create_AmazonSimpleWorkflowClient() { AmazonServiceClient amazonSimpleWorkflowClient = Session.CreateClientByInterface <IAmazonSimpleWorkflow>(); Assert.NotNull(amazonSimpleWorkflowClient); AssertAmazonClient.AssertClientConfiguration(amazonSimpleWorkflowClient); }
public static void SetResponse( AmazonServiceClient client, string requestId = null, string s3ExtendedRequestId = null, string content = null, bool isOK = true) { var response = Create(content, requestId, s3ExtendedRequestId, isOK); SetResponse(client, response); }
public void Should_Able_To_Create_AmazonResourceGroupsClient() { AmazonServiceClient amazonResourceGroupsClient = Session.CreateClientByInterface <IAmazonResourceGroups>(); Assert.NotNull(amazonResourceGroupsClient); AssertAmazonClient.AssertClientConfiguration(amazonResourceGroupsClient); }
public static void SetResponse( AmazonServiceClient client, string content, string requestId, bool isOK) { var response = Create(content, requestId, isOK); SetResponse(client, response); }
public void Should_Able_To_Create_AmazonIoTJobsDataPlaneClient() { AmazonServiceClient amazonIoTJobsDataPlaneClient = Session.CreateClientByInterface <IAmazonIoTJobsDataPlane>(); Assert.NotNull(amazonIoTJobsDataPlaneClient); AssertAmazonClient.AssertClientConfiguration(amazonIoTJobsDataPlaneClient); }
public void ItemSearchProxy() { var client = new AmazonServiceClient(); var result = client.ItemSearch(CountryType.UK, SearchIndexType.Electronics, 1); Console.WriteLine(result); }
public static void ConfigureClient(AmazonServiceClient client) { if (FailOriginalRequests) { ForceConfigureClient(client); } }
protected override void PreInvoke(IExecutionContext executionContext) { var request = executionContext.RequestContext.OriginalRequest; var config = executionContext.RequestContext.ClientConfig; var copySnapshotRequest = request as CopySnapshotRequest; if (copySnapshotRequest != null) { if (string.IsNullOrEmpty(copySnapshotRequest.DestinationRegion)) { copySnapshotRequest.DestinationRegion = AWS4Signer.DetermineSigningRegion(config, "ec2", alternateEndpoint: null); } if (string.IsNullOrEmpty(copySnapshotRequest.SourceRegion)) { throw new AmazonEC2Exception("SourceRegion is required to perform the copy snapshot."); } var endpoint = RegionEndpoint.GetBySystemName(copySnapshotRequest.SourceRegion); if (endpoint == null) { throw new AmazonEC2Exception(string.Format(CultureInfo.InvariantCulture, "No endpoint for region {0}.", copySnapshotRequest.SourceRegion)); } // Make sure the presigned URL is currently null so we don't attempt to generate // a presigned URL with a presigned URL. copySnapshotRequest.PresignedUrl = null; // Marshall this request but switch to the source region and make it a GET request. var marshaller = new CopySnapshotRequestMarshaller(); var irequest = marshaller.Marshall(copySnapshotRequest); irequest.UseQueryString = true; irequest.HttpMethod = "GET"; irequest.Parameters.Add("X-Amz-Expires", AWS4PreSignedUrlSigner.MaxAWS4PreSignedUrlExpiry.ToString(CultureInfo.InvariantCulture)); irequest.Endpoint = new Uri("https://" + endpoint.GetEndpointForService(config.RegionEndpointServiceName).Hostname); // Create presigned URL. var metrics = new RequestMetrics(); var immutableCredentials = _credentials.GetCredentials(); if (immutableCredentials.UseToken) { irequest.Parameters["X-Amz-Security-Token"] = immutableCredentials.Token; } var signingResult = AWS4PreSignedUrlSigner.SignRequest(irequest, config, metrics, immutableCredentials.AccessKey, immutableCredentials.SecretKey, "ec2", copySnapshotRequest.SourceRegion); var authorization = "&" + signingResult.ForQueryParameters; var url = AmazonServiceClient.ComposeUrl(irequest); copySnapshotRequest.PresignedUrl = url.AbsoluteUri + authorization; } }
private static AWSCredentials GetCredentials(AmazonServiceClient client) { var type = client.GetType(); var property = type.GetProperty("Credentials", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); var credentials = property.GetValue(client, null) as AWSCredentials; return(credentials); }
public static void ReplaceHttpRequestHandler <T>( AmazonServiceClient client, IHttpRequestFactory <T> httpRequestFactory) { var httpHandler = new HttpHandler <T>(httpRequestFactory, client); ReplaceHttpHandler(client, httpHandler); }
public ServiceResponseCounter(AmazonServiceClient client, Predicate <AmazonWebServiceRequest> requestsToCount = null) { ResponseCount = 0; Client = client; RequestsToCount = requestsToCount; SetCallbacks(Attach, Detach); }
public ServiceResponseCounter(AmazonServiceClient client, Predicate<AmazonWebServiceRequest> requestsToCount = null) { ResponseCount = 0; Client = client; RequestsToCount = requestsToCount; SetCallbacks(Attach, Detach); }
/// <summary> /// Converts the SDK's IRequest to the CRT's HttpRequest Object /// </summary> /// <param name="request">SDK request</param> /// <returns>CRT request</returns> public static Aws.Crt.Http.HttpRequest ConvertToCrtRequest(IRequest request) { // Remove any query params that CRT will set if (request.ParameterCollection != null && request.ParameterCollection.Count > 0) { foreach (var queryParam in request.ParameterCollection.GetSortedParametersList()) { if (CrtForbiddenQueryParams.Contains(queryParam.Key)) { request.ParameterCollection.Remove(queryParam.Key); } } } var crtRequest = new Aws.Crt.Http.HttpRequest { // Using OriginalString here because ComposeUrl -> ResolveResourcePath -> // JoinResourcePathSegments -> UrlEncode will escape some sequeneces (e.g. Ä -> %C3%84) // but initializing that as a Uri will convert it back to Ä Uri = AmazonServiceClient.ComposeUrl(request, false).OriginalString, Method = request.HttpMethod }; if (request.ContentStream != null) { if (request.ContentStream.CanSeek) { crtRequest.BodyStream = request.ContentStream; } else if (request.ContentStream is WrapperStream wrappedStream) { crtRequest.BodyStream = wrappedStream.GetSeekableBaseStream(); } else { throw new AWSCommonRuntimeException("Unable to pass an HTTP request with a non-seekable content stream to CRT."); } } else if (request.Content != null) { crtRequest.BodyStream = new MemoryStream(request.Content); } var headerList = new List <HttpHeader>(request.Headers.Count); foreach (var header in request.Headers) { // Skip CRT-calculated headers if (!CrtForbiddenHeaders.Contains(header.Key)) { headerList.Add(new HttpHeader(header.Key, header.Value)); } } crtRequest.Headers = headerList.ToArray(); return(crtRequest); }
public static void SetResponse( AmazonServiceClient client, Func <HttpHandlerTests.MockHttpRequest, HttpWebResponse> responseCreator) { var requestFactory = new HttpHandlerTests.MockHttpRequestFactory(); requestFactory.ResponseCreator = responseCreator; ReplaceHttpRequestHandler(client, requestFactory); }
public static void SetEndpoint(AmazonServiceClient client, string serviceUrl) { var clientConfig = client .GetType() .GetProperty("Config", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(client, null) as ClientConfig; clientConfig.ServiceURL = serviceUrl; }
/// <summary> /// Generate a token for IAM authentication to an RDS database. /// </summary> /// <param name="credentials">The credentials for the token.</param> /// <param name="region">The region of the RDS database.</param> /// <param name="hostname">Hostname of the RDS database.</param> /// <param name="port">Port of the RDS database.</param> /// <param name="dbUser">Database user for the token.</param> /// <returns></returns> public static string GenerateAuthToken(AWSCredentials credentials, RegionEndpoint region, string hostname, int port, string dbUser) { if (credentials == null) { throw new ArgumentNullException("credentials"); } if (region == null) { throw new ArgumentNullException("region"); } if (port < 0 || port > 65535) { throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "{0} is an invalid port. Port must be 0 to 65535.", port)); } hostname = hostname?.Trim(); if (string.IsNullOrEmpty(hostname)) { throw new ArgumentException("Hostname must not be null or empty."); } dbUser = dbUser?.Trim(); if (string.IsNullOrEmpty(dbUser)) { throw new ArgumentException("DBUser must not be null or empty."); } GenerateRDSAuthTokenRequest authTokenRequest = new GenerateRDSAuthTokenRequest(); IRequest request = new DefaultRequest(authTokenRequest, RDSServiceName); request.UseQueryString = true; request.HttpMethod = HTTPGet; request.Parameters.Add(XAmzExpires, FifteenMinutes.TotalSeconds.ToString(CultureInfo.InvariantCulture)); request.Parameters.Add(DBUserKey, dbUser); request.Parameters.Add(ActionKey, ActionValue); request.Endpoint = new UriBuilder(HTTPS, hostname, port).Uri; var immutableCredentials = credentials.GetCredentials(); if (immutableCredentials.UseToken) { request.Parameters[XAmzSecurityToken] = immutableCredentials.Token; } var signingResult = AWS4PreSignedUrlSigner.SignRequest(request, null, new RequestMetrics(), immutableCredentials.AccessKey, immutableCredentials.SecretKey, RDSServiceName, region.SystemName); var authorization = "&" + signingResult.ForQueryParameters; var url = AmazonServiceClient.ComposeUrl(request); // remove the https:// and append the authorization return(url.AbsoluteUri.Substring(HTTPS.Length + URISchemeDelimiter.Length) + authorization); }
/// <summary> /// Add tracing event handler to a given AmazonServiceClient. /// </summary> /// <param name="serviceClient">The target AmazonServiceClient</param> /// <exception cref="System.ArgumentNullException">Thrown when serviceClient is null.</exception> public void AddEventHandler(AmazonServiceClient serviceClient) { if (serviceClient == null) { throw new ArgumentNullException("serviceClient"); } serviceClient.BeforeRequestEvent += BeforeRequestEventHandler; serviceClient.AfterResponseEvent += AfterResponseEventHandler; serviceClient.ExceptionEvent += ExceptionEventHandler; }
public static void ReplaceHttpHandler <T>( AmazonServiceClient client, HttpHandler <T> httpHandler) { var pipeline = client .GetType() .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .GetValue(client, null) as RuntimePipeline; pipeline.ReplaceHandler <HttpHandler <T> >(httpHandler); }
public static void AssertClientHasCredentials(AmazonServiceClient client, AWSCredentials credentials) { var prop = client.GetType().GetProperty("Credentials", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy); var actualCredentials = ((AWSCredentials)prop.GetValue(client)).GetCredentials(); var givenCredentials = credentials.GetCredentials(); if (actualCredentials?.AccessKey != givenCredentials.AccessKey || actualCredentials?.SecretKey != givenCredentials.SecretKey || actualCredentials?.Token != givenCredentials.Token) { throw new Exception("Credentials do not match"); } }
public static void AddToClient(AmazonServiceClient client) { var pipeline = client .GetType() .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .GetValue(client, null) as RuntimePipeline; var requestFactory = new RetryHttpRequestFactory(); var httpHandler = new HttpHandler <Stream>(requestFactory, client); pipeline.ReplaceHandler <HttpHandler <Stream> >(httpHandler); }
public static void SetEndpoint(AmazonServiceClient client, string serviceUrl, string region = null) { var clientConfig = client .GetType() .GetProperty("Config", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(client, null) as ClientConfig; clientConfig.ServiceURL = serviceUrl; if (region != null) { clientConfig.AuthenticationRegion = region; } }
public static CacheKey Create(AmazonServiceClient client, object cacheType) { if (client == null) { throw new ArgumentNullException("client"); } return(new CacheKey { ImmutableCredentials = client.Credentials?.GetCredentials(), RegionEndpoint = client.Config.RegionEndpoint, ServiceUrl = client.Config.ServiceURL, CacheType = cacheType }); }
public static void SetResponse( AmazonServiceClient client, Func<HttpHandlerTests.MockHttpRequest, HttpWebResponse> responseCreator) { var pipeline = client .GetType() .GetProperty("RuntimePipeline", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic) .GetValue(client, null) as RuntimePipeline; var requestFactory = new HttpHandlerTests.MockHttpRequestFactory(); requestFactory.ResponseCreator = responseCreator; var httpHandler = new HttpHandler<Stream>(requestFactory, client); pipeline.ReplaceHandler<HttpHandler<Stream>>(httpHandler); }
private void btnAmazonOrders_Click(object sender, EventArgs e) { AmazonServiceClient mwsOrders = new AmazonServiceClient(); DateTime FromDate = DateTime.Now.AddDays(-3).Date; DateTime ToDate = DateTime.Now.AddMinutes(-10).Date; AmazonOrderOptions orderOptions = new AmazonOrderOptions(FromDate, ToDate); ExternalOrderResult result = mwsOrders.GetOrders(orderOptions); if (result.Success) { MessageBox.Show("Success"); } }
private void btnAmazonShipped_Click(object sender, EventArgs e) { IOrderShipmentRequest orderShipmentRequest = new AmazonOrderShipmentRequest(); IExternalStoreService serviceClient = new AmazonServiceClient(); orderShipmentRequest.ShipmentList.Add( new eBayOrderShipmentIfo { IsPartialShipment = false, OrderId = txtAmazonOrderId.Text.Trim(), ShipmentDate = DateTime.UtcNow, StoreProvider = StoreProviderTypeEnum.Amazon, TrackingNo = "0", TotalItems = 1, }); ExternalOrderShippedResult result = serviceClient.SetOrderShipped(orderShipmentRequest); }
public ExternalOrderResult GetUnshippedOrders(OrderSearchOptions orderOptions) { IOrderOptions extOrderOptions = null; IExternalStoreService externalService = null; if (orderOptions.StoreProvider == StoreProviderTypeEnum.eBay) { externalService = new eBayServiceCall(); extOrderOptions = new eBayOrderOptions(orderOptions.FromDate, orderOptions.ToDate); } if (orderOptions.StoreProvider == StoreProviderTypeEnum.Amazon) { externalService = new AmazonServiceClient(); extOrderOptions = new AmazonOrderOptions(orderOptions.FromDate, orderOptions.ToDate); } ExternalOrderResult orderResult = externalService.GetOrders(extOrderOptions); int serialNo = 0; //if (orderResult.Success) //{ // foreach (ExternalOrder extOrder in orderResult.Orders) // { // { // serialNo += 1; // ExternalOrderViewModel extOrderVM = new ExternalOrderViewModel(extOrder); // extOrderVM.SerialNo = serialNo; // vmResult.ExternalOrderViewModels.Add(extOrderVM); // } // } // vmResult.Success = true; //} return orderResult; }
public FindResult<StoreProductSearchModel> SearchExternalStoreProducts(StoreProductSearchRequest searchRequest) { IExternalStoreService externalService = null; FindResult<StoreProductSearchModel> result = new FindResult<StoreProductSearchModel>(); if (searchRequest.StoreType == Lotus.Core.Common.StoreProviderTypeEnum.Amazon) { externalService = new AmazonServiceClient(); } if (searchRequest.StoreType == Lotus.Core.Common.StoreProviderTypeEnum.eBay) { externalService = new eBayServiceCall(); } result = externalService.SearchExternalStoreProduct(searchRequest); return result; }
private void btnSearchAmazonProducts_Click(object sender, EventArgs e) { StoreProductSearchRequest request = new StoreProductSearchRequest(); request.ProductName = txtSearchProductName.Text.Trim(); request.StoreType = StoreProviderTypeEnum.Amazon; AmazonServiceClient amazonClient = new AmazonServiceClient(); FindResult<StoreProductSearchModel> findResult = amazonClient.SearchExternalStoreProduct(request); if(findResult.Success) { } }
private void btnGetFeedResult_Click(object sender, EventArgs e) { AmazonServiceClient amazon = new AmazonServiceClient(); ExternalOrderShippedResult result = amazon.GetSubmitFeedResult(txtFeedSubmissionId.Text.Trim()); if (result.Success) { } }
public ExternalOrderShippedResult SetOrdersShipped(ApiOrderShipmentRequest request) { ExternalOrderShippedResult result = null; IOrderShipmentRequest shipmentRequests = null; List<IOrderShipmentInfo> shipmentList = new List<IOrderShipmentInfo>(); IExternalStoreService externalService = null; if (request.StoreProvider == StoreProviderTypeEnum.eBay) { shipmentRequests = new eBayShipmentRequest(); foreach (var item in request.ShippedOrders) { shipmentList.Add(new eBayOrderShipmentIfo { OrderId = item.StoreProviderOrderId, IsPartialShipment = false, StoreProvider = StoreProviderTypeEnum.eBay, TrackingNo = "0", ShipmentDate = Utility.ConvertToGMT(DateTime.UtcNow), ExternalOrderHeaderId = item.ExternalOrderHeaderId, }); } externalService = new eBayServiceCall(); } if (request.StoreProvider == StoreProviderTypeEnum.Amazon) { shipmentRequests = new AmazonOrderShipmentRequest(); foreach (var item in request.ShippedOrders) { shipmentList.Add(new AmazonOrderShipmentInfo { OrderId = item.StoreProviderOrderId, IsPartialShipment = false, StoreProvider = StoreProviderTypeEnum.Amazon, TrackingNo = "0", ShipmentDate = DateTime.UtcNow.AddMinutes(-10), }); } externalService = new AmazonServiceClient(); //result = new ExternalOrderShippedResult() { Success = false, ErrorMessage = "Yet not implemented" }; //return result; } shipmentRequests.ShipmentList = shipmentList; result = externalService.SetOrderShipped(shipmentRequests); return result; }
private static AWSCredentials GetCredentials(AmazonServiceClient client) { var type = client.GetType(); var property = type.GetProperty("Credentials", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic); var credentials = property.GetValue(client, null) as AWSCredentials; return credentials; }