private RequestBody(ContentStreamProvider contentStreamProvider, long contentLength, String contentType) { this.contentStreamProvider = paramNotNull(contentStreamProvider, "contentStreamProvider"); this.contentLength = contentLength; this.contentType = paramNotNull(contentType, "contentType"); validState(contentLength >= 0, "Content length must be greater than or equal to zero"); }
@Override public Builder content(Path contentLocation) { Validate.paramNotNull(contentLocation, "profileLocation"); Validate.validState(contentLocation.toFile().exists(), "Profile file '%s' does not exist.", contentLocation); this.content = null; this.contentLocation = contentLocation; return this; }
@Override public Builder content(Path contentLocation) { Validate.paramNotNull(contentLocation, "profileLocation"); Validate.validState(contentLocation.toFile().exists(), "Profile file '%s' does not exist.", contentLocation); this.content = null; this.contentLocation = contentLocation; return this; }
/** * Validate the result of calling an interceptor method that is attempting to modify the message to make sure its result is * valid. */ private void validateInterceptorResult(Object originalMessage, Object newMessage, ExecutionInterceptor interceptor, String methodName) { if (!Objects.equals(originalMessage, newMessage)) { LOG.debug(() -> "Interceptor '" + interceptor + "' modified the message with its " + methodName + " method."); LOG.trace(() -> "Old: " + originalMessage + "\nNew: " + newMessage); } Validate.validState(newMessage != null, "Request interceptor '%s' returned null from its %s interceptor.", interceptor, methodName); Validate.isInstanceOf(originalMessage.getClass(), newMessage, "Request interceptor '%s' returned '%s' from its %s method, but '%s' was expected.", interceptor, newMessage.getClass(), methodName, originalMessage.getClass()); }
/** * Load an assumed-role credentials provider that has been configured in this profile. This will attempt to locate the STS * module in order to generate the credentials provider. If it's not available, an illegal state exception will be raised. * * @param children The child profiles that source credentials from this profile. */ private AwsCredentialsProvider roleBasedProfileCredentialsProvider(Set<String> children) { requireProperties(ProfileProperty.SOURCE_PROFILE); Validate.validState(!children.contains(name), "Invalid profile file: Circular relationship detected with profiles %s.", children); Validate.validState(credentialsSourceResolver != null, "The profile '%s' must be configured with a source profile in order to use assumed roles.", name); children.add(name); AwsCredentialsProvider sourceCredentialsProvider = credentialsSourceResolver.apply(properties.get(ProfileProperty.SOURCE_PROFILE)) .flatMap(p -> new ProfileCredentialsUtils(p, credentialsSourceResolver) .credentialsProvider(children)) .orElseThrow(this::noSourceCredentialsException); return stsCredentialsProviderFactory().create(sourceCredentialsProvider, profile); }
static MethodSpec consumerBuilderVariant(MethodSpec spec, String javadoc) { Validate.validState(spec.parameters.size() > 0, "A first parameter is required to generate a consumer-builder method."); Validate.validState(spec.parameters.get(0).type instanceof ClassName, "The first parameter must be a class."); ParameterSpec firstParameter = spec.parameters.get(0); ClassName firstParameterClass = (ClassName) firstParameter.type; TypeName consumer = ParameterizedTypeName.get(ClassName.get(Consumer.class), firstParameterClass.nestedClass("Builder")); MethodSpec.Builder result = MethodSpec.methodBuilder(spec.name) .returns(spec.returnType) .addExceptions(spec.exceptions) .addJavadoc(javadoc) .addModifiers(Modifier.PUBLIC, Modifier.DEFAULT) .addTypeVariables(spec.typeVariables) .addParameter(ParameterSpec.builder(consumer, firstParameter.name).build()); // Parameters StringBuilder methodBody = new StringBuilder("return $L($T.builder().applyMutation($L).build()"); for (int i = 1; i < spec.parameters.size(); i++) { ParameterSpec parameter = spec.parameters.get(i); methodBody.append(", ").append(parameter.name); result.addParameter(parameter); } methodBody.append(")"); result.addStatement(methodBody.toString(), spec.name, firstParameterClass, firstParameter.name); return result.build(); }
static MethodSpec consumerBuilderVariant(MethodSpec spec, String javadoc) { Validate.validState(spec.parameters.size() > 0, "A first parameter is required to generate a consumer-builder method."); Validate.validState(spec.parameters.get(0).type instanceof ClassName, "The first parameter must be a class."); ParameterSpec firstParameter = spec.parameters.get(0); ClassName firstParameterClass = (ClassName) firstParameter.type; TypeName consumer = ParameterizedTypeName.get(ClassName.get(Consumer.class), firstParameterClass.nestedClass("Builder")); MethodSpec.Builder result = MethodSpec.methodBuilder(spec.name) .returns(spec.returnType) .addExceptions(spec.exceptions) .addJavadoc(javadoc) .addModifiers(Modifier.PUBLIC, Modifier.DEFAULT) .addTypeVariables(spec.typeVariables) .addParameter(ParameterSpec.builder(consumer, firstParameter.name).build()); // Parameters StringBuilder methodBody = new StringBuilder("return $L($T.builder().applyMutation($L).build()"); for (int i = 1; i < spec.parameters.size(); i++) { ParameterSpec parameter = spec.parameters.get(i); methodBody.append(", ").append(parameter.name); result.addParameter(parameter); } methodBody.append(")"); result.addStatement(methodBody.toString(), spec.name, firstParameterClass, firstParameter.name); return result.build(); }
/** * Load an assumed-role credentials provider that has been configured in this profile. This will attempt to locate the STS * module in order to generate the credentials provider. If it's not available, an illegal state exception will be raised. * * @param children The child profiles that source credentials from this profile. */ private AwsCredentialsProvider roleBasedProfileCredentialsProvider(Set<String> children) { requireProperties(ProfileProperty.SOURCE_PROFILE); Validate.validState(!children.contains(name), "Invalid profile file: Circular relationship detected with profiles %s.", children); Validate.validState(credentialsSourceResolver != null, "The profile '%s' must be configured with a source profile in order to use assumed roles.", name); children.add(name); AwsCredentialsProvider sourceCredentialsProvider = credentialsSourceResolver.apply(properties.get(ProfileProperty.SOURCE_PROFILE)) .flatMap(p -> new ProfileCredentialsUtils(p, credentialsSourceResolver) .credentialsProvider(children)) .orElseThrow(this::noSourceCredentialsException); return stsCredentialsProviderFactory().create(sourceCredentialsProvider, profile); }
Validate.validState(credentials != null, "Credential providers must never return null.");