software.amazon.awssdk.core.SdkClient Java Examples

The following examples show how to use software.amazon.awssdk.core.SdkClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AwsScannerTest.java    From clouditor with Apache License 2.0 6 votes vote down vote up
static <B extends SdkClient, C extends AwsClientBuilder<C, B>, T extends ToCopyableBuilder>
    void discoverAssets(
        Class<B> apiClass, Supplier<AwsScanner<B, C, T>> supplier, Consumer<B> configurator) {
  var scanner = supplier.get();

  System.setProperty("aws.region", "mock");
  System.setProperty("aws.accessKeyId", "mock");
  System.setProperty("aws.secretAccessKey", "mock");

  // mock the client
  var api = mock(apiClass);
  // scanner.init(); don't init
  scanner.setInitialized(true);

  configurator.accept(api);

  // force the api
  scanner.setApi(api);

  assets = scanner.scan(null);
}
 
Example #2
Source File: AsyncClientInterface.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSpec poetSpec() {
    TypeSpec.Builder result = PoetUtils.createInterfaceBuilder(className);

    result.addSuperinterface(SdkClient.class)
          .addField(FieldSpec.builder(String.class, "SERVICE_NAME")
                             .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
                             .initializer("$S", model.getMetadata().getSigningName())
                             .build());

    PoetUtils.addJavadoc(result::addJavadoc, getJavadoc());

    if (!model.getCustomizationConfig().isExcludeClientCreateMethod()) {
        result.addMethod(create());
    }

    result.addMethod(builder())
          .addMethods(operationsAndSimpleMethods());

    if (model.getCustomizationConfig().getUtilitiesMethod() != null) {
        result.addMethod(utilitiesMethod());
    }

    return result.build();
}
 
Example #3
Source File: SyncClientInterface.java    From aws-sdk-java-v2 with Apache License 2.0 6 votes vote down vote up
@Override
public TypeSpec poetSpec() {
    TypeSpec.Builder result = PoetUtils.createInterfaceBuilder(className);

    result.addSuperinterface(SdkClient.class)
          .addField(FieldSpec.builder(String.class, "SERVICE_NAME")
                             .addModifiers(Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
                             .initializer("$S", model.getMetadata().getSigningName())
                             .build());

    PoetUtils.addJavadoc(result::addJavadoc, getJavadoc());

    if (!model.getCustomizationConfig().isExcludeClientCreateMethod()) {
        result.addMethod(create());
    }

    result.addMethod(builder())
          .addMethods(operations())
          .addMethod(serviceMetadata());

    if (model.getCustomizationConfig().getUtilitiesMethod() != null) {
        result.addMethod(utilitiesMethod());
    }

    return result.build();
}
 
Example #4
Source File: AbstractAmazonServiceProcessor.java    From quarkus with Apache License 2.0 5 votes vote down vote up
protected void buildClients(List<AmazonClientBuilderConfiguredBuildItem> configuredClients,
        Function<RuntimeValue<? extends AwsClientBuilder>, RuntimeValue<? extends SdkClient>> syncClient,
        Function<RuntimeValue<? extends AwsClientBuilder>, RuntimeValue<? extends SdkClient>> asyncClient) {

    for (AmazonClientBuilderConfiguredBuildItem client : configuredClients) {
        if (configName().equals(client.getAwsClientName())) {
            if (client.getSyncBuilder() != null) {
                syncClient.apply(client.getSyncBuilder());
            }
            if (client.getAsyncBuilder() != null) {
                asyncClient.apply(client.getAsyncBuilder());
            }
        }
    }
}
 
Example #5
Source File: BaseHandlerStd.java    From cloudformation-cli-java-plugin with Apache License 2.0 4 votes vote down vote up
protected abstract ProgressEvent<ResourceModel, CallbackContext> handleRequest(
final AmazonWebServicesClientProxy proxy,
final ResourceHandlerRequest<ResourceModel> request,
final CallbackContext callbackContext,
final ProxyClient<SdkClient> proxyClient,
final Logger logger);
 
Example #6
Source File: StubReadHandler.java    From cloudformation-cli-java-plugin with Apache License 2.0 4 votes vote down vote up
protected ProgressEvent<ResourceModel, CallbackContext> handleRequest(
    final AmazonWebServicesClientProxy proxy,
    final ResourceHandlerRequest<ResourceModel> request,
    final CallbackContext callbackContext,
    final ProxyClient<SdkClient> proxyClient,
    final Logger logger) {

    this.logger = logger;

    // TODO: Adjust Progress Chain according to your implementation
    // https://github.com/aws-cloudformation/cloudformation-cli-java-plugin/blob/master/src/main/java/software/amazon/cloudformation/proxy/CallChain.java

    // STEP 1 [initialize a proxy context]
    return proxy.initiate("{{ call_graph }}::{{ operation }}", proxyClient, request.getDesiredResourceState(), callbackContext)

        // STEP 2 [TODO: construct a body of a request]
        .translateToServiceRequest(Translator::translateToReadRequest)

        // STEP 3 [TODO: make an api call]
        // Implement client invocation of the read request through the proxyClient, which is already initialised with
        // caller credentials, correct region and retry settings
        .makeServiceCall((awsRequest, client) -> {
            AwsResponse awsResponse = null;
            try {

                // TODO: add custom read resource logic

            } catch (final AwsServiceException e) { // ResourceNotFoundException
                /*
                * While the handler contract states that the handler must always return a progress event,
                * you may throw any instance of BaseHandlerException, as the wrapper map it to a progress event.
                * Each BaseHandlerException maps to a specific error code, and you should map service exceptions as closely as possible
                * to more specific error codes
                */
                throw new CfnGeneralServiceException(ResourceModel.TYPE_NAME, e); // e.g. https://github.com/aws-cloudformation/aws-cloudformation-resource-providers-logs/commit/2077c92299aeb9a68ae8f4418b5e932b12a8b186#diff-5761e3a9f732dc1ef84103dc4bc93399R56-R63
            }

            logger.log(String.format("%s has successfully been read.", ResourceModel.TYPE_NAME));
            return awsResponse;
        })

        // STEP 4 [TODO: gather all properties of the resource]
        // Implement client invocation of the read request through the proxyClient, which is already initialised with
        // caller credentials, correct region and retry settings
        .done(awsResponse -> ProgressEvent.defaultSuccessHandler(Translator.translateFromReadResponse(awsResponse)));
}
 
Example #7
Source File: ClientBuilder.java    From cloudformation-cli-java-plugin with Apache License 2.0 4 votes vote down vote up
public static SdkClient getClient() {
  return null;
}