Skip to content

Commit

Permalink
delegate credential provider (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed Dec 21, 2020
1 parent 5d1b4b6 commit f3a8329
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/aws/auth/auth.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
30 changes: 30 additions & 0 deletions include/aws/auth/credentials.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

/*
Expand Down Expand Up @@ -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.
*
Expand Down
3 changes: 3 additions & 0 deletions source/auth.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down
25 changes: 25 additions & 0 deletions source/crdential_provider_delegate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0.
*/

#include <aws/auth/credentials.h>

#include <aws/auth/private/credentials_utils.h>
#include <aws/common/environment.h>
#include <aws/common/string.h>

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;
}

0 comments on commit f3a8329

Please sign in to comment.