diff --git a/include/aws/auth/auth.h b/include/aws/auth/auth.h index 1a17e287..2f17e0fa 100644 --- a/include/aws/auth/auth.h +++ b/include/aws/auth/auth.h @@ -25,6 +25,7 @@ enum aws_auth_errors { AWS_AUTH_SIGNING_ILLEGAL_REQUEST_HEADER, AWS_AUTH_SIGNING_INVALID_CONFIGURATION, AWS_AUTH_CREDENTIALS_PROVIDER_INVALID_ENVIRONMENT, + AWS_AUTH_CREDENTIALS_PROVIDER_INVALID_DELEGATE, AWS_AUTH_CREDENTIALS_PROVIDER_PROFILE_SOURCE_FAILURE, AWS_AUTH_CREDENTIALS_PROVIDER_IMDS_SOURCE_FAILURE, AWS_AUTH_CREDENTIALS_PROVIDER_STS_SOURCE_FAILURE, diff --git a/include/aws/auth/credentials.h b/include/aws/auth/credentials.h index 71861582..7707fd2a 100644 --- a/include/aws/auth/credentials.h +++ b/include/aws/auth/credentials.h @@ -406,6 +406,23 @@ struct aws_credentials_provider_chain_default_options { struct aws_client_bootstrap *bootstrap; }; +/** + * Configuration options for the delegate credentials provider. + */ +struct aws_credentials_provider_delegate_options { + struct aws_credentials_provider_shutdown_options shutdown_options; + + /** + * Provide the vtable of functions to get credentials. + */ + struct aws_credentials_provider_vtable *provider_vtable; + + /** + * Optional implementation. + */ + void *impl; +}; + AWS_EXTERN_C_BEGIN /* @@ -705,6 +722,19 @@ struct aws_credentials_provider *aws_credentials_provider_new_process( struct aws_allocator *allocator, const struct aws_credentials_provider_process_options *options); +/** + * Create a credentials provider depends on provided vtable to fetch the credentials. + * + * @param allocator memory allocator to use for all memory allocation + * @param options provider-specific configuration options + * + * @return the newly-constructed credentials provider, or NULL if an error occurred. + */ +AWS_AUTH_API +struct aws_credentials_provider *aws_credentials_provider_new_delegate( + struct aws_allocator *allocator, + struct aws_credentials_provider_delegate_options *options); + /** * Creates the default provider chain used by most AWS SDKs. * diff --git a/source/auth.c b/source/auth.c index b0c029fe..6ae96268 100644 --- a/source/auth.c +++ b/source/auth.c @@ -44,6 +44,9 @@ static struct aws_error_info s_errors[] = { AWS_DEFINE_ERROR_INFO_AUTH( AWS_AUTH_CREDENTIALS_PROVIDER_INVALID_ENVIRONMENT, "Valid credentials could not be sourced from process environment"), + AWS_DEFINE_ERROR_INFO_AUTH( + AWS_AUTH_CREDENTIALS_PROVIDER_INVALID_DELEGATE, + "Valid credentials could not be sourced from the provided vtable"), AWS_DEFINE_ERROR_INFO_AUTH( AWS_AUTH_CREDENTIALS_PROVIDER_PROFILE_SOURCE_FAILURE, "Valid credentials could not be sourced by a profile provider"), diff --git a/source/crdential_provider_delegate.c b/source/crdential_provider_delegate.c new file mode 100644 index 00000000..b9a0627d --- /dev/null +++ b/source/crdential_provider_delegate.c @@ -0,0 +1,25 @@ +/** + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. + * SPDX-License-Identifier: Apache-2.0. + */ + +#include + +#include +#include +#include + +struct aws_credentials_provider *aws_credentials_provider_new_delegate( + struct aws_allocator *allocator, + struct aws_credentials_provider_delegate_options *options) { + struct aws_credentials_provider *provider = aws_mem_calloc(allocator, 1, sizeof(struct aws_credentials_provider)); + if (provider == NULL) { + return NULL; + } + + aws_credentials_provider_init_base(provider, allocator, options->provider_vtable, options->impl); + + provider->shutdown_options = options->shutdown_options; + + return provider; +}