Debian Codegraph @

crt/aws-c-auth/tests/shared_credentials_test_definitions.h

raw symbols SCIP
1 #ifndef SHARED_CREDENTIALS_TEST_DEFINITIONS_H
2 #define SHARED_CREDENTIALS_TEST_DEFINITIONS_H
3 /**
4 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
5 * SPDX-License-Identifier: Apache-2.0.
6 */
7
8 #include <aws/common/string.h>
9 #include <aws/common/uuid.h>
10 #include <aws/io/file_utils.h>
11
12 #include <errno.h>
13
14 #ifdef _MSC_VER
15 /* fopen, fprintf etc... */
16 # pragma warning(push)
17 # pragma warning(disable : 4996)
18 #endif
19
20 AWS_STATIC_STRING_FROM_LITERAL(s_default_profile_env_variable_name, "AWS_PROFILE");
21 AWS_STATIC_STRING_FROM_LITERAL(s_default_config_path_env_variable_name, "AWS_CONFIG_FILE");
22 AWS_STATIC_STRING_FROM_LITERAL(s_default_credentials_path_env_variable_name, "AWS_SHARED_CREDENTIALS_FILE");
23 AWS_STATIC_STRING_FROM_LITERAL(s_access_key_id_env_var, "AWS_ACCESS_KEY_ID");
24 AWS_STATIC_STRING_FROM_LITERAL(s_secret_access_key_env_var, "AWS_SECRET_ACCESS_KEY");
25 AWS_STATIC_STRING_FROM_LITERAL(s_session_token_env_var, "AWS_SESSION_TOKEN");
26
27 static struct aws_string *aws_create_process_unique_file_name(struct aws_allocator *allocator) {
28 char file_name_storage[64] = {0};
29 struct aws_byte_buf filename_buf = aws_byte_buf_from_empty_array(file_name_storage, sizeof(file_name_storage));
30
31 #ifndef WIN32
32 AWS_FATAL_ASSERT(aws_byte_buf_write_from_whole_cursor(&filename_buf, aws_byte_cursor_from_c_str("./")));
33 #endif
34
35 AWS_FATAL_ASSERT(
36 aws_byte_buf_write_from_whole_cursor(&filename_buf, aws_byte_cursor_from_c_str("config_creds_test")));
37
38 struct aws_uuid uuid;
39 AWS_FATAL_ASSERT(aws_uuid_init(&uuid) == AWS_OP_SUCCESS);
40 AWS_FATAL_ASSERT(aws_uuid_to_str(&uuid, &filename_buf) == AWS_OP_SUCCESS);
41
42 return aws_string_new_from_array(allocator, filename_buf.buffer, filename_buf.len);
43 }
44
45 static int aws_create_profile_file(const struct aws_string *file_name, const struct aws_string *file_contents) {
46 /* avoid compiler warning if some files include this header but don't actually use those variables */
47 (void)s_default_profile_env_variable_name;
48 (void)s_default_config_path_env_variable_name;
49 (void)s_default_credentials_path_env_variable_name;
50 (void)s_access_key_id_env_var;
51 (void)s_secret_access_key_env_var;
52 (void)s_session_token_env_var;
53
54 FILE *fp = fopen(aws_string_c_str(file_name), "w");
55 if (fp == NULL) {
56 return aws_translate_and_raise_io_error(errno);
57 }
58
59 int result = fprintf(fp, "%s", aws_string_c_str(file_contents));
60 fclose(fp);
61
62 if (result < 0) {
63 return aws_translate_and_raise_io_error(errno);
64 }
65
66 return AWS_OP_SUCCESS;
67 }
68
69 #ifdef _MSC_VER
70 # pragma warning(pop)
71 #endif
72
73 #endif /* SHARED_CREDENTIALS_TEST_DEFINITIONS_H */