public async Task <string> GetVersionAsync(string url, GetVersionRequest request, RegionEndpoint region, AWSCredentials creds) { HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, url) { Content = HttpClientExtensions.GetStringContent(request) }; // Current AutoUpdate service only has US-WEST-2 endpoint await AWSV4SignerExtensions.SignRequestAsync(message, RegionEndpoint.USWest2.SystemName, SERVICE_NAME, creds); using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5))) { return(await httpClient.SendRequest(message, cts.Token)); } }
public async Task <HttpResponseMessage> PutMetricsAsync(IDictionary <string, object> data) { HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Put, TELEMETRIC_SERVICE_URI + "metrics"); message.Content = HttpClientExtensions.GetStringContent(data); //Get credential if no credential or withing 5 minute of expiration if (_cognitoCredentials == null || _cognitoCredentials.Expiration - AWSSDKUtils.CorrectedUtcNow < TimeSpan.FromMinutes(5)) { var getCredentialsForIdentityResponse = await _cognitoIdentityClient.GetCredentialsForIdentityAsync(ClientId); _cognitoCredentials = getCredentialsForIdentityResponse.Credentials; } await AWSV4SignerExtensions.SignRequestAsync(message, REGION, SERVICE_NAME, _cognitoCredentials); return(await _httpClient.SendAsync(message)); }
public async Task <string> GetVersionAsync(string url, GetVersionRequest request, RegionEndpoint region, AWSCredentials creds) { HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, url) { Content = HttpClientExtensions.GetStringContent(request), Headers = { { "X-Api-Key", request.ProductKey }, // API Gateway API Key { "AgentId", request.AgentId } // For potential future use by API Gateway } }; await AWSV4SignerExtensions.SignRequestAsync(message, region.SystemName, SERVICE_NAME, creds); using (var cts = new CancellationTokenSource(TimeSpan.FromMinutes(5))) { return(await this.httpClient.SendRequest(message, cts.Token)); } }
public async Task PutMetricsAsync(IDictionary <string, object> data, CancellationToken cancellationToken) { var clientId = await GetClientIdAsync(cancellationToken); using var message = new HttpRequestMessage(HttpMethod.Put, TELEMETRIC_SERVICE_URI + "metrics"); message.Content = HttpClientExtensions.GetStringContent(data); //Get credential if no credential or withing 5 minute of expiration #pragma warning disable CS0618 // Type or member is obsolete if (_cognitoCredentials == null || _cognitoCredentials.Expiration - AWSSDKUtils.CorrectedUtcNow < TimeSpan.FromMinutes(5)) #pragma warning restore CS0618 // Type or member is obsolete { var getCredentialsForIdentityResponse = await _cognitoIdentityClient.GetCredentialsForIdentityAsync(clientId); _cognitoCredentials = getCredentialsForIdentityResponse.Credentials; } await AWSV4SignerExtensions.SignRequestAsync(message, REGION, SERVICE_NAME, _cognitoCredentials); using var response = await _httpClient.SendAsync(message, cancellationToken); response.EnsureSuccessStatusCode(); }