credentials_provider_delegate.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/auth/private/credentials_utils.h>
  6. struct aws_credentials_provider_delegate_impl {
  7. aws_credentials_provider_delegate_get_credentials_fn *get_credentials;
  8. void *user_data;
  9. };
  10. static int s_credentials_provider_delegate_get_credentials(
  11. struct aws_credentials_provider *provider,
  12. aws_on_get_credentials_callback_fn callback,
  13. void *callback_user_data) {
  14. struct aws_credentials_provider_delegate_impl *impl = provider->impl;
  15. return impl->get_credentials(impl->user_data, callback, callback_user_data);
  16. }
  17. static void s_credentials_provider_delegate_destroy(struct aws_credentials_provider *provider) {
  18. aws_credentials_provider_invoke_shutdown_callback(provider);
  19. aws_mem_release(provider->allocator, provider);
  20. }
  21. static struct aws_credentials_provider_vtable s_credentials_provider_delegate_vtable = {
  22. .get_credentials = s_credentials_provider_delegate_get_credentials,
  23. .destroy = s_credentials_provider_delegate_destroy,
  24. };
  25. struct aws_credentials_provider *aws_credentials_provider_new_delegate(
  26. struct aws_allocator *allocator,
  27. const struct aws_credentials_provider_delegate_options *options) {
  28. AWS_ASSERT(options);
  29. AWS_ASSERT(options->get_credentials);
  30. struct aws_credentials_provider *provider = NULL;
  31. struct aws_credentials_provider_delegate_impl *impl = NULL;
  32. aws_mem_acquire_many(
  33. allocator,
  34. 2,
  35. &provider,
  36. sizeof(struct aws_credentials_provider),
  37. &impl,
  38. sizeof(struct aws_credentials_provider_delegate_impl));
  39. if (!provider) {
  40. return NULL;
  41. }
  42. AWS_ZERO_STRUCT(*provider);
  43. AWS_ZERO_STRUCT(*impl);
  44. aws_credentials_provider_init_base(provider, allocator, &s_credentials_provider_delegate_vtable, impl);
  45. provider->shutdown_options = options->shutdown_options;
  46. impl->get_credentials = options->get_credentials;
  47. impl->user_data = options->delegate_user_data;
  48. return provider;
  49. }