/** * Identifies the static query parameters in Uri resource path for and adds it to * request. * * Returns the updated uriResourcePath. */ @SdkTestInternalApi static String addStaticQueryParametersToRequest(SdkHttpFullRequest.Builder request, String uriResourcePath) { if (request == null || uriResourcePath == null) { return null; } String resourcePath = uriResourcePath; int index = resourcePath.indexOf("?"); if (index != -1) { String queryString = resourcePath.substring(index + 1); resourcePath = resourcePath.substring(0, index); for (String s : queryString.split("[;&]")) { index = s.indexOf("="); if (index != -1) { request.putRawQueryParameter(s.substring(0, index), s.substring(index + 1)); } else { request.putRawQueryParameter(s, (String) null); } } } return resourcePath; }
/** * Add a single un-encoded query parameter to be included in the created HTTP request. * * <p>This completely <b>OVERRIDES</b> any values already configured with this parameter name in the builder.</p> * * @param paramName The name of the query parameter to add * @param paramValue The un-encoded value for the query parameter. */ @Override default Builder putRawQueryParameter(String paramName, String paramValue) { return putRawQueryParameter(paramName, singletonList(paramValue)); }
/** * Identifies the static query parameters in Uri resource path for and adds it to * request. * * Returns the updated uriResourcePath. */ @SdkTestInternalApi static String addStaticQueryParametersToRequest(SdkHttpFullRequest.Builder request, String uriResourcePath) { if (request == null || uriResourcePath == null) { return null; } String resourcePath = uriResourcePath; int index = resourcePath.indexOf("?"); if (index != -1) { String queryString = resourcePath.substring(index + 1); resourcePath = resourcePath.substring(0, index); for (String s : queryString.split("[;&]")) { index = s.indexOf("="); if (index != -1) { request.putRawQueryParameter(s.substring(0, index), s.substring(index + 1)); } else { request.putRawQueryParameter(s, (String) null); } } } return resourcePath; }
.putRawQueryParameter(PARAM_DESTINATION_REGION, destinationRegion) .removeQueryParameter(PARAM_SOURCE_REGION) .build();
.putRawQueryParameter(PARAM_DESTINATION_REGION, destinationRegion) .removeQueryParameter(PARAM_SOURCE_REGION) .build();
protected SdkHttpFullRequest.Builder doPresign(SdkHttpFullRequest request, Aws4SignerRequestParams requestParams, U signingParams) { SdkHttpFullRequest.Builder mutableRequest = request.toBuilder(); long expirationInSeconds = generateExpirationTime(signingParams); addHostHeader(mutableRequest); AwsCredentials sanitizedCredentials = sanitizeCredentials(signingParams.awsCredentials()); if (sanitizedCredentials instanceof AwsSessionCredentials) { // For SigV4 pre-signing URL, we need to add "X-Amz-Security-Token" // as a query string parameter, before constructing the canonical // request. mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_SECURITY_TOKEN, ((AwsSessionCredentials) sanitizedCredentials).sessionToken()); } // Add the important parameters for v4 signing String timeStamp = requestParams.getFormattedSigningDateTime(); addPreSignInformationToRequest(mutableRequest, sanitizedCredentials, requestParams, timeStamp, expirationInSeconds); String contentSha256 = calculateContentHashPresign(mutableRequest, signingParams); String canonicalRequest = createCanonicalRequest(mutableRequest, contentSha256, signingParams.doubleUrlEncode()); String stringToSign = createStringToSign(canonicalRequest, requestParams); byte[] signingKey = deriveSigningKey(sanitizedCredentials, requestParams); byte[] signature = computeSignature(stringToSign, signingKey); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_SIGNATURE, BinaryUtils.toHex(signature)); return mutableRequest; }
protected SdkHttpFullRequest.Builder doPresign(SdkHttpFullRequest request, Aws4SignerRequestParams requestParams, U signingParams) { SdkHttpFullRequest.Builder mutableRequest = request.toBuilder(); long expirationInSeconds = generateExpirationTime(signingParams); addHostHeader(mutableRequest); AwsCredentials sanitizedCredentials = sanitizeCredentials(signingParams.awsCredentials()); if (sanitizedCredentials instanceof AwsSessionCredentials) { // For SigV4 pre-signing URL, we need to add "X-Amz-Security-Token" // as a query string parameter, before constructing the canonical // request. mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_SECURITY_TOKEN, ((AwsSessionCredentials) sanitizedCredentials).sessionToken()); } // Add the important parameters for v4 signing String timeStamp = requestParams.getFormattedSigningDateTime(); addPreSignInformationToRequest(mutableRequest, sanitizedCredentials, requestParams, timeStamp, expirationInSeconds); String contentSha256 = calculateContentHashPresign(mutableRequest, signingParams); String canonicalRequest = createCanonicalRequest(mutableRequest, contentSha256, signingParams.doubleUrlEncode()); String stringToSign = createStringToSign(canonicalRequest, requestParams); byte[] signingKey = deriveSigningKey(sanitizedCredentials, requestParams); byte[] signature = computeSignature(stringToSign, signingKey); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_SIGNATURE, BinaryUtils.toHex(signature)); return mutableRequest; }
/** * Includes all the signing headers as request parameters for pre-signing. */ private void addPreSignInformationToRequest(SdkHttpFullRequest.Builder mutableRequest, AwsCredentials sanitizedCredentials, Aws4SignerRequestParams signerParams, String timeStamp, long expirationInSeconds) { String signingCredentials = sanitizedCredentials.accessKeyId() + "/" + signerParams.getScope(); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_ALGORITHM, SignerConstant.AWS4_SIGNING_ALGORITHM); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_DATE, timeStamp); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_SIGNED_HEADER, getSignedHeadersString(mutableRequest.headers())); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_EXPIRES, Long.toString(expirationInSeconds)); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_CREDENTIAL, signingCredentials); }
/** * Includes all the signing headers as request parameters for pre-signing. */ private void addPreSignInformationToRequest(SdkHttpFullRequest.Builder mutableRequest, AwsCredentials sanitizedCredentials, Aws4SignerRequestParams signerParams, String timeStamp, long expirationInSeconds) { String signingCredentials = sanitizedCredentials.accessKeyId() + "/" + signerParams.getScope(); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_ALGORITHM, SignerConstant.AWS4_SIGNING_ALGORITHM); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_DATE, timeStamp); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_SIGNED_HEADER, getSignedHeadersString(mutableRequest.headers())); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_EXPIRES, Long.toString(expirationInSeconds)); mutableRequest.putRawQueryParameter(SignerConstant.X_AMZ_CREDENTIAL, signingCredentials); }
@Override public void marshall(QueryMarshallerContext context, String path, List<?> val, SdkField<List<?>> sdkField) { // Explicitly empty lists are marshalled as a query param with empty value in AWS/Query if (val.isEmpty() && !(val instanceof SdkAutoConstructList)) { context.request().putRawQueryParameter(path, ""); return; } for (int i = 0; i < val.size(); i++) { ListTrait listTrait = sdkField.getTrait(ListTrait.class); String listPath = pathResolver.resolve(path, i, listTrait); QueryMarshaller<Object> marshaller = context.marshallerRegistry().getMarshaller( ((SdkField<?>) listTrait.memberFieldInfo()).marshallingType(), val); marshaller.marshall(context, listPath, val.get(i), listTrait.memberFieldInfo()); } }
@Override public void marshall(QueryMarshallerContext context, String path, List<?> val, SdkField<List<?>> sdkField) { // Explicitly empty lists are marshalled as a query param with empty value in AWS/Query if (val.isEmpty() && !(val instanceof SdkAutoConstructList)) { context.request().putRawQueryParameter(path, ""); return; } for (int i = 0; i < val.size(); i++) { ListTrait listTrait = sdkField.getTrait(ListTrait.class); String listPath = pathResolver.resolve(path, i, listTrait); QueryMarshaller<Object> marshaller = context.marshallerRegistry().getMarshaller( ((SdkField<?>) listTrait.memberFieldInfo()).marshallingType(), val); marshaller.marshall(context, listPath, val.get(i), listTrait.memberFieldInfo()); } }
@Override public void marshall(QueryMarshallerContext context, String path, Map<String, ?> val, SdkField<Map<String, ?>> sdkField) { MapTrait mapTrait = sdkField.getTrait(MapTrait.class); AtomicInteger entryNum = new AtomicInteger(1); val.forEach((key, value) -> { String mapKeyPath = resolveMapPath(path, mapTrait, entryNum, mapTrait.keyLocationName()); context.request().putRawQueryParameter(mapKeyPath, key); String mapValuePath = resolveMapPath(path, mapTrait, entryNum, mapTrait.valueLocationName()); QueryMarshaller<Object> marshaller = context.marshallerRegistry() .getMarshaller(((SdkField<?>) mapTrait.valueFieldInfo()).marshallingType(), val); marshaller.marshall(context, mapValuePath, value, mapTrait.valueFieldInfo()); entryNum.incrementAndGet(); }); }
@Override public void marshall(QueryMarshallerContext context, String path, Map<String, ?> val, SdkField<Map<String, ?>> sdkField) { MapTrait mapTrait = sdkField.getTrait(MapTrait.class); AtomicInteger entryNum = new AtomicInteger(1); val.forEach((key, value) -> { String mapKeyPath = resolveMapPath(path, mapTrait, entryNum, mapTrait.keyLocationName()); context.request().putRawQueryParameter(mapKeyPath, key); String mapValuePath = resolveMapPath(path, mapTrait, entryNum, mapTrait.valueLocationName()); QueryMarshaller<Object> marshaller = context.marshallerRegistry() .getMarshaller(((SdkField<?>) mapTrait.valueFieldInfo()).marshallingType(), val); marshaller.marshall(context, mapValuePath, value, mapTrait.valueFieldInfo()); entryNum.incrementAndGet(); }); }
@Override public void marshall(QueryMarshallerContext context, String path, T val, SdkField<T> sdkField) { context.request().putRawQueryParameter(path, valueToString.convert(val, sdkField)); }
private SdkHttpFullRequest.Builder fillBasicRequestParams(OperationInfo operationInfo) { return ProtocolUtils.createSdkHttpRequest(operationInfo, endpoint) .encodedPath("") .putRawQueryParameter("Action", operationInfo.operationIdentifier()) .putRawQueryParameter("Version", operationInfo.apiVersion()); }
/** * Add a single un-encoded query parameter to be included in the created HTTP request. * * <p>This completely <b>OVERRIDES</b> any values already configured with this parameter name in the builder.</p> * * @param paramName The name of the query parameter to add * @param paramValue The un-encoded value for the query parameter. */ @Override default Builder putRawQueryParameter(String paramName, String paramValue) { return putRawQueryParameter(paramName, singletonList(paramValue)); }
@Override public void marshall(QueryMarshallerContext context, String path, T val, SdkField<T> sdkField) { context.request().putRawQueryParameter(path, valueToString.convert(val, sdkField)); }
private SdkHttpFullRequest.Builder fillBasicRequestParams(OperationInfo operationInfo) { return ProtocolUtils.createSdkHttpRequest(operationInfo, endpoint) .encodedPath("") .putRawQueryParameter("Action", operationInfo.operationIdentifier()) .putRawQueryParameter("Version", operationInfo.apiVersion()); }