Debian Codegraph @

crt/aws-c-sdkutils/include/aws/sdkutils/aws_profile.h

raw symbols SCIP
1 /**
2 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 * SPDX-License-Identifier: Apache-2.0.
4 */
5
6 #ifndef AWS_SDKUTILS_AWS_PROFILE_H
7 #define AWS_SDKUTILS_AWS_PROFILE_H
8 #include <aws/sdkutils/sdkutils.h>
9
10 AWS_PUSH_SANE_WARNING_LEVEL
11
12 struct aws_allocator;
13 struct aws_string;
14 struct aws_byte_buf;
15 struct aws_byte_cursor;
16
17 /*
18 * A set of data types that model the aws profile specification
19 *
20 * A profile collection is a collection of zero or more named profiles
21 * Each profile is a set of properties (named key-value pairs)
22 * Empty-valued properties may have sub properties (named key-value pairs)
23 *
24 * Resolution rules exist to determine what profile to use, what files to
25 * read profile collections from, and what types of credentials have priority.
26 *
27 * The profile specification is informally defined as "what the aws cli does" and
28 * formally defined in internal aws documents.
29 */
30 struct aws_profile_property;
31 struct aws_profile;
32 struct aws_profile_collection;
33
34 /**
35 * The profile specification has rule exceptions based on what file
36 * the profile collection comes from.
37 */
38 enum aws_profile_source_type { AWS_PST_NONE, AWS_PST_CONFIG, AWS_PST_CREDENTIALS };
39
40 /*
41 * The collection can hold different types of sections.
42 */
43 enum aws_profile_section_type {
44 AWS_PROFILE_SECTION_TYPE_PROFILE,
45 AWS_PROFILE_SECTION_TYPE_SSO_SESSION,
46 AWS_PROFILE_SECTION_TYPE_SERVICES,
47
48 AWS_PROFILE_SECTION_TYPE_COUNT,
49 };
50
51 AWS_EXTERN_C_BEGIN
52
53 /*************************
54 * Profile collection APIs
55 *************************/
56
57 /**
58 * Increments the reference count on the profile collection, allowing the caller to take a reference to it.
59 *
60 * Returns the same profile collection passed in.
61 */
62 AWS_SDKUTILS_API
63 struct aws_profile_collection *aws_profile_collection_acquire(struct aws_profile_collection *collection);
64
65 /**
66 * Decrements a profile collection's ref count. When the ref count drops to zero, the collection will be destroyed.
67 * Returns NULL.
68 */
69 AWS_SDKUTILS_API
70 struct aws_profile_collection *aws_profile_collection_release(struct aws_profile_collection *collection);
71
72 /**
73 * @Deprecated This is equivalent to aws_profile_collection_release.
74 */
75 AWS_SDKUTILS_API
76 void aws_profile_collection_destroy(struct aws_profile_collection *profile_collection);
77
78 /**
79 * Create a new profile collection by parsing a file with the specified path
80 */
81 AWS_SDKUTILS_API
82 struct aws_profile_collection *aws_profile_collection_new_from_file(
83 struct aws_allocator *allocator,
84 const struct aws_string *file_path,
85 enum aws_profile_source_type source);
86
87 /**
88 * Create a new profile collection by merging a config-file-based profile
89 * collection and a credentials-file-based profile collection
90 */
91 AWS_SDKUTILS_API
92 struct aws_profile_collection *aws_profile_collection_new_from_merge(
93 struct aws_allocator *allocator,
94 const struct aws_profile_collection *config_profiles,
95 const struct aws_profile_collection *credentials_profiles);
96
97 /**
98 * Create a new profile collection by parsing text in a buffer. Primarily
99 * for testing.
100 */
101 AWS_SDKUTILS_API
102 struct aws_profile_collection *aws_profile_collection_new_from_buffer(
103 struct aws_allocator *allocator,
104 const struct aws_byte_buf *buffer,
105 enum aws_profile_source_type source);
106
107 /**
108 * Retrieves a reference to a profile with the specified name, if it exists, from the profile collection
109 */
110 AWS_SDKUTILS_API
111 const struct aws_profile *aws_profile_collection_get_profile(
112 const struct aws_profile_collection *profile_collection,
113 const struct aws_string *profile_name);
114
115 /*
116 * Retrieves a reference to a section with the specified name and type, if it exists, from the profile collection.
117 * You can get the "default" profile or credentials file sections by passing `AWS_PROFILE_SECTION_TYPE_PROFILE`
118 */
119 AWS_SDKUTILS_API
120 const struct aws_profile *aws_profile_collection_get_section(
121 const struct aws_profile_collection *profile_collection,
122 const enum aws_profile_section_type section_type,
123 const struct aws_string *section_name);
124
125 /**
126 * Returns the number of profiles in a collection
127 */
128 AWS_SDKUTILS_API
129 size_t aws_profile_collection_get_profile_count(const struct aws_profile_collection *profile_collection);
130
131 /**
132 * Returns the number of elements of the specified section in a collection.
133 */
134 AWS_SDKUTILS_API
135 size_t aws_profile_collection_get_section_count(
136 const struct aws_profile_collection *profile_collection,
137 const enum aws_profile_section_type section_type);
138
139 /**
140 * Returns a reference to the name of the provided profile
141 */
142 AWS_SDKUTILS_API
143 const struct aws_string *aws_profile_get_name(const struct aws_profile *profile);
144
145 /**************
146 * profile APIs
147 **************/
148
149 /**
150 * Retrieves a reference to a property with the specified name, if it exists, from a profile
151 */
152 AWS_SDKUTILS_API
153 const struct aws_profile_property *aws_profile_get_property(
154 const struct aws_profile *profile,
155 const struct aws_string *property_name);
156
157 /**
158 * Returns how many properties a profile holds
159 */
160 AWS_SDKUTILS_API
161 size_t aws_profile_get_property_count(const struct aws_profile *profile);
162
163 /**
164 * Returns a reference to the property's string value
165 */
166 AWS_SDKUTILS_API
167 const struct aws_string *aws_profile_property_get_value(const struct aws_profile_property *property);
168
169 /***********************
170 * profile property APIs
171 ***********************/
172
173 /**
174 * Returns a reference to the value of a sub property with the given name, if it exists, in the property
175 */
176 AWS_SDKUTILS_API
177 const struct aws_string *aws_profile_property_get_sub_property(
178 const struct aws_profile_property *property,
179 const struct aws_string *sub_property_name);
180
181 /**
182 * Returns how many sub properties the property holds
183 */
184 AWS_SDKUTILS_API
185 size_t aws_profile_property_get_sub_property_count(const struct aws_profile_property *property);
186
187 /***********
188 * Misc APIs
189 ***********/
190
191 /**
192 * Computes the final platform-specific path for the profile credentials file. Does limited home directory
193 * expansion/resolution.
194 *
195 * override_path, if not null, will be searched first instead of using the standard home directory config path
196 */
197 AWS_SDKUTILS_API
198 struct aws_string *aws_get_credentials_file_path(
199 struct aws_allocator *allocator,
200 const struct aws_byte_cursor *override_path);
201
202 /**
203 * Computes the final platform-specific path for the profile config file. Does limited home directory
204 * expansion/resolution.
205 *
206 * override_path, if not null, will be searched first instead of using the standard home directory config path
207 */
208 AWS_SDKUTILS_API
209 struct aws_string *aws_get_config_file_path(
210 struct aws_allocator *allocator,
211 const struct aws_byte_cursor *override_path);
212
213 /**
214 * Computes the profile to use for credentials lookups based on profile resolution rules
215 */
216 AWS_SDKUTILS_API
217 struct aws_string *aws_get_profile_name(struct aws_allocator *allocator, const struct aws_byte_cursor *override_name);
218
219 AWS_EXTERN_C_END
220 AWS_POP_SANE_WARNING_LEVEL
221
222 #endif /* AWS_SDKUTILS_AWS_PROFILE_H */