@@ -14,7 +14,7 @@ STATUS createCurlApiCallbacks(PCallbacksProvider pCallbacksProvider, PCHAR regio
14
14
ENTERS ();
15
15
STATUS retStatus = STATUS_SUCCESS , status ;
16
16
PCurlApiCallbacks pCurlApiCallbacks = NULL ;
17
- BOOL useDualStackEndpoint ;
17
+ KvsControlPlaneEndpointType controlPlaneEndpointType ;
18
18
19
19
CHK (pCallbacksProvider != NULL && ppCurlApiCallbacks != NULL , STATUS_NULL_ARG );
20
20
CHK (certPath == NULL || STRNLEN (certPath , MAX_PATH_LEN + 1 ) <= MAX_PATH_LEN , STATUS_INVALID_CERT_PATH_LENGTH );
@@ -80,19 +80,8 @@ STATUS createCurlApiCallbacks(PCallbacksProvider pCallbacksProvider, PCHAR regio
80
80
81
81
// Construct Control Plane URL
82
82
if (IS_NULL_OR_EMPTY_STRING (controlPlaneUrl )) {
83
- #if defined(AWS_KVS_USE_LEGACY_ENDPOINT_ONLY )
84
- useDualStackEndpoint = FALSE;
85
- DLOGI ("Using legacy endpoint from AWS_KVS_USE_LEGACY_ENDPOINT_ONLY" )
86
- #elif defined(AWS_KVS_USE_DUAL_STACK_ENDPOINT_ONLY )
87
- useDualStackEndpoint = TRUE;
88
- DLOGI ("Using dual stack endpoint from AWS_KVS_USE_DUAL_STACK_ENDPOINT_ONLY" )
89
- #else
90
- useDualStackEndpoint = (GETENV (CONTROL_PLANE_USE_DUAL_STACK_ENDPOINT_ENV_VAR ) != NULL ) &&
91
- (0 == STRNCMPI (GETENV (CONTROL_PLANE_USE_DUAL_STACK_ENDPOINT_ENV_VAR ), "true" , 4 ));
92
- DLOGI ("Using %s endpoint from environment" , useDualStackEndpoint ? "dual stack" : "legacy" );
93
- #endif
94
-
95
- constructControlPlaneUrl (pCurlApiCallbacks -> controlPlaneUrl , MAX_URI_CHAR_LEN , pCurlApiCallbacks -> region , !useDualStackEndpoint );
83
+ CHK_STATUS (determineKvsControlPlaneEndpointType (& controlPlaneEndpointType ));
84
+ CHK_STATUS (constructControlPlaneUrl (pCurlApiCallbacks -> controlPlaneUrl , MAX_URI_CHAR_LEN , pCurlApiCallbacks -> region , controlPlaneEndpointType ));
96
85
} else {
97
86
STRNCPY (pCurlApiCallbacks -> controlPlaneUrl , controlPlaneUrl , MAX_URI_CHAR_LEN );
98
87
}
@@ -190,7 +179,51 @@ STATUS createCurlApiCallbacks(PCallbacksProvider pCallbacksProvider, PCHAR regio
190
179
return retStatus ;
191
180
}
192
181
193
- STATUS constructControlPlaneUrl (const char * buffer , SIZE_T bufferSize , const char * region , BOOL useLegacyEndpoint )
182
+ STATUS determineKvsControlPlaneEndpointType (PKvsControlPlaneEndpointType pEndpointType )
183
+ {
184
+ ENTERS ();
185
+ STATUS retStatus = STATUS_SUCCESS ;
186
+ BOOL isDualStack = FALSE;
187
+ const char * envValue ;
188
+
189
+ CHK (pEndpointType != NULL , STATUS_NULL_ARG );
190
+
191
+ #if defined(AWS_KVS_USE_LEGACY_ENDPOINT_ONLY )
192
+ * pEndpointType = ENDPOINT_TYPE_LEGACY ;
193
+ DLOGI ("Using legacy endpoint from AWS_KVS_USE_LEGACY_ENDPOINT_ONLY" );
194
+ #elif defined(AWS_KVS_USE_DUAL_STACK_ENDPOINT_ONLY )
195
+ * pEndpointType = ENDPOINT_TYPE_DUAL_STACK ;
196
+ DLOGI ("Using dual stack endpoint from AWS_KVS_USE_DUAL_STACK_ENDPOINT_ONLY" );
197
+ #else
198
+ envValue = GETENV (CONTROL_PLANE_USE_DUAL_STACK_ENDPOINT_ENV_VAR );
199
+
200
+ // Check for "true" to make sure "false" actually disables it
201
+ // https://docs.aws.amazon.com/sdkref/latest/guide/feature-endpoints.html
202
+ isDualStack = (envValue != NULL ) && (0 == STRNCMPI (envValue , "true" , 4 ));
203
+ * pEndpointType = isDualStack ? ENDPOINT_TYPE_DUAL_STACK : ENDPOINT_TYPE_LEGACY ;
204
+
205
+ DLOGI ("Using %s endpoint from environment" , endpointTypeToString (* pEndpointType ));
206
+ #endif
207
+
208
+ CleanUp :
209
+ CHK_LOG_ERR (retStatus );
210
+
211
+ LEAVES ();
212
+ return retStatus ;
213
+ }
214
+
215
+ const char * endpointTypeToString (const KvsControlPlaneEndpointType type ) {
216
+ switch (type ) {
217
+ case ENDPOINT_TYPE_LEGACY :
218
+ return "LEGACY" ;
219
+ case ENDPOINT_TYPE_DUAL_STACK :
220
+ return "DUAL_STACK" ;
221
+ default :
222
+ return "UNKNOWN" ;
223
+ }
224
+ }
225
+
226
+ STATUS constructControlPlaneUrl (const char * buffer , SIZE_T bufferSize , const char * region , KvsControlPlaneEndpointType endpointType )
194
227
{
195
228
ENTERS ();
196
229
STATUS retStatus = STATUS_SUCCESS ;
@@ -203,21 +236,21 @@ STATUS constructControlPlaneUrl(const char* buffer, SIZE_T bufferSize, const cha
203
236
if (0 == STRNCMP (region , AWS_ISO_B_REGION_PREFIX , STRLEN (AWS_ISO_B_REGION_PREFIX ))) {
204
237
// Top Secret Cloud regions: https://kinesisvideo-fips.us-isob-east-1.sc2s.sgov.gov
205
238
serviceNamePostfix = AWS_KVS_FIPS_ENDPOINT_POSTFIX ;
206
- postfix = useLegacyEndpoint ? CONTROL_PLANE_URI_POSTFIX_ISO_B : CONTROL_PLANE_URI_POSTFIX_ISO_B_DUAL_STACK ;
239
+ postfix = ( endpointType == ENDPOINT_TYPE_LEGACY ) ? CONTROL_PLANE_URI_POSTFIX_ISO_B : CONTROL_PLANE_URI_POSTFIX_ISO_B_DUAL_STACK ;
207
240
} else if (0 == STRNCMP (region , AWS_ISO_REGION_PREFIX , STRLEN (AWS_ISO_REGION_PREFIX ))) {
208
241
// Secret Cloud regions: https://kinesisvideo-fips.us-iso-east-1.c2s.ic.gov
209
242
serviceNamePostfix = AWS_KVS_FIPS_ENDPOINT_POSTFIX ;
210
- postfix = useLegacyEndpoint ? CONTROL_PLANE_URI_POSTFIX_ISO : CONTROL_PLANE_URI_POSTFIX_ISO_DUAL_STACK ;
243
+ postfix = ( endpointType == ENDPOINT_TYPE_LEGACY ) ? CONTROL_PLANE_URI_POSTFIX_ISO : CONTROL_PLANE_URI_POSTFIX_ISO_DUAL_STACK ;
211
244
} else if (0 == STRNCMP (region , AWS_GOV_CLOUD_REGION_PREFIX , STRLEN (AWS_GOV_CLOUD_REGION_PREFIX ))) {
212
245
// US Govcloud regions: https://kinesisvideo-fips.us-gov-east-1.amazonaws.com
213
246
serviceNamePostfix = AWS_KVS_FIPS_ENDPOINT_POSTFIX ;
214
- postfix = useLegacyEndpoint ? CONTROL_PLANE_URI_POSTFIX : CONTROL_PLANE_URI_POSTFIX_DUAL_STACK ;
247
+ postfix = ( endpointType == ENDPOINT_TYPE_LEGACY ) ? CONTROL_PLANE_URI_POSTFIX : CONTROL_PLANE_URI_POSTFIX_DUAL_STACK ;
215
248
} else if (0 == STRNCMP (region , AWS_CN_REGION_PREFIX , STRLEN (AWS_CN_REGION_PREFIX ))) {
216
249
// China regions: https://kinesisvideo.cn-north-1.amazonaws.com.cn"
217
- postfix = useLegacyEndpoint ? CONTROL_PLANE_URI_POSTFIX_CN : CONTROL_PLANE_URI_POSTFIX_CN_DUAL_STACK ;
250
+ postfix = ( endpointType == ENDPOINT_TYPE_LEGACY ) ? CONTROL_PLANE_URI_POSTFIX_CN : CONTROL_PLANE_URI_POSTFIX_CN_DUAL_STACK ;
218
251
} else {
219
252
// Standard regions: https://kinesisvideo.us-west-2.amazonaws.com
220
- postfix = useLegacyEndpoint ? CONTROL_PLANE_URI_POSTFIX : CONTROL_PLANE_URI_POSTFIX_DUAL_STACK ;
253
+ postfix = ( endpointType == ENDPOINT_TYPE_LEGACY ) ? CONTROL_PLANE_URI_POSTFIX : CONTROL_PLANE_URI_POSTFIX_DUAL_STACK ;
221
254
}
222
255
223
256
// Create a fully qualified URI
0 commit comments