aws_profile.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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/aws_profile.h>
  6. #include <aws/auth/credentials.h>
  7. #include <aws/common/environment.h>
  8. #include <aws/common/string.h>
  9. static const struct aws_string *s_profile_get_property_value(
  10. const struct aws_profile *profile,
  11. const struct aws_string *property_name) {
  12. const struct aws_profile_property *property = aws_profile_get_property(profile, property_name);
  13. if (property == NULL) {
  14. return NULL;
  15. }
  16. return aws_profile_property_get_value(property);
  17. }
  18. AWS_STATIC_STRING_FROM_LITERAL(s_access_key_id_profile_var, "aws_access_key_id");
  19. AWS_STATIC_STRING_FROM_LITERAL(s_secret_access_key_profile_var, "aws_secret_access_key");
  20. AWS_STATIC_STRING_FROM_LITERAL(s_session_token_profile_var, "aws_session_token");
  21. struct aws_credentials *aws_credentials_new_from_profile(
  22. struct aws_allocator *allocator,
  23. const struct aws_profile *profile) {
  24. const struct aws_string *access_key = s_profile_get_property_value(profile, s_access_key_id_profile_var);
  25. const struct aws_string *secret_key = s_profile_get_property_value(profile, s_secret_access_key_profile_var);
  26. if (access_key == NULL || secret_key == NULL) {
  27. return NULL;
  28. }
  29. const struct aws_string *session_token = s_profile_get_property_value(profile, s_session_token_profile_var);
  30. return aws_credentials_new_from_string(allocator, access_key, secret_key, session_token, UINT64_MAX);
  31. }