| 1 | #ifndef AWS_S3_S3_PLATFORM_INFO_H |
| 2 | #define AWS_S3_S3_PLATFORM_INFO_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/s3/s3.h> |
| 9 | |
| 10 | struct aws_s3_platform_info_loader; |
| 11 | |
| 12 | AWS_EXTERN_C_BEGIN |
| 13 | |
| 14 | /** |
| 15 | * Initializes and returns a loader for querying the compute platform for information needed for making configuration |
| 16 | * decisions. |
| 17 | * This will never be NULL. |
| 18 | */ |
| 19 | AWS_S3_API |
| 20 | struct aws_s3_platform_info_loader *aws_s3_platform_info_loader_new(struct aws_allocator *allocator); |
| 21 | |
| 22 | AWS_S3_API |
| 23 | struct aws_s3_platform_info_loader *aws_s3_platform_info_loader_acquire(struct aws_s3_platform_info_loader *loader); |
| 24 | |
| 25 | AWS_S3_API |
| 26 | struct aws_s3_platform_info_loader *aws_s3_platform_info_loader_release(struct aws_s3_platform_info_loader *loader); |
| 27 | |
| 28 | /** |
| 29 | * Retrieves the pre-configured metadata for a given ec2 instance type. If no such pre-configuration exists, returns |
| 30 | * NULL. |
| 31 | */ |
| 32 | AWS_S3_API |
| 33 | const struct aws_s3_platform_info *aws_s3_get_platform_info_for_instance_type( |
| 34 | struct aws_s3_platform_info_loader *loader, |
| 35 | struct aws_byte_cursor instance_type_name); |
| 36 | |
| 37 | /** |
| 38 | * Retrieves the metadata for the current environment. If EC2 instance type is unknown, or it is not an EC2 instance at |
| 39 | * all, this value will still include the information about the system that could be determined. This value will never |
| 40 | * be NULL. |
| 41 | * This API is not thread safe. |
| 42 | */ |
| 43 | AWS_S3_API |
| 44 | const struct aws_s3_platform_info *aws_s3_get_platform_info_for_current_environment( |
| 45 | struct aws_s3_platform_info_loader *loader); |
| 46 | |
| 47 | /* |
| 48 | * Retrieves a list of EC2 instance types with recommended configuration. |
| 49 | * Returns aws_array_list<aws_byte_cursor>. The caller is responsible for cleaning up the array list. |
| 50 | */ |
| 51 | AWS_S3_API |
| 52 | struct aws_array_list aws_s3_get_recommended_platforms(struct aws_s3_platform_info_loader *loader); |
| 53 | |
| 54 | /** |
| 55 | * Returns true if the current process is running on an Amazon EC2 instance powered by Nitro. |
| 56 | */ |
| 57 | AWS_S3_API |
| 58 | bool aws_s3_is_running_on_ec2_nitro(struct aws_s3_platform_info_loader *loader); |
| 59 | |
| 60 | /** |
| 61 | * Returns an EC2 instance type assuming this executable is running on Amazon EC2 powered by nitro. |
| 62 | * |
| 63 | * First this function will check it's running on EC2 via. attempting to read DMI info to avoid making IMDS calls. |
| 64 | * |
| 65 | * If the function detects it's on EC2, and it was able to detect the instance type without a call to IMDS |
| 66 | * it will return it. |
| 67 | * |
| 68 | * Finally, it will call IMDS and return the instance type from there. |
| 69 | * |
| 70 | * Note that in the case of the IMDS call, a new client stack is spun up using 1 background thread. The call is made |
| 71 | * synchronously with a 1 second timeout: It's not cheap. To make this easier, the underlying result is cached |
| 72 | * internally and will be freed when aws_s3_library_clean_up() is called. |
| 73 | * @return byte_cursor containing the instance type. If this is empty, the instance type could not be determined. |
| 74 | */ |
| 75 | AWS_S3_API |
| 76 | struct aws_byte_cursor aws_s3_get_ec2_instance_type(struct aws_s3_platform_info_loader *loader, bool cached_only); |
| 77 | |
| 78 | AWS_EXTERN_C_END |
| 79 | |
| 80 | #endif /* AWS_S3_S3_PLATFORM_INFO_H */ |